/* ─────────────────────────────────────────────────────────────
   Beat Machine — styles
   Palette lives here; the canvas keeps its own copy in js/render.js
   because a 2D context silently ignores a var() it cannot resolve.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        #0b0e14;
  --bg-raised: #131926;
  --bg-sunken: #080b11;
  --line:      #232c3f;
  --text:      #e7ecf5;
  --text-dim:  #8b97ad;
  --accent:    #4cc9f0;
  --accent-2:  #b794f6;
  --good:      #06d6a0;
  --bad:       #ef476f;

  --hihat: #ffd166;
  --snare: #ef476f;
  --kick:  #f4a261;
  --tom:   #06d6a0;
  --crash: #b794f6;

  --radius: 14px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* An author rule that sets `display` beats the UA rule for [hidden],
   so every hidden toggle in this app needs this to actually hide. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1100px 600px at 50% -10%, #1a2338 0%, transparent 60%),
    var(--bg);
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ───────────────────────────── Menu ───────────────────────────── */

#menu {
  overflow-y: auto;
  align-items: center;
  gap: 18px;
  padding: 28px 20px 40px;
}

.brand { text-align: center; margin: 12px 0 4px; }

.brand h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: -0.02em;
  font-weight: 800;
  background: linear-gradient(100deg, var(--accent) 0%, var(--accent-2) 55%, var(--hihat) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-mark { -webkit-text-fill-color: initial; color: initial; }

.tagline { margin: 6px 0 0; color: var(--text-dim); font-size: 15px; }

.songlist {
  width: min(680px, 100%);
  display: grid;
  gap: 10px;
}

.song {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-raised), #0f1420);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s, background .15s;
}
.song:hover { border-color: #3a4761; transform: translateY(-1px); }
.song:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.song[aria-pressed="true"] {
  border-color: var(--accent);
  background: linear-gradient(180deg, #16233a, #101827);
  box-shadow: 0 0 0 1px rgba(76,201,240,.25), 0 8px 26px -18px var(--accent);
}

.song-index {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--bg-sunken);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 13px;
}
.song[aria-pressed="true"] .song-index { background: var(--accent); color: #04121a; font-weight: 700; }

.song-body { min-width: 0; }
.song-name { display: block; font-weight: 650; font-size: 16px; }
.song-meta { display: block; color: var(--text-dim); font-size: 12.5px; margin-top: 3px; font-family: var(--mono); }
.song-right { text-align: right; white-space: nowrap; }
.stars { display: block; letter-spacing: 2px; font-size: 13px; color: var(--hihat); }
.best { display: block; color: var(--text-dim); font-size: 12px; font-family: var(--mono); margin-top: 4px; }

.menu-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.hint { color: var(--text-dim); font-size: 13px; margin: 0; min-height: 1.2em; }

/* ───────────────────────────── Buttons ───────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 11px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: #43516e; background: #18202f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #56d2f4, #2ba6cf);
  border-color: #56d2f4;
  color: #041420;
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #6ddaf7, #37b3dd); border-color: #6ddaf7; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-raised); color: var(--text); }
.btn-sm { padding: 7px 11px; font-size: 14px; }

/* ───────────────────────────── HUD ───────────────────────────── */

.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(11,14,20,.65);
}
.hud-song { display: flex; flex-direction: column; min-width: 0; }
.hud-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-bpm { color: var(--text-dim); font-size: 12px; font-family: var(--mono); }
.hud-stats { margin-left: auto; display: flex; gap: 18px; }
.stat { text-align: right; }
.stat-label { display: block; font-size: 10px; letter-spacing: .12em; color: var(--text-dim); text-transform: uppercase; }
.stat-value { font-family: var(--mono); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.groove {
  flex: 0 0 auto;
  position: relative;
  height: 12px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.groove-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--tom), var(--accent));
  transition: width .12s linear, background .3s;
}
.groove.low .groove-fill { background: linear-gradient(90deg, #f4a261, var(--bad)); }
.groove-label {
  position: absolute; inset: 0 auto 0 10px;
  display: flex; align-items: center;
  font-size: 7.5px; font-weight: 700; letter-spacing: .3em; color: #7c8aa5;
  pointer-events: none; mix-blend-mode: difference;
}

/* ───────────────────────────── Stage ─────────────────────────── */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: var(--bg-sunken);
  touch-action: none;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Overlays measure the stage, not the viewport: vw/vh would size to a
   box the stage does not occupy. */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6,9,14,.82);
  backdrop-filter: blur(6px);
  padding: 16px;
  z-index: 5;
}
.overlay.modal { position: fixed; z-index: 20; }

.panel {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-raised), #0e1420);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 30px 80px -30px #000;
}
.panel-wide { width: min(520px, 100%); text-align: left; }
.panel h2 { margin: 0 0 14px; font-size: 22px; }
.panel p { color: var(--text-dim); font-size: 14px; line-height: 1.55; }
.panel-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* ───────────────────────────── Results ───────────────────────── */

#result-verdict { text-align: center; }
.grade {
  text-align: center;
  font-size: 78px;
  font-weight: 800;
  line-height: 1;
  margin: 4px 0 2px;
  background: linear-gradient(160deg, var(--hihat), var(--bad));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.grade[data-grade="S"] { background: linear-gradient(160deg, #ffe27a, #ff9f45); -webkit-background-clip: text; background-clip: text; }
.grade[data-grade="A"] { background: linear-gradient(160deg, #8bf0c6, #2bb37d); -webkit-background-clip: text; background-clip: text; }
.grade[data-grade="B"] { background: linear-gradient(160deg, #8fd4ff, #3f8fd0); -webkit-background-clip: text; background-clip: text; }
.grade[data-grade="C"] { background: linear-gradient(160deg, #c9b6ff, #7a5fd0); -webkit-background-clip: text; background-clip: text; }
.grade[data-grade="D"] { background: linear-gradient(160deg, #ff9db4, #d13d63); -webkit-background-clip: text; background-clip: text; }

.result-score {
  text-align: center;
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 16px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  font-size: 14px;
}
.result-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed #1e2739; }
.result-row b { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.result-timing { text-align: center; font-size: 13px; margin: 14px 0 0; }
.new-best { color: var(--hihat); font-weight: 700; text-align: center; font-size: 13px; }

/* ───────────────────────────── Settings ──────────────────────── */

.setting { margin-bottom: 18px; }
.setting label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.setting output { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.setting-help { font-size: 12.5px; margin: 8px 0 0; }
.setting-row { display: flex; }

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #1d2435;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #0b0e14;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border: 3px solid #0b0e14;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.toggle { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; font-weight: 500; }
.toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

.keytable { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px; }
.keytable th { text-align: left; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); padding-bottom: 6px; }
.keytable td { padding: 7px 0; border-top: 1px solid #1b2233; }
.keytable td:last-child { color: var(--text-dim); font-size: 12.5px; text-align: right; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.swatch[data-lane="hihat"] { background: var(--hihat); }
.swatch[data-lane="snare"] { background: var(--snare); }
.swatch[data-lane="kick"]  { background: var(--kick); }
.swatch[data-lane="tom"]   { background: var(--tom); }
.swatch[data-lane="crash"] { background: var(--crash); }

kbd {
  font-family: var(--mono);
  font-size: 12px;
  background: #1c2435;
  border: 1px solid #2c3750;
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
}

#metro-bpm { max-width: 150px; }

@media (max-width: 560px) {
  .song { grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 14px; }
  .song-index { grid-row: span 2; }
  .song-right { grid-column: 2; text-align: left; display: flex; gap: 10px; align-items: baseline; }
  .best { margin-top: 0; }
  .hud-stats { gap: 12px; }
  .stat-value { font-size: 15px; }
  .menu-actions .btn { flex: 1 1 auto; }
}
