:root {
  --ink: #1d2340;
  --ink-soft: #5a6285;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.9);
  --primary: #ff7a45;
  --primary-2: #ff5f8f;
  --secondary: #4f7cff;
  --good: #22c26b;
  --bad: #ff5f6d;
  --gold: #ffc93c;
  --radius: 22px;
  --shadow: 0 18px 50px rgba(20, 30, 70, 0.22);
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #5fb4ef; }
body { -webkit-tap-highlight-color: transparent; user-select: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }

.screen { position: fixed; inset: 0; display: none; pointer-events: none; }
body[data-screen="home"] #home,
body[data-screen="hud"] #hud,
body[data-screen="lobby"] #lobby { display: flex; }
.screen > * { pointer-events: auto; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: 999px; padding: 12px 22px; font-weight: 800; font-size: 1rem;
  transition: transform .12s ease, box-shadow .2s ease, filter .2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.04); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 10px 24px rgba(255, 95, 143, .4); }
.btn-secondary { background: linear-gradient(135deg, #5b8cff, #7a5cff); color: #fff; box-shadow: 0 10px 24px rgba(90, 100, 255, .35); }
.btn-ghost { background: #fff; border: 2px solid #e3e7f5; }
.btn-mic { background: linear-gradient(135deg, #22c26b, #12a5a0); color: #fff; box-shadow: 0 10px 24px rgba(34, 194, 107, .35); }
.btn-mic.listening { animation: pulse 1s infinite; }
.btn-link { color: var(--ink-soft); text-decoration: underline; padding: 10px; }
.btn-xl { font-size: 1.35rem; padding: 16px 40px; }
.btn.glow { animation: glow 1.2s infinite alternate; }
.chip-btn { background: rgba(255,255,255,.7); border: 1px solid #e3e7f5; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: .92rem; }
.chip-btn:hover { background: #fff; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; font-size: 1.2rem; display: grid; place-items: center; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(34,194,107,.55); } 50% { box-shadow: 0 0 0 14px rgba(34,194,107,0); } }
@keyframes glow { from { box-shadow: 0 0 0 0 rgba(255,122,69,.6); } to { box-shadow: 0 0 0 12px rgba(255,122,69,0); } }

/* ---------- Home ---------- */
#home { align-items: center; justify-content: center; padding: 16px; }
.home-card { width: min(640px, 100%); border-radius: 32px; padding: 28px 28px 22px; text-align: center; max-height: calc(100dvh - 32px); overflow: auto; }
.logo { margin: 0; font-size: clamp(2.2rem, 7vw, 3.6rem); font-weight: 900; letter-spacing: -0.02em; line-height: 1; }
.logo-j { background: linear-gradient(135deg, #ff7a45, #ff5f8f); -webkit-background-clip: text; background-clip: text; color: transparent; display: inline-block; animation: hop 1.6s infinite; }
.logo-w { background: linear-gradient(135deg, #4f7cff, #22c2a0); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-10px); } }
.tagline { margin: 8px 0 18px; color: var(--ink-soft); font-size: 1.05rem; }
.label { font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); margin-bottom: 8px; }
.langs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.lang { padding: 9px 14px; border-radius: 16px; background: #fff; border: 2px solid #e8ebf7; font-weight: 800; display: flex; align-items: center; gap: 8px; transition: .15s; }
.lang .flag { font-size: 1.4rem; }
.lang small { color: var(--ink-soft); font-weight: 700; }
.lang[aria-checked="true"] { border-color: var(--secondary); background: #eef2ff; transform: translateY(-2px); box-shadow: 0 8px 18px rgba(79,124,255,.2); }
.progress-strip { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.stage-pill { min-width: 86px; padding: 8px 10px; border-radius: 14px; background: #fff; border: 2px solid #eef0f8; font-size: .78rem; font-weight: 800; color: var(--ink-soft); }
.stage-pill .stars { display: block; font-size: .9rem; letter-spacing: 1px; margin-top: 2px; }
.stage-pill.unlocked { color: var(--ink); cursor: pointer; }
.stage-pill.unlocked:hover { border-color: #c8d3ff; }
.stage-pill.current { border-color: var(--primary); box-shadow: 0 6px 14px rgba(255,122,69,.2); }
.stage-pill.locked { opacity: .5; }
.home-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }
.home-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.warn { margin-top: 14px; background: #fff4e5; border: 1px solid #ffd59a; color: #8a5300; padding: 10px 14px; border-radius: 14px; font-size: .9rem; font-weight: 700; }

/* ---------- HUD ---------- */
#hud { flex-direction: column; pointer-events: none; }
.hud-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; padding: 14px 16px; align-items: start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-left { justify-self: start; border-radius: 18px; padding: 10px 14px; min-width: 150px; }
.hud-stage { font-weight: 900; font-size: .95rem; }
.dots { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; max-width: 220px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: #e0e4f2; display: block; transition: .2s; }
.dots i.done { background: var(--good); }
.dots i.now { background: var(--gold); transform: scale(1.3); }
.dots i.miss { background: var(--bad); }
.hud-word { position: relative; border-radius: 26px; padding: 12px 56px 12px 28px; text-align: center; min-width: 240px; transition: transform .15s, background .2s; }
.hud-word.ok { background: rgba(225, 255, 236, .92); transform: scale(1.05); }
.hud-word.urgent { animation: shakeX .35s; }
.hw-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.hw-emoji { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.hw-text { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 900; letter-spacing: .01em; line-height: 1.1; }
.hw-hint { color: var(--ink-soft); font-weight: 700; font-size: clamp(.9rem, 2vw, 1.15rem); min-height: 1.2em; }
.hw-listen { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; border: 2px solid #e3e7f5; font-size: 1rem; }
@keyframes shakeX { 0%,100% { transform: translateX(0);} 25% { transform: translateX(-6px);} 75% { transform: translateX(6px);} }
.hud-right { justify-self: end; display: flex; gap: 8px; align-items: center; }
.mic { display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 46px; border-radius: 999px; }
.mic.off { opacity: .55; filter: grayscale(1); }
.mic.live .mic-ico { animation: hop 1.2s infinite; }
.mic-bar { width: 60px; height: 8px; background: #e3e7f5; border-radius: 99px; overflow: hidden; }
.mic-bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #22c26b, #ffc93c, #ff5f6d); border-radius: 99px; transition: width .08s; }
.heard { align-self: center; margin-top: 4px; padding: 8px 16px; border-radius: 999px; background: rgba(29,35,64,.72); color: #fff; font-weight: 800; opacity: 0; transform: translateY(-6px); transition: .2s; }
.heard.show { opacity: 1; transform: none; }
.heard.bad { background: rgba(200, 40, 60, .85); }
.heard.good { background: rgba(20, 150, 80, .9); }
.combo { position: absolute; left: 50%; top: 42%; transform: translateX(-50%); font-weight: 900; font-size: 1.4rem; color: #fff; text-shadow: 0 3px 10px rgba(0,0,0,.25); opacity: 0; transition: .3s; }
.combo.show { opacity: 1; }
.type-form { position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); padding: 8px; border-radius: 999px; width: min(440px, calc(100% - 32px)); pointer-events: auto; }
.type-form input { width: 100%; border: 0; outline: 0; background: #fff; padding: 12px 18px; border-radius: 999px; font-size: 1.1rem; font-weight: 800; text-align: center; }
.race-board { position: absolute; right: 16px; top: 80px; border-radius: 18px; padding: 10px 12px; width: 210px; font-size: .88rem; pointer-events: auto; }
.race-board h4 { margin: 0 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.race-row { display: flex; justify-content: space-between; gap: 6px; padding: 3px 0; font-weight: 700; }
.race-row.out { opacity: .5; text-decoration: line-through; }
.race-row.me { color: var(--primary); }

/* ---------- Lobby ---------- */
#lobby { align-items: center; justify-content: center; padding: 16px; }
.lobby-card { position: relative; width: min(560px, 100%); border-radius: 30px; padding: 26px; text-align: center; }
.lobby-card h2 { margin: 0 0 10px; }
.ring-wrap { position: relative; width: 150px; height: 150px; margin: 6px auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e6e9f5; stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--primary); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 326.7; transition: stroke-dashoffset .3s linear; }
.ring-text { position: absolute; inset: 0; display: grid; place-content: center; }
.ring-text div { font-size: 2.6rem; font-weight: 900; line-height: 1; }
.ring-text small { color: var(--ink-soft); font-weight: 800; }
.muted { color: var(--ink-soft); }
.players { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; min-height: 40px; }
.player-chip { background: #fff; border: 2px solid #e8ebf7; border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: .9rem; }
.player-chip.me { border-color: var(--primary); }
.lobby-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .92rem; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 45, .38); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .2s; }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; border-radius: 28px; padding: 26px; background: rgba(255,255,255,.93); animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
.modal-card h2 { margin: 0 0 6px; }
.close { position: absolute; top: 12px; right: 14px; width: 36px; height: 36px; border-radius: 50%; font-size: 1rem; background: #f0f2fa; z-index: 2; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

/* Learn card */
.learn { text-align: center; }
.learn-badge { display: inline-block; background: #ffe9ea; color: #b4233a; font-weight: 900; padding: 6px 14px; border-radius: 999px; font-size: .9rem; }
.learn-emoji { font-size: 3.4rem; margin-top: 10px; }
.learn-word { font-size: clamp(2.6rem, 9vw, 4.2rem); font-weight: 900; line-height: 1.1; }
.learn-hint { font-size: 1.3rem; font-weight: 700; color: var(--ink-soft); }
.learn-syll { margin-top: 6px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.learn-syll span { background: #eef2ff; color: #3a4fb8; border-radius: 10px; padding: 4px 10px; font-weight: 800; }
.learn-heard { min-height: 1.6em; margin: 12px 0 4px; font-weight: 800; }
.learn-heard.good { color: var(--good); }
.learn-heard.bad { color: var(--bad); }
.learn-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.learn-streak { font-size: 1.4rem; min-height: 1.6em; letter-spacing: 4px; }
.learn-foot { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* Character picker */
.chars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.char-opt { background: #fff; border: 3px solid #eef0f8; border-radius: 20px; padding: 8px 8px 10px; font-weight: 800; transition: .15s; }
.char-opt canvas { width: 100%; height: 110px; display: block; }
.char-opt[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 8px 20px rgba(255,122,69,.25); transform: translateY(-2px); }

/* Settings */
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #eef0f8; flex-wrap: wrap; }
.set-row label { font-weight: 800; }
.set-row small { display: block; color: var(--ink-soft); font-weight: 600; }
.seg { display: inline-flex; background: #eef0f8; border-radius: 999px; padding: 3px; }
.seg button { padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: .9rem; }
.seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.08); }
select { font: inherit; padding: 8px 10px; border-radius: 12px; border: 2px solid #e3e7f5; background: #fff; max-width: 260px; }
.text-in { font: inherit; padding: 12px 16px; border-radius: 14px; border: 2px solid #e3e7f5; width: 100%; font-weight: 800; font-size: 1.1rem; outline: none; }
.text-in:focus { border-color: var(--secondary); }
.err { color: var(--bad); font-weight: 800; min-height: 1.4em; margin: 6px 0; }

/* Leaderboard */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.tabs button { padding: 7px 12px; border-radius: 999px; background: #eef0f8; font-weight: 800; font-size: .88rem; }
.tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }
table.board { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.board th { text-align: left; color: var(--ink-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; padding: 6px; }
table.board td { padding: 8px 6px; border-top: 1px solid #eef0f8; font-weight: 700; }
table.board tr.me td { background: #fff4ec; }
.medal { font-size: 1.1rem; }
.empty { text-align: center; color: var(--ink-soft); padding: 22px 0; font-weight: 700; }

/* Tricky + misc lists */
.tricky { display: grid; gap: 8px; margin-top: 12px; }
.tricky-row { display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid #eef0f8; border-radius: 16px; padding: 8px 12px; }
.tricky-row .w { font-weight: 900; font-size: 1.2rem; flex: 1; text-align: left; }
.tricky-row .w small { display: block; color: var(--ink-soft); font-weight: 700; font-size: .85rem; }
.tricky-row .m { color: var(--bad); font-weight: 800; font-size: .85rem; }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 16px 0; }
.podium > div { background: #fff; border-radius: 14px 14px 0 0; padding: 8px 12px; min-width: 90px; font-weight: 800; border: 2px solid #eef0f8; }
.podium .p1 { height: 120px; border-color: var(--gold); }
.podium .p2 { height: 95px; }
.podium .p3 { height: 75px; }

.intro-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.intro-steps div { background: #fff; border-radius: 16px; padding: 12px 8px; border: 2px solid #eef0f8; font-weight: 800; font-size: .9rem; }
.intro-steps b { display: block; font-size: 2rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(29,35,64,.9); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 800; z-index: 60; animation: fade .2s; max-width: calc(100% - 32px); text-align: center; }

@media (max-width: 720px) {
  .hud-top { grid-template-columns: 1fr auto; }
  .hud-word { grid-column: 1 / -1; grid-row: 2; justify-self: center; padding: 8px 52px 8px 20px; min-width: 0; }
  .hud-left { padding: 8px 10px; min-width: 0; }
  .mic-bar { width: 36px; }
  .race-board { top: auto; bottom: 12px; right: 12px; width: 170px; }
  .chars { grid-template-columns: repeat(2, 1fr); }
  .home-card { padding: 22px 16px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .logo-j, .mic.live .mic-ico, .btn-mic.listening, .btn.glow { animation: none; }
}
.flag-svg { display: inline-flex; width: 26px; height: 18px; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,.08); vertical-align: -3px; flex: none; }
.flag-svg svg { width: 100%; height: 100%; display: block; }

/* ---------- logo, install, microphone help ---------- */
.home-logo { display: block; width: 84px; height: 84px; margin: -6px auto 8px; border-radius: 22px; box-shadow: 0 10px 24px rgba(40, 110, 200, .28); }
.chip-install { background: linear-gradient(135deg, #fff3d6, #ffe0ec); border-color: #ffd2a8; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.link-btn { background: none; border: 0; padding: 0; color: #2f6fe0; font-weight: 800; text-decoration: underline; cursor: pointer; font: inherit; }
.mic-panel { margin-top: 6px; }
.mic-help { text-align: left; background: #fff; border: 2px solid #ffe0b3; border-radius: 18px; padding: 14px 16px; margin: 10px 0 4px; }
.mic-help h3 { margin: 0 0 4px; font-size: 1.05rem; }
.mic-help p { margin: 0 0 8px; font-size: .92rem; }
.mic-help ol, .install-step ol { margin: 0 0 10px; padding-left: 1.3em; display: grid; gap: 6px; font-size: .93rem; line-height: 1.35; }
.mic-help-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mic-help-btns .btn { padding: 10px 16px; font-size: .95rem; }
.install-logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 10px 24px rgba(40, 110, 200, .28); }
.install h2 { margin: 10px 0 2px; }
.install-step { display: flex; gap: 12px; text-align: left; background: #fff; border: 2px solid #eef0f8; border-radius: 18px; padding: 14px; margin-top: 12px; }
.install-step > div { flex: 1; min-width: 0; }
.install-step h3 { margin: 2px 0 8px; font-size: 1.05rem; }
.install-step .mic-panel { text-align: center; }
.step-n { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #4f7cff, #22c2a0); color: #fff; font-weight: 900; }
@media (max-width: 520px) { .home-logo { width: 64px; height: 64px; border-radius: 18px; } }
