:root {
  --bg: #E4E6E1;
  --surface: #F3F4F1;
  --ink: #1F2622;
  --muted: #5E6862;
  --line: #C3C8C1;
  --board: #9C7A55;
  --board-edge: #7A5C3D;
  --slot: #2A211A;
  --guide: #2F5FC4;
  --warn: #A8431E;
  --field: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1F1C;
    --surface: #242925;
    --ink: #E3E7E2;
    --muted: #9AA39D;
    --line: #3A413C;
    --board: #7E6244;
    --board-edge: #5F4830;
    --slot: #141110;
    --guide: #7FA2EE;
    --warn: #E68A62;
    --field: #1B1F1C;
  }
}
:root[data-theme="dark"] {
  --bg: #1B1F1C;
  --surface: #242925;
  --ink: #E3E7E2;
  --muted: #9AA39D;
  --line: #3A413C;
  --board: #7E6244;
  --board-edge: #5F4830;
  --slot: #141110;
  --guide: #7FA2EE;
  --warn: #E68A62;
  --field: #1B1F1C;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Barlow", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
.app {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
aside {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 24px 22px 32px;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
h1 {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-weight: 600;
  font-size: 30px;
  line-height: 1.05;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.units { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin: 0 0 20px; }
.units button { font: inherit; font-size: 14px; background: transparent; color: var(--ink); border: 0; padding: 5px 14px; cursor: pointer; }
.units button + button { border-left: 1px solid var(--line); }
.units button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
fieldset {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 16px 0 6px;
}
legend {
  font-weight: 600;
  font-size: 14px;
  padding: 0 0 8px;
  float: left;
  width: 100%;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; clear: both; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
label.f { display: block; margin-bottom: 10px; }
label.f span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
label.f span.scrub { width: fit-content; cursor: ew-resize; user-select: none; touch-action: none; }
body.scrubbing, body.scrubbing * { cursor: ew-resize !important; user-select: none; }
input[type=number], select {
  width: 100%;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--guide);
  outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; clear: both; }
.check input { width: 16px; height: 16px; accent-color: var(--guide); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; clear: both; }
.presets button, .ghost {
  font: inherit; font-size: 13px;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 9px; cursor: pointer;
}
.presets button:hover, .ghost:hover { border-color: var(--ink); }
main { padding: 24px 28px 32px; display: flex; flex-direction: column; min-width: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.stage {
  flex: 1 0 auto;
  min-height: 420px;
  height: 62vh;
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
}
#preview { width: 100%; height: 100%; }
.bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 14px; border-top: 1px solid var(--line); padding-top: 14px;
}
.stats { display: flex; flex-wrap: wrap; gap: 22px; }
.stat b {
  display: block;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-weight: 600; font-size: 24px; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat small { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; }
.primary {
  font: inherit; font-weight: 600;
  background: var(--ink); color: var(--surface);
  border: 1px solid var(--ink); border-radius: 4px;
  padding: 9px 16px; cursor: pointer;
}
.primary:hover { opacity: 0.9; }
.msg { font-size: 13px; color: var(--muted); min-height: 1.4em; margin-top: 8px; }
.msg.warn { color: var(--warn); }
details { margin-top: 14px; }
summary { cursor: pointer; font-size: 14px; color: var(--muted); }
textarea {
  width: 100%; height: 180px; margin-top: 8px;
  font: 12px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 4px; padding: 8px;
  resize: vertical;
}
.note { font-size: 13px; color: var(--muted); margin: 16px 0 0; }
.thick { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; clear: both; }
.thick button { font: inherit; font-size: 13px; background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 3px 8px; cursor: pointer; font-variant-numeric: tabular-nums; }
.thick button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.plan { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.plan h2 { font-family: "Barlow Condensed", "Arial Narrow", sans-serif; font-weight: 600; font-size: 22px; margin: 0 0 4px; }
.plan .fit { margin: 0 0 12px; font-size: 14px; }
.plan .fit.warn { color: var(--warn); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 12px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 13px; }
td small { display: block; color: var(--muted); font-size: 12px; white-space: normal; }
.plan ol { margin: 12px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); max-width: 72ch; }
.plan ol li { margin-bottom: 4px; }
.src { font-size: 12px; color: var(--muted); margin: 10px 0 0; max-width: 72ch; }
.note p { margin: 0 0 6px; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; height: auto; overflow: visible; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); height: auto; overflow: visible; }
  main { height: auto; overflow: visible; }
  .stage { min-height: 320px; }
}
