:root {
  --bg: #FBF6EE;
  --surface: #FFFFFF;
  --surface-2: #F3ECE0;
  --paper: #FFFDF5;
  --paper-line: #E8DECC;
  --text: #2A2724;
  --muted: #655D54;
  --line: #DDD2C1;
  --primary: #1F6F6B;
  --primary-ink: #FFFFFF;
  --primary-soft: #DDEFEC;
  --good: #2E8B57;
  --good-soft: #DDF3E4;
  --bad: #C2513A;
  --bad-soft: #FBE4DD;
  --soft: #FFF1CC;
  --focus: #E9A21B;
  --shadow: 0 1px 0 rgba(60, 40, 20, .05), 0 6px 18px rgba(60, 40, 20, .08);
  --radius: 18px;
  color-scheme: light;
  font-size: 20px;
}
:root[data-size="large"] { font-size: 23px; }
:root[data-size="xl"] { font-size: 26px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B1A18;
    --surface: #272522;
    --surface-2: #322F2B;
    --paper: #2D2A26;
    --paper-line: #423D37;
    --text: #F4EFE7;
    --muted: #BDB4A8;
    --line: #48423B;
    --primary: #5CC2B8;
    --primary-ink: #0E2927;
    --primary-soft: #1E3B38;
    --good: #5BC98A;
    --good-soft: #1D3A28;
    --bad: #F08A72;
    --bad-soft: #43271F;
    --soft: #3D3420;
    --shadow: 0 6px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.6rem; line-height: 1.2; margin: .2em 0 .5em; }
p { margin: .4em 0; }
.small { font-size: .85rem; color: var(--muted); }
.label { font-size: 1rem; font-weight: 700; margin: 1.2em 0 .5em; }

button, .btn { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  min-height: 56px;
  padding: .5em 1.1em;
  border-radius: 14px;
  border: 2px solid transparent;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-quiet { background: transparent; color: var(--primary); }
.btn-big { width: 100%; min-height: 64px; font-size: 1.1rem; }
.btn:disabled { opacity: .45; }
.btn.danger { background: var(--bad-soft); border-color: var(--bad); color: var(--text); }
.btn:active:not(:disabled) { transform: translateY(1px); }

/* ---------- Home ---------- */

.home-head { margin-bottom: 18px; }
.home-head h1 { font-size: 1.9rem; margin: .1em 0 .4em; }
.date { margin: 0; color: var(--muted); font-weight: 600; }
.streak {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .8em 1em;
}

.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }

.card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 16px;
  align-items: center;
  padding: 18px;
  background: var(--surface);
  border: 3px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
.card:active { transform: scale(.99); }
.card-pick { border-color: var(--primary); }
.card-icon {
  grid-row: span 3;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.3rem;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--tint) 35%, var(--surface));
}
.card-title { font-size: 1.2rem; font-weight: 800; line-height: 1.25; }
.card-blurb { color: var(--muted); font-size: .9rem; line-height: 1.35; }
.card-best { color: var(--primary); font-size: .85rem; font-weight: 700; margin-top: 4px; }
.badge {
  position: absolute;
  top: -13px;
  right: 14px;
  padding: 2px 12px;
  border-radius: 99px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: .75rem;
  font-weight: 800;
}
.home-foot { margin-top: 28px; display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* ---------- Shared page parts ---------- */

.topbar { display: flex; align-items: center; gap: 8px; margin: -6px 0 10px -10px; }
.topbar .back { padding-inline: .5em; white-space: nowrap; flex-shrink: 0; }
.topbar-title { margin-left: auto; color: var(--muted); font-size: .85rem; font-weight: 700; text-align: right; }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
}

.intro { text-align: center; }
.intro-icon {
  width: 96px;
  height: 96px;
  margin: 0 auto 6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 3rem;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--tint) 35%, var(--surface));
}
.howto { text-align: left; font-size: 1.05rem; }
.level-hint { min-height: 1.5em; font-weight: 600; }
.best-line { color: var(--primary); font-weight: 700; min-height: 1.5em; margin-bottom: 1em; }

.segmented { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 8px; }
.seg {
  min-height: 60px;
  padding: .3em;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}
.seg[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 700; margin: 1.2em 0 .5em; }
input[type="text"] {
  width: 100%;
  min-height: 60px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.1rem;
}

/* ---------- Game stage ---------- */

.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.status { font-size: 1.3rem; font-weight: 800; text-align: center; margin: 0; }
.sub-status { color: var(--muted); text-align: center; margin: 0; font-weight: 600; }
.stage-actions { width: 100%; max-width: 440px; display: grid; gap: 10px; }

.note {
  width: 100%;
  max-width: 440px;
  padding: 14px 16px;
  border-radius: 14px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}
.note p { margin: .2em 0; font-weight: 600; }
.note strong { font-size: 1.2em; letter-spacing: .04em; }
.note-good { background: var(--good-soft); }
.note-soft { background: var(--soft); }

/* Feedback stays mounted with reserved space, so messages never shift the layout. */
.feedback {
  min-height: 2.8em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.note-slot { visibility: hidden; }

/* Matching pairs */
.pairs-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 460px;
}
.flip {
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  perspective: 800px;
}
.flip-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform .45s ease;
  transform-style: preserve-3d;
}
.flip.up .flip-inner { transform: rotateY(180deg); }
.flip-back, .flip-front {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .13) 0 8px, transparent 8px 16px),
    var(--primary);
  box-shadow: var(--shadow);
}
.flip-front {
  transform: rotateY(180deg);
  background: var(--surface);
  border: 3px solid var(--line);
  font-size: clamp(2rem, 10vw, 3rem);
}
.flip.matched .flip-front { border-color: var(--good); background: var(--good-soft); }

/* Repeat the pattern */
.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(100%, 360px); }
.pad {
  aspect-ratio: 1;
  border: 0;
  border-radius: 24px;
  background: var(--pad);
  color: rgba(255, 255, 255, .92);
  font-size: 3rem;
  opacity: .5;
  transition: opacity .1s, transform .1s, box-shadow .1s;
}
.pad.lit {
  opacity: 1;
  transform: scale(1.05);
  box-shadow: 0 0 0 6px var(--surface), 0 0 0 10px var(--pad), 0 0 28px var(--pad);
}
.pad.hint { opacity: 1; outline: 6px dashed var(--text); outline-offset: 5px; }
.pads.locked .pad { cursor: default; }

/* Remember the number */
.number-show { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0; }
.number-show span {
  display: grid;
  place-items: center;
  width: 1.4em;
  height: 1.8em;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 2.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.timebar { width: min(100%, 360px); height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.timebar i {
  display: block;
  height: 100%;
  background: var(--primary);
  transform-origin: left;
  animation: shrink linear forwards;
}
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.digit-boxes { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.digit-box {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.9em;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1.6rem;
  font-weight: 800;
}
.digit-box.cursor { border-color: var(--primary); border-width: 3px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100%, 340px); }
.key {
  min-height: 64px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 800;
}
.key:active:not(:disabled) { background: var(--surface-2); }
.key-fn { color: var(--muted); }
.key-ok { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-size: 1.05rem; }
.key-ok:disabled { opacity: .4; }

/* Shopping list */
.paper {
  width: min(100%, 420px);
  margin: 6px 0;
  padding: .5em 1.2em;
  list-style: none;
  border-radius: 6px;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(transparent 0 calc(2.4em - 2px), var(--paper-line) calc(2.4em - 2px) 2.4em);
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 2.4em;
}
.paper li { display: flex; align-items: center; gap: .5em; }
.paper .emo { font-size: 1.3em; }

/* Choice tiles (shopping shelf, what's missing) */
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; }
@media (min-width: 560px) { .choices { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1em;
  min-height: 92px;
  padding: .45em .4em;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.choice .emo { font-size: 2rem; line-height: 1.15; }
.choice .mark { position: absolute; top: 2px; right: 8px; font-size: 1.3rem; font-weight: 800; }
.choice[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.choice[aria-pressed="true"] .mark { color: var(--primary); }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right .mark { color: var(--good); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .mark { color: var(--bad); }
.choice.missed { border-style: dashed; border-color: var(--good); background: var(--soft); }
.choice.faded { opacity: .5; }
.choice:disabled { cursor: default; }

/* What's missing */
.items { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 10px; width: min(100%, 440px); }
.item {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: clamp(2.2rem, 11vw, 3.2rem);
}

/* Quick sums & yes/no questions */
.question { font-size: 2.6rem; font-weight: 800; margin: .2em 0; font-variant-numeric: tabular-nums; text-align: center; }
.answers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 440px); }
.answers-2 { grid-template-columns: repeat(2, 1fr); }
.answer {
  min-height: 84px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.9rem;
  font-weight: 800;
}
.answer.right { border-color: var(--good); background: var(--good-soft); }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer:disabled { cursor: default; }
.dots { display: flex; gap: 7px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.dots i.now { background: var(--primary); }
.dots i.good { background: var(--good); }
.dots i.miss { background: var(--muted); opacity: .6; }

/* Picture Perfect */
.scene {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 768 / 535;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-obj { position: absolute; aspect-ratio: 1; object-fit: contain; }

/* New Friends (faces & names) */
.faces-grid { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 12px; width: min(100%, 480px); }
.face-card { margin: 0; text-align: center; }
.face-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.face-card figcaption { margin-top: 6px; font-size: 1.15rem; font-weight: 800; }
.face-big {
  width: min(60vw, 260px);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.answers-names { grid-template-columns: repeat(2, 1fr); }

/* Story Time */
.story {
  width: min(100%, 500px);
  padding: .6em 1.3em;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 2;
}
.story p { margin: .3em 0; }
.story-q { font-size: 1.7rem; }
.answers-text .answer {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  min-height: 88px;
  padding: .4em .6em;
}

/* Making change */
.bills { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.bill {
  min-width: 84px;
  min-height: 58px;
  padding: .3em .7em;
  border: 2px solid #B7C9A8;
  border-radius: 10px;
  background: #EAF3E4;
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.bill:active { transform: translateY(1px); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 62px; align-items: center; }
.bill.chip { border-style: dashed; background: var(--surface); min-height: 52px; font-size: 1.2rem; }
.receipt li strong { font-size: 1.1em; }

/* Where Was It? (location memory) */
.loc-grid { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 8px; width: min(100%, 440px); }
.loc-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: clamp(1.7rem, 8.5vw, 2.5rem);
  line-height: 1;
}
.loc-cell:disabled { cursor: default; }
.loc-cell.right { border-color: var(--good); background: var(--good-soft); }
.loc-cell.wrong { border-color: var(--bad); background: var(--bad-soft); }
.loc-cell.missed { border-style: dashed; border-color: var(--good); background: var(--soft); }
.loc-item { font-size: clamp(2.6rem, 13vw, 3.4rem); line-height: 1.2; }
.loc-obj { width: 80%; height: 80%; object-fit: contain; pointer-events: none; }
.loc-item-img { width: min(28vw, 120px); height: min(28vw, 120px); object-fit: contain; }

/* Tricky Colors (Stroop) */
.stroop-word {
  font-size: clamp(3rem, 16vw, 4.2rem);
  font-weight: 900;
  letter-spacing: .08em;
  line-height: 1.2;
  text-align: center;
  margin: 8px 0;
}
.stroop-swatches { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; width: min(100%, 460px); }
.stroop-swatch {
  min-height: 78px;
  border: 3px solid transparent;
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
}
.stroop-swatch:active { transform: translateY(1px); }

/* ---------- Results ---------- */

.result { text-align: center; }
.result-icon { font-size: 4rem; line-height: 1.2; }
.result-main { font-size: 1.3rem; font-weight: 800; }
.result-detail { color: var(--muted); }
.new-best { display: inline-block; padding: .3em 1em; border-radius: 99px; background: var(--soft); font-weight: 800; }
.nudge { font-weight: 700; color: var(--primary); }
.actions { display: grid; gap: 10px; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  .flip-inner, .pad { transition: none; }
}
.status-sm { font-size: 1.05rem; }
