/* Shell layout / geometry / responsive overrides.
   Linked after editor.css. Theme colors live in editor.css — keep this file geometry-first.
   Use !important only when a fixed size must beat a broader control rule. */

/* Compact control sizing (desktop chrome packing). */
button,select,.field input[type=number]{min-height:38px;font-size:.875rem;padding:6px 9px}
.color-grid button{min-height:0;padding:0;border:0;border-radius:0;box-shadow:none;transform:none}
.drawing-strip{justify-content:flex-start;gap:8px;padding:6px 10px;flex-wrap:wrap;align-items:center;column-gap:6px}
header{height:auto;min-height:61px;flex-wrap:wrap;align-items:center;column-gap:8px;row-gap:6px}
header .app-title{flex-basis:0}
header .header-brand,
header .header-system,
header .header-project,
header .header-actions{
 display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-width:0;
}
header .header-system{
 margin-inline-start:4px;
 padding-inline-start:10px;
 border-inline-start:1px solid color-mix(in srgb,var(--case-seam) 70%,transparent);
}
header .header-project{
 margin-inline-start:4px;
 padding-inline-start:10px;
 border-inline-start:1px solid color-mix(in srgb,var(--case-seam) 70%,transparent);
}
header .header-actions{
 margin-inline-start:auto;
 padding-inline-start:10px;
 border-inline-start:1px solid color-mix(in srgb,var(--case-seam) 70%,transparent);
}
.header-save-wrap{display:inline-flex;align-items:center;gap:4px}
header #saveStatus{
 display:inline-flex;align-items:center;justify-content:center;gap:0;min-width:36px;min-height:36px;padding:0;
 border-radius:999px;border:1px solid var(--header-control-border,var(--case-seam));
 background:var(--header-control-bg,transparent);
}
header #saveStatus .save-status-icon{
 display:inline-flex;align-items:center;justify-content:center;width:36px;height:36px;font-size:1rem;font-weight:700;line-height:1;
}
header #saveStatus[data-state=saved] .save-status-icon{color:var(--header-control-fg,var(--case-text))}
header #saveStatus[data-state=failed]{border-color:#b44;background:#4a1e1e}
header #saveStatus[data-state=failed] .save-status-icon{color:#ffe8e8}
header #saveStatus .save-status-full,header #saveStatus .save-status-compact{
 position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0;
}
header .header-save-wrap .help-trigger{width:28px;height:28px;min-width:28px;min-height:28px;padding:0}
.text-entry{flex:none;max-height:35%;overflow:auto;border:1px solid var(--panel-well-border);border-radius:9px;padding:8px}
.text-entry textarea{min-height:48px;max-height:90px;font:1rem/1.3 ui-monospace,monospace;resize:vertical}
.text-entry .row{align-items:center;margin:4px 0 0}
.text-entry .note{flex:1;min-width:140px}
.text-entry button{flex:none}
.recovery-group{display:flex;gap:4px;margin-left:auto;flex-shrink:0}
/* Fixed tool-icon box must beat generic button padding (drawing strip uses 44px). */
.tool-icon{width:38px;height:38px;padding:8px!important;display:inline-grid;place-items:center;box-sizing:border-box}
.drawing-strip .tool-icon,.drawing-strip .tool-mode-trigger,.drawing-strip .tool-mode-option{width:44px;height:44px;min-width:44px;min-height:44px;padding:10px!important}
.drawing-strip #canvasTool{display:inline-grid;place-items:center;width:44px;min-width:44px;max-width:44px}
.tool-icon svg,.tool-mode-trigger svg,.tool-mode-option svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round}
#quickglyph{display:none}
.stagefoot{font-size:.8rem;min-height:1.6em}
.note{font-size:.8rem}
.selection-dock{height:46px;flex:none;overflow-x:auto;overflow-y:hidden}
.selection-actions{width:max-content;min-width:100%;height:44px;flex-wrap:nowrap;padding:3px 0;background:transparent}
.selection-actions button,.selection-actions span{flex-shrink:0}
.stage{position:relative}
.sidebar{transition:none}
/* Compact help affordance geometry (colors in editor.css). */
.help-trigger{width:28px;min-width:28px;min-height:28px;height:28px;padding:2px!important;border-radius:50%;font-size:.75rem;font-weight:bold}
.menu-help-row{display:flex;justify-content:flex-end;margin:-2px 0 6px}
/* Must stay positioned: the enlarged ::after hit area (inset:-6px) would otherwise cover the whole menu. */
.machine-menu .menu-help-row .help-trigger{position:relative}
.field-help-anchor{display:flex;justify-content:flex-end;margin-top:6px}
.help-section{position:relative}
.help-section>details>summary,.help-section>#projectMenu>summary{padding-right:40px}
.help-section>.help-trigger{position:absolute;right:5px;top:7px}
.section-heading{display:flex;align-items:center;justify-content:space-between;gap:8px}
.section-heading h3{margin:0}
.context-help{position:fixed;inset:auto 12px 12px auto;margin:0;width:min(360px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;border-radius:12px;padding:16px;z-index:30;font-size:.9rem;line-height:1.5}
.context-help h3{margin:0}
.context-help button{float:right}
.context-help .help-intro{margin:12px 0;font-weight:600;line-height:1.45}
.context-help .help-points{margin:8px 0 2px;padding-left:1.25rem;display:grid;gap:10px}
.context-help .help-points li{padding-left:3px;line-height:1.5}
.context-help h4{margin:16px 0 6px;font-size:.86rem}
.context-help .help-control,.context-help .help-key{display:inline-block;vertical-align:baseline;padding:1px 6px;border-radius:5px;font-size:.86em;font-weight:650;line-height:1.55;white-space:nowrap}
.context-help .help-example{margin-top:16px;padding:12px;border-radius:8px}
.context-help .help-example p{margin:6px 0 0}
.context-help .help-points strong{font-weight:700}

.canvas-frame:has(canvas.preview-locked){
 border-color:var(--ui-bezel-highlight) #b9af9e #a69c8b var(--ui-bezel-highlight);
}

@media(prefers-reduced-motion:no-preference){
 header button,.drawing-strip button,.sidebar button,.glyph-picker button,
 .preview-banner button{transition:background-color .12s,border-color .12s,box-shadow .12s,transform .12s}
}

.glyph-picker .picker-heading{padding-inline:12px}

/* Symmetry disclosure geometry (colors in editor.css). */
#symmetryMenu{position:relative;display:flex;align-items:center;min-height:44px;margin-left:0;border:0!important;background:transparent!important}
#symmetryMenu.tool-slot-inactive{opacity:.42}
#symmetryMenu.tool-slot-inactive>summary{cursor:not-allowed}
#symmetryMenu>summary{
 display:inline-flex;align-items:center;justify-content:center;gap:6px;
 height:44px;min-height:44px;padding:0 10px!important;margin:0;cursor:pointer;border-radius:8px!important;
 list-style:none;font:inherit;line-height:normal;box-sizing:border-box;
 transform:none!important;box-shadow:none!important;
}
#symmetryMenu>summary::-webkit-details-marker{display:none}
#symmetryMenu>summary::marker{content:""}
#symmetryMenu>summary:after{content:"▾";font-size:.7em;opacity:.75;margin-left:3px}
#symmetryMenu[open]>summary:after{content:"▴"}
#symmetryMenu>summary:focus-visible{outline:3px solid var(--ui-focus-border);outline-offset:2px}
#symmetryMenu>summary:active,#symmetryMenu>summary.symmetry-on{transform:none!important}
.symmetry-chevron{font-size:1rem;line-height:1;opacity:.8;margin-left:2px}

.tool-mode-menu{position:relative;display:inline-flex;align-items:center;min-height:44px;border:0!important;background:transparent!important}
.tool-mode-menu>summary.tool-mode-trigger{
 display:inline-grid;place-items:center;position:relative;
 margin:0;cursor:pointer;border-radius:9px!important;border:1px solid var(--case-edge);
 list-style:none;font:inherit;line-height:normal;box-sizing:border-box;
 transform:none!important;box-shadow:none!important;background:var(--case-raised);
}
.tool-mode-menu>summary::-webkit-details-marker{display:none}
.tool-mode-menu>summary::marker{content:""}
.tool-mode-menu>summary .tool-mode-chevron{position:absolute;right:2px;bottom:1px;font-size:.55rem;line-height:1;opacity:.7;pointer-events:none}
.tool-mode-menu[open]>summary .tool-mode-chevron{transform:rotate(180deg)}
.tool-mode-menu>summary:focus-visible{outline:3px solid var(--ui-focus-border);outline-offset:2px}
.tool-mode-menu>summary.active{border-color:var(--ui-focus-border)}
.tool-mode-menu .tool-mode-popover{top:calc(100% + 4px);right:0;left:auto}

#inkPopover .dialog-heading,#canvasPopover .dialog-heading{align-items:center;gap:8px}
#inkPopover .dialog-heading>button,#canvasPopover .dialog-heading>button{width:42px;min-width:42px;height:42px;min-height:42px;padding:0;display:grid;place-items:center}
#canvasPopover .dialog-heading-lead{display:flex;align-items:center;gap:8px;min-width:0;flex:1 1 auto}
#canvasPopover .dialog-heading-lead h2{flex:0 1 auto}
#canvasPopover .dialog-heading-lead .help-trigger{flex:0 0 auto}
#canvasPopover .dialog-heading>#canvasClose{margin-left:auto;flex:0 0 auto}
.picker-title{justify-content:flex-start;gap:8px}
.picker-title #glyphPin,.picker-title #glyphClose{width:42px;min-width:42px;height:42px;min-height:42px;padding:0;display:inline-flex;align-items:center;justify-content:center;border-radius:8px}
.picker-title #glyphPin{margin-left:auto}
.drawing-strip>button{min-height:44px;box-sizing:border-box}
.stage-canvas-view #symmetryMenu>summary{min-height:44px;box-sizing:border-box}
@media(max-width:800px){.drawing-strip{gap:6px}}
@media(max-width:600px){.drawing-strip{gap:4px}}

/* Unified top-bar geometry: Project/Machine are details/summary, not buttons. */
header button,header select,header #projectMenu>summary,header #machineMenu>summary,header #downloadOpen{box-sizing:border-box;min-height:44px;height:44px;max-height:44px;display:inline-flex;align-items:center;justify-content:center;vertical-align:middle;line-height:1.2;padding-top:0;padding-bottom:0}
header #projectMenu>summary,header #machineMenu>summary{padding-top:0;padding-bottom:0}
header #projectMenu,header #machineMenu{align-self:center}
@media(max-width:600px){header{column-gap:6px}header #projectMenu>summary,header #machineMenu>summary{padding-top:0;padding-bottom:0}}

/* Glyph favorite is a compact utility action, not a full-width palette control. */
#favoriteGlyph{flex:0 0 42px!important;inline-size:42px;min-inline-size:42px;max-inline-size:42px;block-size:42px;min-block-size:42px;max-block-size:42px;box-sizing:border-box;padding:0;display:inline-flex;align-items:center;justify-content:center;align-self:center;font-size:1.2rem;line-height:1}
.picker-heading .glyph-filter{display:flex;align-items:center;min-height:42px;gap:6px}
.picker-heading #glyphFamily{box-sizing:border-box;height:42px;min-height:42px;max-height:42px;align-self:center;margin-block:0;padding-block:0;line-height:1.2}
.picker-heading #favoriteGlyph{align-self:center}
.glyph-filter-row{display:grid;grid-template-columns:minmax(0,1fr) 42px;column-gap:8px;align-items:end}
.glyph-filter-row>.field{min-width:0;display:flex;flex-direction:column;gap:5px}
.glyph-filter-row #glyphFamily{width:100%;min-width:0;height:42px;min-height:42px;max-height:42px;box-sizing:border-box;margin:0;padding-block:0}
.glyph-filter-row #favoriteGlyph{width:42px;min-width:42px;max-width:42px;height:42px;min-height:42px;max-height:42px;box-sizing:border-box;align-self:end;justify-self:end;margin:0;padding:0;flex:none}

.row:not(.glyph-filter-row),.picker-title,.dialog-heading,.section-heading{align-items:center;column-gap:8px}
.row:not(.glyph-filter-row)>button{align-self:center}
.row:not(.glyph-filter-row)>.field{align-self:stretch}
.picker-title>button,.section-heading>button,.dialog-heading>button{align-self:center;flex-shrink:0}

button{box-sizing:border-box;min-width:max(38px,1.9em)}
.dialog-heading>button[aria-label]{width:44px;min-width:44px;height:44px;min-height:44px;padding:0;flex:0 0 44px;display:inline-flex;align-items:center;justify-content:center}
dialog button{min-width:max(44px,2em);box-sizing:border-box}
dialog button[hidden]{display:none!important}
#cancelSheetDownload{min-height:44px;padding-inline:14px}
.project-menu .row{display:flex;flex-direction:column;align-items:stretch;width:100%;box-sizing:border-box}
.project-menu .row>button:not([hidden]){display:block;width:100%;min-width:0;box-sizing:border-box;flex:0 0 auto}
.project-menu .project-name>button{width:44px;min-width:44px;flex:0 0 44px}
.project-menu fieldset{box-sizing:border-box;width:100%}

#c64Readiness{border:1px solid var(--panel-well-border);border-radius:8px;padding:12px;margin:10px 0;font-size:.85rem}
#c64Readiness p{margin:5px 0}
#c64Readiness ul{padding-left:20px}

@media(min-width:691px) and (max-width:900px){
 .sidebar{position:static;width:280px;box-shadow:none}
 .sidebar.closed{width:0;padding:0;visibility:hidden}
 .app-title h1{font-size:.95rem}
}
@media(max-width:600px){
 .drawing-strip{gap:4px}
 header{gap:6px}
 .app-title{min-width:0}
 .app-title h1{font-size:.8rem}
}
@media(max-height:500px) and (max-width:1000px) and (orientation:landscape){
 /* Retain the current-tool hint for assistive technology; help remains available. */
 #stageHint{position:absolute;width:1px;height:1px;min-height:0;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
 /* Short landscape keeps one header row and one drawing-strip row so the canvas keeps its height.
    Title hides, Machine becomes an icon, and Project moves into the sidebar. */
 header{flex-wrap:nowrap;min-height:44px;height:auto}
 .app-title{display:none}
 header .header-brand{flex:0 0 auto}
 #machineSummary{font-size:0;width:44px;min-width:44px;max-width:44px;padding:0;overflow:hidden}
 #machineSummary::before{content:"▣";font-size:16px;line-height:1}
 .drawing-strip{flex-wrap:nowrap}
 #projectMenuSlot:empty{display:none}
 #projectMenuSlot #projectMenu>summary{width:100%;box-sizing:border-box}
 #projectMenuSlot #projectMenu>.project-menu{position:static;width:auto;max-height:none;box-shadow:none;border:0;background:transparent;padding:8px 0 0}
}
@media(max-width:600px),(max-height:500px) and (max-width:1000px){
 .app{padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}
 .sidebar{position:absolute;left:0;top:0;bottom:0;z-index:5;width:min(320px,86%);box-shadow:12px 0 30px #0008}
 .sidebar.closed{transform:translateX(-100%);width:min(320px,86%);padding:10px;visibility:hidden}
 .stage{padding:6px;gap:5px}
 .canvas-frame{padding:5px}
}

/* Layout stability (Raskin review H1): state changes must not move stage controls.
   Status and dimensions keep equal fixed slots so the centered view controls stay put;
   the preview banner overlays the stage bar instead of inserting a row. */
.stagebar{position:relative}
.stagebar>.preview-banner{position:absolute;inset:0 36px 0 0;z-index:2;padding:0 4px;background:var(--stage-wash-top)}
.stagebar>.preview-banner[hidden]{display:none}
#previewLabel{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.preview-banner button{flex:none}
@media(min-width:601px){
 .stagebar #dimensions,.stagebar #status{flex:0 0 clamp(64px,18%,220px);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
 .stagebar #status{text-align:right}
}
/* Tablet/desktop: one fixed footer row holds the tool hint and selection actions,
   so choosing Select, Line or Rectangle does not resize the canvas. Phones and short
   landscape screens keep the earlier behavior and give idle space to artwork. */
.stage-footer{display:none}
@media(min-width:601px) and (min-height:501px){
 .stage-footer{display:flex;align-items:center;justify-content:center;gap:8px;flex:none;min-width:0;height:46px}
 .stage-footer>#stageHint{order:-1;flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
 .stage-footer>.selection-dock{flex:0 1 auto;min-width:0}
 .stage-footer>.selection-dock:has(>.selection-actions[hidden]){visibility:hidden;width:0}
 /* Text entry: one line in the footer, replacing the hint while Text is active. */
 .stage-footer:has(>.text-entry:not([hidden]))>#stageHint{display:none}
 .stage-footer>.text-entry{flex:1 1 auto;min-width:0;max-height:none;height:42px;box-sizing:border-box;display:flex;align-items:center;gap:6px;padding:3px 6px;overflow:hidden}
 .stage-footer>.text-entry[hidden]{display:none}
 .stage-footer>.text-entry>label{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
 .stage-footer>.text-entry textarea{flex:1 1 45%;min-width:80px;height:34px;min-height:34px;max-height:34px;resize:none;padding:5px 8px;box-sizing:border-box}
 .stage-footer>.text-entry .row{flex:0 1 auto;min-width:0;margin:0;gap:6px;flex-wrap:nowrap}
 .stage-footer>.text-entry .note{flex:0 1 auto;min-width:0;max-width:32ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
}
@media(max-width:600px),(max-height:500px){
 /* Reserve gesture actions before a drag, but give idle drawing tools the space. */
 .app:not(:has(#tool-select[aria-pressed=true],#tool-line[aria-pressed=true],#tool-rectangle[aria-pressed=true])) .selection-dock:has(>.selection-actions[hidden]){display:none}
}
/* Download dialog: fixed height so switching tabs keeps the tabs and Close in place. */
@media(min-width:601px){
 #downloadDialog[open]{height:min(680px,calc(100dvh - 24px));box-sizing:border-box}
}
/* Preview consistency (Raskin review H2): every drawing tool looks unavailable during
   read-only preview, including the Paint/Pick/Fill menu triggers that use aria-disabled. */
.drawing-strip .tool-mode-trigger[aria-disabled=true]{cursor:default;opacity:.5}
/* Tool option badge (Raskin review H3): visible on the button face, not only in its menu. */
.tool-mode-menu>summary .tool-mode-badge{position:absolute;left:2px;top:2px;width:15px;height:15px;display:grid;place-items:center;border-radius:50%;background:var(--key-active);color:var(--text-on-accent);pointer-events:none}
.tool-mode-menu>summary .tool-mode-badge svg{width:9px;height:9px;fill:currentColor;stroke:none}
.tool-mode-menu>summary.active .tool-mode-badge{background:var(--text-on-accent);color:var(--key-active)}
/* Raskin review M2: device save state reads as a word, not only an icon, where space allows. */
@media(min-width:601px){
 header #saveStatus .save-status-compact{position:static;width:auto;height:auto;margin:0 10px 0 -6px;overflow:visible;clip-path:none;font-size:.8rem;font-weight:600}
 header #saveStatus[data-state=saved] .save-status-compact{color:var(--header-control-fg,var(--case-text))}
 header #saveStatus[data-state=failed] .save-status-compact{color:#ffe8e8}
}
/* Raskin review M4: Canvas commands sit with Undo/Redo, apart from drawing tools. */
.drawing-strip .strip-end{display:flex;align-items:center;gap:4px;margin-left:auto;flex-shrink:0}
.drawing-strip .strip-end>.recovery-group{margin-left:0}
.drawing-strip #canvasTool{position:relative}
.drawing-strip #canvasTool .tool-mode-chevron{position:absolute;right:2px;bottom:1px;font-size:.55rem;line-height:1;opacity:.7;pointer-events:none}
/* Raskin review L3: small help buttons keep their look but get a ~40px touch area. */
.help-trigger{position:relative}
.help-trigger::after{content:'';position:absolute;inset:-6px;border-radius:50%}
.space-pan,.space-pan canvas{cursor:grab}
