/* GG Rooftop Band — MVP front-end */
:root {
  --bg: #0B0F2C;
  --blue: #1764FF;
  --cyan: #00D4FF;
  --pink: #FF2D7A;
  --gold: #FFB800;
  --ink: #E8F0FF;
  --ink-dim: #8A93C7;
  --panel: rgba(16, 22, 64, 0.88);
  --font-px: 'Press Start 2P', 'Courier New', ui-monospace, monospace;
  --font-ui: 'VT323', 'Courier New', ui-monospace, 'PingFang TC', 'Hiragino Sans', 'Microsoft JhengHei', monospace;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 20px;
  line-height: 1.2;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
img { -webkit-user-drag: none; user-select: none; }
.px, .px img, .sprite img { image-rendering: crisp-edges; image-rendering: pixelated; }
[hidden] { display: none !important; }

/* ---------- neon text ---------- */
.neon-text {
  font-family: var(--font-px);
  color: #fff;
  text-align: center;
  letter-spacing: 0.06em;
  text-shadow: 0 0 4px #fff, 0 0 10px var(--cyan), 0 0 22px var(--blue), 0 0 40px var(--pink);
}

/* ---------- intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 55%, #1a1f5c 0%, var(--bg) 70%);
  cursor: pointer;
  transition: opacity .35s ease;
}
.intro.out { opacity: 0; } /* keeps catching pointer events while fading, so a click can't fall through onto a musician */
.intro-inner { width: min(86vw, 900px); padding: 0 var(--gutter); }
.intro-logo { display: block; width: 100%; height: auto; animation: neonFlicker 2.4s steps(1, end) both; }
.intro-logo-text { font-size: clamp(18px, 5.2vw, 56px); line-height: 1.5; animation: neonFlicker 2.4s steps(1, end) both; }
.intro-skip { position: absolute; right: var(--gutter); bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px)); }
@keyframes neonFlicker {
  0% { opacity: 0; filter: brightness(.4); }
  8% { opacity: 1; filter: brightness(1.4) drop-shadow(0 0 12px var(--cyan)); }
  12% { opacity: .15; }
  18% { opacity: 1; filter: brightness(1.2) drop-shadow(0 0 10px var(--pink)); }
  22% { opacity: .3; }
  26% { opacity: 1; }
  44% { opacity: .55; }
  46% { opacity: 1; filter: brightness(1.3) drop-shadow(0 0 16px var(--cyan)); }
  100% { opacity: 1; filter: brightness(1.15) drop-shadow(0 0 18px var(--blue)); }
}

/* ---------- layout ---------- */
.app {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--gutter) var(--gutter) 0;
}
.stage-wrap { position: relative; width: 100%; }

/* 16:9 stage, scaled to fit width (and viewport height on desktop) */
.stage {
  position: relative;
  width: 100%;
  max-width: calc((100vh - 190px) * 16 / 9);
  min-width: 0;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(23,100,255,.45), transparent 60%),
    radial-gradient(ellipse at 20% 10%, rgba(255,45,122,.25), transparent 50%),
    linear-gradient(180deg, #0B0F2C 0%, #141a52 70%, #1d1146 100%);
  box-shadow: 0 0 0 2px #1d2566, 0 0 24px rgba(0,212,255,.18);
  container-type: inline-size;
  user-select: none;
}
@media (max-height: 520px) and (orientation: landscape) {
  .stage { max-width: calc((100vh - 40px) * 16 / 9); }
}
.stage-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 50%;
}
.stage-logo {
  position: absolute; left: 50%; top: 2.5%;
  width: 38%; height: auto;
  transform: translateX(-50%);
  z-index: 3; pointer-events: none;
  filter: drop-shadow(0 0 6px rgba(0,212,255,.55));
}
.stage-logo-text {
  position: absolute; left: 0; right: 0; top: 5%;
  font-size: 3.2cqw; z-index: 3; pointer-events: none;
}

/* ---------- musicians ---------- */
.row {
  position: absolute; left: 0; right: 0;
  display: flex; justify-content: center; align-items: flex-end;
}
.row-back { bottom: 37%; gap: 4%; z-index: 4; }
.row-front { bottom: 2.5%; gap: 3%; z-index: 5; }
.row-back .musician { width: 15%; }
.row-front .musician { width: 18%; }

.musician {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  outline: none;
}
.musician:focus-visible .sprite { outline: 2px dashed var(--gold); outline-offset: 2px; }
.sprite {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  transition: filter .12s linear, opacity .12s linear;
  transform-origin: 50% 100%;
}
/* Hit-testing: the square sprite box is mostly transparent at the top and
   would cover the back row's nameplates. Only the body area (::before) and
   the nameplate receive pointer events. */
.row, .row .musician { pointer-events: none; }
.sprite > * { pointer-events: none; }
.sprite::before {
  content: ""; position: absolute; z-index: 1;
  left: 12%; right: 12%; top: 22%; bottom: 0;
  pointer-events: auto; cursor: pointer;
}
.plate { pointer-events: auto; }
.sprite img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.sprite .f1 { visibility: hidden; }
.sprite.frame-1 .f0 { visibility: hidden; }
.sprite.frame-1 .f1 { visibility: visible; }
.sprite.idle { animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(-1.2%) scaleY(1.012); }
}

/* fallback when sprite PNGs are missing */
.sprite .fallback {
  position: absolute; left: 10%; right: 10%; bottom: 4%; top: 18%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 14%;
  background: var(--fb-color, var(--blue));
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.25), 0 0 14px var(--fb-color, var(--blue));
  color: #fff;
  text-align: center;
  overflow: hidden;
}
.fallback .fb-emoji { font-size: 6.5cqw; line-height: 1; }
.fallback .fb-name { font-family: var(--font-ui); font-size: max(11px, 1.6cqw); margin-top: 4%; }
.sprite.has-fallback.frame-1 .fallback { transform: rotate(-4deg) translateY(-3%); }

/* silhouette: muted or excluded by solo */
.musician.silhouette .sprite { filter: brightness(0); opacity: .82; }
.musician.silhouette .sprite.has-fallback .fallback { box-shadow: none; }

/* nameplate */
.plate {
  display: flex; align-items: center; gap: 4px;
  max-width: 100%;
  margin-top: -2%;
  padding: 0 0 0 6px;
  background: rgba(11,15,44,.82);
  border: 2px solid var(--cyan);
  border-radius: 6px;
  box-shadow: 0 0 8px rgba(0,212,255,.35);
  transition: opacity .12s, border-color .12s, box-shadow .12s;
}
.plate .key {
  font-family: var(--font-px); font-size: 8px; color: var(--gold);
  flex: none;
}
.plate .name {
  flex: 1 1 auto; min-width: 0;
  font-size: max(15px, 1.7cqw);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink);
}
.btn-solo {
  flex: none;
  min-width: 40px; min-height: 40px;
  padding: 0;
  font-family: var(--font-px); font-size: 11px;
  color: var(--ink-dim);
  background: transparent;
  border: 0; border-left: 2px solid rgba(0,212,255,.35);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}
.btn-solo[aria-pressed="true"] { color: var(--bg); background: var(--gold); }
.musician.muted .plate { opacity: .45; border-color: var(--ink-dim); box-shadow: none; }
.musician.silhouette:not(.muted) .plate { opacity: .7; border-color: #3a4290; box-shadow: none; }
.musician.solo .plate { border-color: var(--gold); box-shadow: 0 0 10px rgba(255,184,0,.5); opacity: 1; }

/* ---------- loader ---------- */
.loader {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11,15,44,.78);
  transition: opacity .3s;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader-box { width: min(70%, 420px); text-align: center; }
.loader-text { font-family: var(--font-px); font-size: clamp(9px, 1.4cqw, 14px); color: var(--cyan); margin-bottom: 12px; }
.loader-bar { height: 12px; border: 2px solid var(--cyan); padding: 2px; }
.loader-fill { height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--pink) 0 8px, var(--gold) 8px 16px); transition: width .15s; }
.loader-pct { margin-top: 8px; color: var(--ink-dim); }
.loader.error .loader-text { color: var(--pink); }

/* ---------- tap hint ---------- */
.tap-hint {
  /* sits just under the stage logo (logo: top 2.5%, width 38%, 1200x443 => height 14.03cqw) */
  position: absolute; left: 50%; top: calc(2.5% + 14.03cqw + 6px); z-index: 30;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  font-size: 22px;
  color: var(--bg);
  background: var(--gold);
  border-radius: 999px;
  box-shadow: 0 0 0 3px var(--bg), 0 0 18px var(--gold);
  white-space: nowrap;
  animation: pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.05); } }

/* ---------- controls ---------- */
.controls {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px 14px;
  margin: 12px auto 0;
  max-width: calc((100vh - 190px) * 16 / 9);
  padding: 10px 12px;
  background: var(--panel);
  border: 2px solid #232c78;
  border-radius: 8px;
}
.song-info { flex: 1 1 180px; min-width: 0; }
.song-title {
  font-family: var(--font-px); font-size: 12px; color: var(--gold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.6;
}
.song-artist { color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transport, .toggles { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.seek { flex: 3 1 260px; display: flex; align-items: center; gap: 10px; min-width: 0; }
.time { flex: none; font-variant-numeric: tabular-nums; color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; min-width: 40px;
  padding: 0 12px;
  font-family: var(--font-ui); font-size: 20px;
  color: var(--ink);
  background: #18206a;
  border: 2px solid var(--blue);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 3px 0 #0a0e33;
}
.btn:hover { border-color: var(--cyan); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0a0e33; }
.btn:focus-visible { outline: 2px dashed var(--gold); outline-offset: 2px; }
.btn .ico { font-size: 18px; line-height: 1; }
.btn-play { background: var(--pink); border-color: #ff7aa8; min-width: 96px; }
.btn-play.is-playing { background: #18206a; border-color: var(--pink); }
.btn-toggle[aria-pressed="true"] { background: var(--cyan); color: var(--bg); border-color: #8af0ff; }

.range {
  -webkit-appearance: none; appearance: none;
  flex: 1 1 auto; width: 100%; min-width: 0;
  height: 40px; margin: 0;
  background: transparent; cursor: pointer;
}
.range::-webkit-slider-runnable-track { height: 8px; background: linear-gradient(90deg, var(--cyan) var(--fill, 0%), #2a3285 var(--fill, 0%)); border-radius: 0; }
.range::-moz-range-track { height: 8px; background: #2a3285; }
.range::-moz-range-progress { height: 8px; background: var(--cyan); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 22px; margin-top: -7px; background: var(--gold); border: 2px solid var(--bg); border-radius: 0; }
.range::-moz-range-thumb { width: 16px; height: 20px; background: var(--gold); border: 2px solid var(--bg); border-radius: 0; }
.range:focus-visible { outline: 2px dashed var(--gold); }
.vol { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 140px; }
.vol-lbl { color: var(--ink-dim); flex: none; }
.vol .range { width: 110px; }
.keys-hint { flex: 1 1 100%; font-size: 16px; color: var(--ink-dim); }

.foot {
  padding: 14px var(--gutter) calc(18px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 15px;
  color: var(--ink-dim);
  opacity: .8;
}

/* ---------- THE SCORE ---------- */
.score {
  --row-h: 96px;
  --lbl-w: 96px;
  margin: 12px auto 0;
  max-width: calc((100vh - 190px) * 16 / 9);
  min-width: 0;
  background: var(--panel);
  border: 2px solid #232c78;
  border-radius: 8px;
  overflow: hidden;
}
.score-head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  border-bottom: 2px solid #232c78;
  min-width: 0;
}
.score-title {
  margin: 0; flex: none;
  font-family: var(--font-px); font-size: 12px; font-weight: normal;
  color: var(--gold); letter-spacing: .08em;
  text-shadow: 0 0 8px rgba(255,184,0,.45);
}
.score-page { flex: 1 1 auto; min-width: 0; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.score-nav { flex: none; display: flex; gap: 8px; }
.btn-nav { padding: 0; width: 44px; font-size: 22px; }
.btn-nav:disabled { opacity: .35; cursor: default; }
.btn-nav:disabled:active { transform: none; box-shadow: 0 3px 0 #0a0e33; }
.score-body {
  position: relative;
  height: 300px;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
}
@media (min-width: 768px) {
  /* desktop: the panel grows to fit every row (6 × --row-h) — no inner scrolling */
  .score-body { height: auto; overflow: hidden; }
  .score-body > .score-msg { height: 200px; }
  /* low ledger-line notes of the last row hang up to ~0.56 row below the SVG (get_lucky p.35) — give them room instead of clipping */
  .score-area { padding-bottom: calc(var(--row-h) * 0.6); }
  .score-svg-host svg { overflow: visible; }
}
.score-msg {
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  font-family: var(--font-px); font-size: 12px; color: var(--ink-dim);
  text-align: center; padding: 0 var(--gutter);
}
.score-sheet { display: flex; align-items: flex-start; min-width: 0; }
.score-labels { flex: none; width: var(--lbl-w); }
.score-label {
  display: flex; align-items: center; gap: 6px;
  width: 100%; height: var(--row-h);
  padding: 0 6px 0 10px;
  font-family: var(--font-ui); font-size: 20px; text-align: left;
  color: var(--ink);
  background: transparent;
  border: 0; border-right: 2px solid #232c78; border-bottom: 1px dashed rgba(138,147,199,.18);
  cursor: pointer;
  transition: opacity .12s;
}
.score-label:hover { color: var(--cyan); }
.score-label:focus-visible { outline: 2px dashed var(--gold); outline-offset: -3px; }
.score-label .k { font-family: var(--font-px); font-size: 8px; color: var(--gold); flex: none; }
.score-label .n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-label .n.wrap { white-space: normal; word-break: break-all; line-height: 1.05; }
.score-label.dim { opacity: .3; }
.score-label.dim .n { text-decoration: line-through; text-decoration-thickness: 1px; }
.score-area { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.score-svg-host { position: relative; z-index: 1; line-height: 0; }
.score-svg-host svg, .score-cache svg { display: block; overflow: hidden; }
/* VexFlow draws black; recolour for the dark panel */
.score-svg-host svg { fill: var(--ink); stroke: var(--ink); }
.score-svg-host svg [fill]:not([fill="none"]) { fill: var(--ink); }
.score-svg-host svg [stroke]:not([stroke="none"]) { stroke: var(--ink); }
.score-svg-host svg g.vf-stave, .score-svg-host svg .vf-stave [stroke]:not([stroke="none"]), .score-svg-host svg .vf-stave [fill]:not([fill="none"]) { stroke: #6f78b8; fill: #6f78b8; }
.score-svg-host g.score-row { transition: opacity .12s; }
.score-svg-host g.score-row.dim { opacity: .25; }
.score-hits { position: absolute; inset: 0; z-index: 2; }
.score-hit { position: absolute; top: 0; bottom: 0; cursor: pointer; border-left: 1px solid transparent; }
.score-hit:hover { background: rgba(0,212,255,.07); }
.score-hit.cur { background: rgba(255,184,0,.05); }
.score-playline {
  position: absolute; top: 0; bottom: 0; left: 0; z-index: 3;
  width: 2px; margin-left: -1px;
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold), 0 0 14px rgba(255,184,0,.6);
  pointer-events: none;
  will-change: transform;
}
.score-cache { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }

/* ---------- info bar ---------- */
.infobar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px;
  margin: 10px auto 0;
  max-width: calc((100vh - 190px) * 16 / 9);
  padding: 6px 12px;
  min-width: 0;
  color: var(--ink-dim);
}
.info-text { font-size: 20px; color: var(--ink); white-space: nowrap; }
.key-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; min-width: 0; }
.key-chips li { display: inline-flex; align-items: center; gap: 5px; font-size: 16px; white-space: nowrap; }
.key-chips kbd {
  font-family: var(--font-px); font-size: 8px; color: var(--cyan);
  padding: 4px 5px; border: 1px solid #2c3690; border-bottom-width: 2px; border-radius: 4px;
  background: #121852;
}
/* Press Start 2P draws ← → as tiny marks — use the UI font for the arrow chip, same box height */
.key-chips kbd.kbd-arrows { font-family: var(--font-ui); font-size: 16px; line-height: 10px; }

/* ---------- portrait / phone ---------- */
@media (max-width: 760px), (orientation: portrait) {
  .stage, .controls { max-width: 100%; }
  .stage { aspect-ratio: 3 / 4; max-height: none; }
  .stage-logo { width: 78%; top: 3%; }
  .stage-logo-text { font-size: 5.6cqw; top: 6%; }
  .row-back { bottom: 36%; gap: 2.5%; }
  .row-front { bottom: 2%; gap: 2%; }
  .row-back .musician { width: 28%; }
  .row-front .musician { width: 31%; }
  .fallback .fb-emoji { font-size: 11cqw; }
  .fallback .fb-name { font-size: 3.2cqw; }
  .plate { padding-left: 4px; }
  .plate .key { display: none; }
  .plate .name { font-size: 15px; }
  .row-back .plate { max-width: 114%; }
  .keys-hint { display: none; }
  .score, .infobar { max-width: 100%; }
  .infobar { justify-content: flex-start; }
  .tap-hint { font-size: 18px; padding: 6px 12px; top: calc(3% + 28.8cqw + 6px); } /* logo here: top 3%, width 78% */
  .seek { flex-basis: 100%; }
  .song-info { flex-basis: 100%; }
}
@media (max-width: 420px) {
  body { font-size: 18px; }
  .controls { padding: 8px; gap: 8px; }
  .btn { padding: 0 10px; font-size: 18px; }
  .btn-play { min-width: 84px; }
  .toggles { flex: 1 1 100%; }
  .vol { flex: 1 1 120px; }
  .vol .range { width: auto; }
  .score { --lbl-w: 66px; }
  .score-label { font-size: 17px; padding: 0 3px 0 5px; gap: 4px; }
  .score-label .k { display: none; }
  .score-head { padding: 6px 8px; gap: 8px; }
  .score-title { font-size: 10px; }
  .score-body { height: 260px; }
}

@media (prefers-reduced-motion: reduce) {
  .sprite.idle, .tap-hint, .intro-logo, .intro-logo-text { animation: none; }
}
