* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #050308;
  color: #e8e6f0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  height: 100%;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  /* The Stage model: internal resolution is always 1280x720; the browser
     scales it to fit the window with letterboxing, so the composition holds
     at every window size and zoom level. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #0a0a14;
  position: relative;
  z-index: 1;
}

/* Optional WebGL post-FX overlay (created only when ?renderer=webgl).
   Pointer-events none so drops/clicks still hit the page/stage handlers. */
#stage-webgl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  z-index: 2;
  display: block;
  background: transparent;
}

.panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 40%, rgba(60, 30, 90, 0.55), rgba(5, 3, 8, 0.92));
  text-align: center;
  padding: 24px;
}

.panel.hidden, .hidden { display: none !important; }

#loader h1 {
  font-size: 2.4rem;
  letter-spacing: 0.12em;
  margin: 0;
  background: linear-gradient(90deg, #ffd76a, #ff7ab6, #7ad1ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub { opacity: 0.8; margin: 0; }
.hint { opacity: 0.5; font-size: 0.8rem; margin-top: 10px; }

#dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  padding: 28px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
#dropzone.drag { border-color: #ffd76a; background: rgba(255, 215, 106, 0.08); }

.filebtn {
  background: #ff7ab6;
  color: #1a0d16;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

#demoBtn, #playAgainBtn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #e8e6f0;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}
#demoBtn:hover, #playAgainBtn:hover { border-color: #7ad1ff; color: #7ad1ff; }

#completePanel h1 {
  font-size: 2.2rem;
  letter-spacing: 0.1em;
  margin: 0;
  color: #ffd76a;
}

#hud {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  z-index: 5;
}

#hudLeft {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

/* Right-hand cluster of the HUD row: difficulty, fullscreen, settings gear,
   track badge. #hud disables pointer-events so the canvas underneath stays
   clickable; this wrapper opts its interactive children back in. */
#hudRight {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: auto;
}
#settingsBtn, #fullscreenBtn {
  line-height: 1;
}

#comboReadout {
  font-size: 1.6rem;
  font-weight: 700;
  color: #ffd76a;
  text-shadow: 0 0 12px rgba(255, 215, 106, 0.6);
  display: inline-block;
}

/* Combo-milestone flourish (follow-up item 6): a quick shatter-and-reform
   pulse, mirroring FractureEngine's terminal-shatter beat in miniature. */
@keyframes comboMilestone {
  0%   { transform: scale(1) rotate(0deg); color: #ffd76a; text-shadow: 0 0 12px rgba(255, 215, 106, 0.6); }
  25%  { transform: scale(1.7) rotate(-8deg); color: #fff6cf; text-shadow: 0 0 34px rgba(255, 246, 207, 0.95); }
  50%  { transform: scale(0.82) rotate(5deg); }
  75%  { transform: scale(1.12) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); color: #ffd76a; text-shadow: 0 0 12px rgba(255, 215, 106, 0.6); }
}
#comboReadout.milestone-pulse {
  animation: comboMilestone 0.55s cubic-bezier(0.2, 0.8, 0.3, 1);
}

/* On-device FPS HUD (mobile performance round): small, always-on-top,
   toggled by the P key or the ?fps URL param -- deliberately much lighter
   than #debugOverlay so it's cheap enough to leave on during play. */
#fpsHud {
  position: absolute;
  left: 8px; bottom: 8px;
  z-index: 20;
  background: rgba(5, 5, 10, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #d8f7c8;
  pointer-events: none;
  white-space: pre;
}

/* Song-end video export row (inside #completePanel) and the top-level
   recording HUD shown while a replay-and-capture export is in progress. */
#exportRow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}
#exportRes, #exportFps {
  background: rgba(255, 255, 255, 0.06);
  color: #e8e6f0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
}
#exportRow .hint {
  flex-basis: 100%;
  margin-top: 4px;
}

#recordingHud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 21;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(20, 4, 4, 0.78);
  border: 1px solid rgba(255, 80, 80, 0.5);
  border-radius: 999px;
  padding: 6px 14px;
  color: #ffdede;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
#recordingHud .recDot {
  color: #ff4d4d;
  animation: recPulse 1.1s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
#recordingHud #recordingCancelBtn {
  padding: 3px 10px;
  font-size: 0.78rem;
}

/* The ordinary-play auto-recording indicator: small and out of the way in
   a corner, unlike the big center HUD (#recordingHud) reserved for an
   explicit replay export -- every play is already being recorded, so this
   shouldn't compete for attention the way a deliberate export does. */
#liveRecHud {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 21;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 4, 4, 0.6);
  border: 1px solid rgba(255, 80, 80, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
  color: #ffdede;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  pointer-events: none;
}
#liveRecHud .recDot {
  color: #ff4d4d;
  animation: recPulse 1.1s ease-in-out infinite;
}

#saveVideoBtn {
  margin-top: 4px;
}

#debugOverlay {
  position: absolute;
  top: 0; right: 0;
  width: 380px;
  height: 100%;
  background: rgba(5, 5, 10, 0.88);
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  padding: 14px;
  overflow-y: auto;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Mario Paint-style wobbling title letters on the COMPLETE panel. */
.wobble-letter {
  display: inline-block;
  animation: letterWobble 1.5s ease-in-out infinite;
}
@keyframes letterWobble {
  0%, 100% { transform: rotate(-5deg) translateY(0); }
  50% { transform: rotate(5deg) translateY(-5px); }
}

/* SoundFont loader row */
.sfRow {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.prefRow {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
}

/* The "No lyrics" toggle reads as engaged when on. */
#noLyricsBtn[aria-pressed="true"] {
  border-color: #7ad1ff;
  color: #7ad1ff;
}

/* Ghost button (outline style) */
.ghostbtn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.15s, color 0.15s;
}
.ghostbtn:hover {
  border-color: #7ad1ff;
  color: #7ad1ff;
}

/* Compact square variant for single-glyph buttons (gear, ×). */
.iconbtn {
  padding: 4px 10px;
  font-size: 1rem;
  border-radius: 6px;
}

/* Auto-hiding SoundFont pill (bottom-center) — click to open the switcher
   popup (#fontModal). */
#fontBar {
  position: absolute;
  bottom: 96px; /* clears the composer strip, now bottom-anchored */
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 6;
}
#fontBar.visible {
  opacity: 1;
  pointer-events: auto;
}
#fontBarBtn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(5, 5, 10, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#fontBarBtn:hover { border-color: #7ad1ff; color: #7ad1ff; }
#fontName {
  min-width: 100px;
  max-width: 220px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Track visibility badge (top-right of the HUD row) — click/tap or press T
   to expand the full per-track breakdown of the loaded MIDI. */
#trackBadge {
  position: relative;
  pointer-events: auto;
}
#trackBadgeBtn {
  background: rgba(5, 5, 10, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#trackBadgeBtn:hover { border-color: #7ad1ff; color: #7ad1ff; }

#trackList {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  max-width: 340px;
  max-height: 320px;
  overflow-y: auto;
  background: rgba(5, 5, 10, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 8px;
  font-size: 0.78rem;
}
#trackBadge.expanded #trackList { display: block; }

.trackRow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
}
.trackRow.intertwined { background: rgba(255, 255, 255, 0.05); }
.trackRow .roleDot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.roleDot.role-MELODY { background: #ffd76a; }
.roleDot.role-BASS   { background: #7ad1ff; }
.roleDot.role-PAD    { background: #b9a3ff; }
.roleDot.role-RHYTHM { background: #ff5a7a; }

.trackRow .trackName {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trackRow .trackMeta {
  flex: none;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
}
/* Casting tag: which character performs this track (Casting.js lanes). */
.trackRow .laneTag {
  flex: none;
  font-size: 0.68rem;
  opacity: 0.75;
  padding: 0 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.trackRow .panGlyph {
  flex: none;
  width: 1.4em;
  text-align: center;
  opacity: 0.8;
}
.trackListHint {
  opacity: 0.5;
  font-size: 0.72rem;
  padding: 4px 6px 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 4px;
}

/* Full-window "drop to play" feedback — shown while dragging a file over
   the page mid-song (the loader screen's own #dropzone already gives its
   own drag feedback pre-game, so this only activates once #loader is
   hidden; see main.js's isLoaderVisible()). pointer-events:none keeps it
   purely decorative — the actual dragenter/dragover/drop listeners live on
   `window`, not on this element. */
#dragOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 3, 8, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 20;
}
#dragOverlay.visible { opacity: 1; }
.dragOverlayMsg {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 20px 40px;
  border: 3px dashed #ffd76a;
  border-radius: 16px;
  color: #ffd76a;
  background: rgba(5, 5, 10, 0.5);
}

/* SoundFont switcher popup — lists every loaded font with a click-to-
   activate row and a × (hide) action; #fontHiddenToggle swaps the same
   list into the "settings" view of hidden fonts with a + (unhide) action. */
.modalBackdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 3, 8, 0.72);
  z-index: 30;
}
.modalPanel {
  width: min(420px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: rgba(8, 6, 14, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex: none;
}
.modalHeader h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: #ffd76a;
}
.fontList {
  overflow-y: auto;
  padding: 8px;
  flex: 1 1 auto;
  min-height: 60px;
}
.fontListEmpty {
  opacity: 0.55;
  font-size: 0.85rem;
  padding: 20px 12px;
  text-align: center;
}
.fontRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.fontRow:hover { background: rgba(255, 255, 255, 0.06); }
.fontRow.active { background: rgba(255, 215, 106, 0.12); }
.fontRow.active .fontRowName { color: #ffd76a; font-weight: 600; }
.fontRowName {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fontRowAction {
  flex: none;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}
/* Hide (×) reads as a removal — red accent, matching RHYTHM's roleDot.
   Unhide (+) reads as a restore — blue accent, matching the shared hover. */
.fontRowAction[data-action="hide"]:hover { border-color: #ff5a7a; color: #ff5a7a; }
.fontRowAction[data-action="unhide"]:hover { border-color: #7ad1ff; color: #7ad1ff; }

/* Per-song audition verdicts (FontRecommender) */
.fontRowStar {
  flex: none;
  color: #ffd76a;
  font-size: 0.9rem;
  cursor: default;
}
.fontRowBadge {
  flex: none;
  min-width: 30px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.72rem;
  text-align: center;
  cursor: default;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.75);
}
.fontRowBadge.ok { border-color: rgba(122, 209, 255, 0.45); color: #7ad1ff; }
.fontRowBadge.dq { border-color: rgba(255, 90, 122, 0.55); color: #ff5a7a; }
.fontRowBadge.pending { opacity: 0.55; }
.auditionStatus {
  flex: none;
  padding: 8px 16px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.auditionStatus.hidden { display: none; }
.modalFooter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex: none;
}
.modalFooter .filebtn, .modalFooter .ghostbtn {
  font-size: 0.78rem;
  padding: 6px 12px;
}
#fontHiddenToggle { margin-left: auto; }

/* The Reel (Movement VI): the COMPLETE panel's highlight filmstrip. */
#filmstrip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: min(560px, 84vw);
}
.filmstripFrame {
  width: 96px;
  height: 54px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  transition: border-color 0.15s, transform 0.15s;
}
.filmstripFrame:hover { border-color: #ffd76a; transform: translateY(-2px); }
.filmstripFrame img { width: 100%; height: 100%; object-fit: cover; display: block; }

.filmstripModalPanel { width: min(720px, 92vw); }
#filmstripModalImg { width: 100%; display: block; background: #000; }

/* --- Player-driven rhythm layer: live score + end-of-song results --- */
#hudLeft {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
#scoreReadout {
  font-size: 1.15rem;
  font-weight: 600;
  color: #e8e6f0;
  text-shadow: 0 0 8px rgba(232, 230, 240, 0.35);
}
#resultsGrid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin: 6px 0 10px;
}
#resultsGrid .rGrade {
  font-size: 3.4rem;
  font-weight: 800;
  color: #ffd76a;
  text-shadow: 0 0 24px rgba(255, 215, 106, 0.65);
  min-width: 64px;
}
#resultsGrid .rRows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-size: 0.95rem;
}
#resultsGrid .rRow {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}
#resultsGrid .rRow b { font-variant-numeric: tabular-nums; }
#resultsGrid .rTiers {
  justify-content: flex-start;
  gap: 10px;
  font-size: 0.8rem;
  opacity: 0.9;
}
.tPerfect { color: #ffd76a; }
.tGreat { color: #4fd8c4; }
.tGood { color: #e8e6f0; }
.tSour { color: #9e84a8; }
.tMiss { color: #8a8794; }

/* --- Audition load screen (font ratings gate the show) --- */
#auditionCanvas {
  display: block;
  margin: 8px auto;
  background: transparent;
}
#auditionBar {
  width: min(420px, 80%);
  height: 6px;
  margin: 10px auto 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
#auditionBarFill {
  width: 0%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #4fd8c4, #ffd76a);
  transition: width 0.25s ease;
}
