/* Five meaningful destinations share one persistent panel, board and game. */
html:has(body.studio){scrollbar-gutter:stable}
/* Continuous tab strip: the active tab joins its content boundary. */
.studio .panel-tabs{display:flex;align-items:stretch;gap:4px;flex:none;min-width:0;padding:0;border:0;border-radius:10px 10px 0 0;background:transparent;position:relative;z-index:1;container-type:inline-size}
.studio .panel-tabs[hidden]{display:none}
.studio .panel-tab{position:relative;flex:1 1 0;min-width:0;min-height:44px;padding:5px 5px;border:1px solid var(--warm-border);border-radius:9px 9px 0 0;background:linear-gradient(var(--warm-button-top),var(--warm-button-bottom));color:var(--warm-button-text);box-shadow:inset 0 1px var(--warm-button-bevel),inset 0 -2px var(--warm-button-shadow);font:700 .75rem/1.25 var(--font-sans);touch-action:manipulation;cursor:pointer;transition:background-color 180ms,color 180ms,box-shadow 180ms}
.studio #tab-appearance{flex-grow:1.3}
.studio .panel-tab[aria-selected=true]{background:var(--warm-surface);color:var(--warm-text);border-bottom-color:var(--warm-surface);box-shadow:inset 0 3px var(--warm-choice-outline),inset 0 1px var(--warm-choice-bevel);font-weight:800;z-index:2}
.studio .panel-tab:hover:not(:disabled):not([aria-selected=true]){filter:brightness(1.08)}
.studio .panel-tab:disabled{background:var(--warm-disabled);color:var(--warm-disabled-text);box-shadow:inset 0 1px var(--warm-choice-bevel);cursor:default}
.studio .panel-tab:focus-visible{outline:2px solid var(--warm-focus);outline-offset:-5px}
.studio .panel-tab:active{box-shadow:inset 0 2px var(--warm-button-shadow)}
.studio .panel-tab-stage{display:flex;flex:1 1 0;flex-direction:column;min-height:0;min-width:0;margin-top:-11px;padding:10px;border:1px solid var(--warm-border);border-radius:0 0 10px 10px;background:var(--warm-surface);box-shadow:inset 0 1px var(--warm-choice-bevel)}
.studio .panel-tab-content{display:flex;flex-direction:column;flex:1 1 0;min-height:0;min-width:0;gap:10px}
.studio .panel-tab-content[hidden]{display:none}
.studio .panel-tab-content{overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
.studio .panel-more{flex:none;margin:0;padding-top:4px;border-top:1px solid var(--warm-border);text-align:center;font:700 .75rem/1.3 var(--font-sans);color:var(--warm-secondary)}
.studio .panel-more[hidden]{display:none}
.studio #panel-new-game,.studio #panel-appearance{overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding:1px 3px 4px 0}
.studio #panel-new-game #setup{margin:0}
.studio #panel-io .record-export{flex:1 1 auto;min-width:0;border:0;background:transparent}
.studio #panel-io .record-export[hidden]{display:none}
.studio #panel-io .lab-analysis-io{padding:0;gap:16px}
.studio #panel-io #analysis-pgn{height:clamp(132px,calc(var(--panel-height,660px) - 430px),300px);min-height:132px}
.studio #panel-main #game-panel{min-height:min-content;flex:1 0 auto}
.studio #analysis-panel .lab-analysis-workspace{min-height:122px}
.studio #panel-main #game-panel .play-score:has(.game-result:not([hidden])){min-height:164px}
.studio #panel-main .game-actions{grid-template-columns:1fr}
.studio #panel-main .training-card.is-off .training-lines{height:0;min-height:0;margin-top:0}
@media(max-width:900px){
 .studio:is([data-page=game],[data-page=analysis]) .play-panel:has(.panel-tabs:not([hidden])){height:auto;min-height:0}
 .studio .panel-tab-stage{min-height:440px;flex:none}
 .studio #panel-main #game-panel,.studio #panel-main #analysis-panel{min-height:440px!important}
 .studio #panel-io #analysis-pgn{height:200px;min-height:150px}
 /* In page flow the visible tab contributes its full intrinsic height.
    A zero flex basis otherwise lets its game/actions escape the stage. */
 .studio .panel-tab-content{overflow:visible;flex:0 0 auto}
 .studio .panel-more{display:none}
}
@media(max-width:600px){.studio .panel-tabs{gap:3px}.studio .panel-tab{font-size:.7rem;padding:5px 3px;min-height:44px}}
@media(prefers-reduced-motion:reduce){.studio .panel-tab{transition:none}}

.studio .mode-navigation-tools{flex:none;margin:0;min-width:0}
.studio .lab-analysis-record > .mode-navigation-tools{margin-top:9px}


/* Compact shared new-game form; mobile/short windows continue in page flow. */
.studio #panel-new-game{overflow:visible;scrollbar-gutter:auto;padding:0}
.studio #setup{gap:9px}
.studio #setup .form-field{margin:0}
.studio #setup .form-row{gap:9px}
.studio #setup .play-choice{margin-top:5px}
.studio #setup .play-choice button{min-height:44px}
.studio #setup .play-setup-actions{margin-top:4px;gap:8px}
.studio #setup .setup-editor-action{min-height:44px;padding:8px}
.studio #clock-presets{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:5px;margin:9px 0}
.studio #clock-presets button{min-height:44px;padding:5px 2px;font-size:.75rem}
.studio #clock-presets button::before{width:8px;height:8px}
.studio .clock-custom{border:1px solid var(--warm-border);border-radius:8px;padding:7px;background:var(--warm-field)}
.studio .clock-custom summary{cursor:pointer;font:700 .8rem/1.3 var(--font-sans);color:var(--warm-text);min-height:24px}
.studio #custom-control-label{float:right;font-variant-numeric:tabular-nums;color:var(--warm-secondary)}
.studio .clock-custom-fields{display:grid;grid-template-columns:repeat(3,minmax(0,1fr)) 44px;gap:7px;align-items:end;margin-top:7px}
.studio .clock-custom-fields label{display:flex;flex-direction:column;gap:4px;color:var(--warm-secondary);font-size:.76rem;min-width:0}
.studio .clock-custom-fields input{box-sizing:border-box;width:100%;height:44px;min-width:0;padding:6px;background:var(--warm-field);color:var(--warm-text);border:1px solid var(--warm-border);border-radius:6px}
.studio #custom-apply{width:44px;height:44px;min-height:44px;font-size:1.5rem;padding:3px}
.studio .custom-error{font-size:.75rem;color:var(--warm-text);margin:8px 0 0}
.studio #panel-editor{overflow:auto}
.studio #editor-analyse[hidden]{display:none}
@media(max-width:900px){.studio .play-panel:has(#panel-new-game:not([hidden])){min-height:0}.studio #panel-editor{overflow:visible}.studio[data-page=editor] .play-panel:has(.panel-tabs){min-height:0}}

@media(max-width:600px){.studio #tab-appearance{flex-grow:1.3}}

.studio #panel-new-game #setup{flex:0 0 auto}

.studio #setup .form-field > label{margin-bottom:0;font-size:.82rem;line-height:1.3}
.studio #setup .play-choice{padding:4px;gap:5px}
.studio #editor-game{grid-column:1/-1}

/* Narrow panels budget the space around six equal touch targets before
   reducing a target. The two tab rows retain full words and a shared edge. */
@media(max-width:420px){
 .studio .panel-tabs{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));grid-auto-rows:44px;gap:0;border:1px solid var(--warm-border);border-radius:9px 9px 0 0;overflow:hidden;background:var(--warm-field)}
 .studio .panel-tab{grid-column:span 2;min-height:44px;padding:5px 6px;font-size:.78rem;line-height:1.25;border-radius:0;border-top:0;overflow-wrap:normal;word-break:normal;hyphens:none;white-space:normal}
 .studio #tab-io,.studio #tab-appearance{grid-column:span 3}
 .studio #tab-appearance{flex-grow:1}
 .studio .panel-tab[aria-selected=true]{border-bottom-color:var(--warm-border)}
}
@media(max-width:360px){
 .studio .play-panel{padding:6px 3px}
 .studio .panel-tab-stage{padding:7px 1px}
 .studio .mode-navigation-tools{gap:1px}
}
@media(max-width:315px){
 .studio .mode-navigation-tools{grid-template-columns:repeat(4,minmax(44px,1fr));gap:4px}
 .studio .mode-navigation-tools #flip-board{grid-column:1;grid-row:2}
 .studio .mode-navigation-tools .navigation [data-step]{grid-row:1}
 .studio .mode-navigation-tools .navigation-menu{grid-column:4;grid-row:2}
}

/* A continuation cue belongs to the menu flow on mobile, never above a link
   or a board square. Desktop keeps its existing non-overlapping reserved top. */
@media(max-width:900px){
 .studio .site-menu .panel-continuation{position:static;align-self:flex-start;max-width:100%;min-height:44px;margin:8px 0 0;padding:10px 12px;right:auto;top:auto;z-index:auto;color:var(--warm-button-text);text-align:center;white-space:normal;overflow-wrap:normal}
}

/* Menu-label selectors must not recolor the volumetric action as plain text. */
html[data-theme] body.studio .site-menu a.panel-continuation{color:var(--warm-button-text);background:linear-gradient(var(--warm-button-top),var(--warm-button-bottom));box-shadow:inset 0 1px var(--warm-button-bevel),0 3px 0 var(--warm-button-shadow)}

/* In a short landscape sidebar, expose the cue before the menu rather than
   letting its own lower lines fall beyond the first viewport. */
@media(min-width:601px) and (max-width:900px) and (max-height:500px){
 html[data-theme] body.studio .site-menu a.panel-continuation{order:-1;margin:0 0 6px;padding:6px;font-size:.75rem;line-height:1.25}
}

/* Moving the mobile cue under the menu must not inherit its relative desktop
   positioning. The reserved top band has space for the existing action. */
@media(min-width:901px){
 html[data-theme] body.studio .site-menu a.panel-continuation{position:fixed;right:24px;top:12px;z-index:55;width:max-content;max-width:calc(100vw - 28px);min-height:44px;margin:0;padding:10px 15px}
}

/* Finished record reuses the approved result and Undo. Fixed controls must not
   shrink when the analysis notation borrows the remaining space. */
.studio #analysis-panel.is-finished-record :is(.game-result,.game-undo){flex:none}
.studio #analysis-panel.is-finished-record .lab-analysis-score{min-height:164px}
@media(max-width:900px){
 .studio #panel-main:has(>#analysis-panel.is-finished-record),.studio #analysis-panel.is-finished-record{flex:none}
 .studio #analysis-panel.is-finished-record :is(.lab-analysis-workspace,.lab-analysis-score){flex:1 0 auto}
 .studio #analysis-panel.is-finished-record .lab-analysis-record{flex:1 1 auto}
}

/* New game retains one model position; the editor owns all FEN entry. */
.studio #setup .setup-position{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-items:center;gap:8px;margin:0}
.studio #setup .setup-position>strong{grid-column:1/-1;font:700 .85rem/1.3 var(--font-sans);color:var(--warm-text)}
.studio #setup .setup-editor-action{margin:0;width:100%}
.studio #setup :is(.setup-editor-action,.play-setup-actions>.button){height:44px;min-height:44px;padding:6px 8px;line-height:1.2}
.studio #setup-position-status{grid-column:1/-1;margin:0;font-size:.8rem;line-height:1.4;color:var(--warm-bad)}
.studio #editor-panel .editor-fen-status{margin:0;font-size:.8rem;line-height:1.4;overflow-wrap:anywhere}
.studio #editor-panel .editor-fen-status:empty{display:none}
.studio #editor-panel .editor-fen-status:not(.is-error){color:var(--warm-secondary)}
.studio #editor-panel .lab-editor-commands{display:flex;flex-direction:column;gap:9px;margin-top:8px}
.studio #editor-panel .editor-primary-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.studio #editor-panel .editor-board-actions{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
.studio #editor-panel .editor-board-actions #flip-board{grid-column:auto;width:100%;min-width:0}
.studio #editor-panel :is(.editor-primary-actions,.editor-board-actions)>button{height:44px;min-height:44px;min-width:0;margin:0;padding:6px 7px;font:650 .82rem/1.2 var(--font-sans);display:inline-flex;align-items:center;justify-content:center;gap:5px;white-space:normal}
.studio #editor-panel .editor-action-note{margin:0;font-size:.8rem;line-height:1.35;color:var(--warm-secondary)}
.studio #editor-panel .editor-position-details{margin:0;border:1px solid var(--warm-border);border-radius:8px;background:var(--warm-field);padding:0 10px;color:var(--warm-text)}
.studio #editor-panel .editor-position-details>summary{min-height:44px;display:list-item;align-content:center;cursor:pointer;font:700 .85rem/1.3 var(--font-sans)}
.studio #editor-panel .editor-position-details[open]{padding-bottom:10px}
.studio #editor-panel .editor-position-details .form-field{margin:0}
.studio #editor-panel .editor-position-details .castling{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;margin:6px 0 10px}
.studio #editor-panel .editor-position-details .castling label{min-height:36px;display:flex;align-items:center;gap:5px;font-size:.8rem}
.studio #editor-panel .editor-position-details .editor-counters{display:grid;gap:9px}
.studio #editor-panel .editor-position-details summary:focus-visible{outline:2px solid var(--warm-focus);outline-offset:2px;border-radius:4px}

.studio #editor-panel .editor-primary-actions>button{grid-column:auto}

/* Intrinsic panel width, rather than viewport width, decides when five labels
   need two rows. Native whole words and full targets remain in the tab strip. */
@container (max-width:380px){
 .studio .panel-tab{flex:1 0 calc((100% - 8px) / 3);min-height:44px;padding:5px 6px;font-size:.78rem;line-height:1.25;white-space:normal;overflow-wrap:normal;word-break:normal}
 .studio #tab-io,.studio #tab-appearance{flex:1 0 calc((100% - 4px) / 2)}
}
.studio .panel-tabs{flex-wrap:wrap}

/* Mobile Appearance continues in page flow; every choice remains visible
   instead of borrowing a fixed panel height with a hidden continuation cue. */
@media(max-width:900px){
 .studio #panel-appearance{overflow:visible;scrollbar-gutter:auto;flex:none}
 .studio .panel-tab-stage:has(#panel-appearance:not([hidden])){flex:none;height:auto;min-height:0}
 .studio .play-panel:has(#panel-appearance:not([hidden])){height:auto!important;min-height:0}
}

/* The measured text-action families share one target. Two-line labels use
   four vertical pixels of padding, keeping their full line box at 44 on touch. */
.studio .play-panel{--panel-action-height:40px}
.studio .play-panel :is(#setup .play-choice button,#clock-presets button,#setup-starting,#setup-editor,#start-game,#editor-copy,#editor-paste,#editor-use-analysis,#editor-turn-choices button,.editor-primary-actions button,.editor-board-actions button,#panel-io [data-copy],#panel-io [data-paste],#panel-appearance .arrow-color-choices button){height:var(--panel-action-height);min-height:var(--panel-action-height);padding-top:4px;padding-bottom:4px}
.studio #setup :is(#setup-starting,#setup-editor){display:inline-flex;align-items:center;justify-content:center;gap:5px;min-width:0;padding-inline:7px;font-size:.83rem;line-height:1.2;white-space:normal}
.studio #setup-starting::before{content:'';box-sizing:border-box;flex:none;width:11px;height:11px;border:1.5px solid currentColor;border-radius:50%}
.studio #setup-starting[aria-pressed=true]::before{background:currentColor;box-shadow:inset 0 0 0 2px var(--warm-choice-selected)}
.studio .play-panel #setup-starting[aria-pressed=true]{background:var(--warm-choice-selected);color:var(--warm-text);box-shadow:inset 0 0 0 1px var(--warm-choice-outline),inset 0 1px var(--warm-choice-bevel),0 3px 0 var(--warm-border)}
.studio #setup-position-status:not(.is-error){color:var(--warm-secondary)}
.studio #setup .play-setup-actions{grid-template-columns:1fr}
.studio #editor-panel .editor-source-actions{display:flex;flex-direction:column;gap:6px;min-width:0}
.studio #editor-use-analysis{width:100%;font-size:.83rem;line-height:1.2}
.studio #editor-panel .editor-board-actions>button{padding-top:4px;padding-bottom:4px}
.studio #editor-panel :is(#editor-copy,#editor-paste,#editor-use-analysis,#editor-turn-choices button,.editor-primary-actions button,.editor-board-actions button){height:var(--panel-action-height);min-height:var(--panel-action-height);padding-top:4px;padding-bottom:4px}
@media(max-width:900px){.studio .play-panel{--panel-action-height:44px}}

/* One external size owner: beside the board, only the board column determines
   the grid row. Tab content cannot enlarge it or lag a participant/resize frame. */
@media(min-width:901px){
 .studio .play-shell{align-items:stretch}
 .studio:is([data-page=game],[data-page=analysis],[data-page=editor]) .play-panel:has(.panel-tabs){height:auto;min-height:0;align-self:stretch;contain:size layout style}
 .studio .panel-tab-stage{flex:1 1 0;min-height:0}
 /* Outward focus rings (2px + 3px offset) and button bevels need paint room
    inside every scrolling destination, including when focus scrolls an edge. */
 .studio :is(#panel-main,#panel-new-game,#panel-editor,#panel-io,#panel-appearance){flex:1 1 0;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;scrollbar-color:var(--warm-border) var(--warm-field);padding:6px;scroll-padding:6px}
 /* The scrolling region owns clipping. Its mode child keeps intrinsic height
    so overflowed descendants cannot swallow the final focus/paint allowance. */
 .studio #panel-main :is(#game-panel,#analysis-panel){min-height:min-content;flex:1 0 auto}
 .studio #panel-main #analysis-panel :is(.lab-analysis-workspace,.lab-analysis-record){min-height:min-content;flex:1 0 auto}
 .studio #panel-main :is(.play-score,.lab-analysis-score){min-height:min-content;flex:1 0 auto}
 /* Existing rows use 1.35em line boxes, 2px button padding and 10px cell
    padding. Two rows plus 6px paint room at each edge keep a whole row visible
    even between scroll stops; the board still owns the outer panel height. */
 .studio #panel-main :is(#play-notation,#analysis-panel .lab-score-body){min-height:calc(2.7em + 36px);padding-block:6px;scroll-padding:6px;overflow:auto;contain:size}
 /* At a deliberately small board, the existing primary action stays visible
    while the full-size controls remain available in the marked scroll region. */
 .studio #panel-new-game{scroll-padding-bottom:58px}
 .studio #setup .play-setup-actions{position:sticky;bottom:6px;z-index:1;padding-top:8px;background:var(--warm-surface);box-shadow:0 -5px 8px var(--warm-surface)}
}
