:root {
  --ink: #2a1215;
  --muted: #6f5a5d;
  --card: #ffffff;
  --brand: #be123c;
  --brand-2: #c2410c;
  --sel: #fff1f2;
  --sel-border: #e11d48;
  --play: #16a34a;
  --play-dark: #15803d;
  --good: #16a34a;
  --mid: #d97706;
  --bad: #dc2626;
  --bg-1: #fb7185;
  --bg-2: #f97316;
  --bg-3: #facc15;
  --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) 55%, 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(136, 19, 55, .3); }
.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(136, 19, 55, .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(225, 29, 72, .2); }
.source { margin: 12px 0 0; }

.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; }
.note { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.note:empty { display: none; }
#prepBtn { margin-top: 10px; font-size: 14px; }

.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 #fecdd3; }
.btn-small { border: 2px solid #fecdd3; 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); }
.privacy { margin: 0; text-align: center; color: #fff; font-weight: 600; font-size: 15px; line-height: 1.4; text-shadow: 0 1px 0 rgba(136, 19, 55, .3); }
.privacy small { font-weight: 500; font-size: 13px; }
.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: 860px; 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-mode { padding: 6px 10px; }
.hud-year { margin-left: auto; background: var(--brand); color: #fff; }
.hud-pause { min-width: 48px; min-height: 44px; }
@media (max-width: 380px) { .pill { padding: 6px 10px; } .hud { gap: 6px; } }

.task { background: rgba(255,255,255,.96); border-radius: var(--radius); padding: 12px 16px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12); display: grid; gap: 6px; 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; }
.tpic { font-family: var(--emoji); font-size: clamp(52px, 12vh, 104px); line-height: 1.1; white-space: nowrap; }
.tpic.small { font-size: clamp(40px, 8vh, 72px); }
.tshow { font-size: clamp(22px, 4vw, 36px); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.tshow.word { font-size: clamp(34px, 7vw, 56px); }
.tshow.question { font-size: clamp(20px, 3.4vw, 30px); }
.thidden { font-size: clamp(20px, 3.4vw, 28px); font-weight: 700; color: var(--brand-2); }
.tframe { font-size: clamp(17px, 2.6vw, 22px); font-weight: 600; color: var(--brand); background: var(--sel); border-radius: 14px; padding: 4px 14px; }
.tmodel { font-size: clamp(16px, 2.4vw, 20px); color: var(--muted); }
.tmodel b { color: var(--ink); }
.task-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }

/* The big microphone button */
.speak { display: grid; justify-items: center; gap: 6px; }
.mic {
  --lvl: 0;
  position: relative; width: 120px; height: 120px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, #fb7185, var(--brand)); color: #fff;
  box-shadow: 0 6px 0 #881337, 0 12px 24px rgba(136, 19, 55, .35);
  display: grid; place-items: center; transition: transform .1s, filter .2s;
}
.mic:active { transform: translateY(3px); box-shadow: 0 3px 0 #881337; }
.mic:disabled { filter: grayscale(.7) opacity(.55); cursor: default; }
.mic-icon { font-family: var(--emoji); font-size: 54px; line-height: 1; position: relative; }
.mic-ring { position: absolute; inset: -8px; border-radius: 50%; border: 6px solid rgba(255,255,255,.9); opacity: 0; transform: scale(calc(1 + var(--lvl) * .35)); transition: transform .08s linear; }
.mic.on { background: radial-gradient(circle at 35% 30%, #f87171, #dc2626); }
.mic.on .mic-ring { opacity: 1; }
.mic.on::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 4px solid #fff; animation: ping 1.4s ease-out infinite; }
.mic.busy .mic-icon { animation: pulse 1s ease-in-out infinite; }
.mic.say { background: radial-gradient(circle at 35% 30%, #fdba74, var(--brand-2)); box-shadow: 0 6px 0 #9a3412, 0 12px 24px rgba(154, 52, 18, .35); }
@keyframes ping { from { transform: scale(1); opacity: .9; } to { transform: scale(1.45); opacity: 0; } }
@keyframes pulse { 50% { opacity: .45; } }
.mic-label { font-size: clamp(17px, 2.6vw, 22px); font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(136, 19, 55, .35); text-align: center; min-height: 1.3em; }
.tries { display: flex; gap: 6px; min-height: 12px; }
.tries span { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.95); }
.tries span.used { background: rgba(255,255,255,.35); }

.heard { background: rgba(255,255,255,.96); border-radius: 16px; padding: 10px 14px; text-align: center; box-shadow: 0 6px 16px rgba(0,0,0,.1); display: grid; gap: 6px; }
.heard-note { font-weight: 600; color: var(--muted); }
.heard-text { font-size: clamp(18px, 2.8vw, 24px); font-weight: 600; }
.heard-words { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.heard-words span { border-radius: 10px; padding: 2px 10px; font-weight: 600; font-size: clamp(16px, 2.4vw, 20px); background: #f1f5f9; color: #64748b; }
.heard-words span.ok { background: #dcfce7; color: #166534; }
.heard-words span.close { background: #fef3c7; color: #92400e; }

.selfbox { background: rgba(255,255,255,.96); border-radius: 16px; padding: 12px; text-align: center; box-shadow: 0 6px 16px rgba(0,0,0,.1); display: grid; gap: 8px; }
.self-q { margin: 0; font-weight: 700; font-size: 18px; }
.rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.rate button { border: 3px solid #fde68a; background: #fffbeb; border-radius: 16px; min-height: 64px; padding: 6px; font-family: var(--emoji), var(--font); font-size: 18px; display: grid; place-items: center; gap: 2px; }
.rate button small { font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--muted); }
.rate button:hover { border-color: #f59e0b; }

.result { display: grid; justify-items: center; gap: 2px; min-height: 1.4em; }
.result-stars { font-family: var(--emoji); font-size: clamp(30px, 6vw, 44px); line-height: 1.1; letter-spacing: 2px; }
.result-stars:empty { display: none; }
.result-stars .off { filter: grayscale(1); opacity: .3; }
.result-stars.pop { animation: pop .45s ease-out; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.message { text-align: center; font-size: clamp(18px, 2.8vw, 24px); font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(136, 19, 55, .35); }
.message small { display: block; font-size: .72em; 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(42, 18, 21, .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); max-height: calc(100dvh - 32px); overflow-y: auto; }
.ov-icon { font-size: 52px; line-height: 1.1; font-family: var(--emoji); }
.panel h2 { margin: 6px 0; font-size: 24px; }
.panel p { margin: 0 0 14px; color: var(--muted); font-size: 17px; line-height: 1.4; white-space: pre-line; }
.ov-small { font-size: 14px !important; }
.bar { height: 16px; border-radius: 999px; background: #ffe4e6; overflow: hidden; margin: 0 0 8px; }
.bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--bg-1), var(--bg-2)); border-radius: 999px; transition: width .2s; }
.bar.indeterminate span { width: 40%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.spinner { width: 48px; height: 48px; margin: 0 auto; border-radius: 50%; border: 6px solid #ffe4e6; border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 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; }
.small-note { margin: 0; }
.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; display: grid; gap: 6px; }
.review li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; border-bottom: 1px solid #f1f5f9; }
.review button { display: block; width: 100%; border: 0; background: none; padding: 8px 0; text-align: left; font-size: 17px; font-weight: 500; line-height: 1.35; min-height: 44px; }
.review .tip-words { display: block; font-size: 14px; color: var(--muted); }
.review .mark { font-family: var(--emoji); font-size: 15px; white-space: nowrap; }
.review .none { text-align: center; color: var(--good); font-weight: 600; border: 0; display: block; padding: 6px 0; }

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