h1, h2, h3, p, dl { margin: 0; }
h1 { font-size: clamp(1.4rem, 2.55vw, 2rem); font-weight: 400; line-height: 1.2; letter-spacing: -.045em; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; line-height: 1.3; }
h3 { font-size: .9rem; }
strong { font-weight: 600; }
.muted, .printer-detail { color: var(--muted); font-size: .87rem; }
.printer-detail:empty, .muted:empty { display: none; }
.warning { color: var(--error-ink); font-size: .88rem; }
.layout { width: var(--workspace-width); margin: 0 auto var(--gutter); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.inventory-actions, .dialog-actions, .history-footer { display: flex; gap: 10px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: var(--inset);
  font: 600 .68rem/1.3 var(--mono);
  letter-spacing: .035em;
  text-transform: uppercase;
}
.badge::before { content: ""; width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: currentColor; }
.badge.live, .badge.printing { color: var(--accent-text); background: var(--accent-surface); border-color: var(--accent-line); }
.badge.live::before, .badge.printing::before { color: var(--accent); box-shadow: 0 0 5px var(--accent-line); }
.badge.failed { color: var(--error-ink); background: var(--error-surface); border-color: var(--error-line); }
.badge.ready, .badge.completed { color: #b0dcb6; background: #24342a; border-color: #507057; }
.badge.blocked, .badge.inspection { color: var(--warning-ink); background: var(--warning-surface); border-color: var(--warning-line); }

body[data-page=home] {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--display);
}
.live-layout {
  flex: 1;
  display: grid;
  grid-template: auto minmax(0,1fr) auto / minmax(0,1fr);
  width: 100%;
  margin: 0;
}
.printer-alert {
  --alert-ink: var(--warning-ink);
  --alert-background: var(--warning-surface);
  --alert-line: var(--warning-line);
  --alert-indicator: #daa656;
  grid-column: 1 / -1;
  grid-row: 1;
  margin: 0 var(--gutter) 12px;
  max-height: min(36dvh, 310px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 16px 14px;
  border: 1px solid var(--alert-line);
  border-radius: 12px;
  background: var(--grain), var(--alert-background);
  color: var(--alert-ink);
  box-shadow: inset 0 1px var(--edge-light), 0 2px 4px #0005;
}
.printer-alert[data-severity=error] { --alert-ink: var(--error-ink); --alert-background: var(--error-surface); --alert-line: var(--error-line); --alert-indicator: var(--accent); }
.printer-alert[data-severity=info] { --alert-ink: var(--info-ink); --alert-background: var(--info-surface); --alert-line: var(--info-line); --alert-indicator: #82b4cf; }
.printer-alert-title { display: flex; align-items: center; gap: 8px; font-size: .89rem; letter-spacing: .08em; text-transform: uppercase; }
.printer-alert-title::before { content: ""; width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--alert-indicator); box-shadow: 0 0 6px var(--alert-line); }
.printer-alert-note { margin-top: 4px; font-size: .82rem; }
.printer-alert-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.printer-alert-item { min-width: 0; font-size: .83rem; overflow-wrap: anywhere; }
.printer-alert-item + .printer-alert-item { border-top: 1px dashed var(--alert-line); padding-top: 9px; }
.printer-alert-item h3 { margin-bottom: 3px; }
.printer-alert-action { margin-top: 4px; }
.printer-alert-footer { display: flex; gap: 4px 16px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: .76rem; }
.printer-alert-footer code { font-family: var(--mono); }
.printer-alert-footer a { text-underline-offset: 3px; }

.live-sidebar {
  z-index: 1;
  grid-area: 3 / 1;
  display: grid;
  gap: 11px;
  align-self: start;
  min-width: 0;
  margin: 0 var(--gutter) var(--gutter);
}
.instrument-heading, .instrument-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.instrument-heading { min-height: 48px; padding: 10px 13px; list-style: none; cursor: pointer; border-radius: var(--radius); }
details:not([open]) > .instrument-heading:hover { background: var(--hover); }
.instrument-heading:hover .menu-chevron { color: var(--accent-text); }
.instrument-heading:focus-visible { outline-offset: -4px; }
.instrument-heading::-webkit-details-marker { display: none; }
.menu-label { margin-right: auto; }
.menu-value { font-size: .8rem; white-space: nowrap; }
[open] > summary .menu-value { display: none; }
.menu-body { padding: 0 13px 13px; }
#print-state { font: 600 .78rem/1.4 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.instrument-footer { margin-top: 12px; padding-top: 11px; border-top: 1px dashed var(--line); }
.instrument-footer p { color: var(--subtle); font-size: .7rem; min-width: 0; }
.instrument-footer .quiet { min-height: 32px; padding-inline: 8px; flex: none; }
.progress-wrap { display: grid; gap: 6px; margin-top: 8px; }
.progress-reading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.progress-reading strong { font: 400 clamp(1.65rem, 4vw, 2.25rem)/1.1 var(--mono); letter-spacing: -.06em; }
.progress-reading span { color: var(--muted); }
.progress-meter {
  appearance: none;
  display: block;
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: 1px;
  overflow: hidden;
  background: #3c3c34;
  color: var(--accent-glow);
  mask-image: repeating-linear-gradient(90deg, #000 0 calc(5% - 2px), transparent calc(5% - 2px) 5%);
}
.progress-meter::-webkit-progress-bar { background: #3c3c34; }
.progress-meter::-webkit-progress-value { background: linear-gradient(#ff864f,#f1481d); }
.progress-meter::-moz-progress-bar { background: linear-gradient(#ff864f,#f1481d); }
.readings { display: grid; gap: 1px; overflow: hidden; margin: 10px 0 0; border-radius: 8px; }
.instrument .readings, .part-readings { grid-template-columns: 1fr 1fr; }
.readings > div { min-width: 0; padding: 8px 9px; }
.readings dt { color: var(--muted); font-size: .69rem; letter-spacing: .045em; text-transform: uppercase; }
.readings dd { margin: 3px 0 0; font: 400 1rem/1.24 var(--mono); overflow-wrap: anywhere; }
.instrument .readings { gap: 0; border-top: 1px dashed var(--line); border-radius: 0; }
.instrument .readings > div { padding: 8px 7px 1px 0; }
.part-readings { background: var(--inset); border: 1px solid var(--line); }

.preview-panel {
  position: relative;
  isolation: isolate;
  grid-area: 2 / 1;
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto;
  gap: 12px;
  min-height: clamp(375px, 68dvh, 660px);
  min-width: 0;
  padding: 0 var(--gutter) 14px;
  color: var(--display-ink);
}
.preview-header { display: flex; justify-content: space-between; align-items: center; gap: 10px 16px; min-width: 0; flex-wrap: wrap; }
.preview-header h1 { font-size: clamp(1rem, 1.75vw, 1.5rem); }
.view-label { color: var(--display-muted); margin-bottom: 4px; }
.print-identity { min-width: 0; flex: 1 1 222px; }
.preview-actions { display: flex; flex: 0 1 auto; flex-wrap: wrap; gap: 8px; }
.preview-header, .preview-footer { pointer-events: none; }
.preview-actions, .view-buttons { pointer-events: auto; }
.preview-actions:empty, .preview-actions:not(:has(> :not([hidden]))) { display: none; }
#workshop-camera-toggle[aria-expanded=true] { color: var(--accent-text); background: var(--accent-surface); border-color: var(--accent-line); }
#workshop-camera {
  position: relative;
  grid-area: 1 / 1 / 2 / -1;
  align-self: stretch;
  display: grid;
  grid-template-rows: minmax(0,1fr) auto;
  border-radius: 12px;
  overflow: hidden;
  background: #0f1010;
  pointer-events: auto;
}
#workshop-camera img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.workshop-camera-status {
  grid-row: 2;
  min-height: 46px;
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--display-muted);
  background: var(--display);
  font-size: .79rem;
}
.show-workshop-camera .plate-stage > :not(#workshop-camera), .show-workshop-camera .preview-footer { visibility: hidden; }
.show-workshop-camera .preview-actions :is(#layer-final,#layer-follow) { display: none; }
.plate-stage {
  display: grid;
  grid-template: minmax(0,1fr) / minmax(0,1fr) auto;
  align-items: center;
  grid-row: 2;
  column-gap: 12px;
  pointer-events: none;
}
.plate-canvas, #part-dimensions { position: absolute; inset: 0; overflow: hidden; }
.plate-canvas { z-index: -2; pointer-events: auto; }
.plate-canvas canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.plate-canvas canvas:active { cursor: grabbing; }
#part-dimensions { z-index: -1; }
.dimension-label {
  position: absolute;
  padding: 3px 7px;
  transform: translate(-50%,-50%);
  border: 1px solid #a96349;
  border-radius: 4px;
  background: #251910;
  color: #ffbc9c;
  font-size: .79rem;
  white-space: nowrap;
}
.preview-note {
  grid-area: 1 / 1;
  place-self: end center;
  width: max-content;
  max-width: calc(100% - 30px);
  padding: 7px 10px;
  border: 1px solid var(--display-line);
  background: #191a16ef;
  color: var(--display-muted);
  border-radius: 6px;
  text-align: center;
  font-size: .78rem;
  pointer-events: none;
}
.layer-controls {
  grid-area: 1 / 2;
  height: min(100%, 420px);
  width: 49px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 6px 4px;
  font-size: .65rem;
  color: var(--ink);
  border: 1px solid var(--key-edge);
  border-radius: 8px;
  background: var(--case-face);
  box-shadow: var(--case-shadow);
  pointer-events: auto;
}
.layer-controls output { font: 400 .79rem var(--mono); padding: 3px 5px; border: 1px solid var(--display-line); border-radius: 4px; background: var(--display); color: var(--display-ink); min-width: 25px; text-align: center; }
.layer-controls input[type=range] { writing-mode: vertical-lr; direction: rtl; flex: 1; min-height: 0; width: 25px; margin: 0; accent-color: var(--accent); cursor: ns-resize; }
.preview-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; min-width: 0; font-size: .78rem; }
#preview-legend { color: var(--display-muted); font-size: .73rem; margin-top: 2px; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--inset); box-shadow: var(--recess-shadow); }
.segmented .quiet { min-height: 33px; padding: 4px 9px; white-space: nowrap; background: transparent; border-color: transparent; box-shadow: none; }
.segmented .quiet[aria-pressed=true] { border-color: var(--accent-line); background: var(--accent-surface); }

.active-filaments { margin: 0; padding: 0; list-style: none; }
.active-filaments:empty { display: none; }
.active-filaments li { display: flex; align-items: center; gap: 8px; }
.active-filaments li + li { margin-top: 7px; }
.filament-name { min-width: 0; margin-right: auto; overflow-wrap: anywhere; font-size: .83rem; }
#filament-weight, .filament-grams { font-size: .81rem; white-space: nowrap; }
.active-filaments .swatch { width: 16px; height: 16px; }
.swatch { flex: none; display: grid; width: 22px; height: 22px; border-radius: 50%; border: 1px solid #ffffff35; overflow: hidden; box-shadow: 0 1px #0005; }
.swatch svg { width: 100%; height: 100%; }
#next-roll-note, #part-hint { margin-top: 7px; }
#part-select { width: 100%; }

@media (min-width: 960px) {
  .live-layout { --printer-rail: clamp(245px, 23vw, 325px); }
  .live-sidebar {
    grid-row: 2;
    width: var(--printer-rail);
    margin-bottom: 14px;
    align-self: stretch;
    align-content: start;
    contain: size;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .preview-panel {
    min-height: min(410px, 58dvh);
    padding-left: calc(var(--gutter) + var(--printer-rail) + 18px);
  }
}

.desk-layout { display: grid; grid-template-columns: minmax(0,1.18fr) minmax(0,.82fr); gap: 14px; align-items: start; }
.builds, .history, .inventory { padding: clamp(14px, 2.2vw, 24px); }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-title p { margin-top: 5px; }
.section-title .quiet, .section-title .primary { flex: none; }
.desk-stats {
  grid-template-columns: repeat(3,minmax(0,1fr));
  padding: 4px;
  margin-block: 17px;
  gap: 0;
  box-shadow: var(--display-shadow);
}
.desk-stats > div + div { border-left: 1px dashed var(--display-line); }
.desk-stats dt { color: var(--display-muted); }
.desk-stats dd { font-size: 1.45rem; }
.queue-filter-row { margin: 15px 0 8px; }
.filter select { font-size: .8rem; }
.build-list, .run-list, .stock-list { padding: 5px; }
.build-list:empty, .run-list:empty, .stock-list:empty { display: none; }
.build-list > p { padding: 8px; }
.build + .build, .run + .run { border-top: 1px dashed var(--line); }
.build-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; list-style: none; padding: 10px; border-radius: 7px; }
.build-title::-webkit-details-marker { display: none; }
.build-title:hover, .spool:hover { background: var(--hover); }
.build[open] > .build-title { color: var(--accent-text); background: var(--accent-surface); }
.build-title small, .plate small, .run small, .spool-body small, .spool-weight small { display: block; margin-top: 3px; }
.chevron { font: 400 1.28rem/1 var(--font); color: currentColor; }
.build[open] .chevron { transform: rotate(90deg); }
.plate-list { list-style: none; padding: 0; margin: 0 6px 5px 13px; border-left: 1px solid var(--line); }
.plate { display: flex; justify-content: space-between; gap: 9px; padding: 8px 9px; overflow-wrap: anywhere; }
.plate + .plate { border-top: 1px dashed var(--line); }
.plate-meta { text-align: right; flex: none; }
.run-list { list-style: none; margin: 10px 0; }
.run { padding: 10px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 4px 10px; align-items: center; }
.run-detail { grid-column: 1 / -1; min-width: 0; overflow-wrap: anywhere; }
.run-usage { min-width: 0; overflow-wrap: anywhere; }
.run .quiet { min-height: 33px; }
#history-status:not(:empty), #queue-error, #stock-status:not(:empty) { margin-top: 10px; }
.history-footer { margin-top: 12px; justify-content: flex-end; }
.inventory-actions { justify-content: flex-end; }
.inventory-columns { display: flex; justify-content: space-between; padding: 15px 15px 6px; color: var(--subtle); font-size: .71rem; text-transform: uppercase; letter-spacing: .07em; }
.spool { display: grid; grid-template-columns: auto minmax(0,1fr) minmax(74px,auto); align-items: center; gap: 11px; min-height: 44px; width: 100%; padding: 9px; border: 0; color: var(--ink); background: transparent; text-align: left; }
.spool + .spool { border-top: 1px dashed var(--line); }
.spool-body { min-width: 0; overflow-wrap: anywhere; }
.spool-weight { font-size: .86rem; text-align: right; color: var(--ink); }
.spool-weight small { font-size: .7rem; color: var(--muted); }

dialog { width: min(446px,calc(100% - 28px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 15px; color: var(--ink); }
dialog::backdrop { background: #0b0b0dd1; backdrop-filter: blur(4px); }
dialog .section-title { margin-bottom: 12px; }
.dialog-heading, .login-heading { padding: 12px 13px; }
.dialog-heading .quiet { min-width: 34px; min-height: 32px; padding: 4px; font-size: 1rem; }
dialog label, .login label { display: grid; gap: 5px; margin: 12px 0; font-weight: 600; font-size: .78rem; }
dialog input[type=color] { width: 56px; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); padding: 2px; }
dialog label.check-option { display: flex; align-items: start; gap: 8px; }
.check-option input { margin: 3px 0 0; width: 1rem; height: 1rem; accent-color: var(--accent-text); }
dialog .warning:not([hidden]), .login .warning:not([hidden]) { margin: 0 0 10px; }
.sign-in { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: min(100%,392px); padding: 15px; }
.login-heading { display: flex; align-items: center; gap: 10px; }
.login form { padding: 0 4px 5px; }
.login .primary { width: 100%; }

@media (max-width: 900px) { .desk-layout { grid-template-columns: 1fr; } }
@media (max-width: 530px) {
  .preview-panel { gap: 9px; }
  .preview-actions .quiet { min-height: 40px; }
  .layer-controls { width: 39px; }
  .inventory-actions { justify-content: flex-start; }
  .plate { flex-wrap: wrap; }
  .plate-meta { text-align: left; }
}
