/* YES! — visual identity.
   All brand decisions live in these variables so the planned rebrand (with
   the kids' input!) is a one-file job. */
:root {
  --bg: #15151b;
  --surface: #23232c;
  --surface-2: #2c2c37;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f6f6f4;
  --text-dim: rgba(246, 246, 244, 0.55);
  --brand: #fde047;          /* the YES! yellow */
  --brand-deep: #eab308;
  --ink: #1c1c22;            /* text on yellow */
  --disc-face: #fffdf2;
  --good: #34d399;
  --good-deep: #059669;
  --bad: #ef4444;
  --radius: 20px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --font: "Nunito", "Varela Round", ui-rounded, "SF Pro Rounded", system-ui,
          -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
}

body { overscroll-behavior-y: none; }

.app {
  max-width: 30rem;
  margin: 0 auto;
  padding: 0.75rem 1rem calc(2rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ------------------------------- top bar ------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0 1.1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

.brand-disc {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fef3a0, var(--brand) 55%, var(--brand-deep));
  color: var(--ink);
  font-weight: 900;
  font-style: italic;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 3px 8px rgba(0, 0, 0, 0.4);
}

.brand-sub {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

.timer-pill {
  min-width: 4.2rem;
  text-align: center;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: var(--brand);
  color: var(--ink);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.timer-pill.urgent {
  background: var(--bad);
  color: #fff;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% { transform: scale(1.07); }
}

.icon-btn {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.1s;
}

.icon-btn:active { transform: scale(0.92); }

/* ------------------------------- screens ------------------------------- */
.screen {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

.screen[hidden] { display: none; }

.screen-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 900;
  text-align: center;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
}

.panel-title.spaced { margin-top: 1.1rem; }

.text-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

.text-input:focus {
  outline: none;
  border-color: var(--brand);
}

.hint {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.name-warn { color: var(--bad); font-weight: 700; }

/* level picker */
.level-grid { display: grid; gap: 0.6rem; }

.level-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem 1rem;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.level-card:active { transform: scale(0.98); }

.level-card[aria-checked="true"] {
  border-color: var(--brand);
  background: linear-gradient(0deg, rgba(253, 224, 71, 0.10), rgba(253, 224, 71, 0.10)) var(--surface-2);
}

.level-emoji { font-size: 1.6rem; }

.level-name { font-weight: 900; }

.level-tag {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
}

/* chips */
.chip-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.chip-row-scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.2rem; }

.chip-spacer { flex: 1; }

.chip {
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.chip[aria-checked="true"], .chip[aria-pressed="true"], .chip.on {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--ink);
}

.best-line {
  margin: 0;
  text-align: center;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 0.9rem;
}

/* buttons */
.btn {
  border: none;
  border-radius: 18px;
  padding: 0.95rem 1.2rem;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--brand);
  color: var(--ink);
  letter-spacing: 0.12em;
  box-shadow: 0 5px 18px rgba(253, 224, 71, 0.28);
}

.btn-primary:hover { filter: brightness(1.05); }

.btn-big { font-size: 1.15rem; padding: 1.1rem; }

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-row { display: flex; gap: 0.6rem; }

.btn-row .btn { flex: 1; }

button:focus-visible, .text-input:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* -------------------------------- board -------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-weight: 800;
  padding: 0 0.3rem 0.6rem;
}

.hud-dim { color: var(--text-dim); margin-left: auto; }

.hud-streak { color: var(--brand); animation: pop 0.3s; }

@keyframes pop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.board {
  display: grid;
  gap: 0.8rem;
  width: 100%;
  margin: 0 auto;
  align-content: center;
  flex: 1;
}

.board.cols-2 { grid-template-columns: repeat(2, 1fr); max-width: 17rem; }
.board.cols-3 { grid-template-columns: repeat(3, 1fr); max-width: 23rem; }
.board.cols-4 { grid-template-columns: repeat(4, 1fr); max-width: 26rem; }

.card {
  position: relative;
  aspect-ratio: 1;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 700px;
  -webkit-tap-highlight-color: transparent;
  container-type: inline-size; /* lets faces size text with cqw units */
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 1.4, 0.6, 1);
}

.card.flipped .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
}

.card-back {
  background: radial-gradient(circle at 32% 28%, #fef3a0, var(--brand) 55%, var(--brand-deep));
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 4px 10px rgba(0, 0, 0, 0.45);
  color: var(--ink);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.03em;
  font-size: clamp(0.9rem, 24cqw, 1.6rem);
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  border: 2px dashed rgba(0, 0, 0, 0.18);
}

.card-front {
  transform: rotateY(180deg);
  background: var(--disc-face);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.12);
  font-weight: 900;
}

.card.matched .card-front {
  background: #d9fbe8;
  border-color: var(--good-deep);
  color: var(--good-deep);
}

.card.matched { cursor: default; }

.card.wrong .card-front { animation: shake 0.35s; border-color: var(--bad); }

@keyframes shake {
  20% { transform: rotateY(180deg) translateX(-6%); }
  50% { transform: rotateY(180deg) translateX(6%); }
  80% { transform: rotateY(180deg) translateX(-3%); }
}

.face-numeral { font-size: clamp(1.4rem, 40cqw, 2.8rem); }

.face-expr { font-size: clamp(0.85rem, 18cqw, 1.5rem); letter-spacing: 0.02em; }

.face-dots { width: 78%; height: 78%; }

.face-dots circle { fill: currentColor; }

/* floating score */
.float-points {
  position: fixed;
  z-index: 30;
  font-weight: 900;
  font-size: 1.3rem;
  color: var(--good);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: float-up 0.9s ease-out forwards;
}

@keyframes float-up {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-3.2rem); }
}

.btn-quit { margin-top: 1rem; }

/* ------------------------------- results ------------------------------- */
.results-panel { text-align: center; }

.results-title { margin: 0.2rem 0 0.3rem; font-size: 1.9rem; font-weight: 900; }

.results-sub { margin: 0 0 1rem; color: var(--text-dim); font-weight: 700; }

.breakdown {
  margin: 0 auto;
  max-width: 17rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem 1rem;
  text-align: left;
  font-weight: 700;
}

.breakdown dt { color: var(--text-dim); }

.breakdown dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.breakdown .total-row {
  border-top: 1px solid var(--line);
  padding-top: 0.45rem;
  color: var(--brand);
  font-size: 1.15rem;
  font-weight: 900;
}

.results-note { margin: 1rem 0 0; font-weight: 700; color: var(--good); min-height: 1.2em; }

.results-note.err { color: var(--text-dim); }

/* ----------------------------- leaderboard ----------------------------- */
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.95rem;
  font-weight: 700;
}

.lb-row.mine { border-color: var(--brand); }

.lb-rank {
  width: 2rem;
  text-align: center;
  font-weight: 900;
  color: var(--text-dim);
}

.lb-rank.medal { font-size: 1.25rem; }

.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lb-meta { font-size: 0.72rem; color: var(--text-dim); display: block; font-weight: 600; }

.lb-score { color: var(--good); font-weight: 900; font-variant-numeric: tabular-nums; }

.lb-empty, .lb-status {
  text-align: center;
  color: var(--text-dim);
  font-weight: 700;
  padding: 2rem 0;
}

/* ------------------------------ how to play ---------------------------- */
.howto {
  max-width: 26rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.4rem 1.5rem;
  font-family: var(--font);
}

.howto::backdrop { background: rgba(0, 0, 0, 0.6); }

.howto h2 { margin-top: 0; }

.howto li { margin-bottom: 0.4rem; }

.howto form { text-align: center; margin-top: 1.2rem; }

/* ------------------------------- confetti ------------------------------ */
#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

/* --------------------------- reduced motion ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
  .timer-pill.urgent, .hud-streak { animation: none; }
  .float-points { animation-duration: 0.5s; }
}
