:root {
  --stage-amber: #ffc983;
}

.shell { width: min(1320px, calc(100% - clamp(24px, 6vw, 88px))); }
.topbar-actions { display: flex; align-items: center; justify-self: end; gap: 10px; }
.topbar-actions .mode-tabs { margin: 0; }
.topbar-actions .mode-tab { white-space: nowrap; }

.karaoke-layout { display: grid; gap: 16px; }
.karaoke-stage {
  overflow: hidden;
  border-radius: 20px;
  box-shadow: 0 18px 70px #0005;
}
.stage-header, .stage-actions { display: flex; align-items: center; }
.stage-header {
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(13px, 2.4vw, 30px);
  background: linear-gradient(108deg, #201a30, var(--surface) 62%);
}
.stage-header .song-actions { min-width: 0; }
.stage-actions { flex: none; gap: 9px; margin-inline-start: auto; }
.stage-header .upload-button, .stage-header .song-select-wrap { margin-bottom: 0; }
.stage-header .song-actions select {
  background: #1b1729;
  border-color: #3a304e;
  min-height: 42px;
  border-radius: 9px;
  font-size: .875rem;
}
.stage-header .song-actions select:hover:enabled { border-color: #5c487c; }
.karaoke-stage .upload-button { min-height: 42px; }
.stage-expand { flex: none; }

.stage-hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; border-block: 1px solid var(--border); }
.stage-metric { display: flex; align-items: center; gap: 11px; padding: 10px clamp(12px, 2.4vw, 30px); }
.stage-metric label { display: block; color: var(--muted); font-size: .78rem; line-height: 1.2; }
.stage-metric output { display: block; margin-top: 4px; color: var(--text); font: 700 1.45rem/.95 var(--display); font-variant-numeric: tabular-nums; }
.stage-metric svg { width: 21px; height: 21px; color: var(--purple); }
.stage-metric-score { justify-content: center; min-width: clamp(117px, 24vw, 250px); text-align: center; border-inline: 1px solid var(--border); }
.stage-metric-score output { color: var(--mint); font-size: clamp(1.7rem, 4vw, 2.75rem); letter-spacing: -.07em; }
.stage-metric-best { justify-content: flex-end; }
.stage-metric-best svg { color: var(--stage-amber); }

.stage-visual { background: #100d1c; }
.stage-guide { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; padding: 9px clamp(12px, 2.4vw, 30px); }
.stage-cue {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #3a304e;
  border-radius: 7px;
  padding: 4px 8px;
  color: #c6b9dc;
  font: 600 .73rem/1.2 var(--mono);
  white-space: nowrap;
}
.stage-cue::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ''; }
.stage-cue[data-cue='sing'] { color: var(--mint); background: #173329; border-color: #2c5143; }
.stage-cue[data-cue='listen'], .stage-cue[data-cue='replay'] { color: var(--mint); }
.stage-guide-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 7px 12px; min-width: 0; }
.stage-guide .legend { flex-direction: row; font-size: .76rem; }
.stage-guide .legend-midi { border-radius: 5px; }
.karaoke-stage .roll-root { --pitch-roll-height: clamp(446px, 59svh, 650px); border: 0; }
.stage-visual .lyrics-root { border-bottom: 1px solid var(--border); }

.stage-progress {
  padding: 9px clamp(12px, 2.4vw, 30px);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.stage-transport-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.stage-transport-controls .play-button.replaying { width: auto; min-width: 90px; }
.stage-overview { position: relative; height: 30px; overflow: hidden; border: 1px solid #3a304e; border-radius: 6px; background: #100d1c; }
.stage-overview canvas { display: block; width: 100%; height: 100%; }
.stage-overview-progress { position: absolute; inset: 0 auto 0 0; width: 0; background: #72edbd29; box-shadow: 1px 0 var(--mint); }

.settings-panels .setup-control .select-wrap { max-width: 68%; min-width: 0; }
.stage-settings-button { display: none; }
.stage-expanded .stage-settings-button { display: inline-flex; }
.take-result-streak { display: flex; align-items: center; gap: 7px; width: fit-content; margin: 14px auto 0; padding: 6px 10px; border: 1px solid #6c5331; border-radius: 7px; background: #32271a; color: var(--stage-amber); font-size: .87rem; }
.take-result-streak svg { width: 16px; height: 16px; }

.stage-expanded { overflow: hidden; }
.stage-expanded .topbar { visibility: hidden; }
.stage-expanded #notice { position: fixed; z-index: 11; inset: auto 14px 14px; max-width: 650px; margin: 0 auto; }
.stage-expanded .karaoke-stage {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: auto;
  border: 0;
  border-radius: 0;
}
.stage-expanded .karaoke-stage .roll-root { --pitch-roll-height: clamp(446px, calc(100svh - 315px), 760px); }

@media (max-width: 900px) {
  .topbar-inner { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; }
  .headphone-tip { grid-area: 2 / 1 / 3 / -1; justify-self: center; }
}

@media (max-width: 820px) {
  .stage-header { flex-wrap: wrap; gap: 11px; }
  .stage-guide { grid-template-columns: minmax(0, 1fr) auto auto; }
  .stage-guide .legend { display: none; }
}

@media (max-width: 560px) {
  .topbar-actions { gap: 6px; }
  .topbar-actions .mode-tab { padding-inline: 8px; }
  .topbar-actions .mode-tab svg { display: none; }
  .header-settings-button { width: 36px; min-height: 36px; }
  .stage-header .song-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: 100%; gap: 7px; }
  .stage-header .song-select-wrap { max-width: 100%; }
  .stage-header .octave-select-wrap { min-width: 0; }
  .stage-header .upload-button { padding-inline: 11px; }
  .stage-metric { column-gap: 6px; }
  .stage-metric svg { width: 16px; height: 16px; }
  .stage-metric output { font-size: 1.125rem; }
  .stage-metric-score output { font-size: 1.75rem; }
  .stage-guide { grid-template-columns: minmax(0, 1fr) auto; justify-items: start; gap: 6px 8px; }
  .stage-guide-tools { justify-self: end; }
  .stage-cue { max-width: 100%; white-space: normal; }
  .stage-cue::before { flex: none; }
  .stage-transport-controls { grid-column: 1 / -1; justify-self: stretch; }
  .stage-transport-controls .timecode { margin-left: auto; }
  .stage-overview { height: 22px; }
  .karaoke-stage .roll-root { --pitch-roll-height: clamp(442px, 58svh, 560px); }
}
