/* Vocaventure — storybook watercolor look.
   Everything that moves uses only "transform" and "opacity", which the browser
   can animate without redrawing the page. That is what keeps it smooth. */
:root {
  --paper: #fbf5ea;
  --ink: #33214d;
  --ink-soft: #6a5a80;
  --plum: #5b3a8c;
  --lav: #cdbfe8;
  --lav-soft: #ece5f8;
  --gold: #e2a93b;
  --gold-soft: #fbe7b5;
  --rose: #d6628a;
  --good: #3f8f6d;
  --good-soft: #dff0e3;
  --try: #c9793c;
  --try-soft: #fbe8d6;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --blob: 26px 20px 28px 18px / 20px 28px 18px 26px;
  --shadow: 0 12px 30px -16px rgba(51, 33, 77, .45);
  --tile: clamp(30px, 8.6vw, 54px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
/* Paper and soft colour washes, on their own fixed layer so scrolling never repaints them. */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(60vw 44vh at 6% 0%, rgba(205, 191, 232, .6), transparent 70%),
    radial-gradient(52vw 42vh at 100% 10%, rgba(242, 184, 198, .45), transparent 70%),
    radial-gradient(70vw 50vh at 50% 112%, rgba(251, 231, 181, .75), transparent 70%),
    url('/art/paper.webp');
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.12; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }
.ar { font-family: 'Noto Naskh Arabic', 'Segoe UI', Tahoma, sans-serif; direction: rtl; unicode-bidi: isolate; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

@keyframes enter { from { opacity: 0; transform: translateY(14px); } }
@keyframes pop { from { opacity: 0; transform: scale(.5); } }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes float { 0%, 100% { transform: translate3d(0, 10px, 0) rotate(-3deg); } 50% { transform: translate3d(6px, -22px, 0) rotate(3deg); } }
.enter { animation: enter .38s cubic-bezier(.2, .8, .3, 1) both; }

/* ---------- the background painting ---------- */
.scene { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: #a892dc url('/art/scene-wide.webp') center bottom / cover no-repeat; }
.scene::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(51, 33, 77, .12), transparent 30%, transparent 62%, rgba(51, 33, 77, .34)); }
@media (orientation: portrait) { .scene { background-image: url('/art/scene-tall.webp'); } }
.float { position: absolute; height: auto; animation: float 12s ease-in-out infinite; will-change: transform; pointer-events: none; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 80; pointer-events: none; }

.pic { border-radius: 18px 14px 20px 14px; overflow: hidden; background: #f3ecdf; box-shadow: var(--shadow); aspect-ratio: 8 / 5; }
.pic img { width: 100%; height: 100%; display: block; object-fit: cover; }
.avatar { width: 1.9em; height: 1.9em; flex: none; display: inline-block; vertical-align: middle; }

/* ---------- building blocks ---------- */
.card {
  background: #fffaf1 url('/art/paper.webp');
  border-radius: var(--blob);
  box-shadow: var(--shadow);
  border: 1.5px solid rgba(91, 58, 140, .14);
  padding: 22px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 12px 28px;
  border: 0; background: url('/art/swatch-plum.webp') center / 100% 100% no-repeat;
  color: #fff; font-weight: 800; font-size: 1rem; cursor: pointer; text-decoration: none;
  transition: transform .12s ease, opacity .15s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.gold { background-image: url('/art/swatch-gold.webp'); color: var(--ink); }
.btn.ghost { background: rgba(255, 250, 241, .92); color: var(--plum); border: 2px solid rgba(91, 58, 140, .35); border-radius: 16px 12px 18px 12px; min-height: 48px; padding: 8px 20px; }
.btn.small { min-height: 40px; padding: 6px 16px; font-size: .9rem; }
.btn.big { min-height: 70px; font-size: 1.25rem; padding: 14px 40px; }
.btn.ghost.small { min-height: 40px; padding: 4px 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-weight: 800; font-size: .8rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.input {
  width: 100%; min-height: 52px; padding: 10px 16px;
  border: 2px solid rgba(91, 58, 140, .28); border-radius: 16px 12px 16px 12px;
  background: #fffdf8; font-size: 1.05rem;
}
.input::placeholder { color: #b9aec8; }
.input:focus { outline: none; border-color: var(--plum); box-shadow: 0 0 0 4px rgba(205, 191, 232, .7); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 999px; background: var(--lav-soft); color: var(--plum); font-weight: 800; font-size: .85rem; }
.pill.gold { background: var(--gold-soft); color: #7c5410; }
.muted { color: var(--ink-soft); }
.hint { font-size: .88rem; color: var(--ink-soft); }
.stack { display: grid; gap: 14px; }
.stack.tight { gap: 8px; }
.center { text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.center-row { justify-content: center; }
.spacer { flex: 1; }
.notice { background: var(--try-soft); color: #7a4418; padding: 10px 16px; border-radius: 14px; font-weight: 700; text-align: center; }
.gap { display: inline-block; width: 3.4em; height: .9em; border-bottom: 4px solid var(--gold); border-radius: 0 0 6px 6px; margin: 0 .15em; }
.say { width: 1.6em; height: 1.6em; border-radius: 50%; border: 0; background: var(--gold-soft); cursor: pointer; font-size: .7em; vertical-align: middle; }
.say:active { transform: scale(.9); }

.timer { position: relative; height: 20px; border-radius: 999px; background: rgba(91, 58, 140, .15); overflow: hidden; }
.timer i { position: absolute; inset: 0; background: linear-gradient(90deg, #e2a93b, #f6cf70); transform-origin: left; border-radius: 999px; will-change: transform; }
.timer b { position: absolute; right: 10px; top: 0; font-size: .8rem; line-height: 20px; }
.timer.low i { background: linear-gradient(90deg, #d6628a, #f2a0b6); }

/* ---------- answers ---------- */
.options { display: grid; gap: 8px; grid-template-columns: 1fr; }
.options.tf { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  min-height: 78px; padding: 14px 30px; border: 0; cursor: pointer;
  color: #fff; font-weight: 800; font-size: 1.15rem;
  background: center / 100% 100% no-repeat;
  transition: transform .12s ease, opacity .25s;
}
.opt:active { transform: scale(.97); }
.opt .key { display: grid; place-items: center; width: 38px; height: 38px; flex: none; border-radius: 50%; background: rgba(255, 255, 255, .3); font-family: var(--display); }
.tone-plum { background-image: url('/art/swatch-plum.webp'); }
.tone-gold { background-image: url('/art/swatch-gold.webp'); color: var(--ink); }
.tone-rose { background-image: url('/art/swatch-rose.webp'); }
.tone-sage { background-image: url('/art/swatch-sage.webp'); }
.opt.dim { opacity: .3; }
.opt.picked { transform: scale(1.02); }
.opt.right { transform: scale(1.04); }
.opt.right::after { content: '✓'; margin-left: auto; width: 1.7em; height: 1.7em; display: grid; place-items: center; border-radius: 50%; background: #fff; color: var(--good); flex: none; }
.opt .count { margin-left: auto; background: rgba(255, 255, 255, .32); border-radius: 999px; padding: 2px 14px; }
.opt.right:has(.count)::after { margin-left: 10px; }
.answer-box { font-size: 1.35rem; text-align: center; min-height: 64px; }

/* matching by lines */
.match { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 64px; user-select: none; -webkit-user-select: none; }
.m-item.left { touch-action: none; }
.match svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.match path { fill: none; stroke: var(--plum); stroke-width: 5; stroke-linecap: round; }
.match path.live { stroke: var(--gold); stroke-dasharray: 3 9; }
.match path.ok { stroke: var(--good); }
.m-item { display: flex; align-items: center; min-height: 60px; padding: 8px 14px; background: #fffdf8; border: 2.5px solid rgba(91, 58, 140, .35); border-radius: 16px 12px 18px 12px; font-weight: 700; cursor: pointer; position: relative; }
.m-item.left { justify-content: flex-end; text-align: right; font-size: 1.1rem; color: var(--plum); }
.m-item.sel { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.m-item.linked { background: var(--lav-soft); border-color: var(--plum); }
.m-item::after { content: ''; position: absolute; top: 50%; width: 16px; height: 16px; margin-top: -8px; border-radius: 50%; background: var(--plum); border: 3px solid #fffdf8; }
.m-item.left::after { right: -11px; }
.m-item.right::after { left: -11px; }

/* letter tiles: reorder the letters, and Scrabble */
.slots, .rack { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: var(--tile); }
.slots { padding: 10px; border-radius: 16px; background: rgba(91, 58, 140, .08); }
.tile, .slot { width: var(--tile); height: calc(var(--tile) * 1.1); border-radius: 9px; flex: none; }
.tile {
  position: relative; border: 0; padding: 0; cursor: pointer;
  font-family: var(--display); font-weight: 700; font-size: calc(var(--tile) * .56); color: #4a3320;
  background: linear-gradient(160deg, #fdf1cf, #efd7a0);
  box-shadow: inset 0 -4px 0 #d8bb7d, inset 0 2px 0 rgba(255, 255, 255, .7), 0 2px 5px rgba(74, 51, 32, .28);
  transition: transform .1s;
}
.tile.pop { animation: pop .18s ease-out both; }
.tile:active { transform: scale(.9); }
.tile sub { position: absolute; right: 4px; bottom: 5px; font-family: var(--body); font-size: calc(var(--tile) * .22); font-weight: 800; line-height: 1; }
.tile.in { background: linear-gradient(160deg, #fff6d8, #f6dc98); }
.slot { border: 2.5px dashed rgba(91, 58, 140, .4); }
.slot.ghost { border-color: rgba(91, 58, 140, .14); }

/* hangman, played with lanterns */
.lives { display: flex; justify-content: center; gap: 4px; }
.life { width: 44px; height: auto; transition: opacity .4s, transform .4s; }
.life.out { opacity: .16; transform: scale(.8) translateY(6px); }
.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
/* The letters shrink to keep a long word on one line, even on a small phone. */
.cell { width: 1.35em; height: 1.7em; border-bottom: 4px solid var(--ink); font-family: var(--display); font-weight: 700; font-size: clamp(.9rem, calc((min(100vw, 600px) - 110px) / var(--n, 8) / 1.75), 1.7rem); display: grid; place-items: center; text-transform: uppercase; }
.cell.on { border-color: var(--good); animation: pop .2s ease-out; }
.cell.space { border: 0; width: .7em; }
.keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.keycap { min-height: 48px; border-radius: 12px; border: 2px solid rgba(91, 58, 140, .3); background: #fffdf8; font-weight: 800; font-size: 1.1rem; cursor: pointer; padding: 0; transition: transform .1s, opacity .2s; }
.keycap:active { transform: scale(.9); }
.keycap.hit { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.keycap.miss { opacity: .3; }

/* ---------- student phone ---------- */
.phone { max-width: 600px; margin: 0 auto; min-height: 100%; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 14px; }
.phone-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800; }
.phone-top .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.phone-top .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-meta { display: flex; align-items: center; gap: 12px; }
.q-meta .timer { flex: 1; }
.q-meta .pill { flex: none; }
.brand { text-align: center; color: #fff; text-shadow: 0 2px 16px rgba(51, 33, 77, .75); padding: 7vh 0 2vh; }
.brand h1 { font-size: clamp(2.5rem, 11vw, 3.6rem); font-style: italic; }
.brand p { font-weight: 800; }
.link-light { color: #fff; font-weight: 800; text-shadow: 0 1px 8px rgba(51, 33, 77, .8); background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 8px; }
.pin-input { text-align: center; font-size: 2rem; letter-spacing: .25em; font-weight: 700; font-family: var(--display); min-height: 68px; }
.name-input { font-size: 1.3rem; font-weight: 800; min-height: 60px; }
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatars button { border: 0; background: none; padding: 3px; border-radius: 50%; cursor: pointer; transition: transform .12s; }
.avatars button .avatar { width: 100%; height: auto; display: block; }
.avatars button.on { transform: scale(1.12); box-shadow: 0 0 0 4px var(--gold); }
.big-avatar .avatar { width: 96px; height: 96px; }
.big-lantern { width: 90px; margin: 0 auto; animation: float 5s ease-in-out infinite; }
.q-prompt { font-family: var(--display); font-size: clamp(1.3rem, 5.2vw, 1.75rem); font-weight: 600; line-height: 1.25; text-align: center; }
.skip { border: 0; background: none; color: var(--ink-soft); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 10px; justify-self: center; }
.skip:hover { color: var(--plum); }
.result { text-align: center; }
.result.good { background: var(--good-soft); border-color: rgba(63, 143, 109, .4); }
.result.try { background: var(--try-soft); border-color: rgba(201, 121, 60, .4); }
.result h2 { font-size: 2.1rem; }
.the-answer { color: var(--plum); font-size: 1.2em; }
.word-card { background: #fffdf8; border-radius: 18px; padding: 14px 18px; border: 2px dashed rgba(91, 58, 140, .3); }
.word-card .w { font-family: var(--display); font-size: 1.7rem; font-weight: 600; color: var(--plum); }
.word-card .ar { font-size: 1.45rem; color: #7c5410; }
.offline { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 18px; border-radius: 999px; font-weight: 700; font-size: .9rem; z-index: 50; }
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px; background: #fffdf8; font-weight: 800; }
.rank-row .n { width: 1.6em; font-family: var(--display); color: var(--ink-soft); }
.rank-row .s { margin-left: auto; color: var(--plum); font-variant-numeric: tabular-nums; }
.rank-row.me { background: var(--gold-soft); }
.roster { max-height: 50vh; overflow: auto; }
.roster .btn { margin-left: auto; }
.rank-row .time { color: var(--ink-soft); font-size: .85em; font-variant-numeric: tabular-nums; }
.rank-row .time + .s { margin-left: 12px; }
.rank-row:has(.time) .time { margin-left: auto; }
.finish-time { font-family: var(--display); font-size: 2.6rem; font-weight: 600; color: var(--plum); font-variant-numeric: tabular-nums; }
#clock { font-variant-numeric: tabular-nums; }
.rank-row .gain { color: var(--good); font-size: .85em; }

/* ---------- teacher: library, editor, word list ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 28px 22px 90px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.logo { font-size: clamp(2.2rem, 4.4vw, 3.2rem); font-style: italic; color: var(--plum); }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.quiz-card { display: grid; gap: 12px; padding: 0; overflow: hidden; }
.quiz-card .pic { border-radius: 0; box-shadow: none; aspect-ratio: 16 / 9; }
.quiz-card .body { padding: 2px 20px 20px; display: grid; gap: 10px; }
.quiz-card h2 { font-size: 1.4rem; }
.restore { margin-top: 22px; }
.title-card { margin-bottom: 20px; }
.title-input { font-family: var(--display); font-size: 1.6rem; min-height: 62px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--lav-soft); color: var(--plum); font-weight: 800; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--lav); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

.q-edit { padding: 0; margin-bottom: 12px; overflow: hidden; }
.q-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.q-edit.closed .q-head:hover { background: rgba(205, 191, 232, .28); }
.q-head .num { font-family: var(--display); font-size: 1.4rem; color: var(--plum); width: 1.6em; flex: none; text-align: center; }
.q-head .pill { flex: none; }
.q-sum { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-ans { flex: none; max-width: 24%; color: var(--good); font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-head .tools { flex: none; flex-wrap: nowrap; gap: 6px; }
.q-form { padding: 6px 20px 22px; border-top: 1.5px dashed rgba(91, 58, 140, .2); }
.q-form summary { cursor: pointer; font-weight: 800; color: var(--ink-soft); }
.feedback { margin-top: 12px; }
.two { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.opt-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.opt-row input[type=radio], .switch input { width: 24px; height: 24px; accent-color: var(--good); flex: none; }
.pair-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 8px; align-items: center; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs button { width: 96px; padding: 0; border: 3px solid transparent; border-radius: 12px; overflow: hidden; background: #fff; cursor: pointer; aspect-ratio: 8 / 5; font-size: .75rem; font-weight: 800; color: var(--ink-soft); }
.thumbs button.on { border-color: var(--gold); }
.thumbs img { width: 100%; height: 100%; display: block; object-fit: cover; }
.undo-bar { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 10px 16px; margin-bottom: 12px; background: var(--gold-soft); border-radius: 14px; font-weight: 700; animation: enter .3s both; }
.add-bar { padding: 20px; border: 2.5px dashed rgba(91, 58, 140, .3); border-radius: var(--blob); margin-top: 20px; display: grid; gap: 14px; }
.type-grid, .choice-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.type-pick, .choice { display: grid; gap: 4px; text-align: left; padding: 14px 16px; border-radius: 16px 12px 18px 12px; border: 2px solid rgba(91, 58, 140, .25); background: #fffdf8; cursor: pointer; transition: transform .12s, border-color .12s; }
.type-pick:hover, .choice:hover { transform: translateY(-2px); border-color: var(--plum); }
.type-pick small, .choice small { color: var(--ink-soft); font-size: .85rem; }
.choice-grid { grid-template-columns: 1fr 1fr; }
.choice-list { display: grid; gap: 10px; }
.choice { position: relative; }
.choice.usual { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.choice .tag { position: absolute; top: -10px; right: 14px; background: var(--gold); color: var(--ink); font-size: .72rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; }
.pace-pick { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.pace { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 16px 12px 18px 12px; border: 2px solid rgba(91, 58, 140, .25); background: #fffdf8; cursor: pointer; }
.pace.on { border-color: var(--plum); background: var(--lav-soft); }
.pace input { width: 22px; height: 22px; accent-color: var(--plum); flex: none; margin-top: 2px; }
.pace span { display: grid; gap: 2px; }
.pace small { color: var(--ink-soft); font-size: .85rem; }
.choice { padding: 20px 18px; }
.choice b { font-size: 1.12rem; }
.options-box summary { cursor: pointer; font-weight: 800; color: var(--plum); margin-bottom: 12px; }
.switch { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.words { display: grid; gap: 8px; }
.w-row { display: grid; grid-template-columns: 1fr 1.4fr .9fr 1.8fr 40px; gap: 8px; align-items: center; }
.w-head span { font-weight: 800; font-size: .78rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
dialog { border: 0; border-radius: var(--blob); padding: 28px; max-width: 600px; width: calc(100% - 32px); background: var(--paper) url('/art/paper.webp'); box-shadow: 0 30px 80px -20px rgba(51, 33, 77, .7); color: var(--ink); animation: enter .25s both; }
dialog::backdrop { background: rgba(51, 33, 77, .55); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 700; z-index: 90; max-width: calc(100% - 32px); text-align: center; }

/* ---------- teacher: big screen ---------- */
.stage { min-height: 100vh; display: flex; flex-direction: column; padding: clamp(12px, min(2.2vw, 3vh), 34px); gap: clamp(10px, 2vh, 26px); font-size: clamp(16px, min(1.55vw, 2.9vh), 30px); }
.stage-top, .stage-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
/* The teacher's main button stays in reach even when a full class fills the screen. */
.stage-foot { position: sticky; bottom: 0; z-index: 5; padding: 10px 0 6px; }
.stage-foot::before { content: ''; position: absolute; inset: -14px -40px -40px; z-index: -1; background: linear-gradient(rgba(251, 245, 234, 0), var(--paper) 30%); pointer-events: none; }
#scene:not([hidden]) ~ #app .stage-foot::before { display: none; }
.stage .pill { font-size: .78em; }
.stage-main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: clamp(10px, 2.4vh, 30px); min-height: 0; }
.lobby { display: grid; grid-template-columns: minmax(280px, 430px) 1fr; gap: clamp(18px, 3vw, 46px); align-items: center; flex: 1; }
.lobby .join h1, .ready h1 { font-size: 2.1em; font-style: italic; color: var(--plum); }
.lobby .join { gap: 1.2vh; padding: 2.4vh 22px; }
.lobby .pin { font-family: var(--display); font-size: clamp(2.6rem, min(6.4vw, 11vh), 6rem); font-weight: 700; letter-spacing: .06em; line-height: 1; }
.lobby .qr { width: min(100%, 290px, 36vh); aspect-ratio: 1; background: #fffdf8; border-radius: 24px; padding: 12px; margin: 0 auto; }
.lobby .qr img { width: 100%; height: 100%; display: block; }
.stage .count-pill { font-size: 1em; }
.ready { max-width: 820px; margin: 0 auto; padding: 1.6em; }
.players { display: flex; flex-wrap: wrap; gap: 12px; align-content: flex-start; justify-content: center; }
.player { display: inline-flex; align-items: center; gap: 8px; padding: 6px 18px 6px 6px; background: rgba(255, 250, 241, .96); border-radius: 999px; font-weight: 800; box-shadow: var(--shadow); border: 0; cursor: pointer; animation: pop .3s cubic-bezier(.3, 1.5, .5, 1) both; font-size: 1em; color: var(--ink); }
.player small { color: var(--ink-soft); font-weight: 700; }
.player.off { opacity: .45; }
.players.many { gap: 8px; }
.players.many .player { font-size: .78em; padding: 4px 12px 4px 4px; }
.player.still { cursor: default; }
button.player:hover span { text-decoration: line-through; }
.waiting { background: rgba(255, 250, 241, .94); }
.pace-note { color: #fff; font-weight: 800; text-shadow: 0 1px 10px rgba(51, 33, 77, .8); }
.stage-main:has(.race) { justify-content: flex-start; }
.race-title { text-align: center; font-size: 1.7em; font-style: italic; color: var(--plum); }
.race { display: grid; gap: .6em; grid-template-columns: repeat(auto-fit, minmax(15em, 24em)); justify-content: center; align-content: start; }
.race[data-size=medium] { font-size: .86em; grid-template-columns: repeat(auto-fit, minmax(13em, 18em)); }
.race[data-size=small] { font-size: .72em; gap: .4em; grid-template-columns: repeat(auto-fill, minmax(11.5em, 1fr)); }
.race[data-size=small] .racer { padding: .4em .6em; gap: .45em; }
.race[data-size=small] .racer .avatar { width: 1.9em; height: 1.9em; }
.racer { display: flex; align-items: center; gap: .6em; padding: .5em .8em; background: #fffaf1 url('/art/paper.webp'); border-radius: 18px 14px 20px 14px; border: 1.5px solid rgba(91, 58, 140, .14); animation: pop .3s both; }
.racer .avatar { width: 2.2em; height: 2.2em; }
button.racer { font: inherit; color: inherit; text-align: left; cursor: pointer; transition: transform .12s, border-color .12s; }
button.racer:hover { transform: translateY(-2px); border-color: var(--plum); }
.racer.stuck { border-color: var(--try); box-shadow: 0 0 0 3px var(--try-soft); order: -1; }      /* students who need help come first */
.racer.stuck .r-info { color: #a45a1c; }
.racer.off { opacity: .5; }
.racer.finished { background: var(--good-soft); border-color: rgba(63, 143, 109, .4); }
.r-main { flex: 1; min-width: 0; display: grid; gap: .3em; }
.r-top { display: flex; justify-content: space-between; gap: .5em; font-size: .8em; }
.r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-info { color: var(--ink-soft); font-weight: 800; font-size: .74em; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.racer.finished .r-info { color: var(--good); }
.r-segs { display: flex; gap: 2px; height: .55em; }
.r-segs i { flex: 1; min-width: 0; border-radius: 999px; background: rgba(91, 58, 140, .14); }
.r-segs i.ok { background: var(--good); }
.r-segs i.no { background: var(--try); }
.r-segs i.part { background: var(--gold); }
.r-segs i.now { background: var(--plum); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }
.r-bar { height: .55em; border-radius: 999px; background: rgba(91, 58, 140, .14); overflow: hidden; }
.r-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #8563c4, #e2a93b); transform-origin: left; transform: scaleX(0); transition: transform .5s cubic-bezier(.2, .8, .3, 1); }
.racer.finished .r-bar i { background: var(--good); }
.r-score { font-weight: 800; color: var(--plum); font-variant-numeric: tabular-nums; flex: none; font-size: .9em; }
.turn { font-size: .9em !important; background: var(--gold-soft); color: #7c5410; }
.verdict { display: inline-block; padding: .3em 1.2em; border-radius: 999px; font-family: var(--display); font-size: 1.3em; font-weight: 600; animation: pop .3s both; }
.verdict.good { background: var(--good-soft); color: var(--good); }
.verdict.try { background: var(--try-soft); color: #9a5a22; }
.stage .q-prompt { font-size: clamp(1.5rem, min(3.4vw, 6vh), 3.4rem); }
.stage .pic { width: min(100%, 56vh); margin: 0 auto; }
.stage .explain.card { padding: .5em 1.2em; }
.stage .explain .w { font-size: 1.5em; }
.stage .q-body { display: grid; gap: clamp(14px, 2vw, 30px); align-items: center; }
.stage .q-body.with-pic { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.stage .options { grid-template-columns: 1fr 1fr; gap: .5em; }
.stage .opt { font-size: 1.15em; min-height: 3.8em; padding: .7em 1.6em; }
.stage div.opt { cursor: default; }
.stage .opt .key { width: 1.8em; height: 1.8em; }
.stage .match { max-width: 1000px; margin: 0 auto; width: 100%; gap: 14px 120px; }
.stage .m-item { font-size: 1em; }
.stage .m-item.left { font-size: 1.05em; }
.stage { --tile: clamp(46px, 5.2vw, 96px); }
.stage .cell { font-size: clamp(2rem, 4.4vw, 4.4rem); }
.stage .life { width: clamp(46px, 4.4vw, 80px); }
.stage .keys { grid-template-columns: repeat(13, 1fr); max-width: 1100px; margin: 0 auto; width: 100%; }
.stage .keycap { min-height: 2.4em; font-size: 1em; }
.stage .answer-box { font-size: 1.4em; min-height: 2.4em; max-width: 800px; margin: 0 auto; }
.stage #typed { justify-items: center; }
.stage .hint { font-size: .8em; }
.type-hint { font-size: 1.2em; }
.explain { display: grid; gap: 6px; text-align: center; }
.explain .w { font-family: var(--display); font-size: 1.8em; color: var(--plum); font-weight: 600; }
.explain .ar { font-size: .9em; color: #7c5410; }
.answers-list { max-width: 700px; margin: 0 auto; width: 100%; }
.board { display: grid; gap: 10px; }
.finale { text-align: center; font-size: min(2.4em, 8vh); font-style: italic; color: #fff; text-shadow: 0 2px 16px rgba(51, 33, 77, .75); }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: clamp(10px, 2vw, 28px); }
.podium .step { display: grid; justify-items: center; gap: 8px; width: clamp(130px, 20vw, 260px); text-align: center; font-weight: 800; animation: enter .7s both; color: #fff; text-shadow: 0 1px 10px rgba(51, 33, 77, .8); }
.podium .step .pill { text-shadow: none; }
.podium .name { background: rgba(255, 250, 241, .95); color: var(--ink); text-shadow: none; padding: 2px 14px; border-radius: 999px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .block { width: 100%; border-radius: 22px 22px 0 0; background: center / 100% 118% no-repeat url('/art/swatch-plum.webp'); color: #fff; font-family: var(--display); font-size: 2.4em; display: grid; place-items: center; }
.podium .p1 .block { height: min(7em, 26vh); background-image: url('/art/swatch-gold.webp'); color: var(--ink); text-shadow: none; }
.podium .p2 .block { height: min(5.2em, 19vh); }
.podium .p3 .block { height: min(3.8em, 14vh); background-image: url('/art/swatch-rose.webp'); }
.podium .p1 { animation-delay: .6s; } .podium .p2 { animation-delay: .3s; }
.podium .avatar { width: 3em; height: 3em; }
.tricky { max-width: 900px; margin: 0 auto; width: 100%; font-size: .8em; }
.stat-bar { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.stat-bar .label { min-width: 9em; }
.stat-bar .bar { flex: 1; height: 16px; border-radius: 999px; background: rgba(91, 58, 140, .14); overflow: hidden; }
.stat-bar .bar i { display: block; height: 100%; background: var(--good); border-radius: 999px; }
.stat-bar .bar i.low { background: var(--try); }
.teams { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 12px; }
.teams .pill { font-size: 1em; padding: 8px 20px; }

@media (max-width: 760px) {
  .lobby { grid-template-columns: 1fr; }
  .stage .q-body.with-pic, .stage .options, .two, .choice-grid, .pace-pick { grid-template-columns: 1fr; }
  .stage .options.tf { grid-template-columns: 1fr 1fr; }
  .match { gap: 10px 44px; }
  .match path { stroke-width: 4; }
  .phone .m-item { min-height: 54px; padding: 6px 12px; font-size: .95rem; }
  .phone .m-item.left { font-size: 1rem; }
  .q-ans, .q-head .pill { display: none; }
  .w-row { grid-template-columns: 1fr 1fr 40px; }
  .w-row .input:nth-child(3), .w-row .input:nth-child(4), .w-head { display: none; }
  .stage .keys { grid-template-columns: repeat(7, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .r-segs i.now { animation: none !important; }
  .enter, .player, .tile.pop, .cell.on, .verdict, dialog, .podium .step, .float, .big-lantern { animation: none !important; }
  .btn, .opt, .life { transition: none !important; }
}

/* ---------- home: student or teacher ---------- */
.home { max-width: 900px; margin: 0 auto; min-height: 100%; padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(36px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 18px; }
.home .brand { padding: 5vh 0 1vh; }
.home .brand h1 { font-size: clamp(2.8rem, 10vw, 4.6rem); }
.home .brand p { font-size: clamp(1rem, 3vw, 1.3rem); }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.role { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.role-pic { width: 92px; height: 92px; border-radius: 50%; box-shadow: 0 0 0 4px var(--gold-soft), var(--shadow); }
.role h2 { font-size: 1.7rem; color: var(--plum); }
.role p { margin: 0; }
.role form { width: 100%; display: grid; gap: 10px; margin-top: auto; }
.role > .btn { width: 100%; margin-top: auto; text-decoration: none; }
.role .notice { margin: 0; }
.back-in { align-self: center; text-decoration: none; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; align-items: center; gap: 10px; background: rgba(255, 250, 241, .92); border-radius: 16px 12px 18px 12px; padding: 10px 14px; font-weight: 700; font-size: .95rem; }
.steps b { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--gold); font-family: var(--display); }
.home-foot { text-align: center; color: #fff; font-weight: 700; text-shadow: 0 1px 8px rgba(51, 33, 77, .8); margin: 0; }
.home-link { display: inline-block; color: var(--plum); font-weight: 800; text-decoration: none; padding: 4px 0; }
.home-link:hover { text-decoration: underline; }
.keep { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px; margin-top: 26px; }
.keep > div:first-child { flex: 1 1 340px; }
.keep h2 { font-size: 1.25rem; margin-bottom: 4px; }
.keep p { margin: 0; }
@media (max-width: 700px) { .roles, .steps { grid-template-columns: 1fr; } .home .brand { padding-top: 2vh; } }

/* ---------- teacher: students and questions while the class plays at its own speed ---------- */
.tabs { display: flex; justify-content: center; gap: .5em; }
.tab { font: inherit; font-weight: 800; font-size: .95em; padding: .45em 1.4em; border-radius: 999px; border: 2px solid rgba(91, 58, 140, .3); background: rgba(255, 250, 241, .92); color: var(--plum); cursor: pointer; }
.tab.on { background: var(--plum); color: #fff; border-color: var(--plum); }
.race-hint { font-size: .8em; margin: 0; font-weight: 700; }
.race[hidden], .browse[hidden], .race-hint[hidden] { display: none; }
.browse { display: grid; gap: .8em; }
.q-nav { display: flex; align-items: center; justify-content: center; gap: .6em; }
.q-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: .5em .4em; padding-top: .4em; }
.q-step { position: relative; font: inherit; font-weight: 800; font-size: .85em; min-width: 2.5em; height: 2.5em; border-radius: 12px 10px 13px 10px; border: 2px solid rgba(91, 58, 140, .25); background: #fffdf8; color: var(--plum); cursor: pointer; }
.q-step:hover { border-color: var(--plum); }
.q-step.on { background: var(--plum); color: #fff; border-color: var(--plum); }
.q-step small { position: absolute; top: -.7em; right: -.5em; min-width: 1.6em; padding: 0 .3em; border-radius: 999px; background: var(--gold); color: var(--ink); font-size: .72em; line-height: 1.6em; }
.q-step small:empty { display: none; }
.q-step.stuck small { background: var(--try); color: #fff; }
.browse-main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(15em, 1fr); gap: .8em; align-items: start; }
.browse-q { justify-items: center; }
.browse-q > * { width: 100%; }
.browse-q > .pill { width: auto; }
.stage .browse .q-prompt { font-size: 1.5em; margin: 0; }
.stage .browse .pic { width: min(100%, 38vh); }
.browse-note { margin: 0; font-size: .9em; }
.browse-side h3 { font-size: 1.05em; }
.browse-side p { margin: 0; font-size: .85em; }
#b-here { max-height: 38vh; overflow-y: auto; }
.here { display: flex; align-items: center; gap: .5em; font-weight: 700; font-size: .88em; }
.here .avatar { width: 1.8em; height: 1.8em; flex: none; }
.here span:nth-of-type(1) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.here span:last-child { margin-left: auto; flex: none; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.here.stuck span:last-child { color: #a45a1c; font-weight: 800; }
@media (max-width: 900px) { .browse-main { grid-template-columns: 1fr; } }
