:root {
  --bg: #0d0f14;
  --panel: #14171f;
  --panel-2: #1a1e28;
  --line: #262b38;
  --text: #e6e9f0;
  --muted: #8a93a6;
  --dim: #454c5e;
  --accent: #6fe3a1;
  --accent-2: #62b6ff;
  --bad: #ff5f6d;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;

  /* content width on a desktop; every screen centres on this */
  --page: 1300px;
  --gutter: 24px;
  --scroll-thumb: #2a3040;
  --scroll-thumb-hover: #3a4356;
}

* { box-sizing: border-box; }

/* The default OS scrollbar is a bright slab against a dark page. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
*::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
button:hover { border-color: #3a4154; background: #222736; }
button:active { transform: translateY(1px); }
button.primary { background: #1e2c42; border-color: #2f4767; color: #cfe4ff; }
button.primary:hover { background: #25374f; }
button.accent { background: #1c3b2b; border-color: #2d6446; color: var(--accent); }
button.accent:hover { background: #224833; }
button.peer { background: transparent; }
button.big { padding: 11px 20px; font-size: 15px; }
button:disabled { opacity: .45; cursor: default; }

input, select {
  font: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus { border-color: #3d6ea8; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #0f121a;
  flex: 0 0 auto;
}
.brand {
  font-weight: 700;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.top-right { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.name-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.name-field input { width: 150px; max-width: 40vw; }

/* ---------- screens ---------- */
.screen { flex: 1 1 auto; min-height: 0; }

/* Any full screen scrolls when its content is taller than the viewport, and
   only then. Without this the rankings page clipped instead of scrolling. */
#screen-home,
#screen-ranks {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;  /* no width jump when the bar appears */
}

/* Dialogs scroll too rather than overflowing a short window. */
.modal { overflow-y: auto; }
.modal-card { max-height: calc(100vh - 40px); overflow-y: auto; }

/* ---------- home ---------- */
.home-wrap {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 44px) var(--gutter) 40px;
}
.home-wrap h1 { font-size: clamp(24px, 3.4vw, 34px); margin: 0 0 8px; line-height: 1.15; }
.sub { color: var(--muted); margin: 0 0 28px; }

/* level / topics / race time share a row while there is width for it */
.opt-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(300px, 2fr) minmax(170px, 1fr);
  gap: 18px;
  align-items: start;
}
.opt-grid .panel { margin-bottom: 0; height: 100%; }
.opt-grid { margin-bottom: 20px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 20px;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
}
.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
}
.lang-grid button {
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px;
}
.lang-grid button.on {
  background: #1c3b2b;
  border-color: var(--accent);
  color: var(--accent);
}
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 20px; }
.join { display: flex; gap: 8px; }
.join input {
  width: 110px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 3px;
  text-align: center;
}
.err { color: var(--bad); min-height: 20px; margin-top: 14px; }

/* ---------- room layout ---------- */
#screen-room { display: flex; overflow: hidden; }

.chat {
  width: 288px;
  flex: 0 0 288px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
.room-code { font-family: var(--mono); color: var(--accent); letter-spacing: 2px; }
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14px;
}
.msg .who { color: var(--accent-2); font-weight: 600; margin-right: 6px; }
.msg.me .who { color: var(--accent); }
.msg .body { color: #d6dae4; word-break: break-word; }
.msg.sys { color: var(--muted); font-style: italic; font-size: 13px; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1 1 auto; min-width: 0; }
.chat-form button { padding: 8px 12px; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 22px 22px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}
/* keep the race column readable on a very wide monitor */
.main > * {
  width: 100%;
  max-width: var(--page);
  margin-left: auto;
  margin-right: auto;
}
.room-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.room-meta { display: flex; align-items: center; gap: 10px; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; }
.code-pill {
  font-family: var(--mono);
  letter-spacing: 3px;
  color: var(--accent);
  background: #14231b;
  border-color: #2d6446;
}
.lang-select { font-family: var(--mono); font-size: 13px; }
.room-ctl { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.badge.racing { color: var(--accent); border-color: #2d6446; }
.badge.countdown { color: #ffc46b; border-color: #6b5326; }

/* ---------- racers ---------- */
.racers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.racer {
  display: grid;
  grid-template-columns: 150px 1fr 150px;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
.racer.me { border-color: #2d6446; }
.racer .who { font-weight: 600; display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.racer .tag { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.racer .tag.ready { color: var(--accent); border-color: #2d6446; }
.bar { height: 10px; background: #0b0d12; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .12s linear;
}
.racer .stat { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.racer .stat b { color: var(--text); }

/* ---------- stage ---------- */
.stage { position: relative; }
.hud { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-bottom: 10px; }
.hud-item { display: flex; align-items: baseline; gap: 6px; }
.hud-item b { font-family: var(--mono); font-size: 20px; color: var(--accent); }
.hud-item span { font-size: 11px; text-transform: uppercase; letter-spacing: 1.3px; color: var(--muted); }

.code-box {
  background: #101219;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  max-height: clamp(180px, 46vh, 640px);
  overflow-y: auto;
  position: relative;
}
.code-box.locked { opacity: .5; filter: saturate(.4); }
.code-box.focus { border-color: #3d6ea8; box-shadow: 0 0 0 1px #3d6ea855; }

.code-area {
  margin: 0;
  font-family: var(--mono);
  font-size: 16.5px;
  line-height: 1.75;
  white-space: pre;
  tab-size: 4;
}

/* per-character states — must come after prism theme to beat token colors */
.code-area .ch { color: var(--dim); position: relative; }
.code-area .ch.done { color: inherit; }
.code-area .ch.cur { background: rgba(98, 182, 255, .18); border-radius: 2px; }
.code-area .ch.cur::after {
  content: "";
  position: absolute;
  left: -1px; top: 4%;
  width: 2px; height: 92%;
  background: var(--accent-2);
  animation: blink 1s steps(1) infinite;
}
.code-area .ch.bad { background: rgba(255, 95, 109, .3); color: #ffd7da; border-radius: 2px; }
.code-area .ch.bad::after { background: var(--bad); }
.code-area .nl::before { content: "¬"; color: #2c3242; }
@keyframes blink { 50% { opacity: 0; } }

.trap { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  background: rgba(13, 15, 20, .82);
  border-radius: 12px;
}
.countdown span {
  font-family: var(--mono);
  font-size: 88px;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(111, 227, 161, .35);
}

/* ---------- results ---------- */
.results {
  margin-top: 18px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}
.results h3 { margin: 0 0 12px; font-size: 14px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.results table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 14px; }
.results th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding-bottom: 8px; }
.results td { padding: 6px 0; border-top: 1px solid var(--line); }
.results tr.me td { color: var(--accent); }

/* ---------- responsive ---------- */

/* laptops: the three option panels no longer fit side by side comfortably */
@media (max-width: 1100px) {
  :root { --gutter: 18px; }
  .opt-grid { grid-template-columns: 1fr 1fr; }
  .opt-grid .opt-wide { grid-column: 1 / -1; order: -1; }
}

@media (max-width: 960px) {
  .chat { width: 240px; flex-basis: 240px; }
  .racer { grid-template-columns: 120px 1fr 120px; }
  .main { padding: 14px 16px 18px; }
}

/* tablets and phones: one column of options, chat under the race */
@media (max-width: 820px) {
  :root { --gutter: 14px; }
  .opt-grid { grid-template-columns: 1fr; gap: 14px; }
  .opt-grid .opt-wide { order: 0; }
  .opt-grid .panel { height: auto; }

  #screen-room {
    flex-direction: column;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
  .main { order: 1; overflow: visible; padding: 14px 14px 18px; }
  .chat {
    order: 2;
    width: 100%;
    flex: 0 0 auto;
    max-height: 42vh;
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .code-area { font-size: 15px; }
  .countdown span { font-size: 64px; }
  .hud-item b { font-size: 18px; }
}

@media (max-width: 620px) {
  .home-wrap h1 { font-size: 22px; }
  .sub { margin-bottom: 20px; }
  .panel { padding: 14px; border-radius: 12px; }
  .lang-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
  .lang-grid button { padding: 9px 6px; font-size: 12px; }

  /* name and bar on one line, progress bar across the row below */
  .racer {
    grid-template-columns: 1fr auto;
    grid-template-areas: "who stat" "bar bar";
    row-gap: 8px;
  }
  .racer .who { grid-area: who; }
  .racer .stat { grid-area: stat; }
  .racer .bar { grid-area: bar; }

  .room-top { gap: 10px; }
  .room-ctl { flex-wrap: wrap; }
  .room-filters .fl { flex-direction: column; gap: 6px; }
  .room-filters .fl-label { padding-top: 0; }

  .actions { flex-direction: column; align-items: stretch; }
  .actions .join { width: 100%; }
  .actions .join input { flex: 1 1 auto; width: auto; }
  .actions button.big { width: 100%; }

  .code-area { font-size: 14px; line-height: 1.7; }
  .code-box { padding: 14px; }
  .countdown span { font-size: 52px; }
  .chip { padding: 5px 8px; font-size: 12px; }
  .lb-row { grid-template-columns: 20px 20px 1fr auto; }
  .lb-row .lb-acc { display: none; }
  .modal-card { padding: 18px; }
}

/* phones in landscape: keep the code area usable */
@media (max-height: 520px) and (orientation: landscape) {
  .code-box { max-height: 52vh; }
  .home-wrap { padding-top: 16px; }
}

/* respect a reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .bar > i { transition: none; }
}

/* ---------- filters: level + topic chips ---------- */
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.panel h2 .head-actions { margin-left: auto; display: flex; gap: 8px; }
.panel h2 { display: flex; align-items: center; gap: 8px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-2);
  font-size: 12px;
}
.link:hover { background: none; text-decoration: underline; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel-2);
}
.chip .chip-n {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  background: #11141b;
  border-radius: 4px;
  padding: 1px 5px;
}
.chip.on { color: var(--accent); border-color: #2d6446; background: #1c3b2b; }
.chip.on .chip-n { color: var(--accent); background: #16301f; }
.chip.off { opacity: .35; cursor: default; }

.warn {
  margin: 10px 0 0;
  font-size: 13px;
  color: #ffc46b;
}

/* ---------- room filter tray ---------- */
.room-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.room-filters .fl { display: flex; align-items: flex-start; gap: 10px; }
.room-filters .fl-label {
  min-width: 52px;
  padding-top: 7px;
  font-size: 12px;
  color: var(--muted);
}
.room-filters p { margin: 0; font-size: 12px; }

.snip-meta {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 7px;
}
.snip-meta.lvl-very-easy { color: var(--accent-2); border-color: #2f4767; }
.snip-meta.lvl-easy { color: var(--accent); border-color: #2d6446; }
.snip-meta.lvl-medium { color: #ffc46b; border-color: #6b5326; }
.snip-meta.lvl-hard { color: var(--bad); border-color: #6b2c31; }

/* ---------- avatars + profile ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2) center / cover no-repeat;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
}
.avatar.has-img { color: transparent; border-color: #2d6446; }
.avatar.sm { width: 20px; height: 20px; flex-basis: 20px; font-size: 10px; }
.avatar.big { width: 72px; height: 72px; flex-basis: 72px; font-size: 28px; }

.profile { display: flex; align-items: center; gap: 8px; }
.profile .pname { font-weight: 600; font-size: 14px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msg { display: flex; align-items: baseline; gap: 6px; }
.msg .avatar { align-self: center; }

/* ---------- leaderboard ---------- */
.lb { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: grid;
  grid-template-columns: 22px 20px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 13px;
}
.lb-row.me { border-color: #2d6446; }
.lb-row .lb-i { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.lb-row .lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .lb-wpm { font-family: var(--mono); color: var(--accent); }
.lb-row .lb-acc { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ---------- profile modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 8, 12, .72);
}
.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-card > .muted { display: block; margin-bottom: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field em { font-style: normal; }
.field input[type="file"] { padding: 7px; font-size: 12px; }

.pf-preview { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.modal-ctl { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- stars ---------- */
.stars { display: inline-flex; align-items: center; gap: 2px; }
.star { color: var(--dim); font-size: 15px; line-height: 1; }
.star.on { color: #ffc46b; text-shadow: 0 0 10px rgba(255, 196, 107, .45); }
.star-note { color: var(--muted); font-size: 12px; font-style: normal; margin-left: 10px; }

/* ---------- simulated run panel ---------- */
.run {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b0d12;
  overflow: hidden;
}
.run-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: #101219;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--muted);
}
.run-head .stars { margin-left: auto; text-transform: none; letter-spacing: 0; }
.run-dots { display: inline-flex; gap: 5px; }
.run-dots i { width: 9px; height: 9px; border-radius: 50%; background: #2a3040; }
.run-dots i:first-child { background: #ff5f6d; }
.run-dots i:nth-child(2) { background: #ffc46b; }
.run-dots i:last-child { background: var(--accent); }
.run-out {
  margin: 0;
  padding: 14px 16px;
  min-height: 62px;
  max-height: 210px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: #cfe7d8;
  white-space: pre-wrap;
  word-break: break-word;
}
.run-note { margin: 0; padding: 0 16px 12px; font-size: 11px; }

/* ---------- opponent carets ---------- */
/* NOTE: named .peer, not .ghost - button.ghost already exists. */
.ghosts { position: absolute; inset: 18px 20px; pointer-events: none; }
.peer {
  position: absolute;
  width: 2px;
  background: var(--c, var(--accent-2));
  box-shadow: 0 0 8px var(--c, var(--accent-2));
  border-radius: 2px;
  transition: left .12s linear, top .12s linear;
}
/* No name label on the caret: it covered the very text being typed.
   The colour matches the dot on that racer's row, and the name is a tooltip. */
.peer.ahead { width: 3px; animation: rush .7s ease-in-out infinite; }
@keyframes rush { 50% { opacity: .45; } }

/* ---------- ratings ---------- */
.dotc {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--dim);
  box-shadow: 0 0 6px currentColor;
}

.rate {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-2);
  border: 1px solid #2f4767;
  background: #101f33;
  border-radius: 5px;
  padding: 1px 6px;
}
.rate.sm { font-size: 10px; padding: 0 4px; }
.avatar.is-bot { border-color: #6b5326; }
.racer.is-bot .nm { color: #ffc46b; }
.results tr.bot td { color: var(--muted); }
.results .botflag {
  font-style: normal;
  font-size: 10px;
  color: #ffc46b;
  border: 1px solid #6b5326;
  border-radius: 4px;
  padding: 0 4px;
}
.results td .up { color: var(--accent); }
.results td .down { color: var(--bad); }
.results td .flat { color: var(--dim); }

/* ---------- bot cards ---------- */
.bot-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.bot-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 10px 12px;
  background: var(--panel-2);
}
.bot-card:disabled { opacity: .4; }
.bot-mid { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.bot-name { font-weight: 600; font-size: 14px; }
.bot-blurb { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bot-rate { font-family: var(--mono); color: var(--accent-2); font-size: 14px; }
.bot-rank { font-size: 10px; white-space: nowrap; }
.modal-card.wide { max-width: 700px; max-height: 84vh; overflow-y: auto; }

/* ---------- rankings ---------- */
.ranks-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.live {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  border: 1px solid #2d6446;
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 6px;
}
.live::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 5px;
  animation: rush 1.6s ease-in-out infinite;
}
.ranks { display: flex; flex-direction: column; gap: 6px; }
.rank-row {
  display: grid;
  grid-template-columns: 34px 26px minmax(0, 1fr) auto 62px auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  font-size: 14px;
}
.rank-row.me { border-color: #2d6446; background: #16241c; }
.rank-row.bot .rk-name { color: #ffc46b; }
.rank-row.outside { margin-top: 10px; border-style: dashed; }
.rk-i { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.rk-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-title { font-size: 11px; white-space: nowrap; }
.rk-rate { font-family: var(--mono); color: var(--accent-2); text-align: right; }
.rk-sub { font-size: 11px; white-space: nowrap; }

.ladder { display: flex; flex-wrap: wrap; gap: 8px; }
.tier {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--panel-2);
  font-size: 12px;
}
.tier b { font-weight: 600; }
.tier span { font-family: var(--mono); font-size: 10px; color: var(--muted); }

@media (max-width: 620px) {
  .rank-row { grid-template-columns: 26px 20px minmax(0, 1fr) auto; gap: 8px; font-size: 13px; }
  .rank-row .rk-title, .rank-row .rk-sub { display: none; }
  .bot-list { grid-template-columns: 1fr; }
}

/* ---------- logo ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  border-radius: 10px;
  padding: 2px 6px 2px 2px;
  transition: background .15s ease;
}
.brand:hover { background: #171b24; }
.brand .logo { width: 32px; height: 32px; flex: 0 0 32px; display: block; }
.brand-text { font-weight: 700; letter-spacing: .4px; font-size: 17px; }
.brand-text em { font-style: normal; color: var(--accent); }

/* ---------- profile button ---------- */
button.profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  background: var(--panel-2);
}
button.profile:hover { background: #222736; }
button.profile .pname {
  font-weight: 600;
  font-size: 14px;
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- bot card artwork ---------- */
.bot-card { position: relative; overflow: hidden; }
.bot-art {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 58%;
  background: right center / cover no-repeat;
  opacity: .42;
}
/* fade the art out towards the text so the labels stay readable */
.bot-card.has-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--panel-2) 34%, rgba(26, 30, 40, .55) 70%,
                              rgba(26, 30, 40, .25));
}
.bot-card.has-art > *:not(.bot-art) { position: relative; z-index: 1; }
.bot-card.has-art:hover .bot-art { opacity: .45; }
.bot-card .avatar { width: 40px; height: 40px; flex-basis: 40px; font-size: 16px; }

@media (max-width: 620px) {
  .brand-text { display: none; }
  button.profile .pname { max-width: 84px; }
}

/* ---------- race outcome overlay ---------- */
.win-card {
  width: 100%;
  max-width: 440px;
  padding: 30px 26px 22px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: radial-gradient(circle at 50% -10%, #1a2430, var(--panel) 62%);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .6);
  animation: pop .26s cubic-bezier(.2, 1.3, .5, 1);
}
.modal.won .win-card { border-color: #2d6446; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

.win-stars { display: flex; justify-content: center; gap: 10px; margin-bottom: 14px; }
.wstar {
  font-size: 46px;
  line-height: 1;
  color: #262b38;
  animation: none;
}
.wstar.on {
  color: #ffc46b;
  text-shadow: 0 0 24px rgba(255, 196, 107, .55);
  animation: star-in .42s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes star-in {
  from { transform: scale(.2) rotate(-35deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

.win-card h3 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.3px; }
.modal.won .win-card h3 { color: var(--accent); }
.win-sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

.win-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.win-stats > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.win-stats b { font-family: var(--mono); font-size: 19px; color: var(--text); }
.win-stats b.up { color: var(--accent); }
.win-stats b.down { color: var(--bad); }
.win-stats span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}
.win-card .modal-ctl { justify-content: center; }
.nostars { color: var(--dim); font-family: var(--mono); }

@media (max-width: 620px) {
  .win-stats { grid-template-columns: repeat(2, 1fr); }
  .wstar { font-size: 38px; }
}

/* ---------- name availability ---------- */
.name-note { font-size: 11px; min-height: 14px; color: var(--muted); }
.name-note.ok { color: var(--accent); }
.name-note.bad { color: #ffc46b; }
.ideas { display: flex; flex-wrap: wrap; gap: 6px; }
.idea {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 8px;
  color: var(--accent-2);
  border-color: #2f4767;
  background: #101f33;
}
.idea:hover { background: #16304d; border-color: #3d6ea8; }

/* ---------- avatar drop zone ---------- */
.drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 16px;
  text-align: center;
  border: 1px dashed #333b4d;
  border-radius: 12px;
  background: #11141b;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.drop:hover, .drop:focus-visible { border-color: #3d6ea8; background: #141926; outline: none; }
.drop.over { border-color: var(--accent); background: #16241c; color: var(--accent); }
.drop b { color: var(--text); font-size: 14px; }
.drop .muted { font-size: 11px; }
.drop-icon { width: 26px; height: 26px; color: var(--accent-2); }
.drop-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- cropper ---------- */
.crop { display: flex; gap: 16px; align-items: flex-start; }
.crop-stage {
  position: relative;
  width: 148px;
  height: 148px;
  flex: 0 0 148px;
  border-radius: 12px;
  overflow: hidden;
  background: #0b0d12;
  cursor: grab;
  touch-action: none;
}
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { width: 100%; height: 100%; display: block; }
/* circular guide showing what the avatar will actually look like */
.crop-ring {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(111, 227, 161, .85);
  box-shadow: 0 0 0 999px rgba(11, 13, 18, .55);
  pointer-events: none;
}
.crop-side { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.crop-zoom { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
.crop-zoom input { width: 100%; accent-color: var(--accent); }
.crop-side p { margin: 0; font-size: 11px; }

/* ---------- bot trash talk ---------- */
.msg.bot .who { color: #ffc46b; }
.msg.bot .body { color: #e7d6b4; font-style: italic; }

@media (max-width: 620px) {
  .crop { flex-direction: column; align-items: stretch; }
  .crop-stage { width: 100%; height: 220px; flex-basis: auto; }
}
