/* Virtual Piano reference studio — presentation only.
 * Screenshot-derived desktop layout; retains the existing controls and JS contracts.
 * The natural studio layout fits at a presentation-only scale on short windows.
 * Layout-aware CSS zoom preserves SVG identity, pointer geometry and horizontal scrolling.
 */
:root {
  --studio-bg: #0b111e;
  --studio-panel: #131c2b;
  --studio-line: #2e3a4e;
  --studio-gold: #f1c875;
  --studio-text: #edf2fb;
  --studio-muted: #a5b0c3;
  --studio-control-height: 44px;
  --studio-height-fit: 1;
  --studio-width-fit: 1;
  --studio-fit: min(var(--studio-height-fit),var(--studio-width-fit));
}
html, body { width:100%; }
/* Keep document overflow observable: a failing fit must not silently clip the page. */
html { height:100%; min-height:0; overflow-x:auto; overflow-y:auto; }
body {
  height:100dvh; min-height:100dvh; overflow:visible;
  background:radial-gradient(ellipse at 55% -35%,#202c42 0%,#0b111e 58%);
  color:var(--studio-text);
}
.shell { height:auto; min-height:calc(100dvh / var(--studio-fit)); padding:0; zoom:var(--studio-fit); }
 /* Conservative stepped fallback for engines with CSS zoom but without typed division. */
@media (max-height:800px) { :root { --studio-height-fit:.95; } }
@media (max-height:760px) { :root { --studio-height-fit:.87; } }
@media (max-height:700px) { :root { --studio-height-fit:.8; } }
@media (max-height:640px) { :root { --studio-height-fit:.72; } }
@media (max-height:580px) { :root { --studio-height-fit:.65; } }
@media (max-height:520px) { :root { --studio-height-fit:.57; } }
@media (max-height:460px) { :root { --studio-height-fit:.49; } }
@media (max-height:400px) { :root { --studio-height-fit:.42; } }
@media (max-width:760px) { :root { --studio-width-fit:.8; } }
@media (max-width:600px) { :root { --studio-width-fit:.65; } }
@media (max-width:480px) { :root { --studio-width-fit:.52; } }
@media (max-width:380px) { :root { --studio-width-fit:.42; } }
@supports (zoom: calc(1px / 1px)) {
  :root { --studio-fit: min(1,calc(100dvh / 800px),calc(100vw / 760px)); }
}
@supports not (zoom: 1) {
  :root { --studio-fit:1; }
}
.shell > header {
  flex:none; height:auto; min-height:61px; margin:0; padding:6px 24px;
  border-bottom:1px solid #243046;
  background:linear-gradient(90deg,#0c1321,#111a2a 60%,#0b1320);
}
.brand { gap:12px; color:#fbfcff; font-size:1.16rem; letter-spacing:.045em; }
.brand-mark {
  width:39px; height:39px; border-radius:10px;
  background:linear-gradient(145deg,#ffdd8c,#f4b944);
  color:#33240c; font-size:1.4rem; box-shadow:0 0 18px #eebc5f55;
}
.key-range-toggle {
  min-height:39px; padding:0 16px; border-radius:10px;
  border-color:#c99935; color:#f1c875; background:#141b29;
  font-size:.89rem; letter-spacing:.16em; font-weight:900;
}
.key-range-toggle:focus-visible,
.playback-panel button:focus-visible,
.score-viewport:focus-visible {
  outline:2px solid #ffdf89; outline-offset:3px;
}
.studio {
  flex:1 0 auto; min-height:auto; display:flex; flex-direction:column;
  justify-content:flex-start; gap:0; padding:0; margin:0;
  border:0; background:transparent; box-shadow:none;
}
.studio-workspace {
  display:grid; grid-template-columns:minmax(0,1fr);
  gap:8px; width:100%; min-height:auto; flex:1 0 auto;
  padding:10px 16px 8px;
}
.playback-panel {
  min-width:0;
  border:1px solid var(--studio-line);
  background:linear-gradient(145deg,#172234,#111928 58%,#111826);
  box-shadow:inset 0 1px #ffffff0c,0 8px 22px #02060e59;
}
.visually-hidden {
  position:absolute!important; width:1px!important; height:1px!important;
  padding:0!important; margin:-1px!important; overflow:hidden!important;
  clip:rect(0,0,0,0)!important; white-space:nowrap!important; border:0!important;
}
.studio-main { display:grid; grid-template-rows:minmax(min-content,1fr) auto auto; gap:8px; min-width:0; min-height:auto; }
.studio-main .score-panel {
  display:flex; flex-direction:column;
  width:100%; height:auto; min-width:0; min-height:min-content;
  margin:0; padding:7px; border-radius:18px;
  border:1px solid #3e4d62; background:linear-gradient(#192338,#111a2b);
  box-shadow:0 8px 20px #050a1461,inset 0 1px #ffffff14;
}
.studio-main .score-heading {
  flex:none; min-height:29px; display:flex; align-items:center; justify-content:space-between;
  gap:12px; margin:0 10px 5px; color:#e0e8f5;
  font-size:.81rem; font-weight:800; letter-spacing:.15em; text-transform:uppercase;
}
.studio-main .score-heading .score-title { flex:0 1 auto; min-width:0; color:#e0e8f5; font-weight:800; letter-spacing:inherit; }
.studio-main .score-heading .score-title > span { margin-right:5px; color:#f3d080; }
.studio-main .score-heading .score-song-select { display:block; flex:0 1 270px; width:270px; max-width:58%; min-width:0; margin-left:auto; }
.studio-main .score-heading .score-song-select::after { right:13px; top:10px; }
.studio-main .score-heading #songSelect {
  appearance:none; display:block; width:100%; min-width:0; height:29px;
  padding:0 29px 0 9px; border:1px solid #344459; border-radius:8px;
  color:#f7f8fd; background:#101726; font-size:.77rem; font-weight:650;
  letter-spacing:0; text-transform:none; cursor:pointer;
}
.studio-main .score-heading #songSelect:focus-visible { outline:2px solid #f1c875; outline-offset:2px; }
.studio-main .score-viewport {
  /* Keep intrinsic SVG dimensions; spacious viewports may use layout-aware canvas zoom below. */
  flex:1 0 auto; height:auto; min-height:220px;
  padding:8px 0 6px; border:1px solid #eadfce;
  border-radius:15px; background:#fcf9f2; color:#292729;
  overflow-x:auto; overflow-y:auto;
}
.studio-main .score-canvas { min-width:100%; min-height:0; }
.studio-main .score-placeholder { min-height:200px; }
.playback-panel {
  display:flex; flex-direction:column; gap:4px; padding:7px 12px 8px;
  border-radius:17px; min-height:0; container:playback-controls / inline-size;
  position:relative; z-index:2; overflow:visible;
}
.playback-header { display:flex; align-items:center; justify-content:flex-end; gap:8px; min-height:16px; }
.playback-panel .screen-status {
  display:inline-flex; gap:6px; align-items:center;
  color:#edf1f8; font-size:.72rem; letter-spacing:0; font-weight:600;
  text-transform:none; white-space:normal; overflow-wrap:anywhere; text-align:right;
}
.playback-panel .screen-status::before { background:#f1c875; box-shadow:0 0 0 3px #f1c87520; }
.playback-content { flex:1; display:grid; grid-template-columns:minmax(0,1.8fr) minmax(0,1.25fr) minmax(0,.8fr); align-items:start; align-content:center; gap:12px; min-height:0; }
.playback-panel .screen-transport {
  display:grid; grid-column:auto; grid-template-columns:minmax(0,1fr) minmax(0,1.25fr) minmax(0,.85fr);
  align-items:stretch; column-gap:11px; row-gap:4px; min-width:0;
}
.playback-panel .screen-transport button {
  width:100%; min-width:0; min-height:var(--studio-control-height);
  border-radius:11px; font-size:.95rem; font-weight:850;
  box-shadow:0 5px 14px #0000003b;
}
.playback-panel #playSong {
  border:1px solid #ffd987; color:#20190e;
  background:linear-gradient(#ffe09a,#efb84a); box-shadow:0 3px 15px #edbd5340;
}
.playback-panel #playSong:hover:not(:disabled) { background:linear-gradient(#ffebae,#f5c96f); }
.playback-panel #playSong[data-playing="true"]::before { content:"Ⅱ"; }
.playback-panel #stopSong {
  border:1px solid #596579; color:#e7edf7;
  background:linear-gradient(#303b4f,#222b3b);
}
.playback-panel #stopSong::before { content:"■"; }
.playback-panel #setLoop {
  display:flex; align-items:center; justify-content:center; gap:6px;
  min-width:0; width:100%; padding:0 8px;
  border:1px solid #e8c471; border-radius:12px;
  color:#f6e7bf; background:linear-gradient(#1d2a3b,#141d2b);
  font-size:.84rem; font-weight:850; white-space:normal;
}
.playback-panel #setLoop > span { min-width:0; overflow-wrap:anywhere; }
.playback-panel #setLoop .section-loop-icon { flex:0 0 auto; width:27px; height:20px; color:#f1c875; }
.playback-panel #setLoop:hover:not(.active):not(:disabled) { border-color:#ffe2a2; background:linear-gradient(#29384a,#1d2a3b); }
.playback-panel #setLoop.active { border-color:#e8c471; color:#162032; background:linear-gradient(#ffe2a2,#ecc16d); }
.playback-panel #setLoop.active .section-loop-icon { color:inherit; }
.playback-panel #setLoop.active:hover:not(:disabled) { background:linear-gradient(#ffe8b5,#f1cb80); }
.playback-panel #setLoop:focus-visible { outline:2px solid #f6d58e; outline-offset:3px; }
.playback-panel .loop-status { grid-column:1 / -1; display:block; min-height:0; min-width:0; font-size:.68rem; line-height:1.2; color:var(--studio-gold); text-align:center; white-space:normal; overflow-wrap:anywhere; }
.playback-panel .loop-status:empty { display:none; }
.playback-panel .playback-metronome-controls {
  display:flex; align-items:center; gap:8px; min-width:0;
  padding-left:12px; border-left:1px solid #3b475a;
}
.playback-panel #metronomePlay {
  display:flex; align-items:center; justify-content:center; gap:6px; flex:1 1 auto;
  min-width:0; min-height:var(--studio-control-height); padding:0 6px; border:1px solid #e8c471;
  border-radius:12px; color:#f6e7bf; background:linear-gradient(#1d2a3b,#141d2b);
  font-size:.84rem; font-weight:850; white-space:normal;
}
.playback-panel #metronomePlay::before { content:none; }
.playback-panel #metronomePlay > span { min-width:0; overflow-wrap:anywhere; }
.playback-panel #metronomePlay .playback-metronome-icon { flex:0 0 auto; width:23px; height:23px; color:#f1c875; }
.playback-panel #metronomePlay:hover:not(:disabled) { border-color:#ffe2a2; background:linear-gradient(#29384a,#1d2a3b); }
.playback-panel #metronomePlay[aria-pressed="true"] { border-color:#e8c471; color:#162032; background:linear-gradient(#ffe2a2,#ecc16d); }
.playback-panel #metronomePlay[aria-pressed="true"] .playback-metronome-icon { color:inherit; }
.playback-panel #metronomePlay[aria-pressed="true"]:hover:not(:disabled) { background:linear-gradient(#ffe8b5,#f1cb80); }
.playback-panel .tutor-actions {
  display:flex; flex-direction:column; justify-content:center; gap:4px;
  padding-left:12px; border-left:1px solid #3b475a; min-width:0;
}
.playback-panel #tutorMode {
  width:100%; min-height:var(--studio-control-height); border:1px solid #e8c471;
  border-radius:12px; color:#f6e7bf; background:linear-gradient(#1d2a3b,#141d2b);
  font-size:.84rem; font-weight:850; padding-inline:6px; white-space:normal;
}
.playback-panel #tutorMode::before { content:"♜"; color:#f1c875; font-size:1rem; margin-right:9px; }
.playback-panel #tutorMode.active { color:#162032; background:linear-gradient(#ffe2a2,#ecc16d); }
.playback-panel #tutorMode.active::before { color:#162032; }
.playback-panel .tutor-status {
  min-width:0; max-width:100%; white-space:normal;
  font-size:.61rem; line-height:1.25; text-align:center; color:#b7c4d4;
}
.studio-main .metronome-beats {
  flex:none; display:flex; justify-content:center; align-items:center;
  gap:7px; width:100%; min-height:36px; padding:2px 5px;
}
.studio-main .metronome-beat {
  display:grid; place-items:center; flex:1 1 0; width:36px;
  height:auto; max-width:36px; min-width:0; aspect-ratio:1;
  border:1px solid #3f4a5d; border-radius:50%;
  color:#aeb9cf; background:linear-gradient(#263247,#172134);
  font-size:clamp(.72rem,1.7vw,1.15rem); font-weight:800;
  box-shadow:0 3px 10px #0005;
  transition:transform .12s,box-shadow .12s,background .12s,border-color .12s;
}
.studio-main .metronome-beat.accent { color:#f1d79d; border-color:#9c8145; background:linear-gradient(#483c2d,#2b2a27); }
.studio-main .metronome-beat.active {
  border-color:#ffd981; color:#171c26;
  background:linear-gradient(#ffe3a2,#e9af43);
  box-shadow:0 0 20px #ffd0699c,inset 0 1px #fff7cf;
  transform:scale(1.07);
}
.studio-main .metronome-beat.accent.active { border-color:#fff3d7; background:linear-gradient(#fff2cb,#efc16a); }
.studio .keyboard-frame {
  flex:none; margin:0; padding:0; width:100%;
  border-top:6px solid #080e18; overflow:hidden;
}
.studio .keyboard {
  height:clamp(170px,calc(25dvh / var(--studio-fit)),285px); margin:0; border-top:0;
  border-radius:0 0 6px 6px;
}
.studio .lower-bar {
  flex:none; min-height:29px; margin:0; padding:4px 18px;
  background:#0d1522; border-top:1px solid #253147;
  font-size:.71rem; color:#b5c2d5;
}
.studio .lower-bar #soundHint { color:#a5b0c3; font-size:.64rem; line-height:1.25; }
.studio .lower-bar .legend { display:flex; gap:6px; margin-left:auto; flex-wrap:wrap; justify-content:flex-end; }
.studio .lower-bar kbd { font-size:.67rem; }
@media (max-width:1180px) and (min-width:921px) {
  .studio-workspace { gap:8px; padding-inline:10px; }
  .playback-panel { padding-inline:10px; }
  .playback-content { gap:8px; }
  .playback-panel .screen-transport { column-gap:6px; }
  .playback-panel .screen-transport button { font-size:.78rem; padding-inline:5px; }
  .playback-panel #setLoop { font-size:.75rem; gap:4px; padding-inline:4px; }
  .playback-panel #setLoop .section-loop-icon { width:21px; height:16px; }
  .playback-panel .playback-metronome-controls, .playback-panel .tutor-actions { padding-left:9px; }
  .playback-panel #metronomePlay { font-size:.75rem; gap:4px; padding-inline:4px; }
  .playback-panel #metronomePlay .playback-metronome-icon { width:20px; height:20px; }
  .playback-panel #tutorMode { font-size:.75rem; padding-inline:4px; }
  .playback-panel #tutorMode::before { margin-right:4px; }
}
@media (max-width:920px) {
  .studio-workspace { gap:8px; padding:10px; }
  .studio .keyboard { height:clamp(150px,calc(23vw / var(--studio-fit)),215px); }
}
@media (max-width:760px) {
  .shell > header { flex-wrap:wrap; min-height:56px; gap:6px; padding:6px 12px; }
  .header-instrument-controls { flex-wrap:wrap; max-width:100%; min-width:0; justify-content:flex-end; }
}
@media (max-width:600px) {
  .shell > header { min-height:56px; margin:0; padding:6px 13px; }
  .brand { font-size:.88rem; gap:7px; }
  .brand-mark { width:33px; height:33px; font-size:1.1rem; }
  .key-range-toggle { min-height:34px; padding:0 8px; font-size:.73rem; }
  .studio-workspace {
    grid-template-columns:minmax(0,1fr);
    padding:8px; gap:9px;
  }
  .studio-main .score-heading { font-size:.7rem; letter-spacing:.11em; margin-inline:5px; }
  .playback-panel { padding:9px; }
  .playback-content { grid-template-columns:minmax(0,1fr); gap:7px; }
  .playback-panel .screen-transport { column-gap:6px; }
  .playback-panel .screen-transport button { min-height:44px; font-size:.75rem; padding:0 6px; }
  .playback-panel #setLoop { font-size:.75rem; gap:4px; padding-inline:4px; }
  .playback-panel #setLoop .section-loop-icon { width:21px; height:16px; }
  .playback-panel .playback-metronome-controls, .playback-panel .tutor-actions { padding-left:0; border-left:0; }
  .playback-panel #metronomePlay { min-height:44px; font-size:.75rem; }
  .playback-panel #tutorMode { min-height:44px; font-size:.71rem; padding:0 4px; }
  .playback-panel #tutorMode::before { font-size:.8rem; margin-right:2px; }
  .studio-main .metronome-beat { max-width:38px; font-size:1rem; }
  .studio .keyboard { height:clamp(130px,calc(29vw / var(--studio-fit)),180px); }
  .studio .lower-bar { padding:6px 8px; font-size:.61rem; }
  .studio .lower-bar .legend { gap:3px; }
  .studio .lower-bar kbd { font-size:.6rem; padding:1px 4px; }
}
@media (max-height:850px) and (min-width:921px) {
  :root { --studio-control-height:40px; }
  .shell > header { min-height:52px; padding-block:4px; }
  .studio-workspace { padding-block:6px; }
  .studio-main { gap:6px; }
  .studio-main .metronome-beats { min-height:30px; }
  .studio-main .metronome-beat { max-width:28px; font-size:.85rem; }
  .playback-panel { padding:5px 10px 6px; }
  .studio .keyboard { height:clamp(170px,calc(25dvh / var(--studio-fit)),215px); }
}
@media (pointer:coarse) {
  :root { --studio-control-height:44px; }
  .shell > header .key-range-toggle { min-height:44px; }
}
@container playback-controls (max-width:720px) {
  .playback-content { grid-template-columns:minmax(0,1.6fr) minmax(0,1fr); gap:8px; }
  .playback-panel .screen-transport { grid-column:1 / -1; }
  .playback-panel .playback-metronome-controls { padding-left:0; border-left:0; }
}
@container playback-controls (max-width:380px) {
  .playback-content { grid-template-columns:minmax(0,1fr); }
  .playback-panel .tutor-actions { padding-left:0; border-left:0; }
}
@media (prefers-reduced-motion:reduce) {
  .studio-main .metronome-beat, .playback-panel #metronomePlay { transition:none; }
}

/* Local score/beat space budget. The compact baseline above is untouched.
   The metronome view measures actual rendered score content before activating this layout. */
.score-resize-handle { display:none; }
@media (min-width:1200px) and (min-height:851px) {
  .studio-main[data-score-layout="active"] {
    grid-template-rows:var(--score-layout-panel) var(--score-layout-beat-area) auto;
  }
  .studio-main[data-score-layout="active"] .score-panel { height:100%; min-height:0; }
  .studio-main[data-score-layout="active"] .score-viewport { flex:1 1 0; min-height:0; }
  .studio-main[data-score-layout="active"] .score-canvas {
    zoom:var(--score-layout-zoom); min-width:0; min-height:0; width:max-content;
  }
  .studio-main[data-score-layout="active"] .score-resize-handle:not([hidden]) {
    flex:none; height:14px; display:grid; place-items:center;
    cursor:ns-resize; touch-action:none; user-select:none; outline-offset:0;
    border-radius:5px; margin:0; padding:0;
  }
  .score-resize-handle span {
    width:52px; height:3px; border-radius:999px; background:#8594ab;
  }
  .score-resize-handle:hover span,.score-resize-handle[data-dragging="true"] span,
  .score-resize-handle:focus-visible span { background:#f1c875; }
  .score-resize-handle:focus-visible { outline:2px solid #f1c875; }
  .studio-main[data-score-layout="active"] .metronome-beats {
    height:var(--score-layout-beat-area); min-height:0;
    gap:var(--score-layout-gap); padding:2px 8px;
  }
  .studio-main[data-score-layout="active"] .metronome-beat {
    flex:0 0 var(--score-layout-beat); width:var(--score-layout-beat);
    max-width:var(--score-layout-beat); height:var(--score-layout-beat);
    font-size:calc(var(--score-layout-beat) * .46);
    border-radius:50%;
  }
  .studio-main[data-score-layout="active"] .metronome-beat.active {
    transform:scale(1.045);
    box-shadow:0 0 calc(var(--score-layout-beat) * .14) #ffd06980,inset 0 1px #fff7cf;
  }
}
