:root {
  --night: #2b211f;
  --night-soft: #3a2b27;
  --stage: #f5f1eb;
  --surface: #f5f1eb;
  --tile: #ece7e0;
  --ink: #352823;
  --muted: #8b7770;
  --line: #e7d8c7;
  --coral: #ff7868;
  --acid: #dfff55;
  --sky: #acd9ff;
  --cream: #f7dcae;
  --pink: #f6b2cc;
  --yellow: #f4df32;
  --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; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.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: 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; min-height: 30px; align-items: center; justify-content: space-between; gap: 18px; }
.board-top h1 {
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 900;
  letter-spacing: .12em;
  line-height: 1;
}
.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: 0; margin: 8px 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 transparent;
  border-radius: 34%;
  background: var(--tile);
  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 .12s ease, opacity .12s ease;
}
.member::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  border: 3px solid rgba(53, 40, 35, .72);
  border-radius: inherit;
  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(96%, 224px);
  aspect-ratio: 1;
  place-items: center;
}
.member-badge img {
  position: relative;
  z-index: 1;
  width: 90%;
  height: 90%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: none;
}
.members-grid.is-showing .member:not(.is-lit) {
  opacity: .45;
  filter: brightness(.48) saturate(.32) contrast(.88);
}
.member.is-lit {
  opacity: 1;
  filter: none;
}
.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(--yellow);
  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: #ead221; 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; }

@keyframes correct { 50% { filter: brightness(1.16) saturate(1.2); } }
@keyframes wrong { 25%, 75% { filter: saturate(.55) contrast(.9); } 50% { filter: saturate(.8) contrast(.8); } }

@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: 4px;
    min-height: 0;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .game-header { min-height: 36px; height: 36px; }
  .brand { gap: 6px; }
  .brand-mark { width: 30px; height: 30px; border-width: 2px; font-size: 18px; box-shadow: 2px 2px 0 rgba(53, 40, 35, .16); }
  .brand-name { font-size: 11px; letter-spacing: .04em; }
  .header-actions { gap: 4px; }
  .best-stat { display: none; }
  .header-stat { min-width: 52px; padding: 3px 6px; border-width: 1.5px; border-radius: 9px; }
  .header-stat span { font-size: 7px; }
  .header-stat strong { font-size: 12px; }
  .sound-button { min-width: 39px; min-height: 32px; padding: 0 6px; border-width: 2px; box-shadow: 2px 2px 0 rgba(53, 40, 35, .16); }
  .sound-icon { font-size: 15px; }
  .sound-label { font-size: 8px; }
  .game-board { padding: 8px 7px 7px; border-width: 2px; border-radius: 18px; box-shadow: 0 7px 0 rgba(53, 40, 35, .14), 0 12px 22px rgba(53, 40, 35, .1); }
  .board-top { min-height: 30px; align-items: center; gap: 8px; }
  .board-top h1 { font-size: 13px; letter-spacing: .1em; }
  .round-chip { min-width: 48px; padding: 5px 7px; border-width: 2px; border-radius: 11px; box-shadow: 2px 3px 0 var(--ink); transform: rotate(2deg); }
  .round-chip strong { font-size: 17px; }
  .round-chip span { font-size: 7px; }
  .progress-row { gap: 0; margin: 3px 0 5px; }
  .progress-track { height: 5px; border-width: 1px; }
  .members-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 2px 0 6px;
  }
  .member { border-width: 2px; border-radius: 34%; box-shadow: inset 0 -6px 0 rgba(53, 40, 35, .07), 0 3px 0 rgba(53, 40, 35, .13); }
  .member::after { border-width: 2px; }
  .member-badge { width: 100%; max-width: 100%; height: 100%; min-height: 0; max-height: 100%; aspect-ratio: auto; }
  .member-badge img { width: 90%; height: 90%; }
  .game-actions { min-height: 48px; gap: 0; }
  .primary-button { width: 100%; min-height: 48px; padding: 0 16px; border-width: 2px; border-radius: 12px; box-shadow: 2px 3px 0 var(--ink); font-size: 13px; }
}

@media (max-height: 690px) and (max-width: 700px) {
  .game-shell { gap: 2px; padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .game-header { min-height: 32px; height: 32px; }
  .brand-mark { width: 28px; height: 28px; font-size: 17px; }
  .brand-name { display: none; }
  .header-stat { padding: 2px 5px; }
  .sound-button { min-height: 30px; }
  .game-board { padding: 6px; }
  .board-top { min-height: 26px; }
  .board-top h1 { font-size: 12px; }
  .progress-row { margin-top: 2px; margin-bottom: 3px; }
  .members-grid { gap: 4px; padding-top: 1px; padding-bottom: 4px; }
  .game-actions { min-height: 48px; }
  .primary-button { min-height: 48px; }
}

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

@media (max-height: 500px) and (orientation: landscape) {
  .game-shell {
    gap: 2px;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .game-header { min-height: 32px; height: 32px; padding: 0 2px; }
  .brand { gap: 5px; }
  .brand-mark { width: 28px; height: 28px; border-width: 2px; font-size: 17px; box-shadow: 2px 2px 0 rgba(53, 40, 35, .16); }
  .brand-name { font-size: 11px; letter-spacing: .04em; }
  .header-actions { gap: 4px; }
  .best-stat { display: none; }
  .header-stat { min-width: 50px; padding: 2px 5px; border-width: 1.5px; border-radius: 9px; }
  .header-stat span { font-size: 7px; }
  .header-stat strong { font-size: 12px; }
  .sound-button { min-width: 39px; min-height: 30px; padding: 0 6px; border-width: 2px; box-shadow: 2px 2px 0 rgba(53, 40, 35, .16); }
  .sound-icon { font-size: 15px; }
  .sound-label { font-size: 8px; }
  .game-board { padding: 5px 6px; border-width: 2px; border-radius: 16px; box-shadow: 0 4px 0 rgba(53, 40, 35, .12); }
  .board-top { min-height: 24px; height: 24px; gap: 6px; }
  .board-top h1 { font-size: 12px; letter-spacing: .08em; }
  .round-chip { min-width: 44px; padding: 2px 6px 3px; border-width: 2px; border-radius: 9px; box-shadow: 2px 2px 0 var(--ink); transform: none; }
  .round-chip strong { font-size: 15px; }
  .round-chip span { font-size: 6px; }
  .progress-row { margin: 2px 0 3px; }
  .progress-track { height: 5px; border-width: 1px; }
  .members-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 4px 6px;
    padding: 1px 0 4px;
  }
  .member { border-width: 2px; border-radius: 28px; box-shadow: inset 0 -5px 0 rgba(53, 40, 35, .06); }
  .member::after { border-width: 2px; }
  .member-badge { width: 100%; max-width: 100%; height: 100%; min-height: 0; max-height: 100%; aspect-ratio: auto; }
  .member-badge img { width: 90%; height: 90%; }
  .game-actions { min-height: 48px; height: 48px; gap: 0; }
  .primary-button { width: 100%; min-height: 48px; padding: 0 14px; border-width: 2px; border-radius: 10px; box-shadow: 2px 2px 0 var(--ink); font-size: 12px; }
}

.heart-count-splash:not([hidden]) { position: fixed; z-index: 100; inset: 0; display: grid; min-height: 100dvh; place-items: center; align-content: center; gap: 12px; padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); background: var(--coral); color: var(--ink); text-align: center; }
.heart-count-splash h2 { margin: 0; font-size: clamp(3rem, 11vw, 8rem); line-height: .9; }
.splash-kicker { margin: 0; font-weight: 900; letter-spacing: .16em; }
.heart-count-splash-dolls { display: flex; width: min(92vw, 980px); align-items: end; justify-content: center; gap: clamp(2px, 2vw, 20px); }
.heart-count-splash-dolls img { width: min(18vw, 180px); height: min(44vh, 360px); object-fit: contain; }
@media (orientation: portrait) {
  .heart-count-splash-dolls { width: min(78vw, 300px); flex-wrap: wrap; gap: 0 .45rem; }
  .heart-count-splash-dolls img { width: min(34vw, 130px); height: min(17vh, 145px); }
}
@media (prefers-reduced-motion: reduce) { .heart-count-splash-dolls img { transform: none !important; } }
