/* Morse Trainer — "night shift in the radio shack".
   Deep navy, electric-blue signal glow, dit-dah motifs. Palette from logo. */

@font-face { font-family: "Chakra Petch"; font-weight: 600; font-display: swap;
  src: url("fonts/chakrapetch-600.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 700; font-display: swap;
  src: url("fonts/chakrapetch-700.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap;
  src: url("fonts/ibmplexsans-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap;
  src: url("fonts/ibmplexsans-600.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap;
  src: url("fonts/ibmplexmono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap;
  src: url("fonts/ibmplexmono-600.woff2") format("woff2"); }

:root {
  --bg0: #070d1f;
  --bg1: #0a1430;
  --panel: #0e1b3d;
  --panel-2: #122350;
  --line: rgba(88, 140, 255, .18);
  --blue: #2e86ff;
  --blue-hot: #4d9bff;
  --blue-dim: #1a4fa3;
  --ink: #e8eefc;
  --ink-dim: #8fa3c8;
  --good: #27d17f;
  --bad: #ff5d6c;
  --amber: #ffb454;
  --glow: 0 0 24px rgba(46, 134, 255, .25);
  --radius: 14px;
  --display: "Chakra Petch", sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; color: var(--ink);
  font: 16px/1.55 var(--body);
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(46, 134, 255, .16), transparent 60%),
    radial-gradient(700px 400px at -10% 30%, rgba(26, 79, 163, .18), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0) 45%);
  background-attachment: fixed;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
body:not(:has(.tabbar)) { padding-bottom: 2rem; }

.static-noise { /* faint band static */
  position: fixed; inset: 0; pointer-events: none; opacity: .05; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}
main { position: relative; z-index: 1; max-width: 820px; margin: 0 auto; padding: 0 1rem; }

h1, h2, h3 { font-family: var(--display); letter-spacing: .02em; }
h1 { font-size: 1.55rem; margin: .9rem 0 .6rem; }
h1 .ref { display: block; font-family: var(--body); letter-spacing: 0; }
h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; }
a { color: var(--blue-hot); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); }
.ref { color: var(--ink-dim); font-size: .85rem; font-weight: 400; }
.center { text-align: center; justify-content: center; }

.section-title { margin: 1.6rem 0 .7rem; display: flex; align-items: center; gap: .6rem; }
.section-title::before { content: "· – ·"; color: var(--blue); font-family: var(--mono);
  font-size: .8rem; letter-spacing: .1em; opacity: .8; }

/* ------------------------------------------------------------- chrome */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem max(1rem, env(safe-area-inset-left));
  background: rgba(7, 13, 31, .82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 14.5%; }
.brand span { font-family: var(--display); font-weight: 700; font-size: 1.02rem; letter-spacing: .04em; }
.brand em { font-style: normal; color: var(--blue-hot); }
.topstats { display: flex; gap: .5rem; align-items: center; }
.stat {
  display: inline-flex; align-items: center; gap: .3rem;
  font-family: var(--mono); font-size: .85rem; color: var(--ink-dim);
  background: var(--panel); border: 1px solid var(--line);
  padding: .22rem .55rem; border-radius: 999px;
}
.stat b { color: var(--ink); font-weight: 600; }
.stat svg { color: var(--amber); }
.stat:first-child svg { color: var(--blue-hot); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: space-around;
  background: rgba(9, 16, 38, .92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  min-width: 56px; padding: .2rem .4rem; border-radius: 10px;
  color: var(--ink-dim); font-size: .64rem; font-family: var(--display);
  letter-spacing: .04em;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--blue-hot); text-shadow: 0 0 12px rgba(46, 134, 255, .8); }
.tabbar a:hover { text-decoration: none; color: var(--ink); }

.flash {
  margin: .8rem 0; padding: .6rem .9rem; border-radius: var(--radius);
  background: rgba(46, 134, 255, .12); border: 1px solid var(--line);
  font-size: .92rem;
}

/* ------------------------------------------------------------- shared */

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: .8rem 0;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

button, .btn {
  font: 600 .95rem var(--display); letter-spacing: .03em;
  color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 11px;
  padding: .55rem 1.1rem; cursor: pointer;
  transition: transform .08s, box-shadow .15s, background .15s;
  display: inline-block;
}
button:hover, .btn:hover { text-decoration: none; box-shadow: var(--glow); }
button:active { transform: translateY(1px) scale(.99); }
button.primary, .btn.primary, form button[type="submit"] {
  background: linear-gradient(180deg, var(--blue-hot), var(--blue));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 18px rgba(46, 134, 255, .4);
}
button.quiet, .btn.quiet { background: transparent; }
button.small { padding: .3rem .6rem; font-size: .8rem; }
button.wide { width: 100%; }
button:disabled { opacity: .45; cursor: default; box-shadow: none; }
.row-actions { display: flex; gap: .6rem; align-items: center; margin-top: .8rem; flex-wrap: wrap; }

input, select, textarea {
  font: 1rem var(--mono); color: var(--ink);
  background: rgba(4, 9, 24, .7); border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 134, 255, .2); }
label { display: block; margin: .6rem 0 .25rem; font-size: .9rem; font-weight: 600; }
select { width: auto; }

/* ------------------------------------------------------------- auth */

.auth-hero { text-align: center; margin: 1.4rem auto .4rem; }
.auth-logo { width: min(210px, 56%); height: auto; border-radius: 14.5%;
  box-shadow: 0 10px 50px rgba(46, 134, 255, .35); }
.auth-layout { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: stretch; margin-top: 1rem; }
.auth-layout.narrow { justify-content: center; }
.auth-info { flex: 1 1 320px; margin: 0; }
.auth-card { flex: 0 1 360px; margin: 0; }
@media (max-width: 640px) { .auth-info, .auth-card { flex-basis: 100%; }
  .auth-layout { flex-direction: column-reverse; } }
.auth-info h2 { margin-top: 0; }
.feature-list { padding-left: 1.1rem; margin: .6rem 0; }
.feature-list li { margin: .45rem 0; font-size: .92rem; color: var(--ink-dim); }
.feature-list strong { color: var(--ink); }
.auth-card h1 { margin-top: 0; }

/* ------------------------------------------------------------- dashboard */

.hero { display: flex; gap: 1rem; align-items: center; justify-content: space-between;
  margin-top: 1rem; overflow: hidden; position: relative; }
.hero::after { /* signal arcs, echoing the logo */
  content: ""; position: absolute; right: -60px; top: -80px; width: 240px; height: 240px;
  border: 2px solid rgba(46, 134, 255, .25); border-radius: 50%;
  box-shadow: 0 0 0 28px rgba(46, 134, 255, .06), 0 0 0 58px rgba(46, 134, 255, .04);
  pointer-events: none;
}
.eyebrow { font-family: var(--mono); font-size: .75rem; letter-spacing: .18em;
  text-transform: uppercase; color: var(--blue-hot); margin: 0 0 .2rem; }
.hero h1 { margin: 0 0 .3rem; }
.hero-actions { margin-top: .8rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.chip-char { display: inline-block; margin-right: .3rem; padding: .1rem .5rem;
  background: rgba(46, 134, 255, .15); border: 1px solid var(--line);
  border-radius: 7px; font-weight: 600; color: var(--blue-hot); }

.dial { position: relative; width: 116px; flex: 0 0 auto; z-index: 1; }
.dial.big { width: 150px; margin: 0 auto; }
.dial svg { width: 100%; transform: rotate(-90deg); display: block; }
.dial-track { fill: none; stroke: rgba(88, 140, 255, .15); stroke-width: 9; }
.dial-fill { fill: none; stroke: var(--blue); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: calc(326.7 * (1 - var(--pct) / 100));
  filter: drop-shadow(0 0 6px rgba(46, 134, 255, .8));
  transition: stroke-dashoffset .8s cubic-bezier(.3, 1, .4, 1); }
.dial-label { position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; }
.dial-label b { font-family: var(--display); font-size: 1.25rem; }
.dial-label span { font-size: .6rem; color: var(--ink-dim); text-transform: uppercase;
  letter-spacing: .08em; }

.level-path { list-style: none; margin: 0; padding: 0; }
.level-path li { display: flex; align-items: center; gap: .8rem; padding: .55rem .4rem;
  border-bottom: 1px dashed rgba(88, 140, 255, .12); }
.lp-node { flex: 0 0 34px; height: 34px; display: flex; align-items: center;
  justify-content: center; border-radius: 50%; font-family: var(--display);
  font-weight: 700; font-size: .85rem; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-dim); }
.level-path li.mastered .lp-node { background: rgba(39, 209, 127, .15);
  color: var(--good); border-color: rgba(39, 209, 127, .4); }
.level-path li.current .lp-node { background: var(--blue); color: #fff;
  border-color: transparent; box-shadow: 0 0 16px rgba(46, 134, 255, .7);
  animation: pulse 2.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 4px rgba(46, 134, 255, .4); } }
.level-path li.locked { opacity: .42; }
.lp-body { flex: 1; min-width: 0; }
.lp-title { font-family: var(--display); font-weight: 600; font-size: .95rem; display: block; }
.lp-chars code { margin-right: .25rem; font-size: .78rem; color: var(--blue-hot); }
.lp-bar { display: block; height: 4px; margin-top: .3rem; border-radius: 4px;
  background: rgba(88, 140, 255, .15); overflow: hidden; }
.lp-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue-dim), var(--blue-hot));
  border-radius: 4px; }
.lp-go { flex: 0 0 auto; font-size: .8rem; padding: .25rem .6rem;
  border: 1px solid var(--line); border-radius: 8px; }
.lp-go:hover { text-decoration: none; box-shadow: var(--glow); }

.session-list { list-style: none; padding: .4rem .9rem; }
.session-list li { display: flex; gap: .7rem; align-items: baseline;
  padding: .4rem 0; border-bottom: 1px dashed rgba(88, 140, 255, .1);
  font-size: .9rem; }
.session-list li:last-child { border-bottom: 0; }
.sl-mode { font-family: var(--mono); font-size: .72rem; padding: .05rem .45rem;
  border-radius: 6px; background: rgba(46, 134, 255, .18); color: var(--blue-hot); }
.sl-mode.send { background: rgba(39, 209, 127, .15); color: var(--good); }
.sl-what { flex: 1; color: var(--ink-dim); }
.sl-score { font-family: var(--mono); }
.sl-xp { color: var(--amber); font-family: var(--mono); font-size: .82rem; }

/* ------------------------------------------------------------- trainer */

.train-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; }
.level-picker { display: flex; align-items: center; gap: .45rem; }
.picker-intro { margin: .2rem 0 .9rem; }

.drill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .7rem; }
.drill-chip { text-align: left; padding: .85rem .9rem; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  display: flex; flex-direction: column; gap: .15rem; min-height: 86px; }
.drill-chip b { font-size: 1.02rem; }
.drill-chip span { font-family: var(--body); font-weight: 400; font-size: .78rem;
  color: var(--ink-dim); letter-spacing: 0; }
.drill-chip em { font-style: normal; font-size: .7rem; color: var(--amber); }
.drill-chip:not(.locked):hover { border-color: var(--blue); }
.drill-chip.locked { opacity: .45; cursor: default; }

.run-top { display: flex; align-items: center; gap: .8rem; margin: .6rem 0 1rem; }
.run-progress { flex: 1; height: 6px; background: rgba(88, 140, 255, .15);
  border-radius: 6px; overflow: hidden; }
.run-progress i { display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--blue-dim), var(--blue-hot));
  transition: width .4s; border-radius: 6px; }

.stage { text-align: center; }
.ear { display: flex; gap: 10px; justify-content: center; margin: 1.6rem 0 1rem; height: 34px; }
.ear span { width: 10px; height: 10px; border-radius: 50%; background: var(--blue);
  opacity: .25; align-self: center; transition: all .2s; }
.listening .ear span { animation: beat 1s infinite; opacity: 1; }
.listening .ear span:nth-child(2) { animation-delay: .15s; width: 10px; border-radius: 6px; }
.listening .ear span:nth-child(3) { animation-delay: .3s; }
@keyframes beat { 0%, 100% { transform: scaleY(1); } 30% { transform: scaleY(2.6); } }

#copy-answer { max-width: 420px; margin: 0 auto; text-align: center;
  font-size: 1.25rem; letter-spacing: .12em; text-transform: uppercase; }

.char-pad { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: center;
  margin: 1.1rem auto 0; max-width: 460px; }
.pad-key { min-width: 42px; padding: .5rem .55rem; font-family: var(--mono);
  font-size: 1rem; border-radius: 9px; }
.pad-key.pad-new { border-color: var(--blue); color: var(--blue-hot);
  box-shadow: 0 0 10px rgba(46, 134, 255, .25); }
.pad-key.pad-space { min-width: 84px; color: var(--ink-dim); }
.pad-key.pad-back { min-width: 56px; color: var(--bad); }

.feedback { min-height: 54px; display: flex; gap: .6rem; align-items: center;
  justify-content: center; flex-wrap: wrap; margin: .4rem 0 .8rem;
  font-family: var(--mono); }
.feedback strong { font-size: 1.3rem; }
.feedback.good strong { color: var(--good); text-shadow: 0 0 14px rgba(39, 209, 127, .7); }
.feedback.bad strong { color: var(--bad); }
.feedback .hint { width: 100%; font-size: .8rem; color: var(--amber); font-family: var(--body); }
.feedback .yours { width: 100%; font-size: .8rem; color: var(--ink-dim); }
.mp-char { display: inline-flex; flex-direction: column; align-items: center;
  padding: .15rem .3rem; }
.mp-char b { font-size: .95rem; }
.mp-char i { font-style: normal; color: var(--blue-hot); font-size: .9rem;
  letter-spacing: .08em; line-height: 1; }
.mp-gap { width: .7rem; }

.send-target { font-family: var(--mono); margin: 1rem 0 .2rem; min-height: 60px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem .4rem; }
.send-target .mp-char b { font-size: 1.25rem; }
.send-readout { font-family: var(--mono); font-size: 1.3rem; min-height: 2rem;
  letter-spacing: .18em; color: var(--good); }
.send-readout .live { color: var(--blue-hot); margin-left: .4rem; }

.straight-pad {
  width: min(230px, 62vw); height: min(230px, 62vw); border-radius: 50%;
  margin: 1.1rem auto .4rem; display: block;
  font: 700 1.3rem var(--display); letter-spacing: .3em; text-indent: .3em;
  background: radial-gradient(circle at 35% 30%, var(--panel-2), var(--bg1) 75%);
  border: 2px solid var(--line);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5), inset 0 2px 12px rgba(88, 140, 255, .15);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.straight-pad.down { background: radial-gradient(circle at 35% 30%, var(--blue-dim), var(--bg1) 80%);
  border-color: var(--blue);
  box-shadow: 0 4px 18px rgba(46, 134, 255, .55), inset 0 2px 20px rgba(46, 134, 255, .4);
  transform: translateY(3px); }
.paddles { display: flex; gap: 1rem; justify-content: center; margin: 1.2rem 0 .6rem; }
.paddle { width: min(150px, 40vw); height: min(150px, 40vw); border-radius: 22px;
  font-size: 3rem; font-family: var(--mono); touch-action: none; user-select: none;
  -webkit-user-select: none; }
.paddle.hit { background: var(--blue-dim); border-color: var(--blue);
  box-shadow: 0 0 22px rgba(46, 134, 255, .5); }

/* ------------------------------------------------------------- summary */

.summary-card { text-align: center; margin-top: 1.2rem; }
.summary-stats { display: flex; gap: 1.2rem; justify-content: center;
  align-items: baseline; margin: .6rem 0; }
.sum-xp { font-family: var(--display); font-weight: 700; font-size: 1.3rem;
  color: var(--amber); text-shadow: 0 0 18px rgba(255, 180, 84, .5); }
.sum-items { list-style: none; padding: 0; margin: .8rem auto; max-width: 420px;
  text-align: left; max-height: 220px; overflow: auto; }
.sum-items li { display: flex; gap: .7rem; align-items: baseline; padding: .3rem .5rem;
  border-radius: 8px; font-size: .92rem; flex-wrap: wrap; }
.sum-items li.good::before { content: "✓"; color: var(--good); }
.sum-items li.bad::before { content: "✗"; color: var(--bad); }
.sum-items li.bad { background: rgba(255, 93, 108, .08); }
.sum-items .yours { color: var(--ink-dim); font-size: .8rem; }

.levelup { text-align: center; padding: 1.4rem 0 .4rem; animation: rise .7s cubic-bezier(.2, 1.4, .4, 1); }
.levelup h2 { font-size: 2rem; margin: .2rem 0;
  background: linear-gradient(90deg, var(--blue-hot), #9cc8ff, var(--blue-hot));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: .2em; }
.levelup-burst { font-size: 2.4rem; color: var(--amber);
  animation: pop 1s cubic-bezier(.2, 1.6, .4, 1) both; }
.levelup p { color: var(--ink-dim); font-family: var(--display); }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
@keyframes pop { 0% { transform: scale(.2); } 65% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ------------------------------------------------------------- progress */

.pg-stats { display: flex; justify-content: space-around; text-align: center; }
.pg-stats b { font: 700 1.6rem var(--display); display: block; color: var(--blue-hot); }
.pg-stats span { font-size: .72rem; color: var(--ink-dim); text-transform: uppercase;
  letter-spacing: .1em; }

.mastery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: .45rem; }
.mg-cell { text-align: center; padding: .4rem .1rem; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); }
.mg-cell b { font-family: var(--mono); font-size: 1rem; display: block; }
.mg-cell span { font-size: .62rem; color: var(--ink-dim); }
.mg-cell.strong { border-color: rgba(39, 209, 127, .5); background: rgba(39, 209, 127, .1); }
.mg-cell.strong b { color: var(--good); }
.mg-cell.mid { border-color: rgba(255, 180, 84, .4); background: rgba(255, 180, 84, .07); }
.mg-cell.mid b { color: var(--amber); }
.mg-cell.weak { border-color: rgba(255, 93, 108, .45); background: rgba(255, 93, 108, .08); }
.mg-cell.weak b { color: var(--bad); }

.confusion-list { list-style: none; padding: .5rem 1rem; }
.confusion-list li { display: flex; gap: .5rem; align-items: baseline; padding: .3rem 0;
  font-size: .95rem; }
.confusion-list code { background: rgba(46, 134, 255, .12); padding: .05rem .45rem;
  border-radius: 6px; }
.confusion-list .ref { margin-left: auto; }
#history { width: 100%; display: block; }

/* ------------------------------------------------------------- settings */

.settings-form h2:first-child { margin-top: 0; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: .3rem 1.4rem; }
.field-grid label { display: flex; flex-direction: column; gap: .3rem; }
.field-grid .ref { float: right; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px;
  background: rgba(88, 140, 255, .2); border: 0; border-radius: 6px; padding: 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px;
  height: 22px; border-radius: 50%; background: var(--blue-hot);
  box-shadow: 0 0 10px rgba(46, 134, 255, .6); cursor: pointer; }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border: 0;
  border-radius: 50%; background: var(--blue-hot); cursor: pointer; }
.key-mode { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.radio { display: flex; align-items: center; gap: .45rem; font-weight: 400; }
.radio input { width: auto; }
.passkey-list { list-style: none; padding: 0; }
.passkey-list li { display: flex; gap: .7rem; align-items: center; padding: .45rem 0;
  border-bottom: 1px dashed rgba(88, 140, 255, .12); flex-wrap: wrap; }
.passkey-list form { margin-left: auto; }

@media (max-width: 560px) {
  .hero { flex-direction: column; text-align: center; }
  .hero-actions { justify-content: center; }
  .hero::after { display: none; }
  .train-head { flex-direction: column; gap: .2rem; }
}
