:root {
  --bg: #0e0e12;
  --bg-2: #16161d;
  --bg-3: #22222c;
  --line: #31313d;
  --text: #f4f4f7;
  --muted: #a0a0b2;
  --dim: #626274;
  --flux: #4641d9;
  --flux-2: #8d8aff;
  --bad: #ff5d73;
  --good: #3dd68c;
  --warn: #e6b450;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 320px at 8% -10%, rgba(70, 65, 217, 0.38), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

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

button { cursor: pointer; }

.app { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 48px; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.mark { width: 32px; height: 32px; }

.brand-name { font-weight: 700; letter-spacing: -0.03em; font-size: 1.15rem; }

.brand-name span { color: var(--flux-2); font-weight: 600; }

.account { display: flex; align-items: center; gap: 10px; }

.who { display: flex; align-items: center; gap: 8px; }

.avatar, .initial {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--flux);
}

.tag { color: var(--muted); font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  align-items: start;
}

.stage, .card, .side section {
  background: rgba(22, 22, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.stage { padding: 22px; min-height: 420px; position: relative; }

.loading, .hint, .muted { color: var(--muted); }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.lengths { margin-top: 10px; }

.mode, .length {
  text-align: left;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.mode strong, .length strong { display: block; margin-bottom: 4px; }

.mode span, .length span { display: block; color: var(--muted); font-size: 0.86rem; line-height: 1.35; }

.mode em { display: block; margin-top: 8px; font-style: normal; color: var(--flux-2); font-size: 0.82rem; }

.mode.selected, .length.selected { border-color: var(--flux); box-shadow: inset 0 0 0 1px var(--flux); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.btn, .key {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: 10px;
  padding: 10px 14px;
}

.btn.primary { background: var(--flux); border-color: transparent; }

.btn.ghost { background: transparent; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.lead { font-size: 1.4rem; margin: 0 0 8px; letter-spacing: -0.03em; }

.join { display: flex; gap: 8px; margin-top: 14px; }

.join input, .dev input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}

.code {
  font-family: var(--mono);
  font-size: 2rem;
  letter-spacing: 0.18em;
  margin: 8px 0;
}

.room-list { list-style: none; padding: 0; margin: 0 0 12px; }

.room-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }

.room-directory { display: grid; gap: 12px; }

.room-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.room-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.room-code {
  font-family: var(--mono);
  font-size: 1.35rem;
  letter-spacing: 0.14em;
}

.room-count { color: var(--muted); }

.rematch-note { margin: 0 0 12px; }

.rematch-note[hidden] { display: none; }

.result-actions { flex-wrap: wrap; }

.race-top, .result-actions, .actions, .account, .join, .dev {
  display: flex;
  align-items: center;
  gap: 10px;
}

.race-top { justify-content: space-between; margin-bottom: 14px; }

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stats { font-family: var(--mono); color: var(--flux-2); }

.passage-wrap { position: relative; min-height: 140px; }

.passage {
  font-family: var(--mono);
  font-size: 1.7rem;
  line-height: 1.65;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.passage.long { font-size: 1.25rem; }

.ch { color: var(--dim); }

.ch.ok { color: var(--text); }

.ch.bad {
  color: var(--bad);
  background: rgba(255, 93, 115, 0.12);
  border-radius: 3px;
}

.ch.cur { box-shadow: -2px 0 0 var(--flux-2); }

.count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: 5.5rem;
  font-weight: 750;
  letter-spacing: -0.05em;
  background: rgba(14, 14, 18, 0.55);
  border-radius: 12px;
}

.count[hidden] { display: none; }

.capture {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  border: 0;
  padding: 0;
  font-size: 16px;
}

.keyboard { margin-top: 18px; display: grid; gap: 6px; user-select: none; touch-action: manipulation; }

.row { display: flex; justify-content: center; gap: 6px; }

.key {
  flex: 1;
  max-width: 58px;
  height: 48px;
  padding: 0;
  box-shadow: 0 2px 0 #09090d;
  font-family: var(--mono);
}

.key.wide { max-width: 92px; flex: 1.5; }
.key.space { max-width: 280px; flex: 5; }
.key.on { background: var(--flux); }
.key:active { transform: translateY(2px); box-shadow: none; }

.locked { color: var(--good); }

.quote { font-family: var(--mono); color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }

th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }

th { color: var(--muted); font-weight: 600; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }

tr.me { background: rgba(70, 65, 217, 0.16); }

.up { color: var(--good); }
.down { color: var(--bad); }

.side { display: grid; gap: 12px; }

#lanes:empty { display: none; }

.side section { padding: 14px; }

.side h2 { margin: 0 0 8px; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.lane { display: grid; grid-template-columns: 92px 1fr auto; gap: 8px; align-items: center; margin: 7px 0; }

.lane b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.track { height: 8px; background: #2a2a36; border-radius: 99px; overflow: hidden; }

.fill { height: 100%; background: var(--flux-2); width: 0; }

.lane .pace { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }

.board-row, .recent-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.board-row span, .recent-row span { color: var(--muted); }

.empty { color: var(--dim); margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #2a2a38;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s linear;
}

.toast.show { opacity: 1; }

.noscript {
  width: min(1120px, calc(100% - 32px));
  margin: 12px auto;
}

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--flux-2);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .layout, .modes { grid-template-columns: 1fr; }
  .passage { font-size: 1.25rem; }
  .app { width: min(1120px, calc(100% - 20px)); }
  .key { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
