:root {
  color-scheme: light;
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  --ink: #202a36;
  --muted: #566576;
  --border: #dce2e7;
  --paper: #ffffff;
  --background: #edf0f3;
  --accent: #a63f23;
  --accent-hover: #88331d;
  --accent-light: #fff0e8;
  --teal: #244e4b;
  --board: #14202c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 290px; color: var(--ink); background: var(--background); font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button, input, select, canvas, summary { outline-offset: 3px; }
:focus-visible { outline: 2px solid #1b7d82; }
h1, h2, p { margin: 0; }
button { border: 1px solid transparent; border-radius: 7px; padding: 8px 10px; color: inherit; background: none; font-weight: 600; }
button:not(:disabled):active { transform: translateY(1px); }

.topbar {
  min-height: 78px;
  padding: 12px clamp(16px, 2.5vw, 38px);
  background: #fdfdfd;
  border-bottom: 1px solid #d8dfe5;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 22px; line-height: 1.2; letter-spacing: -.045em; white-space: nowrap; }
.brand p { color: var(--muted); font-size: 12px; margin-top: 4px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
  background: var(--accent);
}
.brand-mark span { width: 20px; height: 5px; border: 1.5px solid #fff6ee; border-right: 0; border-radius: 4px 0 0 4px; }
.brand-mark span:nth-child(2) { transform: scaleX(-1); }
.project-actions, .stage-actions, .view-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.project-actions { justify-content: flex-end; }
.primary { background: var(--accent); color: #fff; padding-inline: 15px; }
.primary:not(:disabled):hover { background: var(--accent-hover); }
.primary span { margin-right: 4px; font-size: 10px; }
.quiet { background: #f5f7f9; border-color: #e0e5e9; }
.quiet:not(:disabled):hover, .icon-button:not(:disabled):hover { background: #e9eef2; border-color: #cbd5de; }

.workbench {
  display: grid;
  grid-template-columns: minmax(248px, .91fr) minmax(340px, 2.65fr) minmax(247px, .86fr);
  align-items: start;
  gap: 14px;
  max-width: 1850px;
  margin-inline: auto;
  padding: 17px clamp(12px, 2vw, 30px) 0;
}
.panel { background: var(--paper); border: 1px solid var(--border); border-radius: 11px; min-width: 0; }
.settings-section { padding: 15px 14px; display: grid; gap: 11px; }
.settings-section + .settings-section { border-top: 1px solid #e6ebef; }
h2 { font-size: 15px; font-weight: 700; letter-spacing: -.025em; }
.field, .fields { min-width: 0; }
.field { display: grid; gap: 5px; align-content: start; color: #354457; font-size: 12px; font-weight: 640; }
.fields { display: grid; gap: 8px; }
.fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-two { grid-column: 1 / -1; }
.scr-fields { display: grid; gap: 8px; padding: 9px; background: #f2f6f7; border: 1px solid #dde7e8; border-radius: 8px; }
.scr-fields > button { justify-self: start; font-size: 11px; }
input:not([type=checkbox]):not([type=range]):not([type=file]), select {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid #d6dfe7;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--ink);
  background: #fbfcfd;
  font-weight: 520;
}
input[type=number] { appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { appearance: none; margin: 0; }
input[type=number]:disabled { opacity: .48; }
input[type=number]:invalid { border-color: #c85150 !important; }
input[type=number]::placeholder { font-size: 11px; color: #627181; }
.input-unit {
  border-radius: 6px;
  display: flex;
  align-items: stretch;
  min-width: 0;
  border: 1px solid #d6dfe7;
  background: #fbfcfd;
}
.input-unit:focus-within { outline: 2px solid #1b7d82; outline-offset: 1px; }
label.field .input-unit input[type=number] { height: 32px; min-width: 0; border: 0; background: transparent; outline: 0; padding-inline: 7px 1px; }
.input-unit:has(input:invalid) { border-color: #c85150; }
.input-unit > span { flex: none; align-self: center; padding: 0 6px 0 2px; color: #5b6978; font-size: 10px; font-weight: 540; white-space: nowrap; }
.field-note, .small-output { color: var(--muted); font-size: 11px; line-height: 1.55; font-weight: 500; }
.small-output:empty, .field-note:empty { display: none; }
details { font-size: 12px; }
details[open] > :not(summary) { margin-top: 9px; }
summary { color: #3e4d5c; font-weight: 650; cursor: pointer; padding-block: 4px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #455465; }
.check input { accent-color: var(--teal); width: 14px; height: 14px; margin: 0; }
.material-table { display: grid; grid-template-columns: minmax(0, 1.1fr) repeat(2,minmax(0,1fr)); gap: 5px; align-items: center; color: #435364; font-size: 11px; }
.material-table small { display: block; color: var(--muted); }
.material-table input[type=number] { padding-inline: 5px; height: 30px; font-size: 12px; }
.text-button { padding: 2px 0; font-size: 12px; color: #8d331e; text-decoration: underline; text-underline-offset: 2px; }

.workspace { display: grid; gap: 11px; min-width: 0; }
.stage { overflow: hidden; }
.stage-head, .stage-footer { min-height: 48px; padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.stage-head { min-height: 54px; }
.stage-head button, .stage-footer button { font-size: 12px; }
.tab { border: 1px solid transparent; }
.tab[aria-pressed=true] { background: #e9f2f0; color: #194e49; border-color: #cadfd9; }
.tab[aria-pressed=false]:not(:disabled):hover { background: #f0f3f5; }
.icon-button { height: 32px; min-width: 34px; text-align: center; padding: 3px 7px; line-height: 1; background: #f5f7f9; border-color: #e0e5e9; }
#undo, #redo { font-size: 17px; }
.plate-bar {
  padding: 8px 12px 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  border-top: 1px solid #e4e9ee;
}
.plate-size { flex: 1 1 265px; max-width: 370px; display: grid; align-items: center; grid-template-columns: auto 1fr; gap: 10px; }
.plate-size h2 { font-size: 12px; }
.plate-size .field { gap: 3px; }
.viewport-controls { display: flex; align-items: center; gap: 4px; }
.viewport-controls button { height: 28px; min-width: 28px; padding-inline: 5px; font-size: 12px; }
#pan[aria-pressed=true] { background: #e9f2f0; border-color: #a6c9c0; color: #194e49; }
.canvas-shell { height: clamp(350px, 54vh, 720px); position: relative; background: var(--board); overflow: auto; overscroll-behavior: contain; }
.canvas-viewport { position: relative; width: 100%; height: 100%; }
#plate {
  position: absolute;
  top: var(--plate-y, 27px);
  left: var(--plate-x, 38px);
  width: var(--plate-w, 1px);
  height: var(--plate-h, 1px);
  box-shadow: 0 0 0 1px #a3b3c776;
  cursor: crosshair;
  touch-action: none;
}
#plate[data-tool=erase] { cursor: cell; }
#plate.pan-enabled { cursor: grab; }
#plate[data-panning=true] { cursor: grabbing; }
.ruler-x, .ruler-y { position: absolute; display: flex; justify-content: space-between; color: #b1c1d1; font-size: 10px; pointer-events: none; font-variant-numeric: tabular-nums; }
.ruler-x { top: calc(var(--plate-y, 27px) - 19px); left: var(--plate-x, 38px); width: var(--plate-w, 1px); }
.ruler-y { top: var(--plate-y, 27px); right: calc(100% - var(--plate-x, 38px) + 7px); height: var(--plate-h, 1px); flex-direction: column; align-items: flex-end; text-align: right; line-height: 1.1; max-width: 33px; }
.ruler-y span:last-child { white-space: normal; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: #495969; font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.swatch { width: 10px; height: 10px; display: inline-block; flex: none; border-radius: 2px; }
.swatch.sic { background: #29384b; }
.swatch.aln { background: #29645e; }
.swatch.heater { background: #f78c54; border: 1px solid #b96137; }
.heat-legend { display: flex; align-items: center; gap: 7px; color: #495969; font-size: 11px; }
.heat-legend i {
  display: inline-block;
  width: clamp(48px, 10vw, 155px);
  height: 7px;
  border-radius: 20px;
  background: linear-gradient(to right,#191f4d,#30357c,#6c398b,#a73e77,#dd5b51,#fa9943,#fcdc7b,#fff6b9);
}
#position { font-size: 11px; font-variant-numeric: tabular-nums; color: #435365; margin-left: auto; }
.timeline { min-height: 48px; border-top: 1px solid #e7ecf0; display: flex; align-items: center; gap: 10px; padding: 7px 12px; }
.timeline button { font-size: 11px; }
.timeline input { accent-color: var(--accent); width: 100%; min-width: 35px; }
.timeline output { min-width: max-content; font-size: 12px; font-variant-numeric: tabular-nums; }
.status { border-radius: 8px; padding: 9px 12px; background: #e4ebf1; border: 1px solid #d7e1e9; color: #354a5f; font-size: 12px; line-height: 1.45; }
.status[data-tone=error] { background: #fbe8e5; border-color: #f0c5bd; color: #7e2b23; }
.status[data-tone=success] { background: #e4f1eb; border-color: #cfe4d8; color: #205843; }
.progress { height: 6px; border-radius: 5px; background: #dbe4eb; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 7px; }
.stat { padding: 10px; display: grid; gap: 5px; line-height: 1.3; }
.stat span { color: #4e5d6b; font-size: 11px; }
.stat strong { font-size: clamp(13px, 1.25vw, 19px); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#maxTemp { color: #9d3e24; }

.tool-targets { display: grid; grid-template-columns: 1.55fr 1fr 1fr; gap: 5px; }
.choice { color: #435365; background: #f6f8fa; border-color: #e1e6eb; font-size: 12px; padding: 8px 4px; min-width: 0; }
.choice[aria-pressed=true] { color: #8e321a; background: var(--accent-light); border-color: #edb6a0; }
.choice[aria-pressed=false]:hover { background: #ebf0f4; }
.tool-targets .choice { display: flex; align-items: center; justify-content: center; gap: 5px; line-height: 1.2; white-space: nowrap; }
.tool-grid { display: grid; grid-template-columns: repeat(2,minmax(0, 1fr)); gap: 5px; }
#trackFields { display: grid; gap: 8px; }
#drawModes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#drawModes button { font-size: 11px; }
.placement-buttons.cad-picks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.controller-results { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 8px 12px; color: #19524b; background: #edf6f2; border-top: 1px solid #d8e9e2; font-size: 12px; font-variant-numeric: tabular-nums; }
.track-readout { color: #244e4b; background: #e9f2f0; border-radius: 5px; padding: 6px 7px; font-size: 11px; }
.track-readout:empty { display: none; }
.sketch-options { display: flex; flex-wrap: wrap; gap: 7px 12px; }
#radius { align-self: end; padding: 0 0 8px 3px; }
#arcFields #radius { grid-column: 1 / -1; padding: 0; }
.coordinates { display: grid; gap: 8px; border-top: 1px solid #e4e9ee; padding-top: 9px; }
.placement-buttons { display: grid; grid-template-columns: 1fr 1.35fr; gap: 5px; }
.placement-buttons button { font-size: 11px; padding-inline: 4px; }
.soft { color: #862d16; border-color: #eab39f; background: var(--accent-light); }
.soft:not(:disabled):hover { color: #fff; }
.pattern-details p:not(.field-note) { display: flex; justify-content: space-between; align-items: center; gap: 7px; color: #4b5a69; font-size: 12px; }
.pattern-details strong { color: var(--ink); font-variant-numeric: tabular-nums; }
#featureHint { color: #8a4b23; }
.app-footer { max-width: 1850px; margin-inline: auto; padding: 12px clamp(12px,2vw,30px) 15px; color: #596777; font-size: 11px; }

@media (max-width: 1000px) {
  .workbench { grid-template-columns: minmax(0, 1fr) minmax(238px, .5fr); }
  .workspace { grid-row: 1; grid-column: 1; }
  .tools { grid-row: 1; grid-column: 2; }
  .settings { grid-column: 1 / -1; }
  #settings { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); align-items: start; }
  #settings > .settings-section + .settings-section { border-top: 0; border-left: 1px solid #e6ebef; }
}
@media (max-width: 690px) {
  .topbar { align-items: flex-start; padding: 10px; }
  .brand { gap: 7px; }
  .brand h1 { font-size: 17px; }
  .brand-mark { width: 33px; height: 33px; }
  .brand p { font-size: 10px; }
  .project-actions { gap: 4px; }
  .project-actions button { font-size: 11px; padding: 6px 7px; }
  .workbench { grid-template-columns: minmax(0,1fr); gap: 10px; padding-top: 10px; }
  .workspace, .tools, .settings { grid-row: auto; grid-column: 1; }
  .workspace { order: -2; }
  .tools { order: -1; }
  .canvas-shell { height: clamp(235px, 50vw, 380px); }
  #settings { display: block; }
  #settings > .settings-section + .settings-section { border-left: 0; border-top: 1px solid #e6ebef; }
}
@media (max-width: 385px) {
  .topbar { flex-wrap: wrap; }
  .stage-head { padding-inline: 6px; }
  .stage-head button { font-size: 11px; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .plate-size { grid-template-columns: minmax(0,1fr); gap: 4px; }
}

