/* Tokens. The canvas reads the --field-* values at start, so a theme is a block of overrides. */
:root {
  /* Neon-on-midnight, approximated from memory of the genre look. Tune freely. */
  --ink: #0b0c22;
  --ink-deep: #05060f;
  --cream: #eef6ff;
  --muted: #8a90c4;
  --gold: #ffc94d;

  --field-lane: #0e1030;
  --field-lane-alt: #121438;
  --field-rule: #262a5c;
  --field-line: #e8fbff;
  --field-pad: #070818;
  --field-tile-0: #35e0ff; /* cyan */
  --field-tile-1: #8a5cff; /* violet */
  --field-tile-2: #ff3fa4; /* magenta */
  --field-tile-ink: #05060f;

  --stage-max: 30rem;
  --font-display: ui-rounded, "Segoe UI Variable Display", "SF Pro Rounded", system-ui, sans-serif;
  --duration-fast: 150ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink-deep);
  color: var(--cream);
  font-family: var(--font-display);
  overscroll-behavior: none;
}

.stage {
  position: relative;
  width: min(100vw, var(--stage-max));
  height: 100dvh;
  margin-inline: auto;
  background: var(--ink);
  box-shadow: 0 0 6rem rgb(0 0 0 / 0.6);
  overflow: hidden;
}

#field {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* the playfield owns every gesture; pinch-zoom still works on the overlay */
  user-select: none;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: end;
  gap: 0.75rem;
  padding: 2rem 1.75rem max(3rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--ink-deep) 35%, rgb(17 9 22 / 0.55));
  transition: opacity var(--duration-fast) var(--ease-out-expo);
}

.overlay[hidden] { display: none; }

.kicker {
  margin: 0;
  color: var(--field-tile-1);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.display {
  margin: 0;
  font-size: clamp(3.5rem, 19vw, 6rem);
  font-weight: 900;
  line-height: 0.88;
  letter-spacing: -0.04em;
}

.display span { display: block; }

.drop {
  padding-left: 0.6em; /* the second word drops a step, like a tile falling */
  color: var(--field-tile-0);
}

/* ---- library ---- */

.library {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: max(1.75rem, env(safe-area-inset-top)) 1.25rem 0;
  overflow-y: auto;
  background: linear-gradient(to bottom, rgb(5 6 15 / 0.82), var(--ink-deep) 45%);
}

.library[hidden] { display: none; }

/* Dragging audio over the song list. The library is the drop target, so this cannot fire mid-run:
   the whole screen is hidden while a song is playing. */
.library.dropping {
  outline: 3px dashed var(--field-tile-0);
  outline-offset: -0.75rem;
  background: linear-gradient(to bottom, rgb(53 224 255 / 0.08), var(--ink-deep) 60%);
}
.library.dropping * { pointer-events: none; }
.library[aria-busy="true"] .song-play,
.library[aria-busy="true"] .song-remove { opacity: 0.45; pointer-events: none; }

.library-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.library-head .display { font-size: clamp(2.6rem, 13vw, 4rem); }
.library-head .kicker { padding-bottom: 0.35rem; color: var(--gold); white-space: nowrap; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 0.25rem;
  border-radius: 0.9rem;
  background: var(--field-lane);
  box-shadow: inset 0 0 0 1px var(--field-rule);
}

.segment, .segment:hover, .segment:active {
  justify-self: stretch;
  padding: 0.65rem 0.4rem;
  border-radius: 0.7rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: none;
  transform: none;
}
.segment[aria-checked="true"] { background: var(--field-tile-1); color: var(--cream); }
.segment:disabled { opacity: 0.45; cursor: not-allowed; }

.status {
  margin: 0;
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: pre-line;
}

.songs { display: grid; gap: 0.7rem; margin: 0; padding: 0; list-style: none; }

.song {
  display: grid;
  grid-template-columns: 1fr auto;
  border-radius: 1rem;
  background: var(--field-lane-alt);
  box-shadow: inset 4px 0 0 var(--stripe), 0 0.6rem 1.4rem rgb(0 0 0 / 0.35);
  overflow: hidden;
  transition: transform var(--duration-fast) var(--ease-out-expo);
}
.song:hover { transform: translateX(3px); }

.song-play, .song-play:hover, .song-play:active {
  display: grid;
  gap: 0.2rem;
  justify-self: stretch;
  padding: 0.95rem 0.5rem 0.95rem 1.2rem;
  border-radius: 0;
  background: transparent;
  color: var(--cream);
  text-align: left;
  box-shadow: none;
  transform: none;
}
.song-title { font-size: 1.05rem; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.song-meta { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.song-best { color: var(--gold); font-size: 0.85rem; font-weight: 700; letter-spacing: 0.04em; }
.song-best[data-medal="platinum"] { color: var(--cream); }
.song-best[data-medal="diamond"] { color: var(--field-tile-0); text-shadow: 0 0 0.8em var(--field-tile-0); }

.song-remove, .song-remove:hover, .song-remove:active {
  align-self: stretch;
  padding: 0 1.1rem;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  box-shadow: none;
  transform: none;
}
.song-remove:hover { color: var(--field-tile-2); }

.import {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 1.5rem 0 max(1.25rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--ink-deep) 60%, transparent);
}
.import input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.import span {
  display: block;
  padding: 1rem;
  border-radius: 0.9rem;
  background: var(--cream);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 0.35rem 0 var(--field-tile-0);
  cursor: pointer;
}
.import:focus-within span { outline: 3px solid var(--field-tile-2); outline-offset: 4px; }

.lede {
  margin: 0 0 1rem;
  max-width: 26ch;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.4;
  white-space: pre-line; /* results arrive as a few short lines */
}

.actions { display: flex; flex-wrap: wrap; gap: 0.9rem; }
.actions [hidden] { display: none; }

button.ghost {
  background: transparent;
  color: var(--cream);
  box-shadow: inset 0 0 0 2px var(--field-rule);
}
button.ghost:hover { box-shadow: inset 0 0 0 2px var(--muted); }
button.ghost:active { box-shadow: inset 0 0 0 2px var(--cream); }

button {
  padding: 1rem 1.6rem;
  border: 0;
  border-radius: 0.9rem;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 0.35rem 0 var(--field-tile-0);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out-expo),
    box-shadow var(--duration-fast) var(--ease-out-expo);
}

button:hover { transform: translateY(-2px); box-shadow: 0 0.5rem 0 var(--field-tile-0); }
button:active { transform: translateY(0.3rem); box-shadow: 0 0.05rem 0 var(--field-tile-0); }
button:focus-visible { outline: 3px solid var(--field-tile-2); outline-offset: 4px; }

/* ---- settings panel ---- */

.panel {
  border-radius: 1rem;
  background: var(--field-lane);
  box-shadow: inset 0 0 0 1px var(--field-rule);
}

.panel summary {
  display: flex;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: '+'; font-size: 1.1rem; line-height: 1; }
.panel[open] summary::after { content: '−'; }
.panel summary:focus-visible { outline: 3px solid var(--field-tile-2); outline-offset: 2px; }

.panel-body { display: grid; gap: 1.15rem; padding: 0.25rem 1.1rem 1.2rem; }

.setting { display: grid; gap: 0.4rem; }
.setting-row { grid-auto-flow: column; justify-content: start; align-items: center; gap: 0.7rem; }
.setting-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.setting-label { font-size: 0.95rem; font-weight: 700; }
.setting-value {
  color: var(--field-tile-0);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.setting-hint { margin: 0; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }

/* accent-color themes the native controls: no rebuilt slider, no rebuilt checkbox. */
.setting input[type='range'] {
  width: 100%;
  height: 1.6rem;
  margin: 0;
  accent-color: var(--field-tile-1);
  background: transparent;
  cursor: pointer;
}
.setting input[type='checkbox'] {
  width: 1.3rem;
  height: 1.3rem;
  margin: 0;
  accent-color: var(--field-tile-1);
  cursor: pointer;
}
.setting-row .setting-label { cursor: pointer; }

button.wide { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .overlay, button { transition: none; }
}
