:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --paper: #f4f1e7;
  --card: #fffcf4;
  --ink: #292d25;
  --muted: #5c5f52;
  --line: #ddd8ca;
  --blueprint: #132e32;
  --blueprint-line: #3e5959;
  --blueprint-light: #b8cfca;
  --accent: #9b4029;
  background: var(--paper);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 2px solid #bd592f; outline-offset: 3px; }
.shell { width: min(100% - 64px, 1260px); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }

.masthead { border-bottom: 1px solid var(--line); }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 16px; }
.file-actions, .part-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.file-actions button, .part-actions button {
  min-height: 40px;
  border: 1px solid #bbb6a7;
  border-radius: 5px;
  background: var(--card);
  padding: 7px 12px;
  color: var(--ink);
  font-size: .84rem;
  font-weight: 700;
}
.file-actions button:hover:not(:disabled), .part-actions button:hover:not(:disabled) { background: #eee6d5; }
.file-actions .primary { color: #fff9eb; background: #333e32; border-color: #333e32; }
.file-actions .primary:hover:not(:disabled) { background: #4d5946; }
.primary span { padding-left: 3px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-block: clamp(32px, 5.4vw, 77px) 28px; }
.intro h1 { margin: 0; font-size: clamp(2.38rem, 5.6vw, 5rem); line-height: 1.03; letter-spacing: -.06em; }
.intro p { margin: 13px 0 0; color: var(--muted); font-size: clamp(.9rem, 1.5vw, 1.04rem); line-height: 1.6; word-break: keep-all; }
.jump-link { display: none; color: var(--accent); font-size: .83rem; font-weight: 700; min-height: 36px; align-items: center; gap: 5px; }
.file-status { font-size: .86rem; color: #354a30; margin: 0 0 11px; }
.file-status:empty, .validation:empty { display: none; }
.file-status[data-error="true"], .validation { color: #8e301e; }

.workspace { display: grid; grid-template-columns: minmax(315px, .92fr) minmax(0, 1.82fr); gap: clamp(12px, 2vw, 25px); align-items: start; }
.inputs, .results { min-width: 0; display: grid; gap: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.panel-header, .drawing-heading { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; padding: 17px 19px 12px; }
.panel-header h2, .drawing-heading h2 { margin: 0; font-size: 1.16rem; letter-spacing: -.045em; }
.units { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.stock-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 0 19px 17px; }
.stock-fields label, .part-fields label { display: grid; gap: 4px; color: var(--muted); font-size: .76rem; font-weight: 650; }
.stock-fields input, .part input:not([type="checkbox"]) {
  width: 100%;
  min-height: 37px;
  border: 1px solid #c9c4b6;
  border-radius: 5px;
  background: #fffefb;
  padding: 6px 8px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stock-fields input:invalid, .part input:invalid { border-color: #ac4630; }
.part-list { display: grid; gap: 8px; padding: 0 12px; }
.part { padding: 8px; border: 1px solid #e4ddd0; background: #f7f3e9; border-radius: 7px; }
.part-heading { display: grid; grid-template-columns: 31px minmax(0, 1fr) 36px; align-items: center; gap: 7px; }
.part-label { min-width: 28px; min-height: 28px; display: grid; place-items: center; border: 1px solid #0002; border-radius: 4px; font: 750 .75rem ui-monospace, monospace; color: #282713; }
.part-name { min-width: 0; }
.part .part-name input { font-size: .86rem; font-weight: 700; }
.remove-part { width: 36px; min-height: 36px; border: 0; border-radius: 5px; background: transparent; color: #645b50; font-size: 1.28rem; }
.remove-part:hover { background: #f2dfd4; color: #902e1c; }
.part-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(47px, .74fr); align-items: end; gap: 6px; margin-top: 6px; }
.part-fields input:not([type="checkbox"]) { font-size: .85rem; }
.part-fields .rotate { display: flex; align-items: center; gap: 4px; min-height: 37px; cursor: pointer; white-space: nowrap; }
.rotate input { appearance: auto; width: 15px; height: 15px; margin: 0; accent-color: #435d43; }
.part-actions { justify-content: space-between; padding: 10px 12px 12px; }
.part-actions .quiet { border-color: transparent; background: transparent; color: var(--accent); }
.validation { margin: 0; padding: 10px 12px; background: #fae5dc; border: 1px solid #e7b2a3; border-radius: 6px; font-size: .86rem; line-height: 1.55; }

.drawing {
  min-width: 0;
  scroll-margin-top: 16px;
  padding: clamp(12px, 2.5vw, 22px);
  border: 1px solid #091e21;
  border-radius: 11px;
  background: var(--blueprint);
  color: #fff4df;
}
.drawing-heading { padding: 0 0 13px; }
.drawing-heading span, .metrics dt, .sheet-controls > span:last-child { color: var(--blueprint-light); font-size: .78rem; }
.drawing-heading span { text-align: right; line-height: 1.3; }
.drawing[data-stale] .metrics, .drawing[data-stale] .sheet-wrap { opacity: .62; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 12px; border-block: 1px solid #476261; }
.metrics > div { padding: 9px 9px 10px; }
.metrics > div:first-child { padding-left: 0; }
.metrics > div + div { border-left: 1px solid #476261; padding-left: 11px; }
.metrics dd { margin: 4px 0 0; font: 650 clamp(1rem, 3vw, 1.7rem)/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace; white-space: nowrap; letter-spacing: -.07em; }
.strategy-list { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.strategy-list button { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px 10px; min-height: 44px; padding: 7px 10px; text-align: left; border: 1px solid #5c7875; border-radius: 5px; font-weight: 700; color: #fff4df; background: #193a3e; font-size: .83rem; }
.strategy-list button:hover { background: #28474a; }
.strategy-list button[aria-pressed="true"] { color: #182b26; border-color: #e4bc80; background: #e4bc80; }
.strategy-list small { font-variant-numeric: tabular-nums; font-size: .77rem; font-weight: 600; }
.drawing :focus-visible { outline-color: #f8c88f; }
.sheet-controls { display: flex; min-height: 42px; margin-top: 10px; align-items: center; gap: 9px; font-size: .81rem; }
.sheet-controls button { color: #fff4df; min-width: 37px; min-height: 37px; background: #193a3e; border: 1px solid #5c7875; border-radius: 5px; }
.sheet-controls button:hover:not(:disabled) { background: #325358; }
#board-index { white-space: nowrap; font-variant-numeric: tabular-nums; }
#board-use { margin-left: auto; text-align: right; }
.sheet-wrap {
  --sheet-height: clamp(180px, 29vw, 380px);
  display: grid;
  place-items: center;
  min-height: clamp(150px, 22vw, 295px);
  position: relative;
  overflow: hidden;
  padding: 11px;
  border: 1px solid #527071;
  margin-top: 7px;
  border-radius: 5px;
  background-color: #15383d;
  background-image: linear-gradient(#b3d7d210 1px, transparent 1px), linear-gradient(90deg,#b3d7d210 1px, transparent 1px);
  background-size: 14px 14px;
}
.sheet {
  position: relative;
  aspect-ratio: var(--ratio, 2);
  width: min(100%, calc(var(--sheet-height) * var(--ratio, 2)));
  outline: 1px solid #bfd4c9;
  box-shadow: 0 3px 17px #0716199e;
  background: repeating-linear-gradient(135deg, #779f9b49 0 1px, transparent 1px 7px), #12282c;
}
.piece {
  position: absolute;
  display: grid;
  place-content: center;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #282713;
  box-shadow: inset 0 0 0 1px #553b3866;
  background-color: var(--part-fill);
  background-image: repeating-linear-gradient(0deg, #3f310510 0 1px, transparent 1px 9px);
  font: 750 clamp(.55rem, 1.1vw, .88rem)/1 ui-monospace, "SFMono-Regular", monospace;
}
.piece[data-rotated] { background-image: repeating-linear-gradient(90deg, #3f310510 0 1px, transparent 1px 9px); }
.piece:hover { filter: brightness(1.13); z-index: 1; }
.piece[aria-pressed="true"], .piece:focus-visible { z-index: 2; outline-offset: -2px; outline: 2px solid #162f33; box-shadow: 0 0 0 2px #fff5cf; filter: brightness(1.17); }
.diagram-empty { max-width: 30ch; margin: 0; padding: 16px 9px; color: #fff2d9; text-align: center; font-size: .9rem; line-height: 1.5; }
.piece-detail { min-height: 1.6em; margin: 8px 0 0; color: #d4e3dc; font-size: .78rem; line-height: 1.55; overflow-wrap: anywhere; }

.coordinates { padding-bottom: 4px; }
.coordinate-table { margin-inline: 15px; }
table { width: 100%; border-collapse: collapse; table-layout: auto; text-align: left; font-size: .8rem; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 700; }
td, th { padding: 7px 4px; border-bottom: 1px solid #e9e3d7; }
td:not(:first-child), th:not(:first-child) { text-align: right; }
tr:last-child td { border-bottom: 0; }
td:first-child { overflow-wrap: anywhere; }
td:first-child button { position: relative; text-align: left; border: 0; border-radius: 3px; background: transparent; color: inherit; padding: 4px 4px 4px 13px; min-height: 30px; font-size: inherit; }
td:first-child button::before { content: ""; position: absolute; width: 7px; height: 7px; border: 1px solid #0003; left: 1px; top: .8em; border-radius: 50%; background: var(--part-fill); }
td:first-child button[aria-pressed="true"], td:first-child button:hover { background: #eee4d2; }
.unplaced { margin: 10px 12px 8px; border: 1px solid #e7b2a3; border-radius: 5px; padding: 9px; background: #fbeee7; font-size: .82rem; color: #7e2c20; overflow-wrap: anywhere; }
.unplaced h3, .unplaced p { margin: 0; }
.unplaced h3 { font-size: .88rem; }
.unplaced ul { margin-block: 6px; padding-left: 20px; line-height: 1.5; }
.unplaced p { line-height: 1.5; }

.model { margin-block: 26px 52px; max-width: 72ch; color: var(--muted); font-size: .86rem; line-height: 1.6; }
.model summary { color: var(--ink); font-weight: 700; cursor: pointer; width: fit-content; }
.model p { margin: 8px 0 0; }

@media (max-width: 780px) {
  .shell { width: min(100% - 32px, 600px); }
  .workspace { grid-template-columns: 1fr; }
  .intro { display: grid; justify-content: normal; margin-block: 29px 20px; gap: 3px; }
  .jump-link { display: inline-flex; width: fit-content; }
  .sheet-wrap { --sheet-height: clamp(175px, 54vw, 340px); }
}

@media (max-width: 390px) {
  .masthead-inner { gap: 6px; min-height: 56px; }
  .masthead .brand { font-size: 16px; }
  .masthead .brand-mark { width: 16px; margin-right: 5px; }
  .file-actions { gap: 4px; }
  .file-actions button { padding-inline: 6px; font-size: .74rem; }
  .stock-fields { padding-inline: 13px; }
  .panel-header { padding-inline: 13px; }
  .metrics dt, .drawing-heading span { font-size: .72rem; }
  .coordinate-table { margin-inline: 9px; }
}
