:root {
  --bg: #121418;
  --panel: #1a1d23;
  --panel-2: #20242b;
  --line: #2a2f38;
  --dim: #4c5361;
  --sub: #8a909c;
  --text: #ece7dc;
  --accent: #ff7a1a;
  --gold: #ffc53d;
  --err: #ff3d5e;
  --extra: #8f2238;
  --good: #5ee6a8;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Roboto Mono', ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--mono);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 50% -120px, rgba(255, 122, 26, 0.10), transparent 70%),
    var(--bg);
}

button, input { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55em 1em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a0d03; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--sub); }
button.small { font-size: 0.8rem; padding: 0.3em 0.7em; }

input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55em 0.8em;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem;
}
.logo { display: flex; align-items: center; gap: 0.6rem; color: var(--sub); text-decoration: none; font-size: 1.35rem; letter-spacing: -0.02em; }
.logo svg { width: 26px; height: 26px; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; fill: none; }
.logo b { color: var(--accent); font-weight: 700; }
.head-right { display: flex; align-items: center; gap: 0.8rem; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.2em 0.8em; letter-spacing: 0.2em; color: var(--accent); font-weight: 700; }
.net { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.net.on { background: var(--good); }
.net.off { background: var(--err); animation: blink 1s steps(2) infinite; }

main { max-width: 1040px; margin: 0 auto; padding: 0 1.5rem 4rem; }

/* ---------- home ---------- */
#home { max-width: 640px; margin: 4vh auto 0; }
#home h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 0.5rem; letter-spacing: -0.02em; }
.sub { color: var(--sub); margin: 0 0 1.5rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem 1.3rem; }
#home-form label { display: grid; gap: 0.4rem; color: var(--sub); font-size: 0.9rem; margin-bottom: 1rem; }
#home-form #name { font-size: 1.1rem; color: var(--text); }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.or { color: var(--dim); }
#code { width: 6.5em; text-transform: uppercase; letter-spacing: 0.25em; text-align: center; }
.err { color: var(--err); min-height: 1.2em; margin: 0.8rem 0 0; font-size: 0.9rem; }
.how { color: var(--sub); line-height: 1.7; padding-left: 1.2rem; margin-top: 1.6rem; font-size: 0.92rem; }
.how b { color: var(--text); }

/* ---------- settings bar ---------- */
.config { display: grid; gap: 0.5rem; justify-items: center; margin: 0.5rem 0 1.4rem; }
.config-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; justify-content: center; background: var(--panel); border-radius: 10px; padding: 0.35rem 0.8rem; }
.group { display: flex; align-items: center; gap: 0.1rem; }
.group + .group { border-left: 1px solid var(--line); padding-left: 1rem; }
.group-label { color: var(--dim); font-size: 0.78rem; margin-right: 0.4rem; }
.pill { background: none; border: none; color: var(--sub); padding: 0.3em 0.55em; font-size: 0.85rem; }
.pill:hover:not(:disabled) { color: var(--text); }
.pill.on { color: var(--accent); }
.pill:disabled:not(.on) { color: var(--dim); }
.custom { width: 4.6em; padding: 0.15em 0.4em; font-size: 0.85rem; margin-left: 0.3rem; color: var(--sub); }
.custom.on { color: var(--accent); border-color: var(--accent); }
.config-note { color: var(--dim); font-size: 0.78rem; margin: 0; }

/* ---------- lanes ---------- */
.track { display: grid; gap: 0.35rem; margin-bottom: 1.6rem; }
.lane { display: grid; grid-template-columns: 9rem 1fr 3.2rem; align-items: center; gap: 0.8rem; }
.lane-name { color: var(--sub); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.lane.you .lane-name { color: var(--text); }
.rail {
  position: relative;
  height: 26px;
  border-bottom: 1px dashed var(--line);
  background: linear-gradient(90deg, transparent calc(100% - 3px), var(--accent) calc(100% - 3px));
}
.unit { position: absolute; left: 0; bottom: 3px; width: 24px; height: 14px; transition: left 0.16s linear; }
.unit svg { width: 24px; height: 14px; fill: var(--c); display: block; filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c) 55%, transparent)); }
.unit-wpm { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); font-size: 0.7rem; color: var(--sub); white-space: nowrap; }
.lane-tag { font-size: 0.8rem; color: var(--gold); }
.lane.dropped { opacity: 0.4; }
.lane.dropped .lane-tag { color: var(--dim); }
.lane.hit .unit { animation: hit 0.6s; }
@keyframes hit { 0%, 100% { transform: none; } 20% { transform: translate(-3px, -2px) rotate(-8deg); } 40% { transform: translate(3px, 1px) rotate(6deg); } 60% { transform: translate(-2px, 0); } }

/* ---------- typing ---------- */
.hud { display: flex; align-items: baseline; gap: 1.4rem; min-height: 2.2rem; }
.hud .big { color: var(--accent); font-size: 1.5rem; }
.charge { color: var(--sub); font-size: 0.9rem; }

.typing { position: relative; margin-top: 0.4rem; cursor: text; }
.viewport { position: relative; overflow: hidden; }
.words { position: relative; display: flex; flex-wrap: wrap; font-size: 1.65rem; line-height: 1.5; transition: transform 0.12s ease-out; user-select: none; }
.word { margin: 0.2em 0.32em; color: var(--dim); border-bottom: 2px solid transparent; }
.word span.ok { color: var(--text); }
.word span.bad { color: var(--err); }
.word span.extra { color: var(--extra); }
.word.err { border-bottom-color: var(--err); }

.caret {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 1.5em;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--accent);
  transition: transform 0.09s ease-out;
  z-index: 1;
}
.caret.idle { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.typing.blurred .viewport { filter: blur(5px); opacity: 0.5; }
.typing.finished .viewport { opacity: 0.35; }
.typing.jammed .words { filter: blur(3.5px); }
.typing.jammed { animation: shake 0.25s linear 8; }
.typing.nope .viewport { animation: nope 0.18s; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes nope { 0%, 100% { transform: none; } 50% { transform: translateX(3px); } }

.focus-msg, .countdown, .done-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.focus-msg { color: var(--text); }
.countdown { font-size: 5rem; font-weight: 700; color: var(--accent); text-shadow: 0 0 30px rgba(255, 122, 26, 0.5); background: rgba(18, 20, 24, 0.7); }
.done-msg { color: var(--text); font-size: 1.2rem; text-align: center; padding: 0 1rem; }
.ghost-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; pointer-events: none; }
.source { color: var(--dim); font-size: 0.85rem; margin: 1rem 0 0; }
.spectate { color: var(--sub); text-align: center; margin: 2rem 0; }

/* ---------- lobby ---------- */
.lobby { display: grid; gap: 1.2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; }
.card h2 { font-size: 1.05rem; margin: 0; }
.tag { color: var(--accent); font-size: 0.85rem; }

table.results { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.results th { text-align: right; color: var(--dim); font-weight: 400; font-size: 0.78rem; padding: 0.3rem 0.6rem; }
.results th:nth-child(2) { text-align: left; }
.results td { padding: 0.45rem 0.6rem; border-top: 1px solid var(--line); }
.results td.num { text-align: right; color: var(--sub); }
.results td.big-num { color: var(--text); font-size: 1.1rem; }
.results td.pts { color: var(--accent); }
.results td.place { color: var(--sub); width: 3rem; }
.results td.place.gold { color: var(--gold); font-weight: 700; }
.results tr.you td.name { color: var(--accent); }
.name { white-space: nowrap; }
.legend { color: var(--dim); font-size: 0.75rem; margin: 0.8rem 0 0; }

.standings { list-style: none; margin: 0 0 1.2rem; padding: 0; }
.standings li { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-top: 1px solid var(--line); }
.standings li:first-child { border-top: 0; }
.standings li.offline { opacity: 0.5; }
.standings .pname { font-weight: 700; }
.standings .pts { margin-left: auto; color: var(--accent); }
.standings .wins { color: var(--sub); font-size: 0.85rem; width: 4.5rem; text-align: right; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.5rem; vertical-align: middle; flex: none; }
.standings .dot { margin-right: 0; }
.badge { font-size: 0.7rem; color: var(--sub); border: 1px solid var(--line); border-radius: 999px; padding: 0.05em 0.6em; }
.you-badge { color: var(--accent); border-color: var(--accent); }

.invite { display: grid; gap: 0.4rem; color: var(--sub); font-size: 0.85rem; }
.invite input { flex: 1; min-width: 14rem; color: var(--text); }
.start-row { margin-top: 1.3rem; text-align: center; }
.big-btn { font-size: 1.1rem; padding: 0.75em 2.2em; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 10; justify-items: center; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.55rem 1rem; animation: pop 0.2s ease-out; }
.toast.bad { border-color: var(--err); color: var(--err); }
.toast.good { border-color: var(--good); color: var(--good); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 640px) {
  .lane { grid-template-columns: 5.5rem 1fr 2.6rem; }
  .words { font-size: 1.25rem; }
  .group + .group { border-left: 0; padding-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .typing.jammed, .typing.nope .viewport, .lane.hit .unit { animation: none; }
  .caret, .unit, .words { transition: none; }
}
