:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --ink: #20231f;
  --muted: #687064;
  --line: #d7d0c1;
  --panel: #fffdf7;
  --panel-strong: #f0eadc;
  --accent: #1b6f78;
  --accent-dark: #11535b;
  --accent-soft: #d8ecec;
  --warn: #a14b21;
  --shadow: 0 18px 40px rgba(50, 44, 32, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(32, 35, 31, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(32, 35, 31, 0.035) 1px, transparent 1px), var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    transform 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #aeb7aa;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.primary:disabled {
  border-color: var(--line);
  background: var(--panel-strong);
  color: var(--muted);
  cursor: default;
  transform: none;
}

button.ghost {
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.7rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

.unit-toggle,
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.unit-toggle button,
.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-weight: 700;
}

.unit-toggle button.active,
.segmented button.active {
  background: var(--accent);
  color: white;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.panel,
.layout-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.layout-area {
  min-width: 0;
  padding: 16px;
}

fieldset {
  display: grid;
  gap: 12px;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.divider-list-wrap,
.sheet-picker,
.compact + .compact {
  margin-top: 12px;
}

.sheet-picker[hidden],
.piece-picker[hidden] {
  display: none;
}

.piece-picker {
  gap: 0;
  margin: 14px 0 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.piece-picker legend {
  margin: 0;
  padding: 0 4px;
  font-size: 0.9rem;
}

.piece-list {
  max-height: 180px;
  overflow: auto;
}

.piece-choice {
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  cursor: pointer;
}

.piece-choice input {
  width: 16px;
  min-height: auto;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.piece-choice .piece-size {
  font-size: 0.8rem;
  font-weight: 500;
}

.piece-select-all {
  border-bottom: 1px solid var(--line);
}

.section-heading,
.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.canvas-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.readout {
  min-width: max-content;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.plan-frame,
.cut-frame {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf5;
}

.plan-frame {
  min-height: 520px;
}

.cut-frame {
  height: 440px;
  background: var(--panel-strong);
  margin-top: 14px;
}

svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  touch-action: none;
}

.divider-list {
  display: grid;
  gap: 10px;
}

.divider-row {
  display: grid;
  grid-template-columns: 1fr 92px 36px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.divider-row strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.9rem;
}

.divider-row input {
  min-height: 36px;
  padding: 6px 8px;
}

.icon-button {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  color: var(--warn);
  font-size: 1.3rem;
  line-height: 1;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.drawer-outline {
  fill: #fffef9;
  stroke: #1d2520;
  stroke-width: 2;
}

.drawer-grid {
  stroke: rgba(32, 35, 31, 0.12);
  stroke-width: 1;
}

.divider-line {
  fill: var(--accent-soft);
  stroke: var(--accent-dark);
  stroke-width: 1.4;
  cursor: grab;
}

.divider-line.active {
  fill: #f5cf79;
  stroke: #8c5b00;
}

.dimension-line {
  stroke: #636b61;
  stroke-width: 1;
  marker-start: url(#arrow);
  marker-end: url(#arrow);
}

.dimension-text {
  fill: #3e443d;
  font-size: 13px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fffef9;
  stroke-width: 4;
}

.piece {
  fill: #f9f0d2;
  stroke: #141814;
  stroke-width: 0.7;
}

.piece-label {
  fill: #242821;
  font-size: 9px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(280px, 360px) 1fr;
  }

  .output-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .workspace,
  .canvas-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace {
    gap: 12px;
  }

  .plan-frame {
    min-height: 380px;
  }

  .cut-frame {
    height: 320px;
  }

  .readout {
    width: fit-content;
  }
}
