
:root {
  --void: #060309;
  --ink: #120e2e;
  --frost: #eef3ff;
  --silver: #aab2cf;
  --aurora: #8a5bff;
  --ember: #ff9a3c;

  --glass-bg: rgba(10, 8, 24, 0.62);
  --glass-border: rgba(180, 190, 230, 0.18);
  --radius-lg: 22px;
  --radius-sm: 12px;

  --font-display: 'Baloo 2', ui-rounded, system-ui, sans-serif;
  --font-body: 'Outfit', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--void);
  color: var(--frost);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background: var(--void);
  color: var(--frost);
  font-family: var(--font-body);
  z-index: 999;
}

/* ---------- Screens & panels ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse at center, rgba(18, 14, 46, 0.35), rgba(6, 3, 9, 0.86));
  z-index: 10;
}

.screen.is-visible {
  display: flex;
}

.panel {
  width: 100%;
  max-width: 420px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 2rem 1.75rem;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel-wide { max-width: 520px; }
.panel-center { max-width: 340px; }
.panel-transparent {
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#screen-menu {
  background-image:
    linear-gradient(to bottom, rgba(4, 3, 9, 0.1) 0%, rgba(4, 3, 9, 0.15) 50%, rgba(4, 3, 9, 0.94) 87%, rgba(4, 3, 9, 0.98) 100%),
    url('../assets/title-screen.jpg');
  background-size: cover;
  background-position: center top;
  align-items: flex-end;
}

.panel-menu {
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding-bottom: 2.25rem;
}

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

.eyebrow-label {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--silver);
  letter-spacing: 0.02em;
}

.title-display {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 11vw, 3.4rem);
  line-height: 1;
  background: linear-gradient(180deg, #ffffff 0%, #cfe0ff 55%, #b98cff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-section {
  margin: 0 0 1.25rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--frost);
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--silver);
  font-size: 0.98rem;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */

.btn {
  display: block;
  width: 100%;
  padding: 0.95rem 1.25rem;
  margin-bottom: 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.02rem;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--aurora), #5a3fce);
  color: #fff;
  box-shadow: 0 10px 26px rgba(138, 91, 255, 0.35);
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--silver);
  border-color: var(--glass-border);
}

.btn-ghost:hover { color: var(--frost); border-color: var(--silver); }

.btn:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

/* ---------- Menu: how-to-play ---------- */

.how-to-play {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--silver);
  font-size: 0.88rem;
}

.how-to-play-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.key-chip {
  padding: 0.15rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--frost);
}

/* ---------- Song select ---------- */

.track-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.track-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--frost);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.track-card:hover { background: rgba(255, 255, 255, 0.07); }
.track-card:active { transform: scale(0.98); }
.track-card:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

.track-swatch {
  width: 0.55rem;
  align-self: stretch;
  border-radius: 6px;
  background: var(--swatch, var(--aurora));
  box-shadow: 0 0 14px var(--swatch, var(--aurora));
  flex-shrink: 0;
}

.track-thumb {
  width: 3rem;
  height: 3rem;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.track-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.track-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
}

.track-artist {
  color: var(--silver);
  font-size: 0.85rem;
}

.track-best {
  color: var(--ember);
  font-size: 0.78rem;
  min-height: 1.1em;
}

.track-note {
  color: var(--silver);
  font-size: 0.78rem;
  opacity: 0.75;
  margin-bottom: 1.25rem;
}

/* ---------- Character select ---------- */

.character-select-hint {
  margin: -0.5rem 0 1.1rem;
  color: var(--silver);
  font-size: 0.88rem;
}

.character-preview-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.2rem;
}

#character-preview-canvas {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, rgba(138, 91, 255, 0.18), rgba(10, 8, 24, 0.4) 70%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), inset 0 0 40px rgba(138, 91, 255, 0.08);
}

.character-preview-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--frost);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  min-height: 1.4em;
}

.character-select-actions {
  display: flex;
  gap: 0.6rem;
}

.character-select-actions .btn {
  width: auto;
  flex: 1;
  margin-bottom: 0;
}

/* ---------- Settings screen ---------- */

.settings-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--glass-border);
  text-align: left;
}

.settings-row:last-of-type { border-bottom: none; }

.settings-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--frost);
}

.settings-control {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
}

.volume-slider {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--aurora);
  box-shadow: 0 2px 8px rgba(138, 91, 255, 0.6);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--aurora);
  box-shadow: 0 2px 8px rgba(138, 91, 255, 0.6);
  cursor: pointer;
}

.settings-value {
  min-width: 3.2rem;
  text-align: right;
  color: var(--silver);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.btn-danger {
  color: #ff9a9a;
  border-color: rgba(255, 106, 106, 0.35);
}

.btn-danger:hover { color: #ffc2c2; border-color: rgba(255, 106, 106, 0.6); }

.btn-danger.is-armed {
  color: var(--void);
  background: #ff6a6a;
  border-color: #ff6a6a;
}

.character-roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding: 1rem 0.6rem 0.85rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--frost);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.character-card:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--silver); }
.character-card:active { transform: scale(0.97); }
.character-card:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

.character-card.is-selected {
  background: rgba(138, 91, 255, 0.16);
  border-color: var(--aurora);
  box-shadow: 0 0 0 1px var(--aurora), 0 8px 20px rgba(138, 91, 255, 0.25);
}

.character-swatch {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--swatch-a, var(--aurora)), var(--swatch-b, var(--ember)));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset, 0 6px 18px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.character-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
  line-height: 1.25;
}

/* ---------- Loading ---------- */

.loading-cover {
  display: none;
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 0 auto 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.loading-cover.is-visible { display: block; }

.loading-track-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--frost);
}

.loading-track-artist {
  margin: 0 0 1rem;
  color: var(--silver);
  font-size: 0.9rem;
}

.loading-label {
  color: var(--silver);
  margin-bottom: 1rem;
}

.loading-bar, .hud-progress {
  width: 100%;
  height: 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.loading-bar-fill, .hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--aurora), var(--ember));
  transition: width 0.15s ease;
}

/* ---------- Countdown ---------- */

.countdown-number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 6rem;
  color: var(--frost);
  text-shadow: 0 0 40px rgba(138, 91, 255, 0.8);
  animation: countdown-pop 0.65s ease;
}

@keyframes countdown-pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Results ---------- */

.best-badge {
  display: inline-block;
  margin: 0 auto 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 154, 60, 0.18);
  color: var(--ember);
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0;
  visibility: hidden;
}

.best-badge.is-visible { opacity: 1; visibility: visible; }

.results-grade {
  font-family: var(--font-display);
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--frost);
  margin-bottom: 0.75rem;
}

.results-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--glass-border);
  color: var(--silver);
  font-size: 0.95rem;
}

.results-row span:last-child { color: var(--frost); font-weight: 600; }

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

.hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  padding: max(1rem, env(safe-area-inset-top)) 1.1rem 1.1rem;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.hud.is-visible { display: flex; }

.hud-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.hud-score-block {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.hud-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.8rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

.hud-multiplier {
  color: var(--ember);
  font-weight: 700;
  font-size: 1.1rem;
}

.hud-combo {
  color: var(--frost);
  font-weight: 600;
  font-size: 1rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

/* ---------- Collection progress (top of HUD) ---------- */

.hud-collection {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.hud-collection-bar {
  flex: 1;
  height: 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}

.hud-collection-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--tier-a, var(--silver)), var(--tier-b, var(--aurora)));
  transition: width 0.25s ease, background 0.3s ease;
}

.hud-collection-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--frost);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  min-width: 6.6rem;
  text-align: right;
}

/* Achievement tiers */
.hud-collection[data-tier="opening-act"] .hud-collection-fill { --tier-a: #8892b0; --tier-b: #aab2cf; }
.hud-collection[data-tier="supporting-act"] .hud-collection-fill { --tier-a: #6f8fd6; --tier-b: #8a5bff; }
.hud-collection[data-tier="headliner"] .hud-collection-fill { --tier-a: #8a5bff; --tier-b: #c07bff; }
.hud-collection[data-tier="chart-topper"] .hud-collection-fill { --tier-a: #ff9a3c; --tier-b: #ffd45a; }
.hud-collection[data-tier="superstar"] .hud-collection-fill {
  --tier-a: #ffd45a;
  --tier-b: #fff6d8;
  animation: superstar-glow 1.1s ease-in-out infinite;
}
.hud-collection[data-tier="superstar"] .hud-collection-label {
  color: #ffe9a8;
  text-shadow: 0 0 10px rgba(255, 212, 90, 0.8);
}

@keyframes superstar-glow {
  0%, 100% { filter: brightness(1) saturate(1); }
  50% { filter: brightness(1.35) saturate(1.3); }
}

.hud-progress { margin-top: 0.9rem; }

/* Hit-flash feedback: a very brief, restrained vignette pulse, not a screen flash */
.hud[data-flash] { animation: hit-flash 0.18s ease; }
@keyframes hit-flash {
  0% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
  30% { box-shadow: inset 0 0 120px 0 rgba(255, 255, 255, 0.08); }
  100% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
}

/* Miss-flash: distinct from a hit's white pulse -- a brief, muted red
   vignette echoing "the track just cut out," not a celebratory cue. */
.hud[data-flash="miss"] { animation: miss-flash 0.18s ease; }
@keyframes miss-flash {
  0% { box-shadow: inset 0 0 0 0 rgba(140, 25, 35, 0); }
  30% { box-shadow: inset 0 0 140px 0 rgba(140, 25, 35, 0.22); }
  100% { box-shadow: inset 0 0 0 0 rgba(140, 25, 35, 0); }
}

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  .btn, .track-card, .character-card, .countdown-number, .hud[data-flash], .hud-collection-fill[style] {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 380px) {
  .panel { padding: 1.5rem 1.25rem; }
  .title-display { font-size: 2.3rem; }
}
