:root {
  --ink: #1e1b4b;
  --muted: #55607a;
  --card: #ffffff;
  --brand: #0f766e;
  --brand-2: #0891b2;
  --sel: #ecfeff;
  --sel-border: #0891b2;
  --play: #16a34a;
  --play-dark: #15803d;
  --good: #16a34a;
  --bad: #dc2626;
  --bg-1: #2dd4bf;
  --bg-2: #22d3ee;
  --bg-3: #818cf8;
  --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(15, 23, 42, .2); }
.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(15, 23, 42, .18); }
.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: #f8fafc; border-radius: 18px; min-height: 76px;
  display: grid; place-content: center; gap: 0; 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(8,145,178,.2); }

.dskp { margin-top: 12px; background: #f8fafc; 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: #f8fafc; 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; }
.year small { order: -1; }
/* My Content (the teacher's pack): a wide button under the years */
.year.pack { grid-column: 1 / -1; min-height: 60px; border-style: dashed; }
.year.pack b { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.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 #a5f3fc; }
.btn-small { border: 2px solid #e2e8f0; background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 15px; min-height: 40px; }
#playBtn { font-size: 28px; min-height: 68px; justify-self: center; width: min(100%, 360px); }
.privacy { margin: 0; text-align: center; color: #fff; font-size: 14px; line-height: 1.4; }
.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: hidden; display: block; user-select: none; -webkit-user-select: none; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); opacity: 0; transition: opacity .3s; }
#game.camera #cam { opacity: 1; }
#game.camera::before { content: ''; position: absolute; inset: 0; background: rgba(15, 23, 42, .35); pointer-events: none; }

.layout {
  position: relative; z-index: 1; height: 100%;
  display: flex; flex-direction: column; gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud { display: flex; gap: 8px; align-items: center; }
.pill { background: rgba(255,255,255,.94); 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,.15); white-space: nowrap; }
.hud-year { margin-left: auto; background: var(--brand); color: #fff; }
.hud-pause { min-width: 48px; min-height: 42px; }

.qwrap { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; }
.qcard {
  width: min(100%, 900px); max-height: 100%; overflow: auto;
  background: rgba(255,255,255,.96); border-radius: var(--radius); padding: 14px 18px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); text-align: center; position: relative;
}
.std { display: inline-block; font-size: 12px; font-weight: 600; color: var(--brand); background: var(--sel); border-radius: 999px; padding: 2px 10px; }
.qtitle { margin: 6px 0 0; font-size: clamp(18px, 2.6vw, 26px); color: var(--brand-2); }
.qvisual { font-family: var(--font); font-size: clamp(44px, 9vh, 96px); line-height: 1.15; margin-top: 4px; }
.qletters { font-size: clamp(40px, 9vh, 88px); font-weight: 700; letter-spacing: 4px; color: var(--brand); }
.qtext { font-size: clamp(17px, 2.5vw, 24px); line-height: 1.45; margin-top: 6px; text-align: left; }
.qtext.short { text-align: center; font-size: clamp(20px, 3.4vw, 32px); }
.qtext p { margin: 0 0 8px; }
.qtext b { background: #fef08a; padding: 0 4px; border-radius: 6px; }
.qtext .gap { display: inline-block; min-width: 3.2em; border-bottom: 4px solid var(--brand); }
.qtext .heard { color: var(--muted); font-style: italic; }
.qprompt { font-size: clamp(20px, 3.4vw, 32px); font-weight: 700; margin-top: 8px; }
.qtools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.qtools:empty { display: none; }
.qstatus { margin-top: 6px; font-weight: 600; color: var(--brand); font-size: clamp(15px, 2.2vw, 20px); min-height: 1.3em; }
.bar { height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 0; background: var(--brand-2); }

.answers { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.answer {
  position: relative; overflow: hidden; border: 4px solid #fff; border-radius: 24px;
  background: rgba(255,255,255,.96); min-height: clamp(96px, 22vh, 210px); padding: 10px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: transform .15s, opacity .2s, border-color .2s;
}
.answer .fill { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--p, 0) * 100%); background: rgba(8,145,178,.28); pointer-events: none; }
.answer .arrow { position: absolute; top: 6px; font-size: clamp(22px, 3vh, 32px); line-height: 1; font-family: var(--emoji); }
#ans0 .arrow { left: 12px; }
#ans1 .arrow { right: 12px; }
.a-emoji { font-size: clamp(34px, 7vh, 72px); line-height: 1.1; position: relative; }
.a-emoji:empty { display: none; }
.a-text { font-size: clamp(20px, min(5.5vw, 4.5vh), 40px); font-weight: 700; line-height: 1.15; position: relative; }
.answer.big .a-text { font-size: clamp(56px, 13vh, 120px); }
.answer.disabled { opacity: .55; }
.answer.hold { border-color: var(--brand-2); transform: scale(1.03); }
.answer.correct { border-color: var(--good); background: #dcfce7; }
.answer.wrong { border-color: var(--bad); background: #fee2e2; }
.answer.reveal { border-color: var(--good); }

.middle { display: grid; place-content: center; text-align: center; color: #fff; font-weight: 700; width: clamp(48px, 9vw, 110px); }
.middle span { font-size: 28px; line-height: 1; }
.middle small { font-size: 13px; }
.middle.call { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.18); } }

.track { position: relative; height: 46px; border-radius: 999px; background: rgba(255,255,255,.25); display: grid; grid-template-columns: 38fr 24fr 38fr; overflow: hidden; }
.track .zone { display: block; }
.zone-l, .zone-r { background: rgba(255,255,255,.18); }
.zone-m { background: rgba(255,255,255,.4); }
.you { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 34px; transition: left .08s linear; font-family: var(--emoji); }
.you.lost { opacity: .35; }
#game:not(.camera) .track { display: none; }

.feedback {
  position: absolute; z-index: 3; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.9);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  background: #fff; border-radius: 22px; padding: 14px 22px; text-align: center;
  font-size: clamp(20px, 3.4vw, 32px); font-weight: 700; box-shadow: 0 10px 40px rgba(0,0,0,.3);
  max-width: calc(100% - 32px); border: 5px solid var(--good);
}
.feedback small { display: block; font-size: .6em; font-weight: 500; color: var(--muted); margin-top: 4px; }
.feedback.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.feedback.bad { border-color: var(--bad); }

.overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 16px; background: rgba(15, 23, 42, .4); }
.overlay.clear { background: transparent; align-items: start; padding-top: calc(70px + var(--safe-t)); pointer-events: none; }
.overlay.clear .panel { pointer-events: auto; }
.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; }
.spinner { width: 44px; height: 44px; margin: 4px auto; border-radius: 50%; border: 5px solid #ccfbf1; 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; }
.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 #e2e8f0; 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; }
.std-table .skill { display: block; font-size: 12px; color: var(--muted); }
#copyBtn { justify-self: center; }
.review { text-align: left; margin: 0; padding-left: 24px; display: grid; gap: 8px; }
.review li { line-height: 1.35; }
.review .ok { color: var(--good); font-weight: 600; }
.review .no { color: var(--bad); font-weight: 600; }
.review small { color: var(--muted); }

@media (max-width: 520px) {
  .answers { gap: 6px; }
  .middle small { display: none; }
  .answer { padding: 8px 6px; border-radius: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
