/* BEAT CLASH — neon stage UI. The stage itself is the canvas (js/render.js);
   this file is the menus, the HUD, the versus bars, the coach and the help. */

:root {
  --pink: #ff4fa3;
  --gold: #ffd84f;
  --mint: #4fffd2;
  --blue: #5fa8ff;
  --ink: #f4ecff;
  --muted: #a99bc9;
  --card: rgba(18, 9, 40, 0.88);
  --line: rgba(190, 150, 255, 0.22);
  --fs-accent: #ff4fa3;
  --lb-accent: #ff4fa3;
  --lb-bg: rgba(255, 255, 255, 0.04);
  --lb-border: rgba(190, 150, 255, 0.22);
  --lb-text: #f4ecff;
  --lb-muted: #a99bc9;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b0420; color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; }
#stage { position: fixed; inset: 0; display: block; touch-action: none; }
body.in-song { user-select: none; -webkit-user-select: none; }

button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

/* ── menus ─────────────────────────────────────────────────────────── */
#menu { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto; z-index: 10;
  background: radial-gradient(ellipse at 50% 30%, rgba(40, 10, 70, 0.35), rgba(5, 2, 13, 0.55)); }
.card { position: relative; width: min(460px, 100%); margin: auto; padding: 26px 24px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 0 0 1px rgba(255, 79, 163, 0.08), 0 20px 60px rgba(0, 0, 0, 0.55),
              0 0 60px rgba(255, 79, 163, 0.12);
  backdrop-filter: blur(6px); text-align: center; }
.card.wide { width: min(940px, 100%); }
.card h2 { margin: 6px 0 14px; font-size: 22px; letter-spacing: 0.02em; }

.logo { margin: 8px 0 6px; font-size: 52px; line-height: 1; font-weight: 900; letter-spacing: 0.04em;
  font-style: italic; }
.logo-beat { color: #fff; text-shadow: 0 0 18px var(--pink), 0 0 2px #fff; }
.logo-clash { color: var(--mint); margin-left: 10px;
  background: linear-gradient(90deg, var(--mint), var(--blue));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 12px rgba(79, 255, 210, 0.55)); }
.tagline { color: var(--muted); margin: 6px 0 16px; line-height: 1.45; font-size: 15px; }

input[type=text], select { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font-size: 16px; margin-bottom: 12px; }
select option { background: #1a0b33; }

.primary, .secondary { display: block; width: 100%; padding: 13px 16px; margin: 8px 0; border-radius: 12px;
  font-weight: 800; font-size: 16px; letter-spacing: 0.02em; border: 0; color: #fff; }
.primary { background: linear-gradient(90deg, var(--pink), #b04fff 60%, var(--blue));
  box-shadow: 0 6px 22px rgba(255, 79, 163, 0.35); }
.primary:hover { filter: brightness(1.1); }
.secondary { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.secondary:hover { background: rgba(255, 255, 255, 0.12); }
.primary:disabled, .secondary:disabled { opacity: 0.45; cursor: default; }
.ghost-btn { flex: 1; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font-weight: 700; font-size: 14px; }
.ghost-btn:hover { background: rgba(255, 255, 255, 0.07); }
.home-row { display: flex; gap: 8px; margin: 8px 0 4px; }
.link-btn { background: none; border: 0; color: var(--mint); font-weight: 700; padding: 8px; font-size: 14px; }
.link-btn:hover { text-decoration: underline; }
.back-link { display: inline-block; margin-top: 10px; color: var(--muted); font-size: 14px; text-decoration: none; }
.back-link:hover { color: var(--ink); }
.instructions { margin: 12px 0 4px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.instructions b { color: var(--ink); }

.card-help { position: absolute; top: 12px; left: 12px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--ink); font-weight: 900; }
/* the audio strip is the card's first row (an absolutely placed strip sat on
   top of the logo and every pane heading) */
.menu-audio { display: flex; justify-content: flex-end; margin: -12px -8px 4px 40px; min-height: 36px; }
.menu-audio .mps-audio { gap: 4px; }
.menu-audio .mps-audio-slider { width: 56px; }

.pane-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.pane-head h2 { flex: 1; margin: 4px 36px 8px 0; }

/* segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 9px;
  font-weight: 800; font-size: 14px; }
.seg button.on { color: #fff; background: linear-gradient(90deg, rgba(255, 79, 163, 0.75), rgba(95, 168, 255, 0.75)); }
.seg button:disabled { cursor: default; }
.seg button i { display: block; font-style: normal; font-weight: 600; font-size: 11px; opacity: 0.8; }

/* ── song select ───────────────────────────────────────────────────── */
.song-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; text-align: left; }
.song-list { display: flex; flex-direction: column; gap: 6px; max-height: min(62vh, 560px); overflow-y: auto;
  padding-right: 4px; }
.song-item { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04);
  color: var(--ink); }
.song-item:hover { background: rgba(255, 255, 255, 0.08); }
.song-item.on { border-color: var(--pink); background: linear-gradient(90deg, rgba(255, 79, 163, 0.20), rgba(95, 168, 255, 0.10));
  box-shadow: 0 0 18px rgba(255, 79, 163, 0.25); }
.si-title { font-weight: 800; font-size: 15px; }
.si-sub { grid-column: 1; font-size: 12px; color: var(--muted); }
.si-lv { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 4px; align-items: center; }
.si-lv i { font-style: normal; font-weight: 800; font-size: 12px; min-width: 22px; text-align: center;
  padding: 3px 4px; border-radius: 6px; }
.lv-easy { background: rgba(79, 255, 210, 0.18); color: var(--mint); }
.lv-normal { background: rgba(255, 216, 79, 0.18); color: var(--gold); }
.lv-hard { background: rgba(255, 79, 163, 0.2); color: var(--pink); }
.si-best { position: absolute; top: -6px; right: -4px; font-size: 11px; font-weight: 900; padding: 1px 6px;
  border-radius: 8px; background: var(--gold); color: #2a1404; }
.song-detail { display: flex; flex-direction: column; gap: 10px; }
.sd-title { font-size: 24px; font-weight: 900; line-height: 1.1; }
.sd-meta { color: var(--muted); font-size: 14px; margin-top: -6px; }
.sd-best { font-size: 14px; }
.sd-btns { display: flex; gap: 8px; }
.sd-btns .primary, .sd-btns .secondary { margin: 0; }
.sd-btns .secondary { flex: 0 0 40%; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.toggle small { color: var(--muted); font-weight: 400; }
.toggle input { width: 18px; height: 18px; accent-color: var(--pink); }
.leaderboard-inline { margin-top: 6px; }
.g-S { color: var(--gold); } .g-A { color: var(--mint); } .g-B { color: var(--blue); }
.g-C { color: #c9a8ff; } .g-D, .g-F { color: #ff8a8a; }

/* ── lobby ─────────────────────────────────────────────────────────── */
.roster { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0 12px; }
.p-row { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); }
.p-row.me { border-color: var(--pink); }
.p-name { font-weight: 700; }
.tag { font-size: 11px; color: var(--muted); }
.host-box { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; text-align: left; }
.host-box.readonly { opacity: 0.85; }
.settings-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings-label { width: 82px; color: var(--muted); font-size: 13px; font-weight: 700; }
.settings-row select { flex: 1; margin: 0; min-width: 0; }
.room-pick { margin: 8px 0; font-size: 14px; color: var(--muted); }
.room-pick b { color: var(--ink); }
#lobbyChat { margin: 10px 0; text-align: left; }

/* ── loading ───────────────────────────────────────────────────────── */
.load-bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin: 14px 0; }
#loadBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--blue)); transition: width 0.2s; }
.peers { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; font-size: 13px; }

/* ── settings ──────────────────────────────────────────────────────── */
.set-row { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; text-align: left; }
.set-row label { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; }
.set-row small { color: var(--muted); }
.range { width: 100%; accent-color: var(--pink); }

/* ── results ───────────────────────────────────────────────────────── */
.result-banner { display: none; margin: 0 0 10px; padding: 10px; border-radius: 12px; font-weight: 800; font-size: 18px;
  background: rgba(255, 216, 79, 0.10); border: 1px solid rgba(255, 216, 79, 0.35); }
.result-banner.on { display: block; }
.result-banner.me { background: rgba(255, 216, 79, 0.2); box-shadow: 0 0 24px rgba(255, 216, 79, 0.25); }
.result-top { display: flex; align-items: center; gap: 22px; justify-content: center; text-align: left; margin-bottom: 12px; }
.grade { font-size: 108px; line-height: 1; font-weight: 900; font-style: italic; min-width: 100px; text-align: center;
  text-shadow: 0 0 28px currentColor; }
.result-song { color: var(--muted); font-size: 14px; font-weight: 700; }
.result-score { font-size: 44px; font-weight: 900; letter-spacing: 0.02em; }
.result-line { font-size: 14px; color: var(--muted); line-height: 1.6; }
.result-badges { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: 12px; font-weight: 900; padding: 3px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.08); }
.badge.fc { background: var(--gold); color: #2a1404; }
.badge.pb { background: var(--pink); color: #fff; }
.badge.cr { background: rgba(79, 255, 210, 0.2); color: var(--mint); }
.badge.fail { background: rgba(255, 59, 59, 0.25); color: #ffb0b0; }
.badge.muted { color: var(--muted); }
.result-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.result-btns > button { flex: 1; min-width: 140px; }
#resultTable, #resultAwards { margin: 8px 0; }
.j-p { color: #ffe27a; } .j-g { color: #7fe9ff; } .j-d { color: #8fe08f; } .j-m { color: #ff8a8a; }

/* ── HUD ───────────────────────────────────────────────────────────── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 14px; pointer-events: none; }
.hud-song { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.hud-title { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 40vw; text-shadow: 0 0 10px rgba(255, 79, 163, 0.6); }
.hud-me { font-size: 13px; color: var(--muted); font-weight: 700; }
.diff-badge { font-size: 11px; font-weight: 900; padding: 2px 8px; border-radius: 6px; text-transform: uppercase;
  letter-spacing: 0.06em; }
.d-easy { background: rgba(79, 255, 210, 0.2); color: var(--mint); }
.d-normal { background: rgba(255, 216, 79, 0.2); color: var(--gold); }
.d-hard { background: rgba(255, 79, 163, 0.25); color: var(--pink); }
.hud-score { text-align: right; }
.hud-score b { display: block; font-size: 30px; font-weight: 900; line-height: 1; letter-spacing: 0.02em;
  text-shadow: 0 0 14px rgba(95, 168, 255, 0.6); font-variant-numeric: tabular-nums; }
.hud-score span { font-size: 14px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-btns { display: flex; gap: 6px; pointer-events: auto; position: relative; }
.round-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(20, 10, 40, 0.7); color: var(--ink); font-weight: 900; display: inline-flex;
  align-items: center; justify-content: center; list-style: none; }
.hud-gear summary::-webkit-details-marker { display: none; }
.hud-gear-pop { display: none; }
.hud-gear[open] .hud-gear-pop { display: block; position: absolute; right: 0; top: 44px; padding: 8px;
  border-radius: 12px; background: rgba(20, 10, 40, 0.92); border: 1px solid var(--line); min-width: 250px; }
.hud-songvol { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; padding: 4px 4px 0; }
.hud-songvol input { flex: 1; min-width: 0; }
.hud-songvol b { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.hud-gear-note { display: block; color: var(--muted); font-size: 11px; padding: 2px 4px 6px; }
.hud-toast { position: absolute; left: 50%; top: 58px; transform: translateX(-50%); padding: 8px 14px;
  border-radius: 10px; background: rgba(20, 10, 40, 0.85); border: 1px solid var(--line); font-weight: 700;
  font-size: 14px; opacity: 0; transition: opacity 0.2s; white-space: nowrap; max-width: 92vw; overflow: hidden;
  text-overflow: ellipsis; }
.hud-toast.on { opacity: 1; }
.menu-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 10px 16px;
  border-radius: 10px; background: rgba(20, 10, 40, 0.92); border: 1px solid var(--line); font-weight: 700;
  opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.menu-toast.on { opacity: 1; }

/* versus bars: a column on the right of the highway (desktop), a strip (phone) */
.vs-bars { position: absolute; right: 16px; top: 76px; width: min(250px, 22vw); display: flex; flex-direction: column;
  gap: 8px; }
.vs-row { padding: 8px 10px; border-radius: 12px; background: rgba(20, 10, 40, 0.72); border: 1px solid var(--line); }
.vs-row.me { border-color: var(--pink); box-shadow: 0 0 14px rgba(255, 79, 163, 0.3); }
.vs-row.out { opacity: 0.45; }
.vs-top { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.vs-pos { font-weight: 900; color: var(--muted); font-size: 13px; }
.vs-name { font-weight: 800; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.vs-top .mg-name-title { order: 5; flex-basis: 100%; font-size: 11px; margin-top: -2px; }
.vs-score { font-variant-numeric: tabular-nums; font-size: 14px; }
.vs-bar { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); margin: 5px 0 3px; overflow: hidden; }
.vs-bar i { display: block; height: 100%; border-radius: 4px; transition: width 0.25s; }
.vs-sub { font-size: 11px; color: var(--muted); }

/* tutorial coach */
.coach { position: absolute; left: 16px; top: 76px; width: min(300px, 26vw); padding: 14px; border-radius: 14px;
  background: rgba(20, 10, 40, 0.88); border: 1px solid rgba(79, 255, 210, 0.45);
  box-shadow: 0 0 24px rgba(79, 255, 210, 0.18); pointer-events: auto; }
.coach h3 { margin: 2px 0 6px; font-size: 20px; color: var(--mint); }
.coach p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; }
.coach-step { font-size: 12px; color: var(--muted); font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }
.coach-prog { height: 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
#coachBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--blue)); transition: width 0.2s; }
.coach-row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.coach-count { font-size: 13px; font-weight: 800; }

/* calibration */
.calib { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(5, 2, 13, 0.9); }
.calib-card { width: min(460px, 100%); padding: 22px; border-radius: 18px; background: #160a30;
  border: 1px solid var(--line); text-align: center; }
.calib-card h2 { margin: 0 0 8px; }
.calib-pulse { width: 92px; height: 92px; margin: 12px auto; border-radius: 50%; border: 3px solid var(--line);
  transition: background 0.05s, box-shadow 0.05s; }
.calib-pulse.on { background: var(--pink); box-shadow: 0 0 40px var(--pink); border-color: #fff; }
.calib-pulse.on.count { background: var(--blue); box-shadow: 0 0 40px var(--blue); }
.calib-ruler { position: relative; height: 34px; margin: 10px 0 4px; border-radius: 8px; background: rgba(255, 255, 255, 0.05); }
.calib-zero { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--mint); }
#calibDots i { position: absolute; top: 9px; width: 10px; height: 16px; margin-left: -5px; border-radius: 5px;
  background: var(--gold); opacity: 0.85; }
.calib-l, .calib-r { position: absolute; bottom: -18px; font-size: 11px; color: var(--muted); }
.calib-l { left: 4px; } .calib-r { right: 4px; }
.calib-result { margin: 24px 0 8px; font-size: 15px; min-height: 22px; }
.calib-tap { width: 100%; height: 76px; border-radius: 14px; border: 2px dashed var(--pink); background: rgba(255, 79, 163, 0.08);
  color: #fff; font-size: 22px; font-weight: 900; letter-spacing: 0.2em; touch-action: manipulation; }
.calib-tap:active { background: rgba(255, 79, 163, 0.3); }
.calib-btns { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.calib-btns .primary, .calib-btns .secondary { margin: 0; flex: 1; }

/* help */
.help-overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(5, 2, 13, 0.75); overflow-y: auto; }
.help-card { position: relative; width: min(620px, 100%); margin: auto; padding: 22px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line); }
.help-x { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--ink); }
.help-card h2 { margin: 0 0 6px; padding-right: 40px; }
.help-lead { color: var(--muted); margin: 0 0 12px; }
.help-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.help-tab { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-weight: 800; }
.help-tab.on { color: #fff; background: rgba(255, 79, 163, 0.25); border-color: var(--pink); }
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.help-item { padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; }
.help-item small { color: var(--muted); line-height: 1.4; }
.help-ico { font-size: 22px; }
.kb, .tc { display: inline-block; font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 6px;
  background: rgba(95, 168, 255, 0.2); color: #cfe3ff; width: fit-content; }
.tc { background: rgba(79, 255, 210, 0.15); color: var(--mint); }
.help-note { color: var(--muted); font-size: 14px; }
.help-rules { padding-left: 18px; line-height: 1.55; font-size: 14px; margin: 0; }
.help-rules li { margin-bottom: 6px; }
.help-again { color: var(--muted); font-size: 13px; }
.help-btns { display: flex; gap: 8px; }
.help-btns > button { flex: 1; margin: 0; }

/* ── phones ────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .song-grid { grid-template-columns: 1fr; }
  .song-list { max-height: 34vh; }
  .card { padding: 22px 14px 16px; }
  .logo { font-size: 42px; margin-top: 8px; }
  .grade { font-size: 78px; min-width: 70px; }
  .result-score { font-size: 32px; }
  .result-top { gap: 12px; }
  .hud-top { padding: 8px 10px; gap: 8px; }
  .hud-title { max-width: 46vw; font-size: 14px; }
  .hud-me { display: none; }
  .hud-score b { font-size: 22px; }
  .hud-score span { font-size: 12px; }
  .round-btn { width: 32px; height: 32px; }
  .vs-bars { left: 8px; right: 8px; top: 52px; width: auto; flex-direction: row; overflow: hidden;
    gap: 6px; }
  .vs-row { flex: 0 0 auto; min-width: 116px; padding: 5px 8px; }
  .vs-sub { display: none; }
  .vs-top .mg-name-title { display: none; }
  .coach { left: 8px; right: 8px; top: 54px; width: auto; padding: 10px 12px; }
  .coach p { font-size: 13px; margin-bottom: 6px; }
  .coach h3 { font-size: 16px; }
  .help-grid { grid-template-columns: 1fr; }
  .help-btns { flex-direction: column; }
  .menu-audio .mps-audio-slider { width: 44px; }
}
@media (max-width: 700px) and (max-height: 760px) {
  .coach p { display: none; }
}

/* a suspended AudioContext (autoplay policy, an iOS interruption): one tap */
#audioGate { position: fixed; inset: 0; z-index: 60; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; border: 0; color: var(--ink);
  background: rgba(8, 3, 22, 0.82); backdrop-filter: blur(4px); }
#audioGate b { font-size: clamp(22px, 5vw, 34px); padding: 18px 28px; border-radius: 16px;
  background: var(--pink); box-shadow: 0 0 40px rgba(255, 79, 163, 0.5); }
#audioGate small { color: var(--muted); font-size: 14px; }
