:root {
  --night: #2b211f;
  --night-soft: #3a2b27;
  --stage: #fff6df;
  --surface: #fffdf8;
  --ink: #352823;
  --muted: #8b7770;
  --line: #e7d8c7;
  --coral: #ff7868;
  --acid: #dfff55;
  --sky: #acd9ff;
  --cream: #f7dcae;
  --pink: #f6b2cc;
  --yellow: #ffe47c;
  --lilac: #c5b2ff;
  --orange: #ffbb83;
  --mint: #a7e6cc;
  --shadow: 0 14px 0 rgba(53, 40, 35, .16), 0 22px 35px rgba(53, 40, 35, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--night); }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--night);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}
button, a { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 4px solid var(--coral); outline-offset: 4px; }

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: min(1240px, 100%);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) clamp(14px, 3vw, 32px) max(12px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 10% 5%, rgba(255, 255, 255, .72), transparent 24%),
    var(--stage);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 4px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--ink);
  color: var(--acid);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 3px 4px 0 rgba(53, 40, 35, .18);
}
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: .08em; }
.brand-name b { font-weight: 950; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.header-stat {
  display: grid;
  min-width: 68px;
  gap: 2px;
  padding: 7px 11px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 248, .7);
}
.header-stat span, .stage-label, #progress-label, .round-chip span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
}
.header-stat strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  letter-spacing: -.08em;
}
.sound-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 44px;
  gap: 4px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--acid);
  font-size: 12px;
  font-weight: 900;
  box-shadow: 3px 4px 0 rgba(53, 40, 35, .18);
}
.sound-button:active { transform: translateY(2px); box-shadow: 1px 2px 0 rgba(53, 40, 35, .18); }
.sound-icon { font-size: 19px; line-height: .8; }
.sound-label { letter-spacing: .08em; }

.game-board {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: clamp(14px, 2.4vw, 28px);
  border: 3px solid var(--ink);
  border-radius: 30px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.board-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.stage-label { margin: 0 0 6px; color: var(--coral); }
.stage-copy h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 950;
  letter-spacing: -.07em;
  line-height: .95;
}
.instruction { margin: 8px 0 0; color: var(--muted); font-size: clamp(12px, 1.8vw, 15px); font-weight: 700; }
.round-chip {
  display: grid;
  min-width: 74px;
  place-items: center;
  gap: 2px;
  padding: 9px 12px 10px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--acid);
  box-shadow: 4px 5px 0 var(--ink);
  transform: rotate(3deg);
}
.round-chip strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 25px; line-height: 1; }
.round-chip span { color: var(--ink); font-size: 8px; }
.progress-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 10px; }
#progress-label { flex: 0 0 auto; min-width: 74px; color: var(--muted); }
.progress-track { height: 8px; flex: 1; overflow: hidden; border: 2px solid var(--line); border-radius: 999px; background: #fff9ed; }
#progress-bar { display: block; width: 0%; height: 100%; border-radius: inherit; background: var(--coral); transition: width .25s ease; }

.members-grid {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
  padding: 5px 0 12px;
}
.member {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border: 3px solid rgba(53, 40, 35, .72);
  border-radius: 25px;
  background: var(--member-color);
  box-shadow: inset 0 -12px 0 rgba(53, 40, 35, .07), 0 6px 0 rgba(53, 40, 35, .13);
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
.member::before {
  position: absolute;
  inset: 8px;
  border: 2px dashed rgba(255, 253, 248, .65);
  border-radius: 19px;
  content: '';
  pointer-events: none;
}
.member::after {
  position: absolute;
  right: -16%;
  bottom: -32%;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 253, 248, .24);
  content: '';
  pointer-events: none;
}
.member:hover:not(:disabled) { transform: translateY(-3px) rotate(-1deg); box-shadow: inset 0 -12px 0 rgba(53, 40, 35, .07), 0 9px 0 rgba(53, 40, 35, .16); }
.member:active:not(:disabled) { transform: translateY(3px) scale(.97); box-shadow: inset 0 -5px 0 rgba(53, 40, 35, .08), 0 2px 0 rgba(53, 40, 35, .14); }
.member:disabled { cursor: default; }
.member-badge {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(78%, 188px);
  aspect-ratio: 1;
  place-items: center;
  border: 3px solid rgba(53, 40, 35, .58);
  border-radius: 47% 53% 49% 51%;
  overflow: hidden;
  background: rgba(255, 253, 248, .78);
  box-shadow: inset 0 5px 0 rgba(255, 255, 255, .66), 0 9px 13px rgba(53, 40, 35, .12);
}
.member-badge img { width: 94%; height: 94%; object-fit: contain; mix-blend-mode: multiply; filter: drop-shadow(0 5px 4px rgba(53, 40, 35, .14)); }
.member.is-lit { transform: translateY(-4px) scale(1.045); border-color: var(--ink); box-shadow: inset 0 -12px 0 rgba(53, 40, 35, .07), 0 10px 0 var(--ink), 0 16px 20px rgba(53, 40, 35, .16); filter: saturate(1.12); }
.member.is-lit .member-badge { border-color: var(--coral); box-shadow: inset 0 5px 0 rgba(255, 255, 255, .7), 0 0 0 5px rgba(255, 120, 104, .2), 0 9px 13px rgba(53, 40, 35, .12); }
.member.is-correct { animation: correct .3s ease; }
.member.is-wrong { animation: wrong .3s ease; }

.game-actions { display: flex; align-items: center; gap: 14px; }
.primary-button {
  min-height: 52px;
  padding: 0 24px;
  border: 3px solid var(--ink);
  border-radius: 17px;
  background: var(--coral);
  color: var(--ink);
  font-size: 15px;
  font-weight: 950;
  box-shadow: 4px 5px 0 var(--ink);
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.primary-button:hover { transform: translateY(-2px); background: #ff897a; box-shadow: 4px 7px 0 var(--ink); }
.primary-button:active { transform: translateY(3px); box-shadow: 1px 2px 0 var(--ink); }
.primary-button span { display: inline-block; margin-left: 7px; font-size: 18px; }
.action-hint { color: var(--muted); font-size: 12px; font-weight: 800; }
.toast {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 18px;
  z-index: 2;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: auto;
  padding: 12px 17px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--acid);
  font-size: 12px;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

@keyframes correct { 50% { transform: scale(1.06) rotate(1deg); } }
@keyframes wrong { 25%, 75% { transform: translateX(-5px); } 50% { transform: translateX(5px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 700px) {
  .game-shell { gap: 8px; min-height: 0; padding-right: max(10px, env(safe-area-inset-right)); padding-left: max(10px, env(safe-area-inset-left)); }
  .game-header { min-height: 48px; }
  .brand-mark { width: 36px; height: 36px; font-size: 21px; }
  .brand-name { font-size: 14px; }
  .header-actions { gap: 6px; }
  .header-stat { min-width: 57px; padding: 6px 8px; border-radius: 12px; }
  .header-stat span { font-size: 8px; }
  .header-stat strong { font-size: 13px; }
  .sound-button { min-width: 46px; min-height: 40px; padding: 0 8px; }
  .sound-label { font-size: 10px; }
  .game-board { padding: 14px 12px 12px; border-radius: 24px; }
  .stage-copy h1 { font-size: clamp(27px, 8vw, 42px); }
  .instruction { margin-top: 5px; font-size: 11px; }
  .round-chip { min-width: 62px; padding: 8px 9px; border-radius: 15px; box-shadow: 3px 4px 0 var(--ink); }
  .round-chip strong { font-size: 21px; }
  .progress-row { margin: 10px 0 7px; }
  .members-grid { gap: 7px; padding-bottom: 9px; }
  .member { border-width: 2px; border-radius: 18px; box-shadow: inset 0 -8px 0 rgba(53, 40, 35, .07), 0 4px 0 rgba(53, 40, 35, .13); }
  .member::before { inset: 5px; border-width: 1.5px; border-radius: 14px; }
  .member-badge { width: 86%; border-width: 2px; box-shadow: inset 0 4px 0 rgba(255, 255, 255, .66), 0 5px 8px rgba(53, 40, 35, .12); }
  .member-badge img { width: 96%; height: 96%; }
  .game-actions { min-height: 46px; gap: 10px; }
  .primary-button { min-height: 46px; padding: 0 17px; border-width: 2px; border-radius: 14px; box-shadow: 3px 4px 0 var(--ink); font-size: 13px; }
  .action-hint { font-size: 10px; }
}

@media (max-height: 690px) and (max-width: 700px) {
  .game-shell { gap: 5px; }
  .game-header { min-height: 42px; }
  .brand-mark { width: 32px; height: 32px; font-size: 19px; }
  .brand-name { font-size: 12px; }
  .header-stat { padding: 4px 7px; }
  .sound-button { min-height: 36px; }
  .game-board { padding-top: 10px; }
  .stage-copy h1 { font-size: 25px; }
  .instruction { font-size: 10px; }
  .progress-row { margin-top: 7px; margin-bottom: 4px; }
  .members-grid { gap: 5px; padding-top: 2px; padding-bottom: 6px; }
  .game-actions { min-height: 42px; }
  .primary-button { min-height: 42px; }
}

@media (min-width: 701px) {
  .game-shell { padding-top: 20px; padding-bottom: 20px; }
  .game-board { max-width: 1120px; width: 100%; margin: 0 auto; }
}
