:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: #172f36;
  background: #edf2f2;
  --ink: #172f36;
  --muted: #50686e;
  --line: #d7e2e2;
  --teal: #087c6b;
  --pale: #e5f5ee;
}
* { box-sizing: border-box }
body { margin: 0 }
[hidden] { display: none !important }
h1,h2,p,dl,dd { margin: 0 }
button,input { font: inherit }
button { cursor: pointer }
button:disabled { cursor: default }
:focus-visible { outline: 3px solid #197dbe; outline-offset: 3px }
.masthead {
  background: #10262e;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 25px;
  min-height: 82px;
  padding: 14px clamp(18px,3vw,48px);
  border-bottom: 3px solid #6bddb9;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; letter-spacing: .12em; font-weight: 800; white-space: nowrap }
.brand svg { width: 35px; fill: none; stroke: #77dfba; stroke-width: 1.8; stroke-linejoin: round }
.brand b { color: #80dfc0; font-weight: 650 }
.mast-title { border-left: 1px solid #4b6269; padding-left: 25px }
.mast-title h1 { font-size: clamp(17px,2.4vw,24px); letter-spacing: -.025em }
.mast-title p { color: #bad1d3; font-size: 13px; margin-top: 2px }
main { display: grid; grid-template-columns: minmax(290px,340px) minmax(0,1fr); gap: 22px; max-width: 1640px; margin: auto; padding: 22px clamp(14px,2.5vw,36px) 36px; align-items: start }
.controls,.preview-card,.summary { border: 1px solid var(--line); background: #fff; border-radius: 12px; box-shadow: 0 2px 6px #173a4109 }
.controls section { padding: 16px 18px }
.controls section + section { border-top: 1px solid var(--line) }
h2 { font-size: 16px; font-weight: 750; letter-spacing: -.012em }
.controls h2 { margin-bottom: 10px }
h2 span { color: var(--muted); font-size: 13px; font-weight: 500; margin-left: 4px }
fieldset { min-width: 0; border: 0; padding: 0; margin: 0 }
legend { color: var(--muted); font-size: 13px; padding: 0; margin-bottom: 6px }
.pattern-group + .pattern-group { margin-top: 8px }
.pattern-group > div { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px }
.pattern,.segments label { position: relative; cursor: pointer }
.pattern input,.segments input { position: absolute; width: 1px; height: 1px; opacity: 0 }
.pattern-inner { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; font-weight: 650; line-height: 1.15 }
.pattern input:checked + .pattern-inner,.segments input:checked + span { background: var(--pale); border-color: #3ba591; color: #075e51 }
.pattern input:focus-visible + .pattern-inner,.segments input:focus-visible + span { outline: 3px solid #197dbe; outline-offset: 2px }
.pattern svg { width: 26px; height: 26px; flex: none; color: #087766; border-radius: 4px; background: #eef4f3; object-fit: cover }
.fields { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px }
.fields.two { grid-template-columns: repeat(2,minmax(0,1fr)) }
.fields label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600 }
.fields input { min-width: 0; width: 100%; padding: 8px; border: 1px solid #c8d7d9; border-radius: 6px; color: var(--ink); background: white; font-variant-numeric: tabular-nums }
.fields input[aria-invalid=true] { border-color: #ab4434 }
.segments { display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; margin-bottom: 10px }
.segments span { display: block; text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 6px 2px; font-size: 13px; font-weight: 650 }
.note { color: var(--muted); font-size: 13px; line-height: 1.5 }
#returns { margin-bottom: 8px }
.workspace { display: grid; gap: 14px; min-width: 0 }
.preview-card { overflow: hidden }
.preview-header,.summary header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px }
.preview-header p { color: var(--muted); font-size: 13px; margin-top: 3px }
.toolbar { display: flex; border: 1px solid var(--line); border-radius: 7px }
.toolbar button { border: 0; min-height: 34px; min-width: 36px; background: transparent; color: var(--ink); font-size: 14px; font-weight: 650 }
.toolbar button + button { border-left: 1px solid var(--line) }
.toolbar button:hover:not(:disabled) { background: var(--pale) }
.toolbar button:disabled { color: #657f84 }
.drawing { position: relative; display: grid; place-items: center; background: radial-gradient(circle, #cddddd 1px, transparent 1.15px) center / 16px 16px, #f3f8f7; border-block: 1px solid var(--line); overflow: hidden }
#drawing { display: block; width: 100%; height: auto; aspect-ratio: 900/560; max-height: 62vh }
#error { position: absolute; max-width: 85%; border-radius: 6px; background: #fff2ed; color: #8d3526; padding: 12px 16px; border: 1px solid #edc0b5 }
.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; color: var(--muted); font-size: 13px }
.legend span { display: flex; align-items: center; gap: 6px }
.drawing-note { margin-left: auto }
.key { width: 16px; border-top: 2px solid #29474f }
.key.border { border-top: 2px dashed #7d969c }
.key.cut { border-color: #087c6b }
.key.fold { border-top: 2px dashed #b35d27 }
.summary header { padding-bottom: 9px }
.summary dl { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); margin: 0 16px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden }
.summary dl div { min-width: 0; padding: 9px 10px }
.summary dl div + div { border-left: 1px solid var(--line) }
.summary dt { color: var(--muted); font-size: 13px }
.summary dd { margin-top: 4px; font-size: clamp(13px,1.35vw,19px); font-weight: 730; font-variant-numeric: tabular-nums; overflow-wrap: anywhere }
.blank-stat { background: #eaf6f0 }
#blank-status { display: inline-block; font-size: 12px; font-weight: 650; color: #166b5b }
#export-note { margin: 8px 16px 12px }
@media (max-width: 760px) {
  main { grid-template-columns: 1fr; gap: 14px }
  .masthead { gap: 12px }
  .mast-title { padding-left: 12px }
  .pattern-inner,.fields label { font-size: 14px }
  #drawing { max-height: none }
}
@media (max-width: 480px) {
  .summary dl { grid-template-columns: repeat(2,minmax(0,1fr)) }
  .summary dl div:nth-child(3) { border-left: 0 }
  .summary dl div:nth-child(n+3) { border-top: 1px solid var(--line) }
  .drawing-note { margin-left: 0 }
}
.controls .summary { border: 0; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; box-shadow: none }
.summary header { padding: 0 0 10px }
.summary header h2 { margin: 0 }
.summary dl { grid-template-columns: repeat(2,minmax(0,1fr)); margin: 0 }
.summary dl div:nth-child(3) { border-left: 0 }
.summary dl div:nth-child(n+3) { border-top: 1px solid var(--line) }
.summary dd { font-size: 15px }
#export-note { margin: 8px 0 0 }
@media (min-width: 761px) {
  .workspace { position: sticky; top: 16px }
  #drawing { max-height: 73vh }
}
.density-note { margin: 0 0 8px }
