:root {
  --ink: #1b2233;
  --paper: #ffffff;
  --accent: #ff6a13;
  --accent-2: #ffb703;
  --accent-ink: #ffffff;
  --muted: #4a5568;
  --focus: #1d4ed8;
  --panel: rgba(255, 255, 255, 0.97);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #0c1020; color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
#stage { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); overflow: hidden; background: #5fb8ff; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }
[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 0.6em; }
button:focus-visible, input:focus-visible + span, input[type=checkbox]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.primary {
  background: linear-gradient(180deg, #ff8a3d, var(--accent)); color: var(--accent-ink); font-weight: 800;
  padding: 0.55em 1.2em; box-shadow: 0 0.22em 0 #b54400, 0 0.4em 0.8em rgba(181, 68, 0, 0.3); letter-spacing: 0.02em;
}
.primary:active { transform: translateY(0.14em); box-shadow: 0 0.08em 0 #b54400; }
.ghost { background: #edf1f7; color: var(--ink); padding: 0.5em 1em; font-weight: 700; }
.big { font-size: 1.45em; padding: 0.45em 1.8em; }
kbd { background: #edf1f7; border-radius: 0.3em; padding: 0 0.35em; font-family: inherit; font-size: 0.9em; border: 1px solid #cbd5e1; }

.icon-btn { position: absolute; top: 0.6em; right: 0.6em; width: 2.5em; height: 2.5em; background: rgba(255,255,255,0.92); font-size: 1em; font-weight: 800; z-index: 5; box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
.icon-btn.small { position: static; width: 2.2em; height: 2.2em; flex: none; background: #edf1f7; box-shadow: none; }

#toast {
  position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%);
  background: rgba(20, 24, 40, 0.88); color: #fff; padding: 0.4em 1em; border-radius: 0.6em; font-weight: 700; font-size: 1.05em;
  opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 4; max-width: 80%; text-align: center;
}
#toast.show { opacity: 1; }

/* Build panel */
.panel {
  position: absolute; left: 50%; top: 8.5%; transform: translateX(-50%); width: 54%;
  background: var(--panel); border-radius: 1em; padding: 0.65em 0.85em 0.6em; z-index: 6;
  box-shadow: 0 0.4em 1.6em rgba(0,0,0,0.3); border: 3px solid var(--accent-2);
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(0.92); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
.bq-row { display: flex; gap: 0.55em; align-items: center; }
.badge { flex: none; width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 900; display: grid; place-items: center; font-size: 1.1em; }
#bq { margin: 0; font-size: 1.12em; font-weight: 700; line-height: 1.3; flex: 1; }
.ans-row { display: flex; gap: 0.6em; align-items: stretch; margin: 0.55em 0 0.45em; }
.ans { flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.25em; background: #fff8e6; border: 2px dashed #f0b44a; border-radius: 0.6em; font-size: 1.5em; font-weight: 800; min-height: 1.9em; }
.ans .val { min-width: 1.6em; text-align: center; border-bottom: 3px solid var(--ink); line-height: 1.1; }
.ans .val:empty::after { content: '?'; color: #b9b9b9; }
#ansUnit { font-size: 0.75em; color: var(--muted); }
.pad { display: grid; grid-template-columns: repeat(11, 1fr); gap: 0.28em; }
.pad button { background: #edf1f7; font-weight: 800; font-size: 1.15em; padding: 0.35em 0; border: 2px solid #cbd5e1; }
.pad button:active { background: var(--accent-2); }
.b-foot { display: flex; gap: 0.6em; align-items: center; justify-content: space-between; }
.hint { margin: 0.45em 0 0; font-size: 0.98em; color: #9a2f00; font-weight: 700; flex: 1; }
.hint:empty { visibility: hidden; margin: 0; min-height: 0; }
#showMeBtn { margin-top: 0.4em; flex: none; background: #e7f5ff; color: #1864ab; border: 2px solid #74c0fc; }

/* Touch controls */
#touch { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 0.8em; pointer-events: none; z-index: 3; }
.touch-btn {
  pointer-events: auto; width: 5.2em; height: 5.2em; border-radius: 50%;
  background: rgba(255,255,255,0.78); font-size: 1em; font-weight: 800; display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1; box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}
.touch-btn span { font-size: 0.7em; margin-top: 0.2em; }

/* Menu, pause, end screens */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 10, 24, 0.35); z-index: 10; }
.card {
  background: rgba(255,255,255,0.95); border-radius: 1.1em; padding: 0.8em 1.4em 0.9em; width: 74%; max-height: 95%; overflow: auto;
  text-align: center; box-shadow: 0 0.6em 2.4em rgba(0,0,0,0.4); border: 3px solid rgba(255,255,255,0.7);
}
.card.narrow { width: 44%; display: flex; flex-direction: column; gap: 0.55em; }
.logo { margin: 0; font-size: 2.6em; line-height: 1.05; font-weight: 900; letter-spacing: 0.01em; }
.logo span:first-child { color: #1aa39a; text-shadow: 0 0.06em 0 #0d5e58; transform-origin: bottom center; }
.logo span:last-child { color: var(--accent); text-shadow: 0 0.06em 0 #b54400; }
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo span:last-child { animation-delay: 0.3s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-0.08em) rotate(1deg); } }
h2 { margin: 0; font-size: 1.9em; }
.tag { margin: 0.15em 0 0.6em; font-size: 1.1em; color: var(--muted); font-weight: 600; }
fieldset { border: 0; margin: 0.55em 0 0; padding: 0; }
legend { font-weight: 800; margin: 0 auto 0.25em; font-size: 0.9em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.row2 { display: flex; justify-content: center; gap: 1.5em; }
.seg { display: inline-flex; background: #edf1f7; border-radius: 0.7em; padding: 0.2em; gap: 0.2em; }
.seg.wrap { flex-wrap: wrap; justify-content: center; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 0.33em 0.8em; border-radius: 0.55em; font-weight: 700; }
.seg input:checked + span { background: var(--accent); color: #fff; box-shadow: 0 2px 4px rgba(181,68,0,0.35); }
.toggles { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.3em 1.1em; margin: 0.8em auto 0; width: fit-content; text-align: left; font-size: 0.92em; }
.toggles label { cursor: pointer; font-weight: 600; }
.toggles input { width: 1.05em; height: 1.05em; vertical-align: -0.12em; accent-color: var(--accent); }
.keys { margin: 0.75em 0 0; font-size: 0.8em; color: var(--muted); line-height: 1.7; }
.stars { font-size: 2.6em; letter-spacing: 0.1em; line-height: 1; }
.stars .s { display: inline-block; color: #d6dbe3; }
.stars .s.on { color: #ffc300; text-shadow: 0 0.05em 0 #c98a00; animation: starpop 0.45s ease-out backwards; }
.stars .s.on:nth-child(2) { animation-delay: 0.25s; }
.stars .s.on:nth-child(3) { animation-delay: 0.5s; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.3) rotate(8deg); } to { transform: scale(1); } }
.stats { list-style: none; padding: 0; margin: 0; font-size: 1.05em; line-height: 1.55; }
.stats b { color: var(--accent); }
.practice { margin: 0; color: var(--muted); font-size: 0.95em; }
.practice:empty { display: none; }

.reduce-motion .logo span, .reduce-motion .panel, .reduce-motion .stars .s.on { animation: none; }
@media (prefers-reduced-motion: reduce) { .logo span, .panel, .stars .s.on { animation: none; } }

.heroes { gap: 0.15em; }
.seg .hero { width: 2.7em; height: 2.7em; padding: 0; border-radius: 50%; display: block; background: #fff; margin: 0.08em; }
.seg input:checked + .hero { background: #ffe8cc; box-shadow: 0 0 0 3px var(--accent); }
.seg input:disabled + .hero { background: #dfe4ec; cursor: not-allowed; }
.seg input:focus-visible + .hero { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Island picker */
.islands { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.45em; }
.islands label { cursor: pointer; display: block; }
.islands input { position: absolute; opacity: 0; pointer-events: none; }
.isle {
  display: flex; flex-direction: column; align-items: center; gap: 0.1em; padding: 0.4em 0.3em 0.45em; border-radius: 0.8em;
  background: linear-gradient(180deg, var(--s0), var(--s1) 70%, var(--g) 70%); border: 3px solid transparent;
  box-shadow: 0 0.15em 0.4em rgba(0,0,0,0.18); color: #fff; min-height: 6.6em; transition: transform 0.12s;
}
.isle .sym { font-size: 1.7em; line-height: 1; font-weight: 900; text-shadow: 0 0.06em 0 rgba(0,0,0,0.35); -webkit-text-stroke: 1px #2b2d42; }
.isle .nm { font-weight: 900; font-size: 0.86em; line-height: 1.1; text-shadow: 0 0 2px #1b2233, 0 0 3px #1b2233, 0 1px 2px #1b2233; }
.isle .sym { text-shadow: 0 0 2px #1b2233, 0 0.06em 0 rgba(0,0,0,0.35); }
.isle .st { color: #ffd43b; font-size: 0.95em; letter-spacing: 0.05em; text-shadow: 0 1px 1px rgba(0,0,0,0.55); }
.isle .st i { font-style: normal; }
.isle .bl { font-size: 0.66em; font-weight: 700; color: #1b2233; background: rgba(255,255,255,0.85); border-radius: 0.5em; padding: 0.1em 0.35em; line-height: 1.2; margin-top: auto; }
.islands input:checked + .isle { border-color: var(--accent); transform: translateY(-0.15em); box-shadow: 0 0 0 3px #fff, 0 0.3em 0.8em rgba(181,68,0,0.4); }
.islands input:focus-visible + .isle { outline: 3px solid var(--focus); outline-offset: 3px; }
.pick-row { display: flex; align-items: flex-end; justify-content: center; gap: 1.2em; margin-top: 0.2em; }
.pick-row #playBtn { margin-bottom: 0.2em; }
#heroName { color: var(--ink); text-transform: none; letter-spacing: 0; }
.more { margin-top: 0.6em; }
.more summary { cursor: pointer; font-weight: 800; color: var(--muted); font-size: 0.9em; }
.more[open] summary { margin-bottom: 0.2em; }
.reduce-motion .isle { transition: none; }
.row2 { flex-wrap: wrap; gap: 0.4em 1.2em; }

/* Gap Island */
.teach-link { display: block; margin-top: 0.3em; font-size: 0.8em; white-space: nowrap; text-align: center; font-weight: 800; color: #1864ab; text-decoration: none; background: #e7f5ff; border: 2px solid #a5d8ff; border-radius: 0.6em; padding: 0.25em 0.6em; }
.teach-link:hover { background: #d0ebff; }
.teach-link:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.island-btn { background: linear-gradient(180deg, #d3f9d8, #b2f2bb); border: 2px solid #51cf66; }
.island-btn .new { background: var(--accent); color: #fff; font-size: 0.7em; border-radius: 0.6em; padding: 0.05em 0.45em; vertical-align: 0.15em; }
#isleUi { position: absolute; inset: 0; pointer-events: none; z-index: 7; }
#isleUi button, #isleUi .isle-talk, #isleUi .panel { pointer-events: auto; }
.isle-bar { position: absolute; left: 0.6em; top: 0.6em; display: flex; align-items: flex-start; gap: 0.6em; }
.isle-quest { background: rgba(255,255,255,0.92); border-radius: 0.7em; padding: 0.35em 0.75em; font-size: 0.82em; box-shadow: 0 0.15em 0.5em rgba(0,0,0,0.2); }
.isle-quest ul { list-style: none; margin: 0.15em 0 0; padding: 0; }
.isle-quest li.done { color: #2b8a3e; }
.isle-coins { margin: 0; background: rgba(255,255,255,0.92); border-radius: 0.7em; padding: 0.35em 0.7em; font-weight: 800; font-size: 0.85em; }
.isle-act { position: absolute; left: 50%; bottom: 3.2em; transform: translateX(-50%); font-size: 1.1em; }
.isle-keys { position: absolute; left: 0.8em; bottom: 0.4em; margin: 0; color: #fff; font-size: 0.75em; font-weight: 700; text-shadow: 0 1px 2px #1b2233; }
.isle-talk { position: absolute; left: 50%; bottom: 1em; transform: translateX(-50%); width: 70%; background: #fffdf7; border: 3px solid var(--accent-2);
  border-radius: 1em; padding: 0.6em 1em 0.7em; box-shadow: 0 0.4em 1.6em rgba(0,0,0,0.35); z-index: 8; }
.isle-who { margin: 0; font-weight: 900; color: var(--accent); }
.isle-say { margin: 0.2em 0 0.5em; font-size: 1.15em; font-weight: 700; line-height: 1.35; }
.isle-btns { display: flex; gap: 0.5em; justify-content: flex-end; }
.isle-panel { z-index: 9; }
.isle-qt { margin: 0 0 0.3em; font-weight: 900; color: var(--accent); font-size: 0.9em; }
#iq { margin: 0; font-size: 1.12em; font-weight: 700; line-height: 1.3; flex: 1; }
.isle-panel .unit { font-size: 0.75em; color: var(--muted); }
#stage.isle-on #toast { bottom: 22%; z-index: 9; }
@media (max-width: 700px) { .isle-talk { width: 92%; } .isle-keys { display: none; } }

/* Closet */
.go-col { display: flex; flex-direction: column; gap: 0.35em; align-items: stretch; margin-bottom: 0.2em; }
.closet-top { display: flex; align-items: center; justify-content: center; gap: 1em; text-align: left; }
#closetPreview { width: 6em; height: 6em; background: #fff8e6; border-radius: 50%; border: 3px solid var(--accent-2); }
.bank { margin: 0.1em 0; font-size: 1.25em; font-weight: 800; }
.bank b { color: var(--accent); }
.tag.small { font-size: 0.85em; margin: 0; }
.hat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4em; margin: 0.6em 0; }
.hat { display: flex; flex-direction: column; align-items: center; background: #edf1f7; border: 3px solid transparent; padding: 0.25em 0.2em 0.35em; }
.hat canvas { width: 3.6em; height: 3.6em; }
.hat .hn { font-weight: 800; font-size: 0.82em; }
.hat .ht { font-size: 0.78em; font-weight: 800; color: var(--accent); }
.hat.owned .ht { color: #2f9e44; }
.hat.on { border-color: var(--accent); background: #fff4e6; }
.hat:disabled { opacity: 0.55; cursor: not-allowed; }
.hat:not(:disabled):hover { background: #fff4e6; }

/* Grade + subject row, reading choices */
.top-row { display: flex; justify-content: center; gap: 1.4em; flex-wrap: wrap; }
.top-row fieldset { margin-top: 0.2em; }
.choices { display: grid; grid-template-columns: 1fr; gap: 0.35em; margin: 0.55em 0 0.2em; }
.choice {
  display: flex; align-items: center; gap: 0.6em; text-align: left; background: #fff8e6; border: 3px solid #f0b44a;
  padding: 0.45em 0.7em; font-size: 1.2em; font-weight: 800; box-shadow: 0 0.15em 0 #d99a2b;
}
.choice kbd { flex: none; font-size: 0.75em; }
.choice:hover:not(:disabled) { background: #ffe8bf; }
.choice:active:not(:disabled) { transform: translateY(0.1em); box-shadow: none; }
.choice:disabled { opacity: 0.4; text-decoration: line-through; cursor: not-allowed; }

/* Next-question preview (shown while running, before the slowdown) */
.preview {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%); max-width: 70%; z-index: 4;
  display: flex; gap: 0.55em; align-items: center; background: rgba(255,255,255,0.94); border: 3px solid var(--accent-2);
  border-radius: 0.9em; padding: 0.4em 0.8em; box-shadow: 0 0.3em 1em rgba(0,0,0,0.25); font-weight: 800; font-size: 1.05em; line-height: 1.25;
  animation: slidein 0.3s ease-out;
}
.preview .pv-tag { display: block; font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.preview .pv-choices { display: block; color: #b45309; margin-top: 0.15em; }
@keyframes slidein { from { transform: translate(-50%, -0.6em); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.reduce-motion .preview { animation: none; }
@media (prefers-reduced-motion: reduce) { .preview { animation: none; } }

/* World map */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.map-summary { margin: 0.3em 0 0.5em; font-weight: 700; text-align: center; }
#mapUi { position: absolute; inset: 0; pointer-events: none; z-index: 7; }
.map-bar {
  pointer-events: auto; position: absolute; left: 0; right: 0; bottom: 0; height: 3.3em;
  display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: 0 0.8em;
  background: rgba(20, 24, 40, 0.84); color: #fff;
}
#mapInfo { margin: 0; font-size: 1.05em; font-weight: 700; text-align: center; flex: 1; }
#mapInfo .st { color: #ffc300; letter-spacing: 0.08em; margin-left: 0.3em; }
#mapInfo .st .off { color: rgba(255, 255, 255, 0.35); }
#mapPlay { font-size: 1.15em; }
#mapPlay:disabled { opacity: 0.6; }
.map-keys { position: absolute; right: 0.8em; bottom: 3.6em; margin: 0; font-size: 0.75em; color: #fff; font-weight: 700; text-shadow: 0 1px 2px #000; }
.map-keys kbd { color: var(--ink); text-shadow: none; }
#stage.map-on #toast { bottom: 17%; z-index: 8; }

/* Closet tabs */
.closet-tabs { display: flex; gap: 0.4em; justify-content: center; margin-top: 0.4em; }
.closet-tabs button { background: #edf1f7; color: var(--ink); font-weight: 800; padding: 0.35em 1em; }
.closet-tabs button[aria-selected=true] { background: var(--accent); color: #fff; }
.hat .ht.star { color: #e67700; }
#mapSwap { white-space: nowrap; }
.map-summary .small { font-size: 0.82em; font-weight: 600; }

/* Week-one fixes */
#mapInfo .std { display: block; font-size: 0.72em; font-weight: 600; opacity: 0.92; }
.map-bar { height: 3.6em; }
.map-keys { bottom: 3.9em; }
.map-goal { position: absolute; left: 0.8em; bottom: 4.1em; display: flex; align-items: center; gap: 0.4em; pointer-events: none;
  background: rgba(20, 24, 40, 0.84); color: #fff; font-weight: 800; font-size: 0.85em; padding: 0.2em 0.8em 0.2em 0.3em; border-radius: 2em; }
.map-goal canvas { width: 2.6em; height: 2.6em; background: #fff4e6; border-radius: 50%; }
.learned { margin: 0.3em 0; font-weight: 700; color: #1864ab; }

/* Week-two: report, save code, assist */
.mini-row { display: flex; gap: 0.4em; margin-top: 0.4em; }
.mini-row button { font-size: 0.85em; padding: 0.4em 0.7em; }
.report-wrap { max-height: 16em; overflow-y: auto; margin: 0.4em 0; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.9em; }
.report-table th, .report-table td { text-align: left; padding: 0.25em 0.4em; border-bottom: 1px solid #e3e7ef; }
.report-table td.num { text-align: right; font-weight: 800; }
.report-table .bar { display: inline-block; height: 0.7em; border-radius: 0.35em; background: #2f9e44; vertical-align: middle; margin-right: 0.4em; }
.report-table .bar.mid { background: #f59f00; }
.report-table .bar.low { background: #e03131; }
.save-code span { display: block; }
.save-code { font: 800 1.2em/1.35 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0; white-space: normal; overflow-wrap: normal; background: #fff4e6; border: 3px dashed var(--accent); border-radius: 0.5em; padding: 0.35em 0.5em; margin: 0.4em 0; text-align: center; }
.load-row { display: flex; flex-direction: column; gap: 0.3em; font-weight: 700; margin: 0.6em 0 0.4em; }
.load-row input { font: 700 1em ui-monospace, Menlo, Consolas, monospace; padding: 0.45em; border: 2px solid #c5ccd8; border-radius: 0.4em; text-transform: uppercase; }
.load-msg { min-height: 1.3em; font-weight: 700; margin: 0.3em 0; }
.load-msg.ok { color: #2f9e44; } .load-msg.bad { color: #c92a2a; }

/* Teacher set start screen */
.free-sub { margin: 0.5em 0 0.25em; font-weight: 900; color: var(--muted); text-align: left; }
.free-grid button { display: block; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; }
.free-grid button:focus-visible .isle { outline: 3px solid var(--focus); outline-offset: 3px; }
.free-grid button:hover .isle { transform: translateY(-0.15em); }
.class-card { text-align: center; }
.class-card h2, .class-card .tag { margin: 0; }
.class-join { display: flex; gap: 0.4em; justify-content: center; }
.class-join[hidden] { display: none; }
#classInput { font: 900 1.6em/1 ui-monospace, Menlo, monospace; letter-spacing: 0.15em; text-transform: uppercase; width: 7.5em; text-align: center;
  border: 3px solid #cfd6e2; border-radius: 0.5em; padding: 0.2em 0.3em; }
#classInput:focus { border-color: var(--accent); outline: none; }
.class-sets { display: flex; flex-direction: column; gap: 0.4em; max-height: 14em; overflow: auto; }
.class-sets:empty { display: none; }
.class-sets button { text-align: left; display: flex; justify-content: space-between; gap: 0.6em; align-items: center; padding: 0.55em 0.9em; }
.class-sets button small { color: var(--muted); font-weight: 600; }
.class-note { font-size: 0.75em !important; }
.set-card { text-align: center; }
.set-kicker { margin: 0; font-weight: 800; color: var(--accent); letter-spacing: 0.02em; }
.set-msg { color: #b42318; font-weight: 700; margin: 0; }
.set-msg:empty { display: none; }
.set-card h2, .set-card .tag { margin: 0; }
.set-card .primary.big, .set-card > .ghost { display: block; margin: 0.3em auto 0; }
.set-report { margin-top: 1em; text-align: left; font-size: 0.9em; }
.set-report summary { cursor: pointer; color: var(--muted); }
.set-reasons { flex-wrap: wrap; margin: 0.6em 0; }
