:root {
  color-scheme: light;
  --paper: #fffdfa;
  --canvas: #f3eee8;
  --ink: #302521;
  --muted: #6c5b52;
  --accent: #843c32;
  --deep: #522b26;
  --line: #ded2c9;
  --wash: #f5e9e3;
  font: 16px/1.5 "Pretendard", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-padding-top: 20px; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
h1, h2, h3, p, figure { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .42; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.masthead { background: var(--deep); color: #fff8ef; border-bottom: 4px solid #a56354; }
.masthead-inner {
  max-width: 1376px; padding: 11px 32px; margin: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 13px; min-height: 48px; text-decoration: none; }
.brand img { width: 122px; display: block; filter: brightness(0) invert(1); }
.masthead nav { display: flex; flex-wrap: wrap; gap: 8px 25px; }
.masthead nav a { text-decoration: none; font-size: .875rem; }
.masthead nav a:hover { text-decoration: underline; text-underline-offset: .35em; }
.masthead :focus-visible { outline-color: #ffe4d8; }
main { max-width: 1376px; padding: 0 32px 28px; margin: auto; }
.hero { padding: 37px 0 28px; display: flex; justify-content: space-between; align-items: end; gap: 18px; }
.hero h1 { font-size: clamp(1.85rem, 4vw, 3.25rem); line-height: 1.18; letter-spacing: -.065em; }
.hero p { margin-top: 11px; color: var(--muted); word-break: keep-all; }
.workspace { display: grid; grid-template-columns: minmax(0, .88fr) minmax(0, 1.5fr); align-items: start; gap: 20px; }
.panel { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 13px; padding: 23px; }
.panel-title { font-size: 1.35rem; letter-spacing: -.035em; }
.panel-heading { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.status { font-size: .85rem; color: var(--accent); font-weight: 700; }
.status:empty { display: none; }

fieldset { min-width: 0; margin: 17px 0 0; border: 0; border-bottom: 1px solid var(--line); padding: 0 0 18px; }
legend { padding: 0; font-size: 1rem; margin-bottom: 10px; font-weight: 800; }
label { display: block; min-width: 0; font-size: .875rem; font-weight: 700; }
.unit { color: var(--muted); font-size: .8rem; font-weight: 500; white-space: nowrap; }
input:not([type=checkbox]), select {
  display: block; width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 9px; background: #fff; min-height: 40px;
}
label > input:not([type=checkbox]), label > select { margin-top: 4px; }
.site-name { margin-top: 12px; }
input[type=checkbox] { accent-color: var(--accent); }
input[type=number] { appearance: textfield; }
input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.two-fields, .cut-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cut-settings { margin-top: 10px; align-items: end; }
.check { display: flex; align-items: center; gap: 5px; min-height: 40px; }
.help { margin-top: 4px; color: var(--muted); font-size: .81rem; }
.row {
  display: grid; grid-template-columns: 28px repeat(2, minmax(0, 1fr)) minmax(36px, .65fr) 34px;
  gap: 6px; align-items: end; margin-bottom: 10px; padding: 9px;
  border: 1px solid var(--line); border-radius: 8px; background: #faf6f2;
}
.piece-index { padding-bottom: 9px; color: var(--accent); font-weight: 800; font-size: .85rem; }
.piece-label { grid-column: 2 / 5; }
.row > .remove { grid-column: 5; grid-row: 1; }
.row > label:nth-of-type(2) { grid-column: 1 / 3; }
.row > label:nth-of-type(4) { grid-column: 4 / 6; }
.fee-row {
  display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, .8fr) minmax(0, 1fr) 34px;
  gap: 6px; align-items: end; margin-top: 8px; padding: 9px;
  border: 1px solid var(--line); border-radius: 8px; background: #faf6f2;
}
.fee-name { grid-column: 1 / 4; }
.fee-row > .remove { grid-column: 4; grid-row: 1; }
.fee-rate { grid-column: 3 / 5; }
.fee-calculation { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; font-size: .875rem; }
.fee-subtotal { color: var(--accent); font-weight: 750; text-align: right; overflow-wrap: anywhere; }
[data-money] { font-variant-numeric: tabular-nums; }
.primary, .secondary, .remove, .step-button {
  display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line);
  background: var(--paper); border-radius: 7px; padding: 8px 12px; font-size: .875rem; font-weight: 750; min-height: 38px;
}
.secondary:hover, .remove:hover:not(:disabled), .step-button:hover:not(:disabled) { background: var(--wash); color: var(--accent); }
.add { margin-top: 6px; }
.remove { width: 34px; min-height: 40px; padding: 0; font-size: 1.1rem; }
.primary { display: flex; width: 100%; margin-top: 16px; background: var(--accent); color: white; border-color: var(--accent); min-height: 48px; font-size: 1rem; }
.primary:hover { background: var(--deep); }
#error { color: #9d2019; font-size: .875rem; margin-top: 9px; }

.empty { display: grid; place-items: center; align-content: center; gap: 18px; min-height: 380px; margin-top: 15px; border: 1px dashed #cdbeb3; border-radius: 9px; background: #faf6f1; padding: 20px; }
.empty p { color: var(--muted); text-align: center; word-break: keep-all; }
.empty-plan {
  width: 94px; height: 120px; border: 1px solid #ac8f82; padding: 5px;
  display: grid; grid-template-columns: 1fr .65fr; grid-template-rows: 1fr 1fr; gap: 3px;
}
.empty-plan span { border: 1px solid #ba9d90; background: #edd5ca; }
.empty-plan span:first-child { grid-row: span 2; background: #e3bcb0; }
.empty-plan span:last-child { background: repeating-linear-gradient(135deg, #faf6f1 0 4px, #e4d5cd 4px 5px); }
.totals { display: grid; grid-template-columns: .75fr 1.1fr 1.3fr; gap: 1px; overflow: hidden; border-radius: 8px; background: #e9d6cd; margin: 15px 0 9px; }
.totals div { min-width: 0; padding: 10px 12px; background: var(--wash); color: var(--deep); font-size: .85rem; }
.totals strong { display: block; font-size: clamp(1rem, 2.4vw, 1.6rem); letter-spacing: -.035em; line-height: 1.3; margin-top: 4px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.note { font-size: .875rem; }
.costs { margin: 10px 0 14px; border-bottom: 1px solid var(--line); padding: 0 0 10px; }
.costs summary { cursor: pointer; font-size: .875rem; font-weight: 700; }
.costs dl { margin: 6px 0 0; }
.costs dl div { display: flex; gap: 12px; justify-content: space-between; font-size: .875rem; padding: 3px 0; }
.costs dt { overflow-wrap: anywhere; }
.costs dd { margin: 0; text-align: right; flex-shrink: 0; }
.offcut-summary { margin: 0 0 12px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.offcut-summary summary { cursor: pointer; font-size: .875rem; font-weight: 700; }
.offcut-summary .note { margin-top: 5px; }
.board-offcuts { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.board-offcuts h4 { margin: 0 0 4px; font-size: .9rem; }
.offcut-list { display: grid; gap: 4px; margin: 6px 0; font-size: .875rem; }
.offcut-list div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; background: #f7f1ea; border-radius: 5px; }
.offcut-list dd { margin: 0; white-space: nowrap; }
.report-actions { display: flex; flex-wrap: wrap; gap: 7px; }
#report-notice { margin-top: 5px; color: var(--accent); }
#report-notice:empty { display: none; }
.board-heading { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: center; margin: 13px 0 8px; }
.board-heading h3 { font-size: 1.05rem; }
.board-controls, .cut-controls { display: flex; align-items: center; gap: 6px; }
.board-controls select { width: auto; min-width: 112px; }
.step-button { min-width: 38px; padding-inline: 8px; }
.board-stage { background: #eee6de; border: 1px solid var(--line); border-radius: 9px; padding: 12px 11px 10px; }
.board-size { margin-bottom: 8px; font-size: .875rem; text-align: center; color: var(--muted); }
.drawing { display: block; width: 100%; height: min(53vh, 480px); overflow: visible; }
.board-caption { margin-top: 9px; text-align: center; font-size: .875rem; color: var(--muted); }
.key { display: flex; flex-wrap: wrap; gap: 4px 13px; margin-top: 8px; font-size: .875rem; }
.key span { display: inline-flex; gap: 5px; align-items: center; }
.chip { display: inline-block; width: 13px; height: 13px; border: 1px solid #8f7d70; border-radius: 2px; }
.chip.cut { background: var(--accent); border-color: var(--accent); }
.chip.offcut { background: repeating-linear-gradient(135deg, #f7f2ec 0 3px, #c9bbae 3px 4px); }
.cut-controls { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; margin: 12px 0 6px; }
.cut-note { min-height: 1.4em; font-size: .875rem; color: var(--muted); }
.photo-select { margin: 8px 0; }
.photo-select select { max-width: 100%; }
.board-pieces { display: grid; gap: 4px; padding: 0; margin: 9px 0; list-style: none; }
.board-pieces li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px 7px; padding: 6px 9px;
  border: 1px solid var(--line); border-radius: 6px; font-size: .875rem; overflow-wrap: anywhere;
}
.board-pieces .chip { flex: none; }
.piece-id { color: var(--accent); font-weight: 800; }
.piece-measure { margin-left: auto; color: var(--muted); }
.material-panel { margin-top: 20px; }
.material-panel > .panel-title { margin-bottom: 12px; }

@media (max-width: 940px) {
  main, .masthead-inner { padding-inline: 20px; }
  .workspace { grid-template-columns: minmax(0, .94fr) minmax(0, 1.12fr); gap: 12px; }
  .panel { padding: 16px; }
}
@media (max-width: 730px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .masthead-inner { align-items: flex-start; flex-direction: column; }
  .hero { align-items: start; flex-direction: column; padding: 24px 0 20px; }
  .empty { min-height: 230px; }
}
@media (max-width: 420px) {
  main, .masthead-inner { padding-inline: 12px; }
  .masthead-inner { gap: 10px; }
  .brand img { width: 88px; }
  .masthead nav { gap: 3px 9px; }
  .masthead nav a { font-size: .8rem; }
  .totals div { padding-inline: 7px; }
}
@media print {
  body { background: white; }
  .masthead, form, .hero button, .board-controls, .cut-controls, .report-actions, .photo-select { display: none; }
  .workspace { display: block; }
  .panel { border: 0; }
}
