/* ミニゲーム「ハムスターのカウントゲーム」(public/js/countgame.js)。
   全画面の枠・えらぶボタン・野原・ミッションは、ぴったりストップ(app.css の .sg-*)をそのまま使う。 */

/* ---- 子の絵: 足もとの色つきプレート(青・赤・黄・猫は紫)。切り抜きの絵には色が見えないので、プレートで色を見せる */
.cg-pet {
  --k: var(--yellow);
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

.cg-pet.k-b {
  --k: var(--blue);
}

.cg-pet.k-r {
  --k: var(--red);
}

.cg-pet.k-y {
  --k: var(--yellow);
}

.cg-pet.k-cat {
  --k: var(--cat);
}

.cg-plate {
  position: absolute;
  inset: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--k);
  box-shadow: 0 4px 0 rgba(74, 52, 40, 0.2);
}

/* 子は、プレートの丸の中に乗せる(プレートの色がまわりにはっきり見えるように、絵は小さめ) */
.cg-pet img {
  position: absolute;
  left: 14%;
  top: 9%;
  display: block;
  width: 72%;
  height: 72%;
  object-fit: contain;
  transform: scaleX(var(--flip, 1));
}

/* お題の「猫」の見本(紫の丸) */
.cg-kind {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--cat);
  box-shadow: 0 0 0 1px rgba(74, 52, 40, 0.15);
}

/* ---- えらぶ画面 */
.cg-rules {
  display: grid;
  gap: 4px;
  max-width: 32em;
  margin: 12px auto 0;
  padding-left: 1.3em;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.6;
  color: var(--ink-soft);
}

.cg-menu .sg-levels {
  margin-top: 18px;
}

/* ---- 遊ぶ画面 */
.cg-round {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  font-size: 0.95rem;
}

.cg-round b {
  font-family: var(--font-pop);
  font-weight: 400;
}

.cg-round em {
  font-style: normal;
  font-weight: 900;
  color: var(--rose);
}

.cg-mission b {
  color: var(--rose);
}

.cg-field .cg-ham {
  width: 17%;
}

.cg-go {
  min-width: 200px;
  min-height: 64px;
  font-size: 1.4rem;
}

/* ---- 数える画面: いまの数と、＋ − のボタン */
.cg-clause {
  display: inline-block;
  max-width: 100%;
}

.cg-tag {
  display: inline-block;
  min-width: 1.5em;
  margin: 0 0.15em;
  padding: 0 0.3em;
  border-radius: 999px;
  color: #fff !important;
  text-align: center;
}

.cg-tag.plus {
  background: var(--rose);
}

.cg-tag.minus {
  background: var(--cat);
}

.cg-counter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  min-width: 190px;
  padding: 4px 26px 8px;
  border-radius: 22px;
  background: #fff;
  box-shadow: inset 0 0 0 3px var(--paper), 0 5px 0 var(--drop);
  font-weight: 900;
}

.cg-counter span {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.cg-counter b {
  min-width: 1.4em;
  font-size: 3.2rem;
  line-height: 1.1;
  text-align: center;
  color: var(--rose);
}

.cg-counter.hide b {
  color: var(--ink-soft);
}

.cg-counter b.pop {
  animation: cg-pop 0.22s ease-out;
}

@keyframes cg-pop {
  0% {
    transform: scale(1.35);
  }

  100% {
    transform: scale(1);
  }
}

.cg-pm {
  display: flex;
  justify-content: center;
  gap: 18px;
  width: min(92vw, 360px);
}

.cg-pmbtn {
  flex: 1;
  min-height: 78px;
  border: 4px solid #fff;
  border-radius: 22px;
  color: #fff;
  font-family: var(--font-pop);
  font-size: 2.6rem;
  line-height: 1;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.06s, box-shadow 0.06s;
}

.cg-pmbtn.plus {
  background: var(--rose);
  box-shadow: 0 6px 0 var(--rose-deep);
}

.cg-pmbtn.minus {
  background: var(--cat);
  box-shadow: 0 6px 0 rgba(74, 52, 40, 0.35);
}

.cg-pmbtn:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--drop);
}

.cg-pmbtn:disabled {
  opacity: 0.45;
}

/* ---- 1ラウンドの結果 */
.cg-score {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  font-weight: 900;
}

.cg-score p {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.cg-score span {
  margin-right: 4px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.cg-score b {
  font-size: 1.9rem;
  line-height: 1.1;
}

.cg-score .pts b {
  color: var(--rose);
}

.cg-score .pts em {
  font-size: 0.8rem;
  font-style: normal;
}

.cg-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 6px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cg-cell {
  position: relative;
  width: 52px;
  height: 52px;
  opacity: 0.5;
  visibility: hidden;
}

/* 答え合わせ: 1匹ずつ出てくる */
.cg-cell.on {
  visibility: visible;
  animation: cg-in 0.25s ease-out;
}

@keyframes cg-in {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }

  100% {
    transform: scale(1);
  }
}

.cg-cell.hit {
  opacity: 1;
}

.cg-cell.hit.cat .cg-plate {
  border-color: var(--cat);
}

.cg-cell.hit .cg-plate {
  border-color: var(--rose);
  border-width: 4px;
}

.cg-no {
  position: absolute;
  right: -4px;
  top: -6px;
  min-width: 1.6em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.6;
  text-align: center;
}

.cg-no.minus {
  background: var(--cat);
}

.cg-counter.run b {
  color: var(--ink);
}

.cg-mine {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  font-weight: 900;
}

.cg-mine span {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.cg-mine b {
  font-size: 2rem;
  line-height: 1.1;
  color: var(--cat);
}

.cg-wait {
  visibility: hidden;
}

.cg-total {
  font-weight: 900;
}

.cg-total b {
  font-size: 1.4em;
  color: var(--rose);
}

/* ---- さいごの結果 */
.cg-rank {
  text-align: center;
}

.cg-rank.rank-4 {
  color: #b14ae0;
}

.cg-big {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  font-weight: 900;
}

.cg-big b {
  font-size: 4rem;
  line-height: 1;
  color: var(--rose);
}

.cg-table {
  width: 100%;
  max-width: 420px;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.cg-table th,
.cg-table td {
  padding: 6px 4px;
  border-bottom: 2px solid var(--paper);
}

.cg-table thead th {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.cg-table td.pts {
  color: var(--rose);
}

/* ---- トップの入口 */
.cg-entry-art {
  height: 104px;
}

.cg-entry-pet {
  position: absolute;
  top: 8px;
  width: 54px;
  height: 54px;
}

.cg-entry-pet.c0 {
  left: 0;
}

.cg-entry-pet.c1 {
  left: 32px;
  top: 30px;
}

.cg-entry-pet.c2 {
  left: 60px;
  top: 6px;
}

@media (max-width: 640px) {
  .cg-cell {
    width: 44px;
    height: 44px;
  }

  .cg-counter b {
    font-size: 2.8rem;
  }

  .cg-pmbtn {
    min-height: 70px;
  }
}

/* hidden のボタンは、ボタンの display に負けずにかくす */
.cg-reveal [hidden] {
  display: none !important;
}

/* ---- ルームでのカウントゲーム(1〜5人) ---- */
.room-count {
  min-height: 100dvh;
}
.count-room {
  padding: 8px 0 24px;
}
.cr-box {
  padding-top: 12px;
  min-height: auto;
}
.cr-note,
.cr-status {
  margin: 6px 0 0;
  text-align: center;
  font-weight: 700;
  opacity: 0.85;
}
.cr-status:empty {
  display: none;
}
.cr-who {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.cr-who-i {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 64px;
  font-size: 0.72rem;
  opacity: 0.75;
}
.cr-who-i.in {
  opacity: 1;
}
.cr-who-n {
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cr-ok {
  position: absolute;
  top: -2px;
  right: 6px;
  display: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3fb16b;
  color: #fff;
  font-style: normal;
  font-size: 0.8rem;
  line-height: 20px;
  text-align: center;
}
.cr-who-i.in .cr-ok {
  display: block;
}
.cr-who-i.me .cr-who-n {
  font-weight: 900;
}
.cr-rows {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.cr-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto 3.2em 3.2em;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
}
.cr-row.head {
  padding-block: 0;
  background: none;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.7;
}
.cr-row.me {
  outline: 2px solid #f4a640;
}
.cr-row.exact .cr-guess {
  color: #d9480f;
}
.cr-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}
.cr-guess {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}
.cr-guess small {
  font-size: 0.65rem;
  font-weight: 700;
}
.cr-pts {
  text-align: right;
  font-weight: 900;
  color: #d9480f;
}
.cr-pts.zero {
  color: #999;
}
.cr-total {
  text-align: right;
  font-weight: 900;
}
.cr-final .cr-row {
  grid-template-columns: 24px 36px minmax(0, 1fr) auto;
}
.cr-final .cr-row.win {
  background: #fff3c4;
}
.cr-crown {
  color: #f2a900;
  text-align: center;
}
.cr-total small {
  margin-left: 2px;
  font-size: 0.7rem;
}
.rule-points {
  margin-top: 8px;
}
@media (max-width: 420px) {
  .cr-row {
    grid-template-columns: 30px minmax(0, 1fr) auto 2.6em 2.6em;
    gap: 5px;
    padding: 5px 7px;
  }
}


/* 結果発表の表(ラウンドごとの正解・全員の数・合計) */
.cr-ftable {
  width: 100%;
  margin: 14px 0 4px;
  border-collapse: separate;
  border-spacing: 0 5px;
  font-weight: 700;
  text-align: center;
  table-layout: fixed;
}
.cr-ftable th,
.cr-ftable td {
  padding: 5px 2px;
  vertical-align: middle;
}
.cr-ftable thead th {
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.cr-ftable col,
.cr-ftable thead tr:first-child th:not(.cr-ft-who):not(.cr-ft-sum) {
  width: 3.6em;
}
.cr-ftable .cr-ft-sum {
  width: 3.4em;
}
.cr-ftable thead .cr-ft-who {
  width: auto;
}
.cr-ft-ans th,
.cr-ft-ans td {
  padding-top: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.cr-ft-ans th {
  text-align: right;
  padding-right: 8px;
}
.cr-ft-ans td b {
  display: block;
  font-size: 1.05rem;
  color: var(--ink);
}
.cr-ft-dots .dots {
  gap: 2px;
  font-size: 0.7rem;
}
.cr-ftable tbody tr > * {
  background: rgba(255, 255, 255, 0.8);
}
.cr-ftable tbody tr > :first-child {
  border-radius: 14px 0 0 14px;
}
.cr-ftable tbody tr > :last-child {
  border-radius: 0 14px 14px 0;
}
.cr-ftable tbody tr.win > * {
  background: #fff3c4;
}
.cr-ftable tbody tr.me > :first-child {
  box-shadow: inset 3px 0 0 #f4a640;
}
.cr-ft-p {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding-left: 4px;
  text-align: left;
}
.cr-ft-p .cr-crown {
  flex: none;
}
.cr-ft-p .ava {
  flex: none;
}
.cr-ft-p .cr-name {
  min-width: 0;
  font-size: 0.9rem;
}
.cr-ftable tbody td b {
  display: block;
  font-size: 1.1rem;
  line-height: 1.1;
}
.cr-ftable tbody td small {
  display: block;
  font-size: 0.68rem;
  color: #d9480f;
}
.cr-ftable tbody td small.zero {
  color: #aaa;
}
.cr-ftable tbody td.exact b {
  color: #d9480f;
}
.cr-ftable tbody td.near b {
  color: #b7791f;
}
.cr-ftable tbody .cr-ft-sum b {
  font-size: 1.25rem;
}
@media (max-width: 370px) {
  .cr-ft-p .ava {
    display: none;
  }
}

/* ラウンドの答え合わせのあと: いまのラウンドの列を目立たせる */
.cr-ftable thead th.cur {
  color: #d9480f;
}
.cr-ftable .cr-ft-ans td.cur {
  background: #ffe8d6;
  border-radius: 10px 10px 0 0;
}
.cr-ftable tbody td.cur {
  background: #fff1e6;
}
.cr-ftable tbody tr.me > :first-child {
  box-shadow: inset 3px 0 0 #f4a640;
}
