/* michtype — dark plum field, candy-pink caret. Letters gain weight as they're struck. */

:root {
  --field: #1d1033;
  --field-deep: #150b27;
  --ink: #f7f1ff;
  --soft: #c9b6ee;
  --faint: #8a72b8;
  --line: rgba(247, 241, 255, 0.14);
  --signal: #ff9fd2;
  --miss: #ff6b6b;
  --ui: "Fredoka", system-ui, sans-serif;
  --type: "Recursive", ui-monospace, monospace;
  --lh: 2.6rem;
  --measure: 62rem;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--field);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 1.0625rem;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; border-radius: 2px; }
.hidden { display: none !important; }

/* keycaps: the only boxed element on the page, used for real keys */
kbd {
  display: inline-block; min-width: 1.9em; padding: 0.1em 0.45em 0.15em; margin: 0 0.1em;
  font: 500 0.78rem/1.4 var(--ui); text-align: center; color: var(--soft);
  background: var(--field-deep); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 5px;
}

/* ---------- header */
.top {
  display: flex; align-items: baseline; gap: 2.5rem; flex-wrap: wrap;
  width: 100%; max-width: var(--measure); margin: 0 auto; padding: 1.75rem 1.5rem 0;
  transition: opacity 0.4s;
}
body.typing .top, body.typing footer, body.typing .modebar, body.typing .ghost-note { opacity: 0; pointer-events: none; }
.logo {
  font-weight: 700; font-size: 1.7rem; letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none; line-height: 1;
}
.logo span { font-weight: 300; }
nav { display: flex; gap: 1.6rem; }
nav button, .modebar button, .tabs button {
  color: var(--soft); padding: 0.2rem 0; border-bottom: 3px solid transparent; transition: color 0.15s;
}
nav button:hover, .modebar button:hover, .tabs button:hover { color: var(--ink); }
nav button.active, .modebar button.active, .tabs button.active { color: var(--ink); border-bottom-color: var(--signal); }
.me { margin-left: auto; display: flex; align-items: baseline; gap: 1.4rem; color: var(--soft); font-size: 0.95rem; }
.name { color: var(--ink); font-weight: 600; border-bottom: 1px dashed var(--faint); }
.name:hover { border-bottom-color: var(--signal); }
.name input { background: none; border: 0; outline: 0; width: 12ch; color: var(--ink); font-weight: 600; }
.name.locked { border-bottom-color: transparent; cursor: default; }
.name-note { color: var(--miss); font-size: 0.85rem; }

/* ---------- sign in */
.auth {
  width: min(26rem, calc(100vw - 2rem)); padding: 1.75rem; border: 1px solid var(--line); border-radius: 18px;
  background: var(--field-deep); color: var(--ink); font-family: var(--ui);
}
.auth::backdrop { background: rgba(10, 5, 20, 0.65); }
.auth-tabs { margin-bottom: 1.25rem; }
.auth-title { font-size: 1.6rem; font-weight: 700; margin: 0 0 0.35rem; }
.auth-sub { color: var(--soft); margin: 0 0 1.25rem; font-size: 0.95rem; }
.field { display: block; color: var(--soft); font-size: 0.9rem; margin-bottom: 0.9rem; }
.field input {
  display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.8rem; border-radius: 10px; outline: 0;
  background: var(--field); border: 1px solid var(--line); color: var(--ink); font-size: 1rem;
}
.field input:focus { border-color: var(--signal); }
.auth .error { margin: 0; font-size: 0.9rem; }
.auth .res-actions { margin-top: 0.75rem; }

/* ---------- layout */
main { flex: 1; width: 100%; max-width: var(--measure); margin: 0 auto; padding: 0 1.5rem; }
.view { display: none; padding-top: 8vh; }
.view.active { display: block; }
h1 { font-weight: 700; font-size: clamp(2.6rem, 6vw, 4.4rem); line-height: 0.98; letter-spacing: -0.015em; margin: 0 0 1.75rem; max-width: 14ch; }
footer { display: flex; gap: 2rem; padding: 2rem 1.5rem; max-width: var(--measure); width: 100%; margin: 0 auto; color: var(--faint); font-size: 0.85rem; transition: opacity 0.4s; }
#kb { position: fixed; top: 0; left: 0; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

/* ---------- practice */
.modebar { display: flex; align-items: baseline; gap: 1.4rem; margin-bottom: 2.5rem; transition: opacity 0.4s; }
.drill-tag { color: var(--signal); font-size: 0.95rem; }
.daily-head h1 { margin-bottom: 0.6rem; }
.daily-head p { color: var(--soft); margin: 0 0 2.5rem; max-width: 46ch; }
.live { display: flex; gap: 1.5rem; align-items: baseline; height: 2.6rem; }
#solo-timer { font-weight: 700; font-size: 2.2rem; color: var(--signal); font-variant-numeric: tabular-nums; }
#solo-wpm { color: var(--soft); font-variant-numeric: tabular-nums; }
.ghost-note { color: var(--faint); font-size: 0.85rem; margin-top: 1.5rem; transition: opacity 0.4s; }

/* ---------- the typing surface */
.typebox {
  position: relative; height: calc(var(--lh) * 3); overflow: hidden; cursor: text;
  font-family: var(--type); font-size: 1.65rem; font-weight: 300;
  font-variation-settings: "MONO" 1, "CASL" 1;
}
.typebox .tb-inner { position: relative; transition: transform 0.2s ease-out; }
.typebox .word { display: inline-block; line-height: var(--lh); margin-right: 0.62ch; color: var(--faint); white-space: pre; }
.typebox .l { transition: font-weight 0.08s; }
.typebox .l.ok { color: var(--ink); font-weight: 650; }
.typebox .l.bad { color: var(--miss); font-weight: 650; text-decoration: line-through 2px; }
.typebox .l.extra { color: var(--miss); font-weight: 650; opacity: 0.55; }
.typebox .word.err { box-shadow: inset 0 -2px 0 var(--miss); }
.typebox .caret, .typebox .ghost {
  position: absolute; left: 0; top: 0; height: 1.75rem; margin-top: calc((var(--lh) - 1.75rem) / 2);
  transition: transform 0.08s ease-out;
}
.typebox .caret { width: 3px; background: var(--signal); }
.typebox .caret.idle { animation: blink 1.05s steps(1) infinite; }
.typebox .ghost { width: 0.62em; border: 1.5px solid var(--soft); opacity: 0.55; transition: transform 0.25s linear; }
.typebox.blurred .tb-inner { filter: blur(4px); opacity: 0.5; }
.typebox.blurred::after {
  content: "Click here or start typing"; position: absolute; inset: 0; display: grid; place-items: center;
  font: 500 1.05rem var(--ui); color: var(--ink);
}
.typebox.locked { cursor: default; }
.typebox.locked.blurred .tb-inner { filter: none; opacity: 0.6; }
.typebox.locked.blurred::after { display: none; }
.typebox.shake { animation: shake 0.2s; }
@keyframes shake { 30% { transform: translateX(-5px); } 70% { transform: translateX(5px); } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- results */
.results { padding-top: 0.5rem; }
.res-top { display: flex; gap: 3rem; align-items: flex-end; flex-wrap: wrap; }
.stat .k { color: var(--soft); font-size: 0.9rem; }
.stat .v { font-weight: 700; font-size: 2.4rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat.big .v { font-weight: 700; font-size: clamp(5rem, 13vw, 8.5rem); line-height: 0.85; }
.stat.big .v small { font-size: 0.25em; font-weight: 500; color: var(--soft); margin-left: 0.2em; }
.note { color: var(--signal); margin: 1.2rem 0 0; }
.note.quiet { color: var(--soft); }
.spark { width: 100%; height: 96px; margin: 2rem 0 0.25rem; display: block; }
.spark path.line { fill: none; stroke: var(--signal); stroke-width: 2.5; stroke-linejoin: round; }
.spark path.best { fill: none; stroke: var(--soft); stroke-width: 1.5; stroke-dasharray: 4 5; }
.spark line { stroke: var(--line); }
.spark text { fill: var(--faint); font: 12px var(--ui); }
.legend { color: var(--faint); font-size: 0.85rem; display: flex; gap: 1.5rem; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2.5px solid var(--signal); vertical-align: middle; margin-right: 0.4rem; }
.legend i.best { border-top: 1.5px dashed var(--soft); }
.res-actions { display: flex; align-items: center; gap: 1.25rem; margin-top: 2rem; flex-wrap: wrap; }
.btn {
  padding: 0.65rem 1.3rem; background: var(--signal); color: var(--field); font-weight: 600; border-radius: 999px;
  transition: transform 0.08s;
}
.btn:active { transform: translateY(1px); }
.btn kbd { background: rgba(29, 16, 51, 0.12); color: var(--field); border-color: rgba(29, 16, 51, 0.25); }
.link { color: var(--ink); border-bottom: 1px solid var(--faint); padding-bottom: 1px; }
.link:hover { border-bottom-color: var(--signal); }

/* weak-key map */
.keys { margin-top: 2.5rem; }
.keys h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.9rem; }
.keys h2 span { color: var(--soft); font-weight: 400; }
.kb-row { display: flex; gap: 6px; margin-bottom: 6px; }
.kb-row:nth-child(3) { padding-left: 22px; }
.kb-row:nth-child(4) { padding-left: 48px; }
.key {
  --heat: 0;
  width: 44px; height: 44px; border-radius: 6px; display: grid; place-items: center; position: relative;
  font: 500 1rem var(--ui); color: var(--soft);
  background: color-mix(in oklab, var(--miss) calc(var(--heat) * 100%), var(--field-deep));
  border: 1px solid var(--line); border-bottom-width: 3px;
}
.key.hot { color: var(--ink); }
.key small { position: absolute; right: 4px; bottom: 1px; font-size: 0.62rem; color: var(--ink); }

/* ---------- race lobby */
.actions { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); max-width: 46rem; }
.actions li { border-bottom: 1px solid var(--line); }
.actions li > button {
  width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 2rem; padding: 1.4rem 0;
}
.a-title { font-weight: 700; font-size: 2rem; line-height: 1.1; transition: color 0.15s; }
.a-sub { color: var(--soft); grid-column: 1; max-width: 48ch; }
.actions kbd { grid-column: 2; grid-row: 1; align-self: center; }
.actions li > button:hover .a-title { color: var(--signal); }
.join { display: flex; align-items: center; gap: 1rem; padding: 1.4rem 0; flex-wrap: wrap; }
.join label { margin-right: auto; }
.join input {
  width: 8.5rem; background: var(--field-deep); border: 1px solid var(--line); border-radius: 4px; padding: 0.55rem 0.8rem;
  font-family: var(--type); font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; outline: 0;
}
.join input:focus { border-color: var(--signal); }
.join button { font-weight: 600; border-bottom: 1px solid var(--faint); }
.error { color: var(--miss); min-height: 1.5em; }

/* ---------- race room */
.room-bar { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1.5rem; }
.status { margin: 0; font-size: 1.15rem; color: var(--soft); }
.status b { color: var(--ink); font-weight: 700; }
.room-actions { margin-left: auto; display: flex; gap: 1.5rem; }
.lanes { margin-bottom: 2.25rem; border-top: 1px solid var(--line); }
.lane {
  display: grid; grid-template-columns: 9.5rem 1fr 4.5rem; align-items: center; gap: 1.25rem;
  padding: 0.7rem 0; border-bottom: 1px solid var(--line);
}
.lane.left { opacity: 0.4; }
.lane .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lane .who small { color: var(--faint); font-weight: 400; margin-left: 0.4rem; font-size: 0.85rem; }
.track { position: relative; height: 18px; }
.track::before { content: ""; position: absolute; inset: 50% 0 auto; border-top: 1px dashed var(--faint); }
.track::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  background: repeating-linear-gradient(var(--ink) 0 3px, var(--field) 3px 6px); }
.track .fill { position: absolute; left: 0; top: 50%; height: 2px; margin-top: -1px; background: var(--soft); transition: width 0.25s linear; }
.track .dot { position: absolute; top: 1px; width: 10px; height: 16px; margin-left: -5px; background: var(--soft); transition: left 0.25s linear; }
.lane.you .who { color: var(--signal); }
.lane.you .fill { background: var(--signal); transition: width 0.08s linear; }
.lane.you .dot { background: var(--signal); transition: left 0.08s linear; }
.lane .spd { text-align: right; white-space: nowrap; color: var(--soft); font-variant-numeric: tabular-nums; }
.lane .spd b { color: var(--ink); font-weight: 700; }
.place { font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.place.p1 { color: var(--signal); }

.race-stage { position: relative; }
.typebox.race { font-size: 1.45rem; --lh: 2.35rem; }
.countdown {
  position: absolute; inset: -1rem 0; display: grid; place-items: center;
  font-weight: 700; font-size: 7rem; color: var(--signal);
  background: color-mix(in srgb, var(--field) 82%, transparent);
}
.countdown.go { animation: go 0.6s ease-out forwards; }
@keyframes go { 60% { opacity: 1; } to { opacity: 0; } }
.host { display: flex; align-items: center; gap: 1.5rem; justify-content: flex-end; margin-top: 1.5rem; color: var(--soft); }
.host label { display: flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.host input { accent-color: var(--signal); width: 1rem; height: 1rem; }
#race-results { margin-top: 2.5rem; }
.podium { list-style: none; padding: 0; margin: 2rem 0 0; border-top: 1px solid var(--line); max-width: 40rem; }
.podium li { display: grid; grid-template-columns: 3rem 1fr 6rem 4rem; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.podium li.you span:nth-child(2) { color: var(--signal); font-weight: 600; }
.podium li span:nth-child(n+3) { text-align: right; color: var(--soft); }

/* ---------- leaderboard */
.board-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.tabs { display: flex; gap: 1.4rem; }
table.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board th { text-align: left; font-weight: 500; color: var(--faint); font-size: 0.9rem; padding: 0 0.75rem 0.6rem; }
.board td { padding: 0.75rem; border-top: 1px solid var(--line); }
.board td.num, .board th.num { text-align: right; }
.board tr.you td { color: var(--signal); }
.board tr.gap td { color: var(--faint); text-align: center; border: 0; padding: 0.25rem; }
.board .rank { width: 3.5rem; color: var(--soft); }
.board .wpm { font-weight: 700; }
.board tbody tr:nth-child(1) .rank { color: var(--signal); font-weight: 700; }
.empty { color: var(--soft); padding: 3rem 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 720px) {
  .top { gap: 1rem 1.5rem; padding-top: 1.1rem; }
  .me { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }
  nav { gap: 1.1rem; }
  .typebox { font-size: 1.25rem; --lh: 2.1rem; }
  .lane { grid-template-columns: 6rem 1fr 3.5rem; gap: 0.75rem; }
  .res-top { gap: 1.75rem; }
  .key { width: 28px; height: 36px; font-size: 0.85rem; }
  .kb-row { gap: 4px; }
  .kb-row:nth-child(3) { padding-left: 14px; }
  .kb-row:nth-child(4) { padding-left: 30px; }
  .a-title { font-size: 1.6rem; }
  footer { display: none; }
  .board .hide-sm { display: none; }
}
