:root {
  --ink: #1f1235;
  --muted: #6b5b73;
  --card: #ffffff;
  --brand: #be185d;
  --brand-2: #4f46e5;
  --sel: #fdf2f8;
  --sel-border: #db2777;
  --play: #16a34a;
  --play-dark: #15803d;
  --good: #16a34a;
  --bad: #dc2626;
  --bg-1: #f472b6;
  --bg-2: #a78bfa;
  --bg-3: #60a5fa;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 50%, var(--bg-3)) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { display: none; }
.screen.active { display: block; }

/* ---------- Home & results ---------- */
#home, #results {
  min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.inner { max-width: 820px; margin: 0 auto; display: grid; gap: 16px; }
.back { color: #fff; font-weight: 600; text-decoration: none; justify-self: start; padding: 6px 2px; }
.brand { text-align: center; color: #fff; }
.brand .logo { font-size: clamp(40px, 10vw, 64px); line-height: 1.1; font-family: var(--emoji); }
.brand h1 { margin: 2px 0 0; font-size: clamp(34px, 8vw, 56px); text-shadow: 0 3px 0 rgba(131, 24, 67, .25); }
.brand p { margin: 4px 0 0; font-size: clamp(16px, 4vw, 20px); font-weight: 500; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(76, 29, 149, .2); }
.card h2 { margin: 0 0 12px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 16px; }

.years { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 640px) { .years { grid-template-columns: repeat(6, 1fr); } }
.year { border: 3px solid #e5e7eb; background: #fafaf9; border-radius: 18px; min-height: 76px; display: grid; place-content: center; padding: 6px; }
.year b { font-size: 28px; line-height: 1; }
.year small { color: var(--muted); font-size: 13px; }
.year[aria-checked="true"] { border-color: var(--sel-border); background: var(--sel); box-shadow: 0 0 0 3px rgba(219, 39, 119, .2); }

.dskp { margin-top: 12px; background: #fafaf9; border-radius: 14px; padding: 10px 12px; }
.dskp summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.dskp ul { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.dskp li { display: grid; grid-template-columns: auto 1fr; gap: 8px; font-size: 14px; line-height: 1.35; }
.dskp .code { font-weight: 700; color: var(--brand); white-space: nowrap; }
.dskp .note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

.option { display: grid; gap: 6px; margin-bottom: 12px; }
.option-label { font-weight: 600; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid #e5e7eb; background: #fafaf9; font-weight: 500; font-size: 15px; }
.seg button[aria-pressed="true"] { border-color: var(--sel-border); background: var(--sel); font-weight: 600; }
.level-seg button { min-height: 56px; font-size: 17px; }
.level-note { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.35; }
.tip { margin: 4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.4; }

.btn { border: 0; border-radius: 999px; min-height: 52px; padding: 10px 26px; font-weight: 700; font-size: 20px; transition: transform .1s; }
.btn:active { transform: translateY(2px); }
.btn-play { background: var(--play); color: #fff; box-shadow: 0 5px 0 var(--play-dark); }
.btn-ghost { background: #fff; color: var(--brand); box-shadow: 0 5px 0 #fbcfe8; }
.btn-small { border: 2px solid #fbcfe8; background: #fff; border-radius: 999px; padding: 6px 16px; font-weight: 600; font-size: 16px; min-height: 44px; }
.btn-small:disabled { opacity: .45; cursor: default; }
#playBtn { font-size: 28px; min-height: 68px; justify-self: center; width: min(100%, 360px); }
.install { display: grid; justify-items: center; gap: 6px; color: #fff; font-size: 14px; text-align: center; }
.install p { margin: 0; }

/* ---------- Game ---------- */
#game.active { position: fixed; inset: 0; overflow-y: auto; overflow-x: hidden; display: block; user-select: none; -webkit-user-select: none; }
.layout {
  min-height: 100%; max-width: 1000px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(16px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud { display: flex; gap: 8px; align-items: center; }
.pill { background: rgba(255,255,255,.95); border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: clamp(15px, 2.4vw, 22px); box-shadow: 0 4px 12px rgba(0,0,0,.12); white-space: nowrap; }
.hud-year { margin-left: auto; background: var(--brand); color: #fff; }
.hud-pause { min-width: 48px; min-height: 44px; }

.task { background: rgba(255,255,255,.96); border-radius: var(--radius); padding: 12px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.12); display: grid; gap: 8px; justify-items: center; text-align: center; }
.std { font-size: 12px; font-weight: 600; color: var(--brand); background: var(--sel); border-radius: 999px; padding: 2px 10px; }
.tprompt { font-size: clamp(20px, 3.2vw, 30px); font-weight: 700; line-height: 1.25; }
.tstatus { font-size: clamp(16px, 2.4vw, 20px); font-weight: 600; color: var(--muted); min-height: 1.3em; }
.tstatus:empty { display: none; }
.tstatus.listening { color: var(--brand-2); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.heard { width: 100%; max-width: 720px; background: #eef2ff; border-radius: 14px; padding: 8px 14px; text-align: left; }
.heard-note { margin: 0 0 2px; font-size: 14px; font-weight: 600; color: var(--brand-2); }
.heard-text { margin: 0; font-size: clamp(17px, 2.5vw, 22px); line-height: 1.4; user-select: text; -webkit-user-select: text; }
.task-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.task-tools:not(:has(button:not([hidden]))) { display: none; }

/* Picture cards */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
.cards.n2 { --cols: 2; }
.cards.n3 { --cols: 3; }
.cards.n4 { --cols: 2; }
@media (min-width: 760px) { .cards.n4 { --cols: 4; } }
.pcard {
  position: relative; border: 4px solid #fff; border-radius: 22px; background: #fff;
  min-height: clamp(120px, 22vh, 220px); padding: 12px 8px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 6px 0 #f9a8d4, 0 10px 20px rgba(76, 29, 149, .18);
  transition: transform .12s, opacity .2s, border-color .2s, background .2s;
}
.pcard:not(:disabled):hover { transform: translateY(-2px); border-color: #fbcfe8; }
.pcard:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 #f9a8d4; }
.pcard:disabled { cursor: default; }
.cards.waiting .pcard { opacity: .5; filter: saturate(.6); }
.pcard .emoji { font-family: var(--emoji); font-size: clamp(48px, 11vh, 112px); line-height: 1.1; white-space: nowrap; }
.pcard.e2 .emoji { font-size: clamp(38px, 8vh, 76px); }
.pcard.e3 .emoji { font-size: clamp(28px, 6vh, 56px); }
.pcard .cap { font-size: clamp(15px, 2.3vw, 21px); font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.cards.pics-only .cap { display: none; }
/* My Content answers: words, with a small speech-bubble icon instead of a picture */
.pcard.textcard { min-height: clamp(84px, 14vh, 150px); }
.pcard.textcard .emoji { font-size: clamp(24px, 4vh, 34px); opacity: .7; }
.pcard.textcard .cap { font-size: clamp(18px, 2.8vw, 26px); }
.pcard .num { position: absolute; top: 6px; left: 8px; font-size: 13px; font-weight: 700; color: var(--muted); background: #f5f3ff; border-radius: 8px; padding: 0 6px; display: none; }
@media (hover: hover) and (pointer: fine) { .pcard .num { display: block; } }
.pcard.correct { border-color: var(--good); background: #dcfce7; }
.pcard.wrong { border-color: var(--bad); background: #fee2e2; animation: shake .45s; }
.pcard.reveal { border-color: var(--good); background: #dcfce7; animation: glow 1s ease-in-out 2; }
.pcard.dim { opacity: .45; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes glow { 50% { box-shadow: 0 0 0 6px #86efac, 0 6px 0 #f9a8d4; } }

/* Narrow phones: three cards in one row would be too small, so stack them as wide rows. */
@media (max-width: 479px) {
  .cards.n3 { --cols: 1; gap: 10px; }
  .cards.n3 .pcard { flex-direction: row; justify-content: flex-start; min-height: 84px; padding: 8px 16px; gap: 14px; text-align: left; }
  .cards.n3 .pcard .emoji { font-size: 44px; min-width: 64px; text-align: center; }
  .cards.n3 .pcard.e3 .emoji { font-size: 30px; }
  .cards.n3 .pcard.textcard .emoji { font-size: 26px; min-width: 40px; }
  .cards.n3.pics-only .pcard { justify-content: center; }
  .cards.n4 { gap: 10px; }
  .cards.n4 .pcard { min-height: clamp(104px, 16vh, 150px); }
}

.message { text-align: center; font-size: clamp(18px, 2.8vw, 26px); font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(76, 29, 149, .35); min-height: 1.4em; }
.message small { display: block; font-size: .7em; font-weight: 500; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.overlay { position: fixed; inset: 0; z-index: 7; display: grid; place-items: center; padding: 16px; background: rgba(31, 18, 53, .45); }
.panel { background: #fff; border-radius: var(--radius); padding: 20px; width: min(100%, 480px); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.ov-icon { font-size: 52px; line-height: 1.1; }
.panel h2 { margin: 6px 0; font-size: 26px; }
.panel p { margin: 0 0 14px; color: var(--muted); font-size: 17px; line-height: 1.4; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- Results ---------- */
.results { display: grid; gap: 10px; text-align: center; }
.results h2 { justify-content: center; font-size: 30px; margin: 0; }
.results h3 { margin: 10px 0 0; font-size: 18px; }
.results h3 small { font-weight: 400; color: var(--muted); }
.stars { font-size: clamp(48px, 13vw, 72px); letter-spacing: 4px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.res-score { margin: 0; font-size: 20px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
.std-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.std-table th, .std-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.std-table th { color: var(--muted); font-weight: 600; }
.std-table td:first-child { font-weight: 700; color: var(--brand); white-space: nowrap; }
.std-table td:last-child { font-weight: 700; white-space: nowrap; }
#copyBtn { justify-self: center; }
.review { text-align: left; margin: 0; padding: 0; list-style: none; counter-reset: r; display: grid; gap: 10px; }
.review li { counter-increment: r; display: grid; grid-template-columns: 26px 1fr; }
.review li::before { content: counter(r) "."; font-size: 16px; line-height: 1.35; font-weight: 700; color: var(--muted); padding-top: 11px; }
.review button { display: block; width: 100%; border: 0; background: none; padding: 11px 0 4px; text-align: left; font-size: 16px; font-weight: 500; line-height: 1.35; min-height: 44px; }
.review .q { font-size: 15px; color: var(--muted); }
.review .ok { color: var(--good); font-weight: 600; }
.review .no { color: var(--bad); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
