/* A tool room in the site's cedar-and-washi frame. Keep all paper, wood and
   illumination on the interface so exported figures have a neutral surface. */
:root {
  color-scheme: light;
  --wood: url('../assets/img/materials/cedar-h.webp');
  --wood-v: url('../assets/img/materials/cedar-v.webp');
  --washi: url('../assets/img/materials/washi-fiber.webp');
  --lattice: url('../assets/img/materials/asanoha-kumiko.webp');
  --sheet: #fffef9;
  --paper: #f6f2e7;
  --rail: #eeeadf;
  --ground: #dfdacb;
  --ink: #2c2924;
  --muted: #655f54;
  --rule: #c9c1b1;
  --hair: #dcd5c8;
  --accent: #87391f;
  --selected: #f3e1cf;
  --brass: #e8d3a2;
  --field: #fffdf6;
  --beam-tint: rgba(39, 27, 16, .30);
  --texture: 349px 349px;
  --serif: 'EB Garamond', 'Iowan Old Style', Georgia, serif;
  --display: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}
html[data-time='dusk'] {
  --paper: #f2e9d4;
  --rail: #e6dac4;
  --ground: #cfc2ad;
  --rule: #bbae95;
  --beam-tint: rgba(52, 32, 18, .40);
}
html[data-time='night'] {
  --paper: #e9dac0;
  --rail: #dccbb0;
  --ground: #a99b85;
  --rule: #b3a48d;
  --ink: #30271c;
  --muted: #5f5241;
  --field: #f7edd9;
  --beam-tint: rgba(24, 16, 10, .48);
}
html[data-material='lacquer'] {
  --wood: url('../assets/img/materials/urushi-black.webp');
  --wood-v: url('../assets/img/materials/urushi-vermilion-v.webp');
  --accent: #85311e;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.4 var(--sans); }
button, input, select, textarea { color: inherit; font: inherit; }
button, select { cursor: pointer; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 10px; border: 1px solid transparent; border-radius: 4px; background: transparent; line-height: 1.2; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible, #canvas:focus-visible { outline: 2px solid #a34d2f; outline-offset: 2px; }
input, textarea, select { min-width: 0; }
input[type='checkbox'], input[type='range'] { accent-color: var(--accent); }
button, a { -webkit-tap-highlight-color: transparent; }
button .icon, a .icon, .paper-control .icon, .search-field .icon { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-bank { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.skip-link:focus { position: fixed; z-index: 20; inset: 5px auto auto 5px; padding: 10px; color: var(--ink); background: var(--paper); }
.studio { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.beam { position: relative; z-index: 3; display: flex; align-items: center; gap: clamp(12px, 2.2vw, 34px); padding: 0 clamp(12px, 2vw, 30px); min-height: 67px; flex: none; color: #f5ead4; background-color: #3c2d22; background-image: linear-gradient(to bottom, #fff0ce24, transparent 2px, transparent calc(100% - 3px), #1e140f99), linear-gradient(var(--beam-tint), var(--beam-tint)), var(--wood); background-size: auto, auto, 1000px 334px; background-position: 0 0, 0 0, -44px -136px; box-shadow: inset 0 1px .5px #dac39b80, 0 1px 3px #211a12b0; }
.masthead { display: flex; align-items: center; flex: none; gap: 10px; }
.home-link { display: inline-grid; place-items: center; flex-shrink: 0; width: 35px; height: 37px; border-radius: 3px; }
.site-mark { width: 30px; height: 30px; background: url('../assets/img/materials/gilt-flower.webp') no-repeat center / contain; filter: drop-shadow(0 1px 1px #170d08); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 0; color: #f1dfba; font: 600 clamp(26px, 2.6vw, 38px)/1 var(--display); letter-spacing: -.035em; text-shadow: 0 1px 1px #21150b; }
.wordmark-z { letter-spacing: -.05em; }
.document-label { min-width: 0; flex: 1 1 auto; padding-left: clamp(10px, 1.8vw, 24px); border-left: 1px solid #c8b58c60; }
#document-title { width: min(100%, 25ch); text-overflow: ellipsis; padding: 4px 6px; color: #eddec6; background: transparent; border: 1px solid transparent; border-radius: 3px; font: 19px/1.2 var(--serif); }
#document-title:hover, #document-title:focus { background: #271d1470; border-color: #ceb89460; }
.main-actions, .history, .view-controls, .zoom-group { display: flex; align-items: center; }
.main-actions { gap: clamp(4px, .8vw, 12px); flex: none; }
.beam-button { min-height: 35px; padding: 7px 9px; color: #f3e7cf; font: 15px var(--sans); }
.beam-button:hover:enabled, .beam-button[aria-expanded='true'], .home-link:hover { border-color: #cfbd9666; background: #f7ebce12; }
.beam :focus-visible { outline-color: var(--brass); }
.history { gap: 1px; padding-inline: 6px; border-inline: 1px solid #c8b58c60; }
.icon-only { width: 31px; padding-inline: 5px; }
.copy-button { padding: 9px 15px; color: #32271b; border: 1px solid #e1cba0; background: linear-gradient(150deg, #f2e6c8, #d8c19a); box-shadow: inset .5px 1px .6px #fff9e1, 1px 2px 3px #20130790; font-size: 14px; font-weight: 600; }
.copy-button:hover { background: linear-gradient(150deg, #faf1d9, #e1cda6); }
.joinery { flex: 0 0 10px; position: relative; z-index: 2; border-bottom: 2px solid #4d3929; background: var(--lattice) center / auto 15px repeat-x, #77694f; box-shadow: inset 0 2px 2px #251c1588, 0 1px 2px #2d211841; }
.workbench { display: flex; position: relative; flex: 1 1 auto; min-height: 0; min-width: 0; isolation: isolate; }
.tool-rail, .side-panel, .statusbar, .studio-dialog { background-color: var(--paper); background-image: linear-gradient(#ffffff38, #ffffff2a), var(--washi); background-size: auto, var(--texture); background-blend-mode: normal, multiply; }
.tool-rail { position: relative; z-index: 2; flex: none; width: 65px; border-right: 1px solid var(--rule); box-shadow: 1px 0 3px #362a1d18; }
.rail-scroll { height: 100%; padding: 9px 7px; overflow: auto; scrollbar-width: thin; }
.tool-group { display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.tool-group:first-child { padding-top: 0; }
.tool-group:last-child { border: 0; }
.tool { position: relative; min-height: 36px; padding: 6px; border-radius: 3px; color: #443d31; }
.tool .icon { width: 19px; height: 19px; }
.tool > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.tool.shape-tool { flex-direction: column; gap: 1px; min-height: 43px; padding: 4px 0; }
.tool.shape-tool > span { position: static; width: auto; height: auto; clip-path: none; font: 10px/1.1 var(--sans); }
.shape-tool .shape-caret { position: absolute; top: 4px; right: 2px; width: 7px; height: 6px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.tool:hover, .utility-button:hover, .view-button:hover, .panel-close:hover, .panel-button:hover { background-color: #7e624c10; border-color: #947b5e6e; }
.tool[aria-pressed='true'], .tool.active, .tool.is-active { color: var(--accent); border-color: #a86c499e; background-color: var(--selected); box-shadow: inset 0 0 0 .5px #fff9e6; }
.tool[aria-pressed='true']::before { content: ''; position: absolute; left: -1px; top: 20%; bottom: 20%; width: 2px; background: var(--accent); }
.drawing-bay { position: relative; display: flex; flex: 1 1 auto; min-width: 0; min-height: 0; padding: 20px; background-color: var(--ground); background-image: radial-gradient(ellipse at 30% 12%, #ffffff70, transparent 85%), var(--washi); background-size: auto, var(--texture); background-blend-mode: normal, multiply; }
.board-frame { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; padding: 4px; border: 1px solid #4f3b29; background: var(--wood) center / 900px 300px; box-shadow: inset 0 .7px 1px #ddc69777, .5px 1px .8px #25190f9c, 2px 4px 6px -2px #3a2a1b52; }
.board-frame::after { content: ''; pointer-events: none; position: absolute; inset: 4px; border: 1px solid #40332244; box-shadow: inset 1px 2px 3px -2px #2b221851; }
#canvas { display: block; width: 100%; height: 100%; background-color: var(--sheet); touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden; outline-offset: -4px; }
.canvas-controls { position: absolute; z-index: 1; display: flex; align-items: center; gap: 3px; right: 36px; top: 36px; padding: 3px; max-width: calc(100% - 60px); background: var(--field); border: 1px solid #bfb3a0; border-radius: 5px; box-shadow: 0 1px 4px #3d2d1b16; }
.utility-button { min-height: 30px; padding: 4px 8px; gap: 6px; color: var(--muted); font-size: 12px; }
.utility-button .icon { width: 15px; height: 15px; }
.utility-button[aria-expanded='true'], .view-button[aria-pressed='true'] { color: var(--accent); }
.empty-state { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; max-width: 92%; pointer-events: none; }
.empty-state p { margin: 0 0 8px; font: 600 clamp(23px, 3vw, 35px)/1.2 var(--display); color: #5a5145; }
.empty-state > div { display: flex; gap: 6px; justify-content: center; }
.empty-state button { pointer-events: auto; }
.quiet-action { border-color: var(--hair); color: var(--muted); background: var(--field); font-size: 12px; white-space: nowrap; }
.quiet-action:hover { border-color: var(--accent); color: var(--accent); }
.side-panel { z-index: 3; display: flex; flex-direction: column; min-width: 0; width: clamp(220px, 23vw, 320px); flex-shrink: 0; border-left: 1px solid var(--rule); box-shadow: -1px 0 4px #332a1e12; }
.panel-heading { display: flex; align-items: center; min-height: 49px; flex: none; gap: 7px; padding: 9px 14px; border-bottom: 1px solid var(--rule); }
.panel-heading h2 { flex: 1; margin: 0; font: 600 24px/1.05 var(--display); color: var(--ink); }
.panel-heading form { display: flex; margin: 0; }
.panel-close { width: 29px; height: 29px; padding: 6px; color: var(--muted); }
.panel-button { font-size: 12px; }
.panel-body { min-height: 0; padding: 12px 14px 20px; overflow: auto; scrollbar-width: thin; }
#inspector { font-size: 13px; }
#inspector h2, #inspector h3, #inspector h4 { margin: 12px 0 8px; font: 600 20px/1.1 var(--display); }
#inspector :is(input, select, textarea):not([type='checkbox'],[type='range'],[type='color']) { min-height: 30px; background: var(--field); border: 1px solid var(--rule); padding: 3px 6px; border-radius: 3px; }
#inspector input[type='number'] { width: 75px; font-variant-numeric: tabular-nums; }
#inspector input[type='color'] { width: 34px; height: 28px; padding: 2px; border: 1px solid var(--rule); background: var(--field); }
#inspector button:not(.tool) { font-size: 12px; border: 1px solid var(--rule); min-height: 30px; margin: 2px; padding: 4px 7px; background: #fffaf13f; }
#inspector button:hover { border-color: var(--accent); }
#inspector label { max-width: 100%; }
#inspector p { margin: 6px 0 10px; color: var(--muted); }
.source-panel { width: clamp(300px, 34vw, 620px); }
#source { flex: 1; display: block; width: 100%; min-height: 5em; padding: 15px; background: #fbf9f2; color: #2f2b23; border: 0; border-radius: 0; resize: none; font: 13px/1.6 var(--mono); tab-size: 2; }
#source:focus-visible { outline-offset: -2px; }
#diagnostics { color: var(--accent); overflow: auto; flex: 0 1 auto; max-height: 32%; padding: 8px 12px; border-top: 1px solid var(--rule); font: 12px/1.5 var(--mono); overflow-wrap: anywhere; white-space: pre-wrap; }
#diagnostics:empty { display: none; }
.preview-panel { width: clamp(240px, 29vw, 470px); }
.preview-output { flex: 1; min-height: 0; overflow: auto; background: var(--sheet); padding: 14px; }
.preview-output :is(svg,img,iframe) { max-width: 100%; }
.preview-output iframe { width: 100%; height: 100%; border: 0; }
.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; min-height: 38px; padding: 0 13px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 12px; }
.save-status { display: flex; align-items: center; min-width: 0; gap: 8px; }
.state-dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: #698373; }
#status { overflow: hidden; display: block; text-overflow: ellipsis; white-space: nowrap; }
.view-controls { gap: 4px; flex: none; }
.view-button { min-width: 27px; min-height: 28px; padding: 4px 6px; font-size: 12px; }
.view-button .icon, .paper-control .icon { width: 14px; height: 14px; }
.paper-control { display: flex; align-items: center; gap: 3px; padding: 0 7px; margin: 0 4px; border-inline: 1px solid var(--rule); }
#paper-width { padding: 3px 0; border: 0; background: transparent; font-size: 12px; color: var(--muted); }
.zoom-group { gap: 1px; }
#zoom-level { min-width: 35px; text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; }
.studio-dialog { color: var(--ink); width: min(450px, calc(100vw - 24px)); max-height: min(76vh, 610px); padding: 0; border: 1px solid #8b755c; border-radius: 6px; box-shadow: 0 3px 8px #1b13032e, 0 13px 35px #32211233; }
.studio-dialog::backdrop { background: rgba(36, 30, 23, .32); }
.studio-dialog .panel-heading { padding: 13px 16px; }
.search-field { display: flex; align-items: center; gap: 9px; margin: 12px; padding: 0 10px; border-radius: 3px; border: 1px solid var(--rule); background: var(--field); }
.search-field:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
#action-search { width: 100%; min-height: 40px; padding: 4px; border: 0; background: transparent; outline: 0; }
.action-results, .file-list, .document-list { display: grid; gap: 2px; padding: 0 10px 10px; }
.action-results button, .file-item, .document-list button { width: 100%; min-height: 35px; justify-content: flex-start; padding: 7px 9px; text-align: left; }
.action-results button:hover, .file-item:hover, .document-list button:hover, .action-results button:focus { background: var(--selected); border-color: #cda68d; }
/* Loading local drafts must keep the file commands under the pointer. */
.file-dialog { width: min(350px, calc(100vw - 24px)); margin-block-start: max(12px, calc((100dvh - min(76dvh, 610px)) / 2)); }
.file-list { padding-top: 8px; }
.document-list:not(:empty) { border-top: 1px solid var(--rule); padding-top: 8px; }
.document-list:empty, .action-results:empty { display: none; }
@media (min-width: 1050px) and (min-height: 880px) {
  .tool-rail { width: 78px; }
  .tool { flex-direction: column; gap: 3px; min-height: 48px; padding: 5px 2px; }
  .tool > span { position: static; height: auto; width: auto; clip-path: none; font: 10px/1.15 var(--sans); }
}
@media (max-width: 1050px) {
  .main-actions { gap: 2px; }
  .beam { min-height: 54px; gap: 10px; }
  .drawing-bay { padding: 13px; }
  .canvas-controls { top: 26px; right: 26px; }
  .side-panel { width: 235px; }
  .source-panel { width: 34%; }
  .preview-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(360px, 90%); }
}
@media (max-width: 760px) {
  .beam { gap: 5px; min-height: 51px; padding: 0 9px; }
  .masthead { gap: 3px; margin-right: auto; }
  .home-link { width: 27px; }
  .site-mark { width: 23px; height: 23px; }
  .document-label { display: none; }
  .history { padding-inline: 2px; }
  .tool-rail { width: 48px; }
  .rail-scroll { padding: 5px 3px; }
  .tool { min-height: 36px; }
  .drawing-bay { padding: 9px; }
  .canvas-controls { right: 20px; top: 20px; }
  .utility-button { min-width: 33px; min-height: 32px; padding: 5px; }
  .utility-button span { display: none; }
  .side-panel { position: absolute; width: min(400px, calc(100% - 66px)); right: 9px; bottom: 9px; max-height: 53%; background-color: var(--paper); border: 1px solid var(--rule); border-radius: 4px; box-shadow: 0 2px 10px #3c2c1a36; }
  .source-panel, .preview-panel { inset: auto 8px 8px; width: auto; height: 55%; max-height: none; }
  .source-panel { z-index: 4; }
  .preview-panel { z-index: 5; }
  .panel-heading { min-height: 39px; padding: 5px 10px; }
  .panel-heading h2 { font-size: 21px; }
  .panel-body { padding: 8px 10px 12px; }
  .view-controls { gap: 0; }
  .statusbar { padding: 0 7px; min-height: 35px; gap: 3px; }
}
@media (max-width: 540px) {
  .beam-button:not(.copy-button) > span { display: none; }
  .beam-button { padding: 6px; min-width: 30px; min-height: 33px; }
  .copy-button { gap: 4px; padding: 6px 8px; font-size: 12px; min-height: 33px; }
  .copy-button .icon { width: 13px; height: 13px; }
  h1 { font-size: 25px; }
  .joinery { flex-basis: 7px; }
  .view-controls .view-button > span, .paper-control .icon { display: none; }
  .view-controls .view-button { min-width: 26px; }
  .paper-control { padding: 0 3px; margin: 0 1px; }
  .save-status { gap: 4px; }
  .statusbar { font-size: 10px; }
}
@media (max-width: 370px) {
  .home-link { width: 19px; }
  .site-mark { width: 17px; height: 17px; }
  .beam { padding: 0 5px; }
  h1 { font-size: 21px; }
  .main-actions, .history { gap: 0; }
  .beam-button { min-width: 28px; padding: 4px; }
  .history { padding: 0; }
  .icon-only { width: 26px; }
  .copy-button .icon { display: none; }
  .view-controls .view-button { min-width: 22px; padding-inline: 3px; }
  #zoom-level { min-width: 30px; }
  .paper-control select { max-width: 65px; }
}
@media (pointer: coarse) {
  .tool { min-height: 42px; }
  .rail-scroll { scrollbar-width: thin; }
  .tool, .beam-button, .view-button { touch-action: manipulation; }
}
@media (max-height: 490px) {
  .beam { min-height: 40px; }
  .joinery { flex-basis: 4px; }
  .statusbar { min-height: 28px; }
  .drawing-bay { padding: 5px; }
  .canvas-controls { top: 14px; right: 14px; }
}
@media (forced-colors: active) {
  .beam, .tool-rail, .statusbar, .side-panel, .studio-dialog, .board-frame { background: Canvas; color: CanvasText; border-color: CanvasText; }
  .beam-button, h1, #document-title { color: CanvasText; }
  .tool[aria-pressed='true'], .view-button[aria-pressed='true'] { outline: 2px solid Highlight; }
}
@media print {
  .studio { display: block; height: auto; overflow: visible; }
  .workbench, .drawing-bay, .board-frame { display: block; padding: 0; margin: 0; border: 0; background: white; box-shadow: none; }
  .board-frame::after, .beam, .joinery, .tool-rail, .canvas-controls, .side-panel, .statusbar, .empty-state { display: none !important; }
  #canvas { width: 100%; height: 80vh; }
}
/* Property editing uses the same compact fields in the inspector and dialogs. */
.ins-section + .ins-section { margin-top: 14px; padding-top: 8px; border-top: 1px solid var(--rule); }
.field { display: grid; align-items: center; grid-template-columns: minmax(65px, 1fr) minmax(0, 1.1fr); gap: 8px; min-width: 0; margin: 6px 0; color: var(--muted); font-size: 12px; }
.field > span { min-width: 0; line-height: 1.25; }
.field > :is(input, select, textarea) { min-width: 0; width: 100%; max-width: 100%; }
.field > input[type='checkbox'] { width: 16px; justify-self: start; }
.fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 4px 9px; }
.fields > .field { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.fields > .field > :is(input,select) { width: 100% !important; }
.field-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 5px; }
.field-actions > .field { display: inline-flex; }
.object-list { margin: 13px 0 5px; padding-top: 8px; border-top: 1px solid var(--rule); }
.object-list summary { cursor: pointer; padding: 5px 0; }
#inspector .object-list button { display: flex; width: calc(100% - 4px); justify-content: flex-start; text-align: left; overflow-wrap: anywhere; }
#inspector .object-list button[aria-pressed='true'] { background: var(--selected); border-color: var(--accent); }
.custom-dialog.wide { width: min(620px,calc(100vw - 24px)); }
.custom-dialog .dialog-head, .custom-dialog .dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }
.custom-dialog .dialog-head { justify-content: space-between; border-bottom: 1px solid var(--rule); }
.custom-dialog .dialog-head h2 { margin: 0; font: 600 25px/1.1 var(--display); }
.custom-dialog .dialog-foot { justify-content: flex-end; border-top: 1px solid var(--rule); }
.custom-dialog > :is(section, div, p, label:not(.sr-only)) { padding: 14px 16px; }
.custom-dialog[open]:has(> .workspace-form) { display: flex; flex-direction: column; max-height: min(84dvh,720px); overflow: hidden; }
.custom-dialog > .workspace-form { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.custom-dialog :is(.dialog-head,.dialog-foot) { flex: none; }
.workspace-form :is(details, .workspace-form > div:has(> .fields)) { margin: 8px 0; padding: 7px 0; border-top: 1px solid var(--rule); }
.workspace-form summary { padding: 5px 0; font-size: 14px; font-weight: 600; cursor: pointer; }
.workspace-form summary:focus-visible { outline-offset: -1px; }
.workspace-form .fields + button { margin-top: 4px; }
.workspace-form > [role='status']:empty { display: none; }
.workspace-form input[type='file'] { width: 100%; height: auto; margin: 5px 0; }
.workspace-form pre { max-width: 100%; overflow-x: auto; font: 12px/1.5 var(--mono); }
.workspace-form small { color: var(--muted); }
.custom-dialog button { min-height: 31px; border-color: var(--rule); background: #ffffff33; font-size: 13px; }
.custom-dialog button:hover { border-color: #a88767; }
.custom-dialog :is(input, textarea, select) { max-width: 100%; min-height: 32px; padding: 5px 7px; border: 1px solid var(--rule); border-radius: 3px; background: var(--field); }
.custom-dialog button.primary { color: #fff6df; background: var(--accent); border-color: var(--accent); }
.custom-dialog textarea { width: 100%; font: 13px/1.5 var(--mono); }
.custom-dialog [role='alert'], .custom-dialog [data-error] { color: var(--accent); }
.dialog-foot + [data-error] { margin: 0; }
@media (max-width: 540px) and (min-height: 491px) {
  .beam { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 0 8px; padding: 3px 8px 5px; }
  .masthead { min-height: 34px; }
  .document-label { display: block; padding-left: 6px; }
  #document-title { width: 100%; padding: 4px; font-size: 15px; }
  .main-actions { grid-column: 1/-1; justify-content: space-between; gap: 2px; }
  .main-actions .beam-button > span, .main-actions .copy-button .icon { display: inline; }
  .beam-button { min-width: 34px; min-height: 38px; font-size: 12px; }
  .main-actions .icon-only { width: 37px; }
  .copy-button { min-height: 35px; }
  .history { gap: 2px; padding-inline: 2px; }
  .statusbar { display: grid; grid-template-columns: 1fr; gap: 0; padding: 2px 8px max(2px, env(safe-area-inset-bottom)); }
  .save-status { min-height: 15px; }
  .save-status:has(#status:empty) { display: none; }
  .view-controls { justify-content: space-between; }
  .view-controls .view-button { min-width: 34px; min-height: 37px; }
  .view-controls .view-button .icon { width: 15px; height: 15px; }
}
.copy-button, .beam-button { white-space: nowrap; }
@media (max-width: 370px) {
  .main-actions .copy-button .icon { display: none; }
}
.compiled-board { position: absolute; inset: 4px; display: grid; grid-template-rows: minmax(0,1fr) auto; background: #f3f0e9; padding: 55px clamp(8px,2.7vw,38px) 16px; gap: 10px; overflow: hidden; }
.compiled-figure { display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: auto; }
.compiled-figure img, .compiled-figure > svg { display: block; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; padding: clamp(12px,2.5vw,42px); background-color: var(--sheet); border: 1px solid #d7cec0; box-shadow: 0 1px 3px #3a332315; }
.compiled-figure p { color: var(--muted); text-align: center; }
.compiled-figure:has(img) { position: relative; overflow: hidden; touch-action: none; overscroll-behavior: contain; cursor: grab; }
.compiled-figure.panning { cursor: grabbing; }
.compiled-figure:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.compiled-figure > img { position: absolute; top: 50%; left: 50%; user-select: none; pointer-events: none; flex: none; max-width: none; max-height: none; box-sizing: border-box; margin: auto; }
.compiled-tools { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.compiled-tools button { min-height: 32px; padding: 5px 10px; background: var(--field); border-color: var(--rule); border-radius: 3px; color: var(--ink); font-size: 12px; }
.compiled-tools button:hover { border-color: var(--accent); color: var(--accent); }
.compiled-figure:empty::before { content: ''; display: block; width: 16px; height: 16px; border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: compile-wait 1s linear infinite; }
@keyframes compile-wait { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .compiled-figure:empty::before { animation: none; } }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 9px 15px; margin: 0; padding: 15px; font-size: 13px; }
.shortcut-list dt { color: var(--accent); }
.shortcut-list dd { margin: 0; }
.view-controls .settings-chevron { min-width: 24px; min-height: 34px; margin-left: -2px; padding: 4px 3px; }
.settings-chevron .icon { width: 12px; }
#compile-status { padding: 6px 12px; font: 12px/1.4 var(--sans); color: var(--muted); overflow-wrap: anywhere; }
#compile-status:empty { display: none; }
.compiled-tools [role='alert'], .compiled-board[data-stale='true'] .compiled-tools [role='status'] { align-self: center; font: 12px var(--sans); color: var(--accent); background: var(--field); padding: 5px 7px; border-left: 2px solid var(--accent); }
.inline-label { position: absolute; z-index: 8; width: min(238px,calc(100% - 12px)); display: flex; gap: 4px; align-items: center; max-width: calc(100% - 12px); padding: 4px; background: var(--field); border: 1px solid var(--accent); border-radius: 3px; box-shadow: 0 2px 4px #32241533; }
.inline-label :is(input,select,button) { min-height: 32px; }
.inline-label input, .inline-label select { max-width: 100%; min-width: 0; border: 1px solid var(--rule); background: #fffdf8; padding: 4px; font-size: 13px; }
.inline-label input { width: 1px; flex: 1; font-family: var(--mono); }
.inline-label button { background: var(--selected); padding: 4px; color: var(--accent); }

.grid-form > svg { display: block; width: 100%; height: 76px; border: 1px solid var(--rule); border-radius: 3px; background: var(--sheet); }
.grid-form .grid-opacity { display: flex; align-items: center; gap: 6px; }
.grid-opacity .field { flex: 1; }
.grid-opacity input[type=range] { padding: 0; accent-color: var(--accent); }
.grid-opacity output { min-width: 4ch; text-align: end; font-variant-numeric: tabular-nums; }
.grid-note { display: block; margin: 5px 0 10px; color: var(--muted); }
@media (max-width: 360px) {
  .view-controls .view-button { min-width: 28px; }
  .view-controls .settings-chevron { min-width: 21px; }
}

.plot-host { position:absolute; z-index:2; inset:4px; overflow:hidden; background:var(--sheet); }
.workbench.in-plot .tool-rail, .workbench.in-plot .canvas-controls { display:none; }
.studio:has(.in-plot) .view-controls { visibility:hidden; }
.canvas-controls select, .page-picker select { font:inherit; color:var(--ink); background:var(--field); border:1px solid var(--rule); padding:4px; border-radius:3px; }
.compiled-board:has(.page-picker) { grid-template-rows:minmax(0,1fr) auto auto; }
.page-picker { display:flex; justify-content:center; padding:3px; }
.workspace-form > textarea[aria-label="TeX to import"] { width:100%; min-height:155px; font-family:var(--mono),monospace; }
@media(max-width:500px){ .canvas-controls:has(select:not([hidden])) { flex-wrap:wrap; } }

#source-panel > select { width: 100%; padding: 6px 10px; border: 0; border-bottom: 1px solid var(--rule); background: var(--field); color: var(--ink); }

.ins-color-state { display: grid; position: relative; }
.ins-color-state input, .ins-color-state > span { grid-area: 1 / 1; }
.ins-color-state > span {
  pointer-events: none;
  align-self: center;
  justify-self: center;
  padding: 0 4px;
  border-radius: 2px;
  background: var(--field);
  color: var(--ink);
  font: 12px var(--sans);
}

.style-gallery { display: grid; gap: 5px; }
.style-gallery .style-tile { display: flex; align-items: center; gap: 10px; text-align: left; }
.style-tile svg { width: 86px; height: 36px; flex: none; }
.shared-style-preview { display: grid; place-items: center; border: 1px solid var(--rule); background: var(--sheet); }
.shared-style-preview svg { width: min(225px, 100%); height: 78px; }
.shared-style-tone { display: flex; align-items: center; gap: 5px; }
.shared-style-tone .field { flex: 1; }
.shared-style-tone input[type='color'] { width: 36px; padding: 3px; }
.shared-style-opacity { display: flex; align-items: center; gap: 6px; }
.shared-style-opacity input { min-width: 0; flex: 1; }
.shared-style-opacity output { min-width: 34px; text-align: right; }

.asset-thumbnail { inline-size: 3.25rem; block-size: 2.5rem; object-fit: contain; background: var(--paper, #fffdf8); border: 1px solid #ccbfae; border-radius: 3px; }

.viewport-menu { position: fixed; z-index: 100; display: grid; min-width: 148px; max-width: calc(100vw - 8px); max-height: calc(100dvh - 8px); overflow: auto; overscroll-behavior: contain; padding: 4px; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); color: var(--ink); box-shadow: 0 4px 18px #30221836; }
.viewport-menu button { text-align: left; padding: 6px 10px; border: 0; border-radius: 3px; font: 13px var(--sans); background: transparent; color: inherit; }
.viewport-menu button:is(:focus-visible,:hover) { outline: 0; color: var(--accent); background: var(--selected); }
