:root {
  --bg: #0b1220; --panel: #151f33; --panel2: #1e2a44; --line: #2a3a5c;
  --text: #f1f5f9; --muted: #94a3b8; --accent: #38bdf8; --ok: #22c55e; --bad: #ef4444; --warn: #f59e0b;
  --radius: 18px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 18px; line-height: 1.35; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 2rem; } h2 { font-size: 1.5rem; } h3 { font-size: 1.15rem; color: var(--muted); font-weight: 600; }
p { margin: .3em 0; }
small { color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: .75rem; }

button, .btn {
  font: inherit; font-weight: 600; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: .6em 1.1em; cursor: pointer; transition: background .15s, transform .05s;
}
button:hover { background: #253658; } button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #06283d; border-color: transparent; }
button.primary:hover { background: #5cc8f5; }
button.ok { background: var(--ok); color: #052e16; border-color: transparent; }
button.bad { background: var(--bad); color: #fff; border-color: transparent; }
button.ghost { background: transparent; }
button.big { font-size: 1.4rem; padding: .8em 1.6em; border-radius: 16px; }
button.small { font-size: .85rem; padding: .35em .7em; border-radius: 9px; }

input, select, textarea {
  font: inherit; color: var(--text); background: #0f172a; border: 2px solid var(--line); border-radius: 12px; padding: .55em .8em; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=color] { padding: 0; width: 2.6em; height: 2.6em; border-radius: 10px; }
input[type=checkbox] { width: 1.3em; height: 1.3em; }
label { display: block; font-size: .95rem; color: var(--muted); margin-bottom: .25em; }
.field { margin-bottom: .9rem; }
.field label { font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.3rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; border-left: 8px solid var(--c, var(--accent)); }

.badge { display: inline-flex; align-items: center; gap: .4em; padding: .25em .7em; border-radius: 999px; font-weight: 700; background: var(--c, var(--panel2)); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.dot { width: .7em; height: .7em; border-radius: 50%; background: var(--bad); display: inline-block; }
.dot.on { background: var(--ok); }

/* toast */
#toast { position: fixed; left: 50%; bottom: 2rem; transform: translate(-50%, 1rem); background: #fff; color: #0b1220; font-weight: 700; padding: .7em 1.2em; border-radius: 12px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* scoreboard */
.scoreboard { display: grid; gap: .5rem; }
.srow { display: grid; grid-template-columns: 2.2em 1fr 3fr 3em; align-items: center; gap: .8em; padding: .5em .8em; border-radius: 12px; background: var(--panel2); border-left: 8px solid var(--c); }
.srow .rank { font-weight: 800; color: var(--muted); }
.srow .tname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow .bar { height: .9em; background: #0f172a; border-radius: 999px; overflow: hidden; }
.srow .bar i { display: block; height: 100%; background: var(--c); border-radius: 999px; transition: width .4s; }
.srow .score { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard.compact .srow { padding: .3em .6em; font-size: .9rem; }

/* results */
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.results li { display: grid; grid-template-columns: 2.4em 1fr auto auto; gap: .8em; align-items: center; padding: .6em .9em; border-radius: 12px; background: var(--panel2); border-left: 8px solid var(--c); }
.results .medal { font-size: 1.3em; }
.results .tname { font-weight: 700; }
.results .detail { color: var(--muted); font-variant-numeric: tabular-nums; }
.results .detail small { display: block; color: var(--text); }
.results .pts { font-weight: 800; color: var(--ok); }
.results li.ineligible { opacity: .5; }

/* ---------- team & wall shared ---------- */
.screen { min-height: 100vh; display: flex; flex-direction: column; padding: 1.2rem 1.5rem; gap: 1rem; }
.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar .title { font-weight: 800; font-size: 1.2rem; }
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1rem; }
.huge { font-size: clamp(3rem, 14vw, 10rem); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.timer { font-size: clamp(2rem, 7vw, 5rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.instructions { max-width: 48rem; font-size: 1.25rem; color: var(--muted); }
.instructions b { color: var(--text); }

/* typing */
.chunk { font-size: clamp(1.6rem, 4.2vw, 3rem); font-weight: 600; line-height: 1.4; max-width: 60rem; word-wrap: break-word; letter-spacing: .01em; }
.chunk .c { border-radius: 4px; }
.chunk .c.ok { color: var(--ok); }
.chunk .c.err { color: #fff; background: var(--bad); }
.chunk .c.cur { box-shadow: inset 0 -4px 0 var(--accent); }
.chunk.prefix-bad { color: #fca5a5; }
.typing-input { font-size: clamp(1.4rem, 3.6vw, 2.4rem); padding: .6em .9em; max-width: 60rem; text-align: center; }
.typing-input.wrong { border-color: var(--bad); animation: shake .3s; }
.typing-input.good { border-color: var(--ok); }
@keyframes shake { 0%,100% { transform: translateX(0);} 25% { transform: translateX(-8px);} 75% { transform: translateX(8px);} }
.progress-pill { font-size: 1.3rem; color: var(--muted); font-weight: 700; }

/* sentence */
.words { display: flex; flex-wrap: wrap; gap: .5em; justify-content: center; max-width: 60rem; }
.word { background: var(--panel2); border: 2px solid var(--line); border-radius: 12px; padding: .3em .7em; font-size: clamp(1.4rem, 3.5vw, 2.4rem); font-weight: 700; }
.word.ghost { opacity: .35; border-style: dashed; }
.word-input { font-size: clamp(1.4rem, 3.6vw, 2.4rem); max-width: 28rem; text-align: center; }

.helpers { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; max-width: 60rem; }
.chip { font: inherit; font-size: 1.15rem; font-weight: 700; color: #fde68a; background: rgba(250,204,21,.12); border: 2px solid rgba(250,204,21,.45); border-radius: 999px; padding: .25em .8em; }
button.chip { cursor: pointer; } button.chip:hover { background: rgba(250,204,21,.25); }
.word.helper { border-color: #facc15; color: #fde68a; }
.hw { color: #fde68a; }
.pausedtag { position: absolute; left: 0; right: 0; bottom: 20%; text-align: center; font-size: 1.8rem; font-weight: 800; color: #fff; background: rgba(11,18,32,.55); padding: .3em 0; }
.scene .doll.paused { filter: grayscale(.2); }

/* math */
.question { font-size: clamp(2.4rem, 8vw, 6rem); font-weight: 800; line-height: 1.15; }
.answer-input { font-size: clamp(2rem, 6vw, 4rem); max-width: 18rem; text-align: center; font-variant-numeric: tabular-nums; }
.levels { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
.levels button { font-size: 1.5rem; padding: 1em 1.4em; min-width: 11rem; }
.levels button small { display: block; color: inherit; opacity: .75; font-size: .75rem; margin-top: .3em; }
.flash { font-size: 2rem; font-weight: 800; padding: .4em 1em; border-radius: 14px; }
.flash.ok { background: rgba(34,197,94,.2); color: var(--ok); }
.flash.bad { background: rgba(239,68,68,.2); color: #fca5a5; }

/* ---------- wall ---------- */
.wall-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; }
.lane { display: grid; grid-template-columns: 14rem 1fr 8rem; gap: 1.2rem; align-items: center; padding: 1.1rem 1.4rem; background: var(--panel); border-radius: var(--radius); border-left: 12px solid var(--c); }
.lane .tname { font-size: 2.1rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane .track { height: 2.6rem; background: #0f172a; border-radius: 999px; overflow: hidden; position: relative; }
.lane .track i { display: block; height: 100%; background: var(--c); border-radius: 999px; transition: width .3s; }
.lane .track span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; text-shadow: 0 1px 2px #000; }
.lane .stat { font-size: 2rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.lane.finished .stat { color: var(--ok); }
.wcard { padding: 1rem 1.2rem; background: var(--panel); border-radius: var(--radius); border-left: 10px solid var(--c); min-height: 9rem; display: flex; flex-direction: column; gap: .5rem; }
.wcard .head { display: flex; align-items: center; gap: .8rem; }
.wcard .tname { font-size: 1.9rem; font-weight: 800; }
.wcard .sentence { font-size: 1.9rem; font-weight: 600; line-height: 1.3; }
.wcard .sentence.hidden-words { color: var(--muted); letter-spacing: .1em; }
.wcard .bigstat { font-size: 3rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.wcard .sub { color: var(--muted); font-weight: 600; }
.wcard .tag { margin-left: auto; font-weight: 800; padding: .2em .6em; border-radius: 8px; background: var(--panel2); }
.wcard .tag.done { background: var(--ok); color: #052e16; }
.wcard .tag.invalid { background: var(--bad); color: #fff; }
.wcard .tag.ok { background: rgba(34,197,94,.25); color: var(--ok); }
.wcard .tag.bad { background: rgba(239,68,68,.25); color: #fca5a5; }
.countdown-overlay { position: fixed; inset: 0; background: rgba(11,18,32,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 40; gap: 1rem; }
.joinbox { display: inline-flex; gap: 1.5rem; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1.4rem; }
.joinbox .code { font-size: 2.2rem; font-weight: 900; letter-spacing: .25em; color: var(--accent); }

/* typing cars */
.lane .road { position: relative; height: 72px; background: #334155; border-radius: 14px; overflow: visible;
  background-image: repeating-linear-gradient(90deg, transparent 0 40px, #e2e8f0 40px 70px); background-size: 100% 4px; background-repeat: no-repeat; background-position: 0 center; }
.lane .road .finish { position: absolute; right: 0; top: -6px; width: 22px; height: 84px; border-radius: 4px;
  background-image: linear-gradient(45deg, #0b1220 25%, transparent 25%, transparent 75%, #0b1220 75%), linear-gradient(45deg, #0b1220 25%, #f8fafc 25%, #f8fafc 75%, #0b1220 75%); background-size: 11px 11px; background-position: 0 0, 5.5px 5.5px; background-color: #f8fafc; }
.lane .road .car { position: absolute; top: 2px; width: 120px; height: 68px; transition: left .35s ease-out; filter: drop-shadow(0 4px 4px rgba(0,0,0,.5)); }
.lane .road .car.done { animation: bounce .6s ease-in-out infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-8px); } }

/* memory blocks */
.blocks { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; }
.block { width: 3.2rem; height: 3.2rem; border-radius: 12px; border: 3px solid rgba(255,255,255,.15); box-shadow: inset 0 -6px 0 rgba(0,0,0,.25); }
.blocks.big .block { width: 5.5rem; height: 5.5rem; }
.block.ghost { background: transparent; border: 3px dashed var(--line); box-shadow: none; }
.block.ok { outline: 4px solid var(--ok); outline-offset: 2px; }
.block.bad { outline: 4px solid var(--bad); outline-offset: 2px; opacity: .6; }
.blocks.wrong { animation: shake .3s; }
.palette { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.swatch { width: 7rem; height: 7rem; border-radius: 20px; border: 4px solid rgba(255,255,255,.2); box-shadow: inset 0 -10px 0 rgba(0,0,0,.25); }
.swatch:active { transform: scale(.94); }
.flashbox { width: min(60vh, 70vw); aspect-ratio: 1; border-radius: 32px; display: flex; align-items: center; justify-content: center; font-size: clamp(4rem, 18vw, 14rem); font-weight: 900; border: 6px dashed var(--line); transition: background .08s; }

/* red light, green light */
.scene { position: relative; height: 62vh; min-height: 24rem; border-radius: var(--radius); overflow: hidden; transition: background .4s;
  background: linear-gradient(#7dd3fc 0 58%, #86efac 58% 100%); }
.scene.red { background: linear-gradient(#fda4af 0 58%, #a3b18a 58% 100%); }
.scene .sun { position: absolute; left: 6%; top: 8%; width: 7rem; height: 7rem; border-radius: 50%; background: #fde68a; box-shadow: 0 0 60px #fde68a; }
.scene .tree { position: absolute; right: 10%; top: 10%; width: 12rem; height: 48%; }
.scene .tree .trunk { position: absolute; left: 45%; bottom: 0; width: 10%; height: 55%; background: #7c4a1e; border-radius: 6px; }
.scene .tree .crown { position: absolute; left: 0; top: 0; width: 100%; height: 60%; background: #15803d; border-radius: 50% 50% 45% 45%; }
.scene .doll { position: absolute; left: 50%; bottom: 36%; height: 60%; width: auto; aspect-ratio: 2 / 3; transform: translateX(-50%); transform-style: preserve-3d; transition: transform .45s cubic-bezier(.4,0,.2,1); }
.scene .doll svg, .scene .doll img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: bottom; backface-visibility: hidden; }
.scene .doll svg.back, .scene .doll img.back { transform: rotateY(180deg); }
.scene .doll.back { transform: translateX(-50%) rotateY(180deg); }
.scene .doll .eye { fill: #ef4444; filter: drop-shadow(0 0 6px #ef4444); }
.scene .finishline { position: absolute; left: 0; right: 0; bottom: 34%; height: 10px; background: repeating-linear-gradient(90deg, #0b1220 0 24px, #f8fafc 24px 48px); }
.scene .lighttext { position: absolute; left: 0; right: 0; bottom: 10%; text-align: center; font-size: clamp(3rem, 9vw, 7rem); font-weight: 900; letter-spacing: .06em; color: #052e16; text-shadow: 0 4px 0 rgba(255,255,255,.5); }
.scene.red .lighttext { color: #7f1d1d; }
.scene .scoreline { position: absolute; left: 0; right: 0; bottom: 3%; text-align: center; font-size: 1.6rem; font-weight: 700; color: #0b1220; }
.scene #sndBtn { position: absolute; right: 1rem; top: 1rem; }
.rgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: .8rem; }
.rcard { display: flex; align-items: center; gap: 1rem; background: var(--panel); border-left: 10px solid var(--c); border-radius: 14px; padding: .7rem 1rem; }
.rcard .tname { flex: 1; font-size: 1.3rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcard .n { font-size: 2.2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.rcard .n small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.rcard .n.ok { color: var(--ok); } .rcard .n.bad { color: #fca5a5; }
.light { font-size: clamp(2.5rem, 9vw, 6rem); font-weight: 900; padding: .3em 1em; border-radius: 24px; color: #052e16; background: var(--ok); transition: background .3s; }
.light.red { background: var(--bad); color: #fff; }
.cross { font-size: clamp(2rem, 7vw, 4.5rem); font-weight: 900; padding: .6em 1.2em; border-radius: 32px; background: var(--accent); color: #06283d; border: none; box-shadow: 0 10px 0 #0e7490; }
.cross:active { transform: translateY(6px); box-shadow: 0 4px 0 #0e7490; }
.cross:disabled { background: var(--ok); color: #052e16; box-shadow: 0 10px 0 #15803d; opacity: 1; }

/* ---------- host ---------- */
.host body, body.host { font-size: 16px; }
.hostwrap { max-width: 64rem; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.hostbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.hostbar h1 { font-size: 1.3rem; margin: 0; }
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; border: none; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); padding: .6em 1em; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.teamrow { display: grid; grid-template-columns: 2.6em 1fr 5em auto; gap: .6rem; align-items: center; padding: .5rem .7rem; background: var(--panel2); border-radius: 12px; border-left: 8px solid var(--c); }
.teamrow .score { font-weight: 800; text-align: center; font-size: 1.2rem; }
.teamrow .actions { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }
.gamepick { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .8rem; }
.gamepick button { padding: 1.2em 1em; font-size: 1.1rem; text-align: left; }
.gamepick button small { display: block; color: var(--muted); font-weight: 400; margin-top: .4em; }
.monitor { display: grid; gap: .5rem; }
.mrow { display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: center; padding: .6rem .8rem; background: var(--panel2); border-radius: 12px; border-left: 8px solid var(--c); }
.mrow .tname { font-weight: 700; }
.mrow .sub { color: var(--muted); font-size: .9rem; }
.mrow .sentence { font-size: 1.05rem; }
.controls { display: flex; gap: .6rem; flex-wrap: wrap; }
.phase { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.login { max-width: 22rem; margin: 10vh auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .lane { grid-template-columns: 1fr; }
  .teamrow { grid-template-columns: 2.2em 1fr 3.5em; }
  .teamrow .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .screen { padding: .8rem; }
}
