/* Beat Runner - one stylesheet, no framework.
 *
 * Contrast note: every text/background pair below was picked to clear WCAG 2.1
 * AA (4.5:1 for body text, 3:1 for large text and UI borders). The dimmest
 * body colour in use, --muted on --bg, measures about 10:1.
 */

:root {
  --bg: #0a0518;
  --bg-2: #100826;
  --panel: #150a2e;
  --panel-2: #1c1040;
  --line: #3a2a6b;
  --text: #ece7ff;
  --muted: #b9aee0;
  --link: #8be9ff;
  --hot: #ff4d7d;
  --warm: #ffb547;
  --cool: #63d7ff;
  --violet: #c58bff;
  --mint: #6ef2b8;
  --focus: #ffe066;
  --radius: 14px;
  --wrap: 68rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #2a0f52 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 400 clamp(1rem, 0.96rem + 0.2vw, 1.08rem)/1.65 ui-sans-serif, system-ui,
    -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

/* ---------- shared type ---------- */

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 {
  font-size: clamp(1.9rem, 1.3rem + 2.6vw, 3.1rem);
  font-weight: 800;
  background: linear-gradient(96deg, #fff 10%, var(--cool) 45%, var(--hot) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
@supports not (background-clip: text) { h1 { color: var(--text); } }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.9rem); }
h3 { font-size: 1.12rem; margin-top: 1.6em; }
p, li { margin: 0 0 0.9em; }
strong { color: #fff; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--panel-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

a { color: var(--link); }
a:hover { color: #c4f4ff; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 50;
  background: var(--focus);
  color: #1a1000;
  padding: 0.6rem 1rem;
  font-weight: 700;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

.fine { color: var(--muted); font-size: 0.92rem; }
.error {
  color: #ffd0dc;
  background: rgba(255, 77, 125, 0.16);
  border: 1px solid var(--hot);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
}

/* ---------- page frame ---------- */

.wrap, main {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 1.1rem;
}

.site-head {
  border-bottom: 1px solid var(--line);
  background: rgba(10, 5, 24, 0.82);
}
.site-head .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.2rem;
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}
.site-head nav { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; }
.site-head nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.93rem;
}
.site-head nav a:hover { color: var(--text); text-decoration: underline; }

main { padding-top: 1.6rem; padding-bottom: 2.5rem; }
main > section { margin-top: 2.6rem; }

.intro { font-size: 1.06em; max-width: 62ch; }

.site-foot {
  border-top: 1px solid var(--line);
  padding: 1.4rem 0 2.4rem;
  color: var(--muted);
  font-size: 0.93rem;
}

/* ---------- the stage ---------- */

.stage { margin: 1.6rem 0 0; }

.board-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #07030f;
  contain: layout paint;
}
@media (max-width: 40rem) {
  .board-wrap { aspect-ratio: 4 / 5; }
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  padding: 0.55rem 0.7rem;
  display: grid;
  gap: 0.35rem;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(7, 3, 15, 0.88), transparent);
}
.hud-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.1rem;
}
.hud-cell { margin: 0; display: flex; align-items: baseline; gap: 0.35rem; }
.hud-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.hud-cell strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.02rem;
}
.hud-row-2 { font-size: 0.9rem; }
.hud-row-2 .hud-cell strong { font-size: 0.95rem; }

.health {
  flex: 1 1 8rem;
  min-width: 6rem;
  height: 9px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.health-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--hot), var(--warm), var(--mint));
  transition: width 0.12s linear;
}
.nofail {
  margin: 0;
  font-size: 0.78rem;
  color: var(--mint);
  border: 1px solid rgba(110, 242, 184, 0.5);
  border-radius: 99px;
  padding: 0.1rem 0.6rem;
}

.judge {
  margin: 0;
  font-weight: 800;
  font-size: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  letter-spacing: 0.04em;
  min-height: 1.6em;
}
.judge-perfect { color: #fff2a8; }
.judge-great { color: var(--cool); }
.judge-good { color: var(--violet); }
.judge-miss { color: var(--hot); }
.judge.pop { animation: pop 0.22s ease-out; }
@keyframes pop {
  from { transform: scale(1.28); opacity: 0.35; }
  to { transform: scale(1); opacity: 1; }
}

body.playing #btn-pause { pointer-events: auto; }

/* ---------- lane key row / tap zones ---------- */

.lane-keys {
  display: none;
  grid-template-columns: repeat(var(--lanes, 4), 1fr);
  gap: 0.4rem;
  margin-top: 0.5rem;
  touch-action: manipulation;
}
body.playing .lane-keys { display: grid; }

.lane-key {
  appearance: none;
  border: 1px solid var(--lane-color, var(--violet));
  border-radius: 10px;
  background: color-mix(in srgb, var(--lane-color, #c58bff) 16%, #0d0620);
  color: var(--text);
  padding: 0.5rem 0.2rem;
  display: grid;
  gap: 0.1rem;
  justify-items: center;
  cursor: pointer;
  font: inherit;
  user-select: none;
}
.lane-key:active { background: color-mix(in srgb, var(--lane-color, #c58bff) 42%, #0d0620); }
.lane-key-cap { font-weight: 800; font-size: 1.25rem; color: #fff; }
.lane-key-note {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- overlay screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: linear-gradient(180deg, rgba(8, 4, 20, 0.94), rgba(10, 5, 26, 0.98));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  display: grid;
  align-items: start;
  justify-items: center;
}
.screen[hidden] { display: none; }
.screen-inner {
  width: min(46rem, 100%);
  padding: 1.1rem 1.2rem 1.6rem;
}
.screen-narrow { max-width: 34rem; }
.screen h2 { margin-top: 0.2rem; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 0.4rem;
}

.btn {
  appearance: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}
.btn:hover { background: #26155a; }
.btn-primary {
  background: linear-gradient(100deg, var(--hot), #ff8a4d);
  border-color: transparent;
  color: #14040f;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
#btn-pause { padding: 0.25rem 0.75rem; font-size: 0.85rem; }

/* ---------- pickers ---------- */

.picker {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem 0.5rem;
  margin: 0 0 1rem;
  background: rgba(21, 10, 46, 0.7);
}
.picker legend {
  padding: 0 0.4rem;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tier-option, .track-option {
  display: flex;
  gap: 0.7rem;
  align-items: start;
  padding: 0.55rem 0.6rem;
  border: 1px solid transparent;
  border-radius: 10px;
  margin-bottom: 0.35rem;
  cursor: pointer;
}
.tier-option:hover, .track-option:hover { background: rgba(255, 255, 255, 0.05); }
.tier-option input, .track-option input {
  margin: 0.35rem 0 0;
  accent-color: var(--cool);
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
}
.tier-option:has(input:checked), .track-option:has(input:checked) {
  border-color: var(--line);
  background: rgba(99, 215, 255, 0.09);
}
.tier-body, .track-body { display: block; }
.tier-name, .track-name {
  display: block;
  font-weight: 800;
  color: var(--accent, #fff);
}
.tier-blurb, .track-blurb {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.dropzone {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  margin-bottom: 1rem;
}
.dropzone.is-over { border-color: var(--cool); background: rgba(99, 215, 255, 0.1); }
.file-label { display: block; font-weight: 700; margin-bottom: 0.4rem; }
#file-input { max-width: 100%; color: var(--muted); }
#upload-note { margin: 0.5rem 0 0; }

.daily {
  border-left: 3px solid var(--warm);
  padding-left: 0.7rem;
  color: var(--muted);
  font-size: 0.93rem;
}

/* ---------- results / best table ---------- */

.result-sub { color: var(--muted); }
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.6rem;
  margin: 1rem 0 0;
}
.result-grid > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}
.result-grid dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.result-grid dd {
  margin: 0.1rem 0 0;
  font-weight: 800;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.best-h { margin-top: 1.8rem; }
.best {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.best th, .best td {
  text-align: left;
  padding: 0.42rem 0.5rem;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.best thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.best td.empty { color: var(--muted); font-variant-numeric: normal; }
.tier-chip {
  display: inline-block;
  border: 1px solid var(--chip, var(--violet));
  color: var(--chip, var(--violet));
  border-radius: 99px;
  padding: 0.02rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ---------- loading / calibration ---------- */

.loadbar {
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  margin: 0.6rem 0 1rem;
}
.loadbar span {
  display: block;
  width: 2%;
  height: 100%;
  background: linear-gradient(90deg, var(--cool), var(--violet), var(--hot));
  transition: width 0.15s linear;
}

.cal-pad {
  width: 100%;
  min-height: 6.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--cool);
  background: rgba(99, 215, 255, 0.12);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  margin-bottom: 0.7rem;
}
.cal-pad:active { background: rgba(99, 215, 255, 0.3); }
.slider-label { display: block; margin-top: 0.8rem; font-size: 0.9rem; color: var(--muted); }
#offset-slider { width: min(22rem, 100%); accent-color: var(--cool); }

/* ---------- prose sections ---------- */

#how ol, #features ul, .tier-list { padding-left: 1.2rem; }
.tier-list { list-style: none; padding-left: 0; }
.tier-list li {
  border-left: 3px solid var(--line);
  padding-left: 0.8rem;
}
#faq h3 { color: #fff; }
#about-build p { max-width: 62ch; }
.dl-note { color: var(--muted); font-size: 0.93rem; }

/* ---------- error pages ---------- */

body.plain main { padding-top: 3rem; }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
