:root {
  --bg: #070707;
  --fg: #f4f4f2;
  --dim: rgba(244, 244, 242, 0.42);
  --faint: rgba(244, 244, 242, 0.2);
  --rule: rgba(244, 244, 242, 0.1);
  --stop: #ff4127;
  --sans: 'Geist', 'Inter', system-ui, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --pad: clamp(20px, 5vw, 72px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
::selection { background: var(--fg); color: var(--bg); }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--faint);
  color: var(--dim);
  padding: 1px 6px 2px;
  border-radius: 5px;
}

/* The page takes its colour from the song. When the music stops, the colour drains. */
.backdrop {
  position: fixed;
  inset: -25%;
  z-index: -2;
  background-size: cover;
  background-position: center;
  filter: blur(110px) saturate(1.7) brightness(0.55);
  opacity: 0;
  transition: opacity 1.2s ease, filter 0.5s ease;
  animation: drift 46s ease-in-out infinite alternate;
}
body:not([data-screen='home']) .backdrop { opacity: 0.62; }
body.stalled .backdrop { filter: blur(110px) saturate(0) brightness(0.3); animation-play-state: paused; }
@keyframes drift {
  from { transform: translate3d(-4%, -3%, 0) scale(1.05) rotate(-4deg); }
  to { transform: translate3d(5%, 4%, 0) scale(1.25) rotate(5deg); }
}
.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 28px;
  flex-wrap: wrap;
  padding: 26px var(--pad);
}
.logo {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.035em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.mark { display: flex; gap: 4px; }
.mark i { width: 5px; height: 17px; border-radius: 1.5px; background: var(--fg); }
.mark i:last-child { animation: blink 1.1s steps(1) infinite; }
body.stalled .mark i { background: var(--stop); animation: none; }
@keyframes blink { 50% { opacity: 0.15; } }

.settings { display: flex; gap: 6px 26px; flex-wrap: wrap; font-family: var(--mono); font-size: 12.5px; }
.settings .group { display: flex; gap: 14px; }
.settings button { color: var(--faint); transition: color 0.15s; }
.settings button:hover { color: var(--dim); }
.settings button.on { color: var(--fg); }
.settings button:focus-visible, .opt button:focus-visible, .res-actions button:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 4px;
  border-radius: 3px;
}

main { flex: 1; width: 100%; padding: 0 var(--pad) 190px; }
.screen { animation: enter 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }

/* ---------- home ---------- */
#home { max-width: 1180px; }
.np {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: clamp(24px, 9vh, 96px);
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--dim);
  transition: color 0.2s;
}
.eq { display: flex; align-items: flex-end; gap: 3px; height: 14px; }
.eq i { width: 3px; height: 100%; background: currentColor; border-radius: 1px; transform-origin: bottom; animation: eq 0.9s ease-in-out infinite alternate; }
.eq i:nth-child(2) { animation-duration: 0.6s; animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-duration: 0.75s; animation-delay: -0.5s; }
.eq i:nth-child(4) { animation-duration: 0.5s; animation-delay: -0.1s; }
@keyframes eq { from { transform: scaleY(0.2); } to { transform: scaleY(1); } }
.np.stopped { color: var(--stop); }
.np.stopped .eq i { animation-play-state: paused; }

#hero {
  margin: 18px 0 clamp(36px, 7vh, 72px);
  font-size: clamp(42px, 8.4vw, 124px);
  font-weight: 600;
  line-height: 0.96;
  letter-spacing: -0.055em;
  position: relative;
}
#hero .hl { display: block; }
#hero .ch { color: var(--faint); transition: color 0.12s; }
#hero .ch.on { color: var(--fg); }
#hero.stopped .ch.pend { color: var(--stop); }
#hero .hcaret {
  display: inline-block;
  width: 0.055em;
  height: 0.8em;
  margin: 0 0.02em -0.04em 0.03em;
  background: var(--fg);
  border-radius: 0.02em;
}
#hero.stopped .hcaret { background: var(--stop); animation: blink 0.7s steps(1) infinite; }

#search-form {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--faint);
  transition: border-color 0.2s;
  max-width: 860px;
}
#search-form:focus-within { border-color: var(--fg); }
#q {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  padding: 14px 0 16px;
  font-size: clamp(18px, 2.1vw, 26px);
  letter-spacing: -0.02em;
}
#q::placeholder { color: var(--faint); }
#search-form button { font-family: var(--mono); font-size: 18px; color: var(--dim); padding: 8px 4px 8px 16px; }
#search-form:focus-within button { color: var(--fg); }

.msg { font-family: var(--mono); font-size: 12.5px; color: var(--dim); min-height: 1.45em; margin: 14px 0; max-width: 860px; }
.msg.err { color: var(--stop); }
.msg.warn { color: var(--dim); }
#home h2 { font-family: var(--mono); font-size: 12.5px; font-weight: 400; color: var(--dim); margin: 44px 0 6px; }

.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); column-gap: 36px; max-width: 1180px; }
.card {
  display: flex;
  gap: 16px;
  align-items: center;
  text-align: left;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  min-width: 0;
  transition: padding 0.2s cubic-bezier(0.2, 0.7, 0.2, 1), border-color 0.2s;
  animation: enter 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 28ms);
}
.card:hover, .card:focus-visible { padding-left: 10px; border-color: var(--fg); outline: 0; }
.card img { width: 76px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; flex: none; background: #151515; filter: saturate(0.85); }
.card:hover img { filter: none; }
.card .c-body { min-width: 0; flex: 1; }
.card .c-title { font-size: 15px; font-weight: 500; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-sub { font-family: var(--mono); font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- game ---------- */
.track-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 10px 28px; flex-wrap: wrap; margin-top: 8px; }
.track-meta { min-width: 0; flex: 1 1 280px; display: flex; gap: 12px; align-items: baseline; }
.track-title { font-weight: 500; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-sub { color: var(--dim); font-size: 14px; white-space: nowrap; }
.track-opts { display: flex; gap: 22px; flex-wrap: wrap; font-family: var(--mono); font-size: 12.5px; color: var(--dim); }
.opt { display: flex; align-items: center; gap: 8px; }
.opt select { background: none; border: 0; color: var(--fg); font-family: var(--mono); font-size: 12.5px; cursor: pointer; max-width: 170px; }
.opt select option { background: #111; }
.opt button { width: 20px; height: 20px; border: 1px solid var(--faint); border-radius: 50%; line-height: 1; color: var(--fg); font-size: 13px; }
.opt button:hover { background: var(--fg); color: var(--bg); }
#off-val { color: var(--fg); min-width: 6ch; text-align: center; }

.stage { margin-top: clamp(28px, 11vh, 120px); max-width: 1280px; }
.lines {
  position: relative;
  font-size: clamp(25px, 3.7vw, 54px);
  font-weight: 600;
  line-height: 1.16;
  letter-spacing: -0.035em;
}
.line { color: var(--faint); min-height: 1.16em; margin: 0.34em 0; transition: opacity 0.3s; }
.line.prev { opacity: 0.5; }
.line.next { opacity: 0.75; }
.line.next2 { opacity: 0.4; }
.line.cur { animation: rise 0.28s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes rise { from { transform: translateY(0.42em); opacity: 0.4; } }
.line.cur .ch { color: var(--dim); }
.line.locked .ch { color: var(--faint); }
.word { display: inline-block; }
.ch { white-space: pre; }
.ch.ok { color: var(--fg) !important; }
.ch.bad { color: var(--stop) !important; }
.ch.sp.bad { box-shadow: inset 0 -0.09em 0 var(--stop); }

.caret {
  position: absolute;
  left: 0;
  top: 0;
  width: 0.07em;
  min-width: 2px;
  height: 0.95em;
  border-radius: 2px;
  background: var(--fg);
  transition: transform 0.1s cubic-bezier(0.2, 0.7, 0.2, 1), background 0.2s;
  animation: blink 1.1s steps(1) infinite;
  pointer-events: none;
}
.caret.typing { animation: none; }
.caret.off { display: none; }
body.stalled .caret { background: var(--stop); }

.timebar { height: 2px; background: var(--rule); margin-top: clamp(20px, 4vh, 40px); max-width: 520px; overflow: hidden; }
#timefill { height: 100%; width: 100%; background: var(--fg); transform-origin: left; transform: scaleX(0); }
#timefill.hot { background: var(--fg); animation: blink 0.35s steps(1) infinite; }
#timefill.stalled { background: var(--stop); }
.status { margin-top: 14px; min-height: 1.5em; font-family: var(--mono); font-size: 12.5px; color: var(--dim); }
.status.stalled { color: var(--stop); }
.status.go { color: var(--fg); }
.stage.shake .lines { animation: shake 0.18s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------- dock: stats + the song as a strip of lines ---------- */
.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 0 var(--pad) 22px; pointer-events: none; }
.hud { display: flex; gap: 22px; align-items: baseline; flex-wrap: wrap; font-family: var(--mono); font-size: 12.5px; color: var(--dim); margin-bottom: 12px; padding-right: 340px; }
.hud b { font-weight: 500; color: var(--fg); font-variant-numeric: tabular-nums; }
.hud .keys { margin-left: 8px; color: var(--faint); }
.hud .keys kbd { margin-left: 10px; }
.timeline { position: relative; height: 18px; }
.seg { position: absolute; top: 6px; height: 6px; min-width: 2px; background: var(--faint); border-radius: 1px; transition: background 0.2s, top 0.2s, height 0.2s; }
.seg.done { background: var(--fg); }
.seg.late { background: var(--stop); }
.seg.cur { top: 2px; height: 14px; background: var(--fg); }
body.stalled .seg.cur { background: var(--stop); }
.playhead { position: absolute; top: -4px; bottom: -4px; left: 0; width: 1px; background: var(--fg); opacity: 0.7; will-change: transform; }

/* ---------- results ---------- */
#done { max-width: 1180px; }
.res-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px 60px; flex-wrap: wrap; margin-top: clamp(8px, 5vh, 56px); }
.res-wpm { display: flex; align-items: baseline; gap: 14px; }
.res-wpm b { font-size: clamp(110px, 21vw, 280px); font-weight: 600; letter-spacing: -0.07em; line-height: 0.82; font-variant-numeric: tabular-nums; }
.res-wpm span { font-family: var(--mono); font-size: 14px; color: var(--dim); }
.res-stats { margin: 0; display: grid; grid-template-columns: auto auto; gap: 6px 28px; font-family: var(--mono); font-size: 13px; padding-bottom: 8px; }
.res-stats div { display: contents; }
.res-stats dt { color: var(--dim); }
.res-stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.chart-title { font-family: var(--mono); font-size: 12.5px; color: var(--dim); margin: 34px 0 12px; }
.dot { display: inline-block; width: 7px; height: 7px; margin: 0 6px 0 16px; }
.dot.ok, .bar.ok { background: var(--fg); }
.dot.bad, .bar.bad { background: var(--stop); }
.chart { display: flex; align-items: flex-end; gap: 2px; height: clamp(70px, 14vh, 130px); border-bottom: 1px solid var(--rule); }
.bar { flex: 1; min-width: 2px; transform-origin: bottom; animation: grow 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; animation-delay: calc(var(--i) * 9ms); }
@keyframes grow { from { transform: scaleY(0); } }
.res-actions { display: flex; gap: 28px; margin-top: 26px; flex-wrap: wrap; font-size: 15px; }
.res-actions button { color: var(--dim); display: flex; gap: 10px; align-items: center; }
.res-actions button:hover { color: var(--fg); }

/* ---------- player ---------- */
.player-card {
  position: fixed;
  right: var(--pad);
  bottom: 62px;
  width: min(300px, 42vw);
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.25s, filter 0.4s;
}
.player-card iframe { width: 100%; height: 100%; display: block; border: 0; pointer-events: none; }
.player-card.clickable iframe { pointer-events: auto; }
.player-card.stalled { box-shadow: 0 0 0 2px var(--stop), 0 24px 70px rgba(0, 0, 0, 0.6); filter: grayscale(1) brightness(0.7); }
body[data-screen='done'] .player-card { bottom: 24px; }

.trap { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }

@media (max-width: 720px) {
  .hud { padding-right: 0; gap: 14px; }
  .hud .keys { display: none; }
  .player-card { width: 150px; bottom: 76px; }
  .track-meta { flex-direction: column; gap: 0; }
  main { padding-bottom: 210px; }
  .res-stats { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
