body.stage-open { overflow: hidden; }
.actionNameOnly, #stage[data-view="play"] #stageMenuHost { position:absolute!important; width:1px!important; height:1px!important; margin:-1px!important; padding:0!important; overflow:hidden!important; white-space:nowrap!important; clip-path:inset(50%); }
#stage[data-view="play"] #stageMenuHost #pianoLegend,
#stage:has(#clockBadge:not([hidden])) #pianoTransportHint { display:none; }
body.stage-open .top { display: none; }
#stage {
  --rail: clamp(126px, 12.6vw, 202px);
  --stage-pad: clamp(8px, 1.1vw, 22px);
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail);
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 0 var(--stage-pad);
  padding: max(var(--stage-pad), env(safe-area-inset-top)) max(var(--stage-pad), env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(var(--stage-pad), env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 60%, #242031, #14121e 68%, #100f19);
  overflow: hidden;
  color: #f1edf8;
}
#stage .stageRail {
  grid-row: 1 / -1;
  display: flex;
  flex-flow: column;
  gap: clamp(12px, 2.4vh, 26px);
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-bottom: 6px;
}
#stageLeft { grid-column: 1; }
#stageRight { grid-column: 3; }
#stage .sheetWrap {
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
}
#sheet { grid-row:2; width: 100%; height: 100%; min-width: 0; min-height: 0; }
#entryCount { position:absolute; z-index:2; top:16%; left:50%; transform:translateX(-50%); padding:.25em .65em; border-radius:.4em; background:#211a36; color:#f1e3ff; font:700 24px var(--mono); pointer-events:none; }
#stage:not([data-view="play"]) #entryCount, #stage:has(#clockBadge:not([hidden])) #entryCount { display:none; }
#stage::after {
  content:""; position:absolute; inset:0; z-index:3; pointer-events:none;
  background:radial-gradient(ellipse at center,transparent 54%,rgba(195,19,47,.22) 77%,rgba(218,20,48,.93) 100%);
  box-shadow:inset 0 0 2.6vmin rgba(223,23,53,.42);
  opacity:var(--health-warning,0);
}
#stage[data-view="editor"]::after,#stage.trainNote::after { opacity:0; }
#stage.low-health #hp { --skin-health-color:#f45264; }
#pausePanel { position:absolute; inset:0; z-index:4; display:grid; overflow:auto; padding:12px; background:#171321d4; }
#pausePanel:has(#clockBadge[hidden]) { display:none; }
#pausePanel .pauseContents { width:min(100%,292px); margin:auto; }
#pausePanel #clockBadge { position:static; transform:none; padding:0; background:none; border:0; border-radius:0; color:#faf6ff; font:700 clamp(26px,4vw,42px)/1.2 "Segoe UI",sans-serif; letter-spacing:-.04em; }
.pauseActions { display:flex; justify-content:center; gap:8px; margin:12px 0; }
.pauseActions button { flex:1; position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px; min-height:56px; padding:7px; color:#ded8e7; background:transparent; }
.pauseKeyHints { display:inline-flex; align-items:center; justify-content:center; gap:3px; }
#pausePanel samp,#stageActions kbd { font:600 10px var(--mono); color:inherit; opacity:.75; }
#pausePanel button { position:relative; }
#pausePanel button:enabled:is(:hover,:focus-visible,.piano-focus) { color:white; }
#pausePanel button:is(:focus-visible,.piano-focus) { outline:none!important; }
#pausePanel button:enabled:is(:hover,:focus-visible,.piano-focus)::after { content:""; position:absolute; bottom:0; left:50%; width:22px; transform:translateX(-50%); border-bottom:2px solid currentColor; }
#pausePanel kbd { white-space:nowrap; font:650 .8em var(--mono); color:#ded0f5; border:0; background:transparent; padding:0; }
#stage[data-input="midi"] #stageActions #restart kbd { display:none; }
.pauseCheckpoints { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:4px; margin:0 0 7px; }
.pauseCheckpoints button { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px; padding:6px 4px; color:#eee8f4; background:transparent; font-size:14px; }
.pauseCheckpoints button:first-child { font-weight:640; }
#pauseDeletePoint:enabled { color:#ffc1c9; }
#pauseDeletePoint.undoCheckpoint { color:#c1eadb; }
.pauseCheckpoints button:disabled { opacity:.44; }
#pausePanel .pianoConnection { width:100%; padding:8px 4px; border:0; border-radius:0; background:transparent; }
#pausePiano kbd { margin-left:auto; }
#pausePanel .ico { width:19px; height:19px; flex:none; }
#pauseDeletePoint:not(.undoCheckpoint) svg:nth-of-type(2),#pauseDeletePoint.undoCheckpoint svg:first-of-type { display:none; }
#stageActions .ico { flex:none; width:15px; height:15px; margin-inline-end:4px; }
#pauseMixer { margin-top:10px; padding-top:7px; border-top:1px solid #b7a6d25c; color:#f7f4fa; }
.pauseMixChannelRow,.pauseMixLevelRow { display:grid; gap:6px; align-items:center; }
.pauseMixChannelRow { grid-template-columns:auto minmax(0,1fr) auto; }
.pauseMixLevelRow { grid-template-columns:auto minmax(35px,1fr) auto auto; margin-top:3px; }
#pauseMixer button { display:inline-flex; align-items:center; justify-content:center; gap:4px; padding:3px 4px; min-width:32px; min-height:28px; color:#eee4f6; background:transparent; }
#pauseMixer button span { font-weight:700; font-size:16px; }
#pauseMixer kbd { font-size:10px; }
#pauseMixChannel { width:100%; padding:3px; font-size:13px; color:inherit; border:0; background:transparent; }
#pauseMixChannel option { background:#211d29; color:white; }
#pauseMixLevel { width:100%; margin:0; accent-color:var(--lav); cursor:pointer; }
#pauseMixValue { font:600 12px var(--mono); text-align:right; min-width:4ch; }
@media (max-height:460px) {
  #pausePanel { padding:6px; }
  .pauseActions { margin:5px 0; }
  .pauseActions button { min-height:28px; padding:3px 10px; }
}
#stage .stageRail h3, #stageCombo small, .stageStats > small:first-child {
  font: 650 11px/1.35 var(--mono);
  letter-spacing: .075em;
  text-transform: uppercase;
  color: #b8adc9;
}
.stageIdentity, #stageHistory, #stagePlayed, .stageStats, #stageCombo { min-width: 0; }
#stage #leave { font-size: 13px; line-height: 1.3; text-align: left; padding: 5px 0; }
#stageTitle { font-size: clamp(17px, 1.65vw, 29px); line-height: 1.12; letter-spacing: -.035em; overflow-wrap: anywhere; margin: 16px 0 5px; }
#stageMeta, #stageRunsEmpty, #liveHands { color: #aea6c0; font-size: 12px; line-height: 1.4; }
#stageScoreTools { margin-top: 12px; }
#stageMenuHost #pianoMenu { position: static; margin: 6px 0 0; max-width: 100%; padding: 5px; font-size: 11px; }
#stageMenuHost #pianoLegend { font-size: 10px; }
#stageHistory { margin: auto 0; }
#stageRuns { list-style: none; margin: 7px 0 0; padding: 0; }
#stageRuns li { display: grid; grid-template-columns: 25px 1fr; gap: 1px 6px; font: 13px/1.3 var(--mono); align-items: baseline; border-top: 1px solid #ffffff17; padding: 7px 0; }
#stageRuns b { color: var(--yellow); grid-row: span 2; }
#stageRuns small { font: 11px/1.2 var(--mono); color: #b6aac7; overflow-wrap: anywhere; }
#stageRuns.liveStanding li { grid-template-columns:max-content minmax(0,1fr); font-variant-numeric:tabular-nums; }
#stageRuns.liveStanding b { color:#aaa0b9; font-weight:500; }
#stageRuns .stageCurrent { box-shadow:inset 2px 0 var(--lav); padding-left:7px; }
#stageRuns .stageCurrent :is(b,small) { color:var(--lav); }
#stageRuns .stageCurrent strong { color:#fff; }
#stageCombo { margin-top: auto; }
#stageCombo small, #stagePoints, #combo, #playedName { display: block; }
#stageCombo #combo { font: 750 clamp(29px, 3.4vw, 56px)/1 var(--mono); letter-spacing: -.07em; color: #dac6ff; }
.stageStats { text-align: right; }
#stagePoints { color: #fbf8ff; font: 750 clamp(24px, 2.45vw, 43px)/1.15 var(--mono); letter-spacing: -.065em; white-space: nowrap; }
.stageAccuracy, .stageHealth { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin-top: 7px; }
#stage .sheetWrap>.stageHealth { grid-row:1; justify-content:flex-start; gap:8px; width:clamp(130px,26vw,350px); max-width:95%; margin:0 0 4px; }
#stage .sheetWrap #hp { max-width:none; }
.stageAccuracy span,.stageHealth small { font-size: 12px; color: #bfb4cf; }
#acc { font: 650 clamp(14px,1.3vw,21px)/1.2 var(--mono); color: #cbafff; }
#hp { appearance: none; flex: 1; min-width: 0; height: 6px; max-width: 75%; border: 0; border-radius: 4px; overflow: hidden; background: #353040; }
#hp::-webkit-progress-bar { background: #353040; }
#hp::-webkit-progress-value { background: #86d7bc; border-radius: 4px; }
#hp::-moz-progress-bar { background: #86d7bc; }
#stagePlayed { margin: auto 0; text-align: right; }
#playedName { font-size: clamp(17px,1.65vw,27px); line-height: 1.15; color: #f0ddff; margin: 5px 0; overflow-wrap: anywhere; }
#playedPitches, #stage #feedback { font: 12px/1.35 var(--mono); color: #b1c9dc; overflow-wrap: anywhere; }
#stage #feedback { text-align: inherit; min-height: 1.4em; margin-top: 5px; }
#stage #feedback[data-tone="error"] { color: #ffabb4; }
#stage #feedback[data-tone="warning"] { color: #f4d09b; }
#stage #feedback[data-tone="success"] { color: #a5e1cc; }
.hide-judgment-text #stage :is(.score-popup,#feedback,#feedbackLastError) { display:none; }
.hide-judgment-text #playedName[data-wrong="true"] { color:var(--skin-judgments-wrong-result,#ff90a0); }
#stage .feedbackLastError { margin: 6px 0 0; padding: 6px 0 0; border-top: 1px solid #a9677066; font: 12px/1.4 var(--mono); color: #ffd6db; }
#stage .feedbackLastError summary { list-style: none; font-weight: 400; }
#stage .feedbackLastError summary::-webkit-details-marker { display: none; }
#stage .feedbackLastError small, #stage .feedbackLastError span { display: block; }
#stage .feedbackLastError small { font: 10px/1.4 "Segoe UI",sans-serif; text-transform: uppercase; letter-spacing: .04em; color: #cf9da8; }
#stage .feedbackLastError span { overflow-wrap: anywhere; }
#stage .feedbackLastError em { font: 10px/1.4 "Segoe UI",sans-serif; color: #cab9e1; text-decoration: underline; }
#stage .feedbackLastError p { margin: 5px 0 0; max-height: 9em; overflow-y: auto; font: 12px/1.45 "Segoe UI",sans-serif; color: #e0cfdd; }
.feedbackReview ol { padding-left: 21px; margin: 12px 0 0; }
.feedbackReview li { margin: 9px 0; }
.feedbackReview li p { margin: 3px 0; }
@media(max-width:900px) and (orientation:portrait),(max-width:540px) {
  #stage .feedbackLastError { margin-top: 3px; padding-top: 3px; font-size: 10px; }
  #stage .feedbackLastError summary span { max-height: 4.2em; overflow-y: auto; }
  #stage .feedbackLastError p { max-height: 6em; font-size: 11px; }
}
#stageLegend { margin: 0; padding: 5px 0 0; color: #bcb2cd; font-size: 12px; }
#stageActions { display: grid; gap: 5px; }
#stageActions .btn, #rangeBar .btn, #rangeBar .primary { min-width: 0; font-size: 13px; line-height: 1.2; padding: 7px 8px; }
#stageActions #pause { border-color: #705f84; }
#stageActions #pause::after { content:"Esc"; margin-inline-start:.45em; font:600 .82em var(--mono); opacity:.8; }
#stage .rangeBar { align-items: stretch; flex-direction: column; gap: 8px; margin: auto 0; }
#stage .rangeChoices { display: grid; gap: 4px; }
#stage .rangeBar .primary { margin-left: 0; }
#stage .pageNav { display: flex; gap: 6px; }
#stage .pageNav button { flex: 1; }
#stage #keysArea { grid-column: 2; grid-row: 2; min-width: 0; gap: 6px; margin: 5px 0 0; }
#keysArea #keys { height: clamp(41px,6vh,62px); max-width: 78%; }
#stageTiming { grid-column: 2; grid-row: 3; display: grid; justify-items: center; min-width: 0; padding: 6px 0 3px; }
#meters { display: flex; justify-content: center; flex-wrap: nowrap; width: min(100%, 530px); gap: clamp(6px,1.4vw,21px); }
#meters .meter { flex: 1; min-width: 0; max-width: 164px; text-align: center; }
#meters small { font: 11px/1.2 var(--mono); display: block; color: #c4b9d2; }
#meters .meterLine { height: 7px; margin-top: 4px; }
#meters .meterReadout { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; margin-top: 5px; font: 10px/1.25 var(--mono); }
#meters .meterReadout > span { color: #c5bcd3; }
#meters .meterValue { font: inherit; color: #f2e8ff; text-align: right; overflow-wrap: anywhere; }
#meters .meterValue[data-direction="zero"] { color: #a8e6cc; }
#meters .meterReadout + .meterLine { height: 4px; margin: 3px 0 4px; }
#meters .meterLine i.attack { height: 8px; top: -2px; background: #f2e8ff; }
#meters .meterLine i.release { height: 8px; top: -2px; background: #9ed7f3; outline: 1px solid #32404d; }
#meters .releaseLine { opacity: .85; }
#timingHint { margin: 5px 0 0; font: 10px/1.3 "Segoe UI",sans-serif; color: #a9a0bd; text-align: center; }
#stage.trainNote #timingHint { display: none; }
@media(max-width:900px) and (orientation:portrait),(max-width:540px) {
  #meters .meterReadout { font-size: 9px; margin-top: 3px; flex-wrap: wrap; gap: 0 3px; }
  #timingHint { font-size: 9px; margin-top: 3px; }
}
#stage[data-view="editor"] .playingHud { display: none; }
#stage.trainNote .stageHealth, #stage.trainNote #liveHands { display: none; }
#stage.trainNote #stagePoints { font-size: clamp(20px,2.1vw,36px); }
#trainPrompt { align-self: center; font: 600 clamp(12px,1.3vw,16px)/1.35 var(--mono); text-align: center; color: #dbc3ff; }
#stage[data-view="editor"] #stageRight { justify-content: end; }
body.stage-open > #pianoMenu { position: fixed; right: var(--stage-pad,10px); bottom: 10px; margin: 0; max-width: min(430px,92vw); }
@media (min-width: 541px) and (max-height: 560px) {
  #stage { --rail: clamp(108px,13vw,144px); --stage-pad: 6px; }
  #stage .stageRail { gap: 6px; }
  #stage #stageLeft { display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
  #stage[data-view="play"] #stageRight { display:grid; grid-template-rows:auto minmax(0,1fr) auto; }
  #stage[data-view="play"] #stagePlayed { min-height:0; margin:0; overflow-y:auto; }
  #stage[data-view="play"] #stageActions { align-self:end; }
  #stageLeft #stageHistory { min-height: 0; max-height: 100%; overflow-y: auto; align-self: center; margin: 0; }
  #stageMenuHost #pianoLegend { max-height: 3.9em; overflow-y: auto; }
  #stageCombo { align-self: end; margin: 0; }
  #stageTitle { margin: 4px 0; font-size: 16px; }
  #stageScoreTools { margin-top: 4px; }
  #stageRuns li { padding: 3px 0; }
  #stageRuns:not(.liveStanding) li:nth-child(n+3), #stageRuns.liveStanding li:not(.stageCurrent,.stageRival) { display: none; }
  #stageMeta,#stageRunsEmpty { font-size: 10px; }
  #stageActions { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 3px; }
  #stageActions .btn { padding: 5px 2px; font-size: 10px; }
  #stageActions #stageFullscreen { grid-column: 1 / -1; }
  #stagePoints { font-size: 23px; }
  #stageLegend { position:relative; }
  #stageScoreLegend { position:absolute; right:0; bottom:100%; z-index:5; width:min(240px,82vw); max-height:45dvh; overflow:auto; padding:8px; background:#211d2b; }
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 540px) {
  #stage { --stage-pad: 6px; grid-template-columns: repeat(12,minmax(0,1fr)); grid-template-rows: auto auto minmax(0,1fr) auto auto auto; gap: 3px 4px; }
  #stage .stageRail { display: contents; }
  .stageIdentity { grid-column: 1/8; grid-row: 1; }
  #stage #leave { font-size: 11px; padding: 1px 0; }
  #stageTitle { font-size: 16px; line-height: 1.1; margin: 1px 0 2px; }
  #stageMeta { font-size: 10px; }
  #stageScoreTools { margin-top: 2px; }
  .stageStats { grid-column: 8/-1; grid-row: 1; }
  #stagePoints { font-size: 22px; }
  .stageAccuracy,.stageHealth { margin-top: 1px; }
  #liveHands { font-size: 10px; }
  #stagePlayed { grid-column: 7/-1; grid-row: 2; }
  #stageHistory { grid-column: 1/7; grid-row: 2; }
  #stageHistory, #stagePlayed { margin: 0; align-self: center; }
  #stageRuns { margin: 0; max-height: 30px; overflow-y: auto; }
  #stageRuns li { grid-template-columns: 23px auto 1fr; gap: 4px; padding: 3px 0; }
  #stageRuns.liveStanding { max-height:none; }
  #stageRuns.liveStanding li { grid-template-columns:max-content auto 1fr;align-items:center; }
  #stageRuns.liveStanding li:not(.stageCurrent,.stageRival) { display:none; }
  #stageRuns.liveStanding li b { grid-row:auto; }
  #stageRuns.liveStanding li small { white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
  #stageRuns li small { font-size: 9px; }
  #stageRunsEmpty, #stage #feedback, #playedPitches { font-size: 10px; }
  #playedName { font-size: 15px; margin: 0; }
  #stage #feedback { margin: 0; min-height: 0; }
  #stage .sheetWrap { grid-column: 1/-1; grid-row: 3; }
  #stage #keysArea { grid-column: 1/-1; grid-row: 4; }
  #stageCombo { grid-column: 1/3; grid-row: 5; margin: 0; }
  #stageCombo #combo { font-size: 23px; }
  #stageTiming { grid-column: 3/11; grid-row: 5; align-self: center; padding: 2px 0; }
  #meters { gap: 4px; } #meters small { font-size: 9px; }
  #stageActions { grid-column: 1/-1; grid-row: 6; display: flex; justify-content: center; flex-wrap: wrap; gap: 3px; }
  #stageActions .btn { font-size: 11px; padding: 6px; }
  #stageLegend { position:relative; grid-column:11/-1; grid-row:5; align-self:center; font-size:10px; }
  #stageScoreLegend { position:absolute; right:0; bottom:100%; z-index:5; width:min(240px,82vw); max-height:45dvh; overflow:auto; padding:8px; background:#211d2b; }
  #stage[data-view="editor"] #stageHistory { display: none; }
  #stage[data-view="editor"] .stageIdentity { grid-column: 1/-1; }
  #stage .rangeBar { grid-column: 1/-1; grid-row: 2; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0; padding: 3px 0; }
  #stage .rangeBar h3 { display: none; }
  #stage .rangeChoices { display: flex; }
  #stage .rangeBar span { font-size: 10px; }
  #stage .rangeBar button { padding: 5px; font-size: 11px; }
}
#restartShade {
  position: absolute; inset: 0; z-index: 60; pointer-events: none;
  display: grid; place-items: center; background: rgba(0,0,0,calc(var(--restart-progress,0) * .88));
}
#restartShade > span { color: #fff; text-align: center; font: 700 clamp(18px,3vw,32px)/1.3 "Segoe UI",sans-serif; text-shadow: 0 2px 12px #000; }
#restartShade small { display: block; margin-top: 7px; font-size: 12px; font-weight: 400; }
#pianoTransportHint { color: #c5b1df; font: 10px/1.25 var(--mono); margin: 5px 0 0; max-height: 3.8em; overflow-y: auto; }
/* Local MP4 may sit under the score; the official YouTube player never does. */
#stage > :not(#stageVideoBackdrop):not(#restartShade):not(.fallen-notes):not(#stageVideoPanel) { position: relative; z-index: 1; }
#stageVideoBackdrop { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
#stageVideoBackdrop video { width: 100%; height: 100%; object-fit: cover; }
#stageVideoInfo { margin-top: 8px; font: 10px/1.35 var(--mono); color: #c7bbda; }
#stageVideoInfo p { margin: 0 0 5px; }
#stageVideoOpen { color: #dac1ff; display: inline-block; }
#stageVideoRetry { margin: 4px 0; font-size: 11px; }
#stageVideoPanel { position:relative; z-index:3; grid-column: 4; grid-row: 1 / -1; align-self: center; min-width: 0; }
#stageVideoPanel h3 { font: 600 12px/1.3 var(--mono); margin: 0 0 8px; }
#stageVideoPanel p { font: 11px/1.4 var(--mono); color: #b9afca; }
#stageVideoMount { width: 100%; height: 220px; min-width: 200px; min-height: 200px; background: #000; }
#stageVideoMount iframe { display: block; width: 100%; height: 100%; border: 0; pointer-events: auto; }
@media(min-width:1200px) and (min-height:650px) {
  #stage.has-youtube { grid-template-columns: var(--rail) minmax(0,1fr) var(--rail) clamp(240px,21vw,380px); }
}
