:root {
  --bg: #05060d;
  --panel: rgba(10, 12, 24, 0.72);
  --panel-solid: #0c0e1c;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef1ff;
  --dim: #8a90ad;
  --accent: #9d45ff;
  --accent2: #0c97e9;
  --gold: #ffd35a;
  --bad: #ff3b6b;
  --great: #3bff9a;
  --good: #4aa8ff;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

body.playing #view { cursor: none; }

button, select, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  background: none;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.play {
  background: var(--accent);
  color: #fff;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.14em;
  box-shadow: 0 0 24px rgba(157, 69, 255, 0.45);
  transition: transform 0.08s, box-shadow 0.15s;
}
.play:hover { box-shadow: 0 0 34px rgba(157, 69, 255, 0.7); }
.play:active { transform: scale(0.97); }
.play:disabled { opacity: 0.4; box-shadow: none; cursor: default; }

.ghost {
  padding: 9px 16px;
  border-radius: var(--radius);
  color: var(--dim);
  border: 1px solid var(--line);
  font-size: 13px;
}
.ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.28); }
.wide { width: 100%; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 600 12px/1.6 ui-monospace, monospace;
  text-align: center;
  color: var(--text);
}

/* --- Menu ------------------------------------------------------------------------------------ */

#menu {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 16px;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 120%, rgba(5, 6, 13, 0) 0%, rgba(5, 6, 13, 0.55) 70%);
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.top nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* The game's ASTRAL artwork (white letters, tinted with the UI accent, deep shadow), then WEB. */
.logo {
  --h: clamp(34px, 6vw, 64px);
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 6px calc(var(--h) * 0.18);
}
.logo-art { position: relative; height: var(--h); aspect-ratio: 1762 / 444; display: block; }
.logo-art i {
  position: absolute;
  inset: 0;
  -webkit-mask: url(logo.png) center / contain no-repeat;
  mask: url(logo.png) center / contain no-repeat;
}
.logo-art .shade { background: #121983; transform: translate(4px, 5px); opacity: 0.9; }
.logo-art .fill { background: var(--accent); }
.logo-web {
  font-weight: 900;
  font-style: italic;
  font-size: calc(var(--h) * 0.58);
  line-height: 0.95;
  letter-spacing: 0.08em;
  color: var(--accent2);
  text-shadow: 3px 4px 0 rgba(18, 25, 131, 0.9);
}
.logo small {
  align-self: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--dim);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 2px 6px;
}

.songs {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(0, 560px);
  justify-content: center;
  align-content: center;
  gap: 16px;
  min-height: 0;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 60vh;
}

.song-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
  letter-spacing: 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.song-card:hover { border-color: rgba(255, 255, 255, 0.25); }
.song-card.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.song-card .thumb {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 7px;
  background: #151a30 center / cover no-repeat;
}
.song-card b { display: block; font-size: 15px; }
.song-card span { display: block; font-size: 12px; color: var(--dim); font-weight: 400; }

.song-detail {
  display: flex;
  gap: 18px;
  padding: 18px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.cover {
  width: 180px;
  height: 180px;
  flex: none;
  border-radius: 10px;
  background: #151a30 center / cover no-repeat;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.detail-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; flex: 1; }
.detail-body h1 { margin: 0; font-size: 26px; line-height: 1.15; overflow-wrap: anywhere; }
.artist { margin: 0; color: var(--dim); font-size: 13px; }
.charts { display: flex; gap: 8px; flex-wrap: wrap; }
.charts button {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--dim);
}
.charts button.sel { color: var(--text); border-color: var(--accent2); box-shadow: inset 0 0 0 1px var(--accent2); }
.charts button i { font-style: normal; color: var(--accent2); margin-left: 6px; }
.best { margin: 0; font-size: 13px; color: var(--dim); min-height: 1.4em; }
.best b { color: var(--gold); }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; color: var(--dim); }
.toggles label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toggles input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.detail-body .play { margin-top: auto; align-self: flex-start; }
.detail-actions { margin-top: auto; display: flex; gap: 10px; align-items: center; }
.detail-actions .play { margin-top: 0; }

.bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.keys { margin: 0; color: var(--dim); font-size: 12px; }

/* --- Overlays -------------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 4, 10, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
  overflow-y: auto;
}

.panel {
  width: min(460px, 100%);
  padding: 24px;
  border-radius: 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.panel.narrow { width: min(300px, 100%); text-align: center; }
.panel h2 { margin: 0; font-size: 15px; letter-spacing: 0.24em; color: var(--accent); }
.panel p { margin: 0; }
.row { display: flex; gap: 10px; justify-content: flex-end; }
.row .play { flex: 1; }
.row .ghost { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { display: flex; justify-content: space-between; color: var(--dim); }
.field em { font-style: normal; color: var(--text); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field select { background: #151a30; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.hint { font-size: 12px; color: var(--dim); }
.credits { margin: 0; padding-left: 18px; color: var(--dim); font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.credits b { color: var(--text); }

.res-song { text-align: center; color: var(--dim); font-size: 13px; }
.res-rank {
  text-align: center;
  font-size: 84px;
  font-weight: 900;
  font-style: italic;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 211, 90, 0.5);
}
.res-rank.fail { color: var(--bad); text-shadow: 0 0 30px rgba(255, 59, 107, 0.5); }
.res-acc { text-align: center; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.res-grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 13px; font-variant-numeric: tabular-nums; }
.res-grid span { color: var(--dim); }
.res-grid b { text-align: right; }
.res-note { text-align: center; font-size: 12px; color: var(--accent2); min-height: 1em; }

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

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-top {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr minmax(120px, 360px) 1fr;
  align-items: center;
  gap: 16px;
  padding-right: 44px;
}
.hud-score { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; text-shadow: 0 0 12px rgba(0, 0, 0, 0.8); }
.hud-acc { justify-self: end; display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; font-weight: 700; text-shadow: 0 0 12px rgba(0, 0, 0, 0.8); }
.hud-acc b { color: var(--gold); font-style: italic; font-size: 20px; }
.hud-bars { display: flex; flex-direction: column; gap: 5px; }
.bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; }
.bar.health i { background: var(--great); }
.bar.health.low i { background: var(--bad); }

.hud-pause {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 36px;
  height: 36px;
  pointer-events: auto;
  border-radius: 8px;
  color: var(--dim);
  display: grid;
  place-items: center;
}
.hud-pause svg { width: 20px; height: 20px; fill: currentColor; }
.hud-pause:hover { color: var(--text); }

.hud-combo {
  position: absolute;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  font-size: 40px;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 18px rgba(157, 69, 255, 0.7);
}
.hud-count {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 90px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(157, 69, 255, 0.8);
}
#popups .pop {
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
  font-weight: 900;
  font-style: italic;
  font-size: 20px;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 0 10px currentColor, 0 2px 6px rgba(0, 0, 0, 0.8);
  animation: pop 0.55s ease-out forwards;
}
#popups .pop small { display: block; font-size: 11px; letter-spacing: 0.16em; margin-top: 3px; opacity: 0.85; }
#popups .crit { color: var(--gold); }
#popups .perfect { color: var(--accent); }
#popups .great { color: var(--great); }
#popups .good { color: var(--good); }
#popups .miss { color: var(--bad); }
@keyframes pop {
  0% { opacity: 0; translate: -50% -40%; scale: 0.7; }
  15% { opacity: 1; translate: -50% -100%; scale: 1.08; }
  30% { scale: 1; }
  100% { opacity: 0; translate: -50% -160%; }
}

.damage {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 120px 30px rgba(255, 30, 70, 0.75);
  opacity: 0;
}
.damage.hit { animation: damage 0.45s ease-out; }
@keyframes damage { 0% { opacity: 1; } 100% { opacity: 0; } }

#crosshair {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 6;
}

@media (pointer: coarse) {
  #openFolder { display: none; } /* phones can't pick folders */
}

/* --- Narrow screens -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  .songs { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .song-list { max-height: none; }
  .song-detail { flex-direction: column; }
  .cover { width: 140px; height: 140px; }
  .keys { display: none; }
  .hud-top { grid-template-columns: 1fr 1fr; padding-right: 44px; }
  .hud-bars { grid-column: 1 / -1; grid-row: 2; }
  .hud-score { font-size: 20px; }
  .hud-combo { font-size: 30px; }
}

/* --- Settings panel -------------------------------------------------------------------------- */

.settings-panel { max-height: calc(100vh - 32px); overflow-y: auto; gap: 10px; }
#settingsBody { display: flex; flex-direction: column; gap: 8px; }
#settingsBody details { border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; }
#settingsBody details[open] { padding-bottom: 12px; }
#settingsBody summary {
  cursor: pointer;
  padding: 10px 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}
#settingsBody .field { margin-top: 10px; }
#settingsBody .field small { color: var(--dim); font-size: 11px; }
#settingsBody .field.toggle { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
#settingsBody .field.toggle span { flex: 1; color: var(--text); }
#settingsBody .field.toggle small { flex-basis: 100%; }
#settingsBody input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
#settingsBody input[type=color] { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; }
.cross-preview {
  height: 64px;
  margin-top: 4px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2a1650, #07021a);
  display: grid;
  place-items: center;
}
.cross-preview svg { margin: 0 !important; }

.beta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius);
  background: var(--accent2);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
  box-shadow: 0 0 18px rgba(12, 151, 233, 0.4);
  transition: box-shadow 0.15s;
}
.beta:hover { box-shadow: 0 0 28px rgba(12, 151, 233, 0.7); }
.beta svg, .intro-close svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* First-visit popup: message on the left, preview and itch.io link on the right. */
.intro-panel { position: relative; width: min(680px, 100%); padding-top: 48px; }
.intro-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--dim);
}
.intro-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.intro-close svg { width: 18px; height: 18px; }
.intro-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: center; }
.intro-text { display: flex; flex-direction: column; gap: 12px; color: var(--dim); }
.intro-text b { color: var(--text); }
.intro-side { display: flex; flex-direction: column; gap: 10px; }
.intro-side img { width: 100%; height: auto; display: block; border-radius: var(--radius); border: 1px solid var(--line); }
.intro-continue { align-self: center; }
@media (max-width: 560px) {
  .intro-body { grid-template-columns: minmax(0, 1fr); }
}

a.ghost { display: inline-flex; align-items: center; text-decoration: none; font-weight: 600; letter-spacing: 0.08em; }

.song-column { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.add-song {
  height: 44px;
  border-radius: var(--radius);
  border: 1px dashed rgba(255, 255, 255, 0.22);
  color: var(--dim);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0;
  background: rgba(10, 12, 24, 0.45);
}
.add-song:hover { color: var(--text); border-color: var(--accent); }
@media (pointer: coarse) { .add-song { display: none; } }

#settingsBody .stepper { display: flex; gap: 6px; align-items: center; }
#settingsBody .stepper button {
  width: 34px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
}
#settingsBody .stepper button:hover { border-color: var(--accent); }
#settingsBody .stepper input[type=number] {
  width: 84px;
  height: 32px;
  text-align: center;
  background: #151a30;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
#settingsBody .stepper input[type=range] { flex: 1; accent-color: var(--accent); }
#loadingText { white-space: pre-line; }
