@font-face { font-family: 'JB'; src: url(/fonts/mono-400.woff2) format('woff2'); font-weight: 400; font-display: block; }
@font-face { font-family: 'JB'; src: url(/fonts/mono-500.woff2) format('woff2'); font-weight: 500 700; font-display: swap; }

:root, :root[data-theme='dark'] {
  --bg: #1b1c20;
  --panel: #222429;
  --line: #2f3137;
  --sub: #5b5e67;
  --sub2: #868993;
  --text: #e6e2d8;
  --acc: #74d3b4;
  --err: #ec5f67;
  --err2: #9a434a;
  --r0: #f2a65a; --r1: #86b2f9; --r2: #d08cf2; --r3: #f27c94; --r4: #c5d466; --r5: #6fd0e6;
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #efebe3;
  --panel: #e5e0d6;
  --line: #d6d0c4;
  --sub: #a59f94;
  --sub2: #7a756c;
  --text: #2b2a27;
  --acc: #0f8a69;
  --err: #d33a45;
  --err2: #e19aa0;
  --r0: #c4680c; --r1: #2c6cd6; --r2: #9a45c7; --r3: #cc3d61; --r4: #6f8a0e; --r5: #138aa3;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'JB', ui-monospace, 'Cascadia Mono', Menlo, monospace;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 28px;
  transition: background-color .2s;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
kbd {
  font: inherit; font-size: 11px; padding: 1px 5px; border-radius: 4px;
  background: var(--panel); color: var(--sub2);
}

/* ---------- header */

.top, .config, .foot, .live #live-wpm { transition: opacity .25s; }
body.typing .top, body.typing .config, body.typing .foot { opacity: 0; pointer-events: none; }

.top { display: flex; align-items: center; gap: 28px; padding: 26px 0 0; }
.logo {
  font-size: 26px; font-weight: 500; color: var(--text); text-decoration: none; letter-spacing: -.5px;
  display: flex; align-items: center;
}
.logo i { display: inline-block; width: 3px; height: 26px; margin-left: 3px; background: var(--acc); border-radius: 2px; animation: blink 1.1s ease-in-out infinite; }
.nav { display: flex; gap: 20px; }
.nav a { color: var(--sub); text-decoration: none; transition: color .12s; }
.nav a:hover, .nav a.on { color: var(--text); }
.who { margin-left: auto; display: flex; align-items: center; gap: 16px; color: var(--sub); font-size: 13px; }
.online::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--acc); margin-right: 7px; vertical-align: 1px; }
.online:empty { display: none; }
.name { color: var(--sub2); }
.name:hover { color: var(--text); }
.name-edit { width: 14ch; background: var(--panel); color: var(--text); border: 0; border-radius: 4px; padding: 2px 6px; outline: none; font-size: 13px; }
.theme { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--sub); background: linear-gradient(90deg, var(--sub) 50%, transparent 50%); }
.theme:hover { border-color: var(--text); background: linear-gradient(90deg, var(--text) 50%, transparent 50%); }

/* ---------- main column */

.main { display: flex; flex-direction: column; justify-content: center; padding: 40px 0; min-height: 0; }

.config { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 56px; font-size: 13px; }
.config .bar { display: flex; flex-wrap: wrap; justify-content: center; row-gap: 4px; background: var(--panel); border-radius: 8px; padding: 6px 4px; }
.config .bar.sub { background: none; padding: 0 4px; }
.config .grp { display: flex; align-items: center; padding: 0 10px; border-left: 1px solid var(--line); }
.config .grp:first-child { border-left: 0; }
.config button { color: var(--sub2); padding: 3px 6px; border-radius: 4px; transition: color .12s; }
.config button:hover { color: var(--text); }
.config button.on { color: var(--acc); }
.config .lbl { color: var(--sub); padding: 0 6px 0 2px; }
.config[data-mode='time'] [data-show='words'],
.config[data-mode='words'] [data-show='time'],
.config[data-mode='time'] [data-show='bots'],
.config:not([data-vs='bots']) [data-show='bots'] { display: none; }

/* ---------- typing */

.stage { position: relative; }
.live { height: 30px; display: flex; gap: 22px; font-size: 22px; color: var(--acc); margin-bottom: 18px; }
#live-wpm { color: var(--sub); }

.box {
  --fs: 27px;
  --lh: 1.6;
  position: relative;
  font-size: var(--fs);
  line-height: var(--lh);
  height: calc(var(--fs) * var(--lh) * 3);
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
}
.view { position: absolute; left: 0; right: 0; bottom: 0; }
.view-words { top: 0; clip-path: inset(0 -40px 0 -40px); }
/* carets get room above the first line for their name tags */
.view-carets { top: -20px; clip-path: inset(0 -200px 0 -200px); pointer-events: none; }
.view-carets .tape { top: 20px; }
.tape { position: relative; will-change: transform; }
.words { position: relative; transition: filter .15s, opacity .15s; }
.word { display: inline-block; vertical-align: top; margin-right: .6ch; white-space: pre; }
.l { color: var(--sub); }
.l.ok { color: var(--text); }
.l.no { color: var(--err); }
.l.x { color: var(--err2); }
.word.err .l { text-decoration: underline 2px var(--err); text-underline-offset: 7px; }

.caret, .rc {
  position: absolute; left: -1px; top: 0; width: 2px; height: 1.15em; border-radius: 1px;
  will-change: transform; transition: opacity .15s;
}
.caret { background: var(--acc); }
.caret.idle { animation: blink 1s ease-in-out infinite; }
.rc { background: var(--c); opacity: .9; }
.rc .tag {
  position: absolute; bottom: 100%; left: 0; margin-bottom: 2px;
  font-size: 10px; line-height: 1; padding: 2px 4px 3px; border-radius: 3px 3px 3px 0;
  background: var(--c); color: var(--bg); white-space: nowrap; font-weight: 500;
}
.rc.off { opacity: 0; }
.rc.done { opacity: .35; }
.rc.done .tag { opacity: 0; }

.input { position: absolute; left: 0; top: 36px; width: 100%; height: calc(27px * 1.6 * 3); opacity: 0; resize: none; border: 0; padding: 0; z-index: -1; pointer-events: none; font-size: 16px; }

.box.blurred .words { filter: blur(5px); opacity: .45; }
.box.blurred .view-carets { opacity: 0; }
.focus-hint {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; color: var(--text);
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.box.blurred .focus-hint { opacity: 1; }
.box.waiting .words { opacity: .55; }
.countdown {
  position: absolute; left: 0; right: 0; top: calc(var(--fs) * var(--lh) * -1.35);
  text-align: right; font-size: 34px; color: var(--acc); pointer-events: none;
}

/* ---------- lanes: everyone's progress through the text */

.lanes { display: grid; gap: 7px; margin: 0 0 30px; font-size: 12px; }
.lane { --c: var(--sub2); display: grid; grid-template-columns: 12ch 1fr 9ch; align-items: center; gap: 14px; color: var(--sub2); }
.lane.mine { --c: var(--acc); }
.lane .nm { color: var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane .tr { position: relative; height: 2px; background: var(--line); border-radius: 1px; }
.lane .fill { position: absolute; inset: 0; background: var(--c); opacity: .3; transform-origin: 0 50%; transform: scaleX(0); will-change: transform; }
.lane .dot { position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--c); will-change: transform; }
.lane .tail { text-align: right; font-variant-numeric: tabular-nums; }
.lane.fin .tail { color: var(--text); }

/* ---------- results */

.result { display: grid; gap: 26px; animation: fade .2s ease-out; }
.res-mine { display: grid; grid-template-columns: auto 1fr; gap: 22px 40px; align-items: center; }
.res-big { display: grid; gap: 14px; }
.res-big .v { font-size: 58px; line-height: 1; color: var(--acc); font-variant-numeric: tabular-nums; }
.k { color: var(--sub); font-size: 14px; }
.pb { color: var(--acc); font-size: 12px; min-height: 1em; }
.chart-wrap { position: relative; height: 190px; }
.chart { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none; background: var(--panel); border-radius: 6px;
  padding: 6px 9px; font-size: 12px; line-height: 1.5; white-space: nowrap; color: var(--sub2);
}
.chart-tip b { color: var(--text); font-weight: 400; }
.res-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 14px 46px; }
.res-row .v { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }

.standings { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.standings td { padding: 8px 10px; border-top: 1px solid var(--line); color: var(--sub2); }
.standings tr:first-child td { border-top: 0; }
.standings td:first-child { width: 4ch; color: var(--sub); padding-left: 0; }
.standings td.nm { color: var(--c, var(--text)); width: 100%; }
.standings td.nm small { color: var(--sub); margin-left: 8px; font-size: 12px; }
.standings tr.mine td.nm { color: var(--acc); }
.standings td.n { text-align: right; white-space: nowrap; }
.standings td.n b { color: var(--text); font-weight: 400; }

.res-actions { display: flex; align-items: center; gap: 16px; }

/* ---------- panels: rooms, lobby */

.panel { animation: fade .2s ease-out; }
.panel h2 { font-size: 22px; font-weight: 500; margin: 0 0 6px; }
.sub { color: var(--sub); font-size: 13px; }
.rooms p.sub { max-width: 56ch; margin: 0 0 28px; }
.rooms-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.or { color: var(--sub); }
.join { display: flex; gap: 8px; }
.join input {
  width: 14ch; background: var(--panel); border: 1px solid transparent; color: var(--text);
  border-radius: 6px; padding: 8px 12px; outline: none;
}
.join input:focus { border-color: var(--sub); }

.btn {
  background: var(--panel); color: var(--text); border-radius: 6px; padding: 8px 16px;
  transition: background-color .12s, color .12s;
}
.btn:hover { background: var(--text); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--sub2); box-shadow: inset 0 0 0 1px var(--line); }
.btn.ghost:hover { color: var(--text); box-shadow: inset 0 0 0 1px var(--sub); background: transparent; }

.lobby { display: grid; gap: 26px; }
.result + .lobby:not([hidden]) { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--line); }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.lobby-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; }
.roster { list-style: none; margin: 0; padding: 0; }
.roster li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); color: var(--c, var(--text)); }
.roster li:first-child { border-top: 0; }
.roster li small { color: var(--sub); font-size: 12px; }
.roster li .x { margin-left: auto; color: var(--sub); padding: 0 4px; }
.roster li .x:hover { color: var(--err); }
.roster li.empty { color: var(--sub); }
.room-cfg { display: grid; gap: 14px; align-content: start; font-size: 13px; }
.room-cfg .row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 4px; }
.room-cfg .row > span { color: var(--sub); width: 9ch; }
.room-cfg button { color: var(--sub2); padding: 3px 6px; border-radius: 4px; }
.room-cfg button:hover:not(:disabled) { color: var(--text); }
.room-cfg button.on { color: var(--acc); }
.room-cfg button:disabled { cursor: default; }
.room-cfg.locked button:not(.on) { color: var(--sub); }
.lobby-foot { display: flex; align-items: center; gap: 18px; min-height: 38px; }

/* ---------- footer, toast */

.foot { display: flex; justify-content: center; gap: 26px; padding: 0 0 22px; font-size: 12px; color: var(--sub); }
.toast {
  position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: var(--panel);
  color: var(--text); padding: 9px 16px; border-radius: 6px; font-size: 13px; animation: fade .15s ease-out;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

@media (max-width: 720px) {
  body { padding: 0 16px; }
  .top { gap: 16px; flex-wrap: wrap; padding-top: 18px; }
  .me { gap: 12px; }
  .online { display: none; }
  .config { margin-bottom: 36px; }
  .box { --fs: 21px; }
  .res-mine { grid-template-columns: 1fr; }
  .res-big { grid-template-columns: auto auto 1fr; align-items: end; gap: 28px; }
  .res-big .v { font-size: 44px; }
  .lobby-body { grid-template-columns: 1fr; gap: 26px; }
  .lane { grid-template-columns: 9ch 1fr 7ch; gap: 10px; }
  .foot { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .caret.idle, .logo i { animation: none; }
}
