/* Bundled fonts (Latin subset, SIL OFL 1.1: see fonts/OFL-*.txt). Glyphs outside it fall back to system fonts. */
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('fonts/space-grotesk-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('fonts/space-grotesk-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('fonts/space-grotesk-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --text: #1f1c17;
  --muted: #6f685b;
  --line: #e3dac8;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fde3d0;
  --good: #2b8a3e;
  --good-soft: #d3f9d8;
  --bad: #c92a2a;
  --bad-soft: #ffe3e3;
  --lamp-off: #d9cfbd;
  --lamp-on: #ffb100;
  --star: #f59f00;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .06);
  --radius: 18px;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --sans: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b;
    --surface: #1b1e28;
    --surface-2: #252937;
    --text: #eceae4;
    --muted: #9a9cab;
    --line: #2e3344;
    --accent: #ff8a3d;
    --accent-ink: #1b1206;
    --accent-soft: #3a2617;
    --good: #51cf66;
    --good-soft: #16301d;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1c;
    --lamp-off: #3a3424;
    --lamp-on: #ffc233;
    --star: #ffc233;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  /* Installed app with viewport-fit=cover: keep content clear of notches and the home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, kbd { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
h1, h2 { letter-spacing: -.02em; line-height: 1.2; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 16px 20px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.4rem; letter-spacing: -.02em; }
.logo .dot-sep { color: var(--accent); padding: 0 1px; }
.lamp {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  background: var(--lamp-off);
  transition: background .03s, box-shadow .03s;
}
body.signal-on .lamp {
  background: var(--lamp-on);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--lamp-on) 30%, transparent), 0 0 20px var(--lamp-on);
}
.stats { display: flex; align-items: center; gap: 10px; }
.pill { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: .9rem; white-space: nowrap; }
.level { position: relative; display: flex; align-items: center; gap: 8px; font-size: .9rem; white-space: nowrap; }
.xpbar { width: 90px; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.xpbar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--lamp-on)); transition: width .5s; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 1.1rem; }
.xp-float {
  position: absolute; right: 0; top: -4px; font-weight: 700; color: var(--accent); font-size: .85rem;
  pointer-events: none; animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-22px); } }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; max-width: 960px; margin: 0 auto; padding: 0 20px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; border-radius: 12px;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

main { max-width: 960px; margin: 0 auto; padding: 20px 20px 80px; }

/* ---------- Common ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.btn {
  border: 1px solid var(--line); background: var(--surface-2);
  padding: 10px 16px; border-radius: 12px; font-weight: 500;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 25%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); background: transparent; }
.btn.small { padding: 6px 11px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: center; margin-top: 18px; }
.actions.left { justify-content: flex-start; }
.muted { color: var(--muted); }
.center { text-align: center; }
.label { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 500; }
.tip { color: var(--muted); font-size: .92rem; margin: 6px 4px 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 12px;
}

/* Morse pattern glyphs */
.pattern { display: inline-flex; align-items: center; gap: .32em; vertical-align: middle; }
.sym { display: inline-block; height: .5em; background: currentColor; border-radius: 99px; }
.sym.dit { width: .5em; }
.sym.dah { width: 1.6em; }
.gap { display: inline-block; width: 1em; }

/* ---------- Learn ---------- */
.learn-head h1 { margin: 4px 0 4px; font-size: 1.8rem; }
.learn-head p { margin: 0 0 14px; color: var(--muted); }
.progress { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-bottom: 20px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--lamp-on)); transition: width .5s; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 12px; }
.lesson {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.lesson-main {
  text-align: left; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; gap: 2px 12px;
  border: 0; background: none; padding: 14px 16px; width: 100%; flex: 1;
}
.lesson-main:disabled { cursor: not-allowed; }
.lesson-actions { display: flex; border-top: 1px dashed var(--line); background: var(--surface-2); }
.lesson-quiz {
  border: 0; border-right: 1px dashed var(--line); background: none;
  padding: 8px 12px; font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.lesson-quiz:only-child { flex: 1; text-align: left; border-right: 0; padding: 8px 16px; }
.lesson-chal {
  flex: 1; min-width: 0; display: flex; justify-content: space-between; align-items: center; gap: 6px;
  border: 0; background: none; white-space: nowrap;
  padding: 8px 12px; font-size: .8rem; font-weight: 700; text-align: left;
}
.lesson-quiz:hover, .lesson-chal:hover { background: var(--accent-soft); color: var(--accent); }
.lesson-chal .cstars { color: var(--star); font-weight: 500; letter-spacing: 1px; }
.lesson-chal .cpct { margin-left: 5px; letter-spacing: 0; color: var(--muted); font-family: var(--mono); font-size: .75rem; }
.lesson-chal .untried { color: var(--muted); }
.lesson .qbest { margin-left: 6px; letter-spacing: 0; color: var(--muted); font-family: var(--mono); font-size: .8rem; }
.lesson-chal.won { background: color-mix(in srgb, var(--star) 14%, var(--surface-2)); }
.lesson:not(.locked):hover { transform: translateY(-2px); border-color: var(--accent); }
.lesson .num {
  grid-row: 1 / 4; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.lesson.done .num { background: var(--good-soft); color: var(--good); }
.lesson .lt { font-weight: 700; }
.lesson .chars { display: flex; gap: 6px; flex-wrap: wrap; font-family: var(--mono); font-weight: 700; color: var(--muted); }
.lesson .stars { color: var(--star); letter-spacing: 2px; font-size: .95rem; }
.lesson.locked { opacity: .5; cursor: not-allowed; box-shadow: none; }
.lesson.locked .stars { color: var(--muted); letter-spacing: 0; }
.lesson.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }

/* Challenge */
.qtype.hot { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.qprompt .big-pattern.long { font-size: 1.5rem; gap: .5em 0; }
.wgap { display: inline-block; margin: 0 .5em; color: var(--muted); font-family: var(--mono); font-size: .8em; }
.speed-badge {
  display: inline-block; padding: 4px 12px; border-radius: 99px; font-family: var(--mono); font-weight: 700; font-size: .9rem;
  background: var(--surface-2); border: 1px solid var(--line);
}
.timer {
  position: relative; height: 22px; border-radius: 99px; background: var(--surface-2); overflow: hidden;
  max-width: 420px; margin: 14px auto 0;
}
.timer i { position: absolute; inset: 0 auto 0 0; background: var(--good); transition: width .1s linear; }
.timer.low i { background: var(--bad); }
.timer span { position: relative; font-family: var(--mono); font-size: .8rem; font-weight: 700; line-height: 22px; }
.answer.long-input { width: min(520px, 100%); font-size: 1.3rem; letter-spacing: .08em; }
.sent-text {
  font-family: var(--mono); font-size: 1.6rem; font-weight: 700; letter-spacing: .1em; min-height: 1.6em;
  word-break: break-all; margin-bottom: 4px;
}
.sent-text .muted { font-size: .9rem; font-weight: 400; letter-spacing: 0; font-family: var(--sans); }
.sent-text .caret { display: inline-block; width: 3px; height: 1em; background: var(--accent); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(1) infinite; }
.cscore { font-size: 1.3rem; font-weight: 700; }
.diff { font-size: 1.5rem; letter-spacing: .1em; }
.d-ok { color: var(--good); }
.d-wrong { color: var(--bad); text-decoration: underline wavy; text-underline-offset: 5px; }
.d-miss { color: var(--bad); opacity: .55; text-decoration: line-through; }
.crows { display: flex; flex-direction: column; gap: 6px; max-width: 560px; margin: 18px auto 0; text-align: left; }
.crow {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: .9rem;
}
.crow .ctext { grid-column: 1; font-size: .85rem; word-break: break-all; }
.crow b { grid-column: 2; grid-row: 1 / 3; font-family: var(--mono); }
.crow b.good { color: var(--good); }
.crow b.bad { color: var(--bad); }

.lesson-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.intro, .quiz, .results { text-align: center; padding: 32px 24px; }
.dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); }
.dots span.on { background: var(--accent); width: 22px; border-radius: 99px; }
.dots span.past { background: var(--accent); opacity: .45; }
.big-char { font-size: 6.5rem; font-weight: 700; line-height: 1; margin: 10px 0 18px; font-family: var(--mono); }
.big-pattern { font-size: 2.4rem; color: var(--accent); min-height: 1.2em; }
.code-text { font-family: var(--mono); color: var(--muted); margin-top: 8px; }
.blurb { max-width: 460px; margin: 16px auto 0; color: var(--muted); }

.qbar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 0 auto 22px; max-width: 420px; }
.qbar > div { height: 100%; background: var(--accent); transition: width .3s; }
.qprompt { min-height: 150px; display: grid; place-items: center; align-content: center; gap: 10px; }
.qprompt .big-char { margin: 0; font-size: 5rem; }
.qprompt .big-pattern { font-size: 2.6rem; }
.qprompt p { margin: 0; color: var(--muted); }
.play-big {
  width: 96px; height: 96px; border-radius: 50%; border: 0; font-size: 2.4rem;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .1s;
}
.play-big:hover { transform: scale(1.05); }
.play-big:active { transform: scale(.97); }
/* Greyed out while its sound plays (and when no replays are left). */
.play-big:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 420px; margin: 22px auto 0; }
.opt {
  border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 16px 10px;
  font-size: 1.6rem; font-weight: 700; font-family: var(--mono); min-height: 70px;
  display: grid; place-items: center; position: relative; transition: border-color .12s, background .12s, transform .1s;
}
.opt .pattern { font-size: 1.4rem; }
.opt:hover { border-color: var(--accent); }
.opt kbd { position: absolute; top: 6px; left: 8px; font-size: .65rem; opacity: .6; padding: 0 4px; }
.opt.right { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.qtype {
  display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700;
}
.qprompt .big-pattern.word { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .35em 0; font-size: 2rem; max-width: 100%; }
.qprompt .big-char.word-text { font-size: 3.4rem; letter-spacing: .1em; word-break: break-all; }
.text-answer { margin-top: 18px; display: flex; flex-direction: column; align-items: center; }
.text-answer .actions { margin-top: 8px; }
.answer.morse-input { width: min(460px, 100%); font-size: 1.4rem; letter-spacing: .12em; }
.keypad { display: flex; gap: 8px; margin-top: 10px; }
.keypad button {
  min-width: 52px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 1.5rem; font-weight: 700; line-height: 1;
}
.keypad button.wide { font-size: .9rem; font-weight: 500; min-width: 90px; }
.keypad button:active { transform: translateY(1px); }
.small-note { font-size: .82rem; margin: 8px 0 0; }
.mono { font-family: var(--mono); font-weight: 700; letter-spacing: .06em; }
.sent { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 6px; }
.slot {
  min-width: 54px; padding: 6px 8px; border-radius: 12px; border: 2px dashed var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.slot b { font-family: var(--mono); font-size: 1.4rem; line-height: 1.1; }
.slot .pattern { color: var(--accent); font-size: .85rem; min-height: .6em; }
.slot.filled { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.slot.cur { border-color: var(--accent); }
.linkish {
  margin-top: 12px; border: 0; background: none; color: var(--muted); font-size: .85rem;
  text-decoration: underline; text-underline-offset: 3px;
}
.linkish:hover { color: var(--text); }
.site-foot { text-align: center; padding: 8px 16px 24px; }
.site-foot .linkish { margin: 0; }
.privacy h3 { margin: 14px 0 4px; font-size: 1rem; }
.privacy p, .privacy li { color: var(--muted); font-size: .92rem; line-height: 1.5; margin: 4px 0; }
.privacy ul { margin: 4px 0; padding-left: 20px; }
.privacy a { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }
a.linkish { display: inline-block; }
.feedback.stacked { flex-direction: column; gap: 6px; }
.results .stars-big { font-size: 3rem; color: var(--star); letter-spacing: 6px; }
.results .stars-big .off { color: var(--surface-2); }
.results h2 { margin: 8px 0 4px; font-size: 1.8rem; }
.results p { color: var(--muted); margin: 4px 0; }

/* ---------- Practice ---------- */
.practice-card { text-align: center; }
.score-row { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; margin-bottom: 8px; }
.score-row b { font-size: 1.5rem; font-family: var(--mono); }
.stage { min-height: 170px; display: grid; place-items: center; align-content: center; gap: 10px; padding: 12px 0; }
.stage p { margin: 0; color: var(--muted); max-width: 440px; }
.stage .read-pattern { font-size: 2.2rem; color: var(--accent); line-height: 1.6; }
.stage .sprint-result { font-size: 3.5rem; font-weight: 700; font-family: var(--mono); line-height: 1; }
.answer {
  width: min(320px, 100%); text-align: center; font-size: 1.6rem; font-family: var(--mono); font-weight: 700;
  text-transform: uppercase; padding: 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg);
  outline: none; transition: border-color .15s;
}
.answer:focus { border-color: var(--accent); }
.answer:disabled { opacity: .5; }
.feedback { min-height: 2.2em; margin-top: 12px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback .pattern { font-size: 1.1rem; }

/* ---------- Key It ---------- */
.key-card { text-align: center; }
.target { font-family: var(--mono); font-size: 3.4rem; font-weight: 700; letter-spacing: .12em; margin: 4px 0; }
.target span.ok { color: var(--good); }
.target span.cur { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 8px; text-decoration-thickness: 3px; }
.hint { font-size: 1.6rem; color: var(--accent); min-height: 1.5em; }
.key-live { margin: 18px 0 14px; min-height: 90px; }
.symbols { font-size: 2rem; min-height: 1.4em; color: var(--accent); display: flex; justify-content: center; align-items: center; gap: 14px; }
.symbols .preview { font-family: var(--mono); font-size: 1.3rem; color: var(--muted); }
.output {
  font-family: var(--mono); font-size: 1.5rem; font-weight: 700; min-height: 1.6em; word-break: break-all;
  letter-spacing: .08em;
}
.output .caret { display: inline-block; width: 3px; height: 1.1em; background: var(--accent); vertical-align: -3px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.telegraph-key {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  width: 100%; height: 170px; border-radius: 20px; border: 2px dashed var(--line); background: var(--surface-2);
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
  transition: background .05s, border-color .05s;
}
.key-knob {
  width: 78px; height: 78px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5a5a5a, #111 70%);
  box-shadow: 0 7px 0 #000, 0 12px 22px rgba(0, 0, 0, .3);
  transition: transform .03s, box-shadow .03s;
}
.key-label { color: var(--muted); font-size: .9rem; }
.telegraph-key.down { border-color: var(--accent); background: var(--accent-soft); }
.telegraph-key.down .key-knob { transform: translateY(6px); box-shadow: 0 1px 0 #000, 0 3px 8px rgba(0, 0, 0, .3); }
.try-key { margin: 26px auto 0; padding-top: 20px; border-top: 1px dashed var(--line); max-width: 460px; }
.try-key .symbols { margin-top: 6px; }
.try-key .feedback { margin-top: 4px; }
.telegraph-key.compact { height: 120px; gap: 10px; margin-top: 6px; }
.telegraph-key.compact .key-knob { width: 58px; height: 58px; }
.key-timing { font-family: var(--mono); font-size: .82rem; min-height: 1.4em; margin-top: 8px; }
.key-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; font-size: .88rem; font-family: var(--mono); }

/* ---------- Translate ---------- */
textarea {
  width: 100%; margin-top: 8px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); resize: vertical; font-size: 1.15rem; outline: none; font-family: var(--mono);
}
textarea:focus { border-color: var(--accent); }
.morse-out { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 14px; min-height: 2em; align-items: flex-end; }
.morse-out .mc {
  display: inline-flex; flex-direction: column; align-items: center; padding: 4px 6px; border-radius: 8px;
  font-family: var(--mono); font-size: 1.1rem; font-weight: 700; transition: background .08s;
}
.morse-out .mc small { font-size: .7rem; color: var(--muted); font-weight: 500; }
.morse-out .mc.on { background: var(--accent); color: var(--accent-ink); }
.morse-out .mc.on small { color: var(--accent-ink); }
.morse-out .mc.unk { color: var(--bad); }
.morse-out .wsep { color: var(--muted); font-family: var(--mono); padding: 4px 2px; }
.text-out { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; margin-top: 12px; min-height: 1.5em; letter-spacing: .06em; word-break: break-word; }
.big-lamp { width: 26px; height: 26px; margin-left: auto; }

/* ---------- Chart ---------- */
#chart h2 { font-size: 1.1rem; margin: 18px 0 10px; color: var(--muted); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.cell {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 10px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; box-shadow: var(--shadow);
  transition: transform .1s, border-color .1s;
}
.cell:hover { transform: translateY(-2px); border-color: var(--accent); }
.cell.playing { border-color: var(--accent); background: var(--accent-soft); }
.cell .cc { font-family: var(--mono); font-weight: 700; font-size: 1.6rem; line-height: 1; }
.cell .fit { container-type: inline-size; width: 100%; display: flex; justify-content: center; align-items: center; height: 1.05rem; overflow: hidden; }
/* Long codes (numbers, punctuation) shrink to fit the cell instead of spilling out. */
.cell .pattern { color: var(--accent); font-size: min(1.05rem, calc(100cqi / var(--w))); }
.cell .acc { width: 70%; height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.cell .acc i { display: block; height: 100%; }

/* ---------- Settings ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(10, 10, 20, .45); backdrop-filter: blur(2px); }
.settings { padding: 22px 24px; display: flex; flex-direction: column; gap: 16px; }
.settings h2 { margin: 0; }
.settings label { display: flex; flex-direction: column; gap: 4px; }
.settings label span { font-weight: 500; }
.settings output { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.settings small { color: var(--muted); font-size: .8rem; }
.settings input[type=range] { accent-color: var(--accent); width: 100%; }
.settings .check { flex-direction: row; align-items: center; gap: 8px; }
.settings .check input { accent-color: var(--accent); width: 18px; height: 18px; }
.settings .row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings .row.end { justify-content: flex-end; }

/* ---------- Toasts & confetti ---------- */
#toasts { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; align-items: center; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 500;
  box-shadow: var(--shadow); animation: toastIn .25s ease-out, toastOut .3s ease-in 2.2s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }
.confetti { position: fixed; top: -14px; width: 8px; height: 13px; z-index: 100; pointer-events: none; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--r)); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .topbar { padding: 12px 16px 8px; }
  .brand { font-size: 1.2rem; }
  .xpbar { width: 56px; }
  .tabs { padding: 0 16px; }
  main { padding: 16px 16px 80px; }
  .card { padding: 18px 16px; }
  .big-char { font-size: 5rem; }
  .target { font-size: 2.6rem; }
  .score-row { gap: 18px; }
  .lesson-grid { grid-template-columns: 1fr; }
}
/* Phones (360–420px): the header stats don't fit beside the logo; keep "Lv n", drop the bar. */
@media (max-width: 420px) {
  .stats { gap: 6px; }
  .level .xpbar { display: none; }
}

/* ---------- Speed test ---------- */
.tab-sep { flex: none; width: 1px; margin: 9px 6px; background: var(--line); }
.test-config { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 14px; }
.test-card { text-align: center; }
.test-hud { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.test-hud b { font-family: var(--mono); font-size: 2.2rem; line-height: 1; color: var(--accent); }
.test-hud span { font-family: var(--mono); font-size: .95rem; }
.test-words { position: relative; overflow: hidden; margin: 16px 0 10px; cursor: text; text-align: left; }
#tWords { position: relative; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 22px; transition: transform .15s; }
.tw { display: inline-flex; gap: 10px; padding: 6px 8px; border-radius: 10px; }
.tw.cur { background: var(--surface-2); }
.tw.past { opacity: .55; }
.tl { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; min-width: 1.1em; }
.tl b { font-family: var(--mono); font-size: 1.25rem; line-height: 1; height: 1em; border-bottom: 2px solid transparent; padding-bottom: 3px; box-sizing: content-box; }
.tl .pattern { font-size: 1rem; height: .6em; }
.tl.cur { color: var(--accent); }
.tl.cur b { border-bottom-color: var(--accent); }
.tl.ok { color: var(--good); }
.tl.bad { color: var(--bad); }
.tl.miss { color: var(--muted); }
.test-words[data-mode=listen] .tl b, .test-words[data-mode=send] .tl b { font-size: 1.7rem; }
.test-words[data-mode=listen] .tl:not(.ok):not(.bad):not(.cur) { color: var(--muted); }
.ghost-input { position: absolute; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; pointer-events: none; }
.test-card .keypad { justify-content: center; }
.test-hint { font-size: .88rem; max-width: 560px; margin: 12px auto 0; }
.btn kbd { background: transparent; border: 1px solid currentColor; opacity: .7; font-size: .75em; margin-left: 4px; }
.wpm-big { font-family: var(--mono); font-weight: 700; font-size: 6rem; line-height: 1; color: var(--accent); margin: 10px 0 6px; }
#tResults .score-row { margin: 22px 0 6px; }
.weak-row { margin-top: 18px; }
.weak-row > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.weak { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 12px; background: var(--surface-2); }
.weak b { font-family: var(--mono); font-size: 1.2rem; }
.weak .pattern { color: var(--accent); font-size: .9rem; }
.weak small { color: var(--bad); font-family: var(--mono); }
@media (max-width: 560px) {
  #tWords { gap: 12px 10px; }
  .tw { gap: 7px; padding: 6px; }
  .tl .pattern { font-size: .62rem; }
  .wpm-big { font-size: 4.5rem; }
}
.test-words[data-mode=read] .tw { gap: 16px; }
.tip .linkish { margin: 0; padding: 0; font-size: inherit; }

/* ---------- Speed test results: graph + history ---------- */
:root { --series-1: #e8590c; --series-2: #3b73b9; }
@media (prefers-color-scheme: dark) { :root { --series-1: #e66d1f; --series-2: #5b93d6; } }
.tblock { text-align: left; max-width: 680px; margin: 26px auto 0; padding-top: 18px; border-top: 1px dashed var(--line); }
.tblock-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin-bottom: 8px; }
.tblock h3 { margin: 0; font-size: 1rem; }
.tblock h3.sub { margin: 18px 0 6px; font-size: .9rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend .sw { margin-right: 0; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.sw-x { color: var(--bad); font-weight: 700; margin-right: 6px; }
.legend .sw-x { margin-right: 0; }
.mono-sm { font-family: var(--mono); font-size: .82rem; }
.tchart, .spark { position: relative; width: 100%; }
.tchart svg, .spark svg { display: block; overflow: visible; touch-action: pan-y; }
.tchart .grid { stroke: var(--line); stroke-width: 1; }
.tchart .axis { stroke: color-mix(in srgb, var(--muted) 60%, var(--line)); stroke-width: 1; }
.tchart .tick { fill: var(--muted); font-family: var(--mono); font-size: 11px; }
.tchart .end { fill: var(--text); font-size: 12px; font-weight: 700; }
.tchart .end.muted { fill: var(--muted); }
.ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ln.s1 { stroke: var(--series-1); }
.ln.s2 { stroke: var(--series-2); }
.dot { stroke: var(--surface); stroke-width: 2; }
.dot.s1 { fill: var(--series-1); }
.dot.s2 { fill: var(--series-2); }
.tchart .err { stroke: var(--bad); stroke-width: 2; stroke-linecap: round; }
.tchart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.ttip {
  position: absolute; top: 4px; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px 10px; font-size: .82rem; white-space: nowrap; line-height: 1.6;
}
.ttip b { font-family: var(--mono); }
.ttable { margin-top: 6px; font-size: .85rem; }
.ttable summary { cursor: pointer; color: var(--muted); }
.ttable table { margin-top: 8px; }
.tblock table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tblock th { text-align: left; font-weight: 500; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.tblock td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tblock td b { font-family: var(--mono); }
.tblock th:nth-child(n+3), .tblock td:nth-child(n+3) { text-align: right; white-space: nowrap; }
.ttable th:nth-child(n+2), .ttable td:nth-child(n+2) { text-align: right; }
.recent tr.now td { background: var(--surface-2); }
.recent td:first-child { white-space: nowrap; color: var(--muted); }

/* ---------- Account ---------- */
.acct-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: .9rem; white-space: nowrap;
}
.acct-btn:hover { border-color: var(--accent); }
.acct-name { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.acct-tier { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.auth-seg { align-self: flex-start; }
.settings input:not([type]), .settings input[type=password] {
  padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); outline: none; font-size: 1rem;
}
.settings input:focus { border-color: var(--accent); }
.profile-tier { font-size: 1.05rem; }
.good-text { color: var(--good); font-weight: 500; }
.bad-text { color: var(--bad); font-weight: 500; }
.verify { min-height: 1.6em; margin-top: 6px; font-size: .9rem; }
.verify .linkish { margin: 0; font-size: inherit; }

/* ---------- Leaderboard ---------- */
.test-config.inline { margin: 0; }
table.board { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.board th { text-align: left; font-weight: 500; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px; border-bottom: 1px solid var(--line); }
table.board td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.board td b { font-family: var(--mono); }
table.board tr.me td { background: var(--accent-soft); }
table.board td:first-child { width: 2.5em; color: var(--muted); font-family: var(--mono); }
.tier-chip { display: inline-block; width: 1.4em; }
.board-you { margin: 0 0 12px; }
.board-you .linkish { margin: 0; font-size: inherit; }

/* ---------- 1v1 ---------- */
.duel-hero { padding: 36px 24px; }
.duel-hero p { max-width: 520px; margin: 8px auto 0; }
.duel-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.duel-grid h2, .duel-card h2 { margin: 0 0 12px; font-size: 1.2rem; }
.create-card .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; align-items: flex-start; }
.create-card .seg { flex-wrap: wrap; }
.lobby-list { display: flex; flex-direction: column; gap: 8px; }
.lobby-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.lobby-row .small-note { margin: 2px 0 0; }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lobby-head h2 { margin: 2px 0 0; }
.pcards { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: stretch; margin-top: 16px; }
.vs { align-self: center; font-weight: 700; color: var(--muted); }
.pcard { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }
.pcard.me { border-color: var(--accent); }
.pcard.empty { justify-content: center; border-style: dashed; background: transparent; }
.pcard .small-note { margin: 4px 0; }
.pname { font-weight: 700; font-size: 1.1rem; overflow-wrap: anywhere; }
.host { font-size: .7rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-left: 4px; }
.pready { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.pready.on { color: var(--good); font-weight: 700; }
.invite { display: flex; gap: 6px; }
.invite input { flex: 1; min-width: 0; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-family: var(--mono); font-size: .8rem; }
.countdown { font-family: var(--mono); font-size: 4rem; font-weight: 700; color: var(--accent); text-align: center; line-height: 1.2; }
.race-bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.race-bars:empty { display: none; }
.race-row { display: grid; grid-template-columns: 6.5em minmax(0, 1fr) 8.5em; gap: 10px; align-items: center; font-size: .9rem; }
.race-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-track { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.race-track i { display: block; height: 100%; border-radius: 99px; background: var(--series-2); transition: width .25s; }
.race-row.me .race-track i { background: var(--series-1); }
.race-stat { font-family: var(--mono); text-align: right; white-space: nowrap; }
.race-clock { text-align: center; font-family: var(--mono); font-weight: 700; color: var(--accent); }
.duel-result { text-align: center; padding: 6px 0 14px; border-bottom: 1px dashed var(--line); }
.duel-result h2 { font-size: 1.8rem; margin: 6px 0 12px; }
.duel-result.won h2 { color: var(--accent); }
.duel-result table { max-width: 560px; margin: 0 auto; text-align: left; }
@media (max-width: 700px) {
  .duel-grid { grid-template-columns: 1fr; }
  .pcards { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
  .race-row { grid-template-columns: 4.5em minmax(0, 1fr) 7.5em; font-size: .8rem; }
  .acct-name { max-width: 5em; }
}
