:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #d9d8d2;
  --accent: #2f5fd0;
  --accent-soft: #dfe7fb;
  --error: #b42318;
  --warning: #8a5a00;
  --paper: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ecebe6;
    --muted: #a3a29b;
    --line: #3a3936;
    --accent: #8aa8ff;
    --accent-soft: #2a3352;
    --error: #ff8a80;
    --warning: #f0c060;
    --paper: #2a2a27;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, sans-serif;
}

header { max-width: 1200px; margin: 0 auto 16px; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 4px; }
header p, .hint { color: var(--muted); margin: 4px 0; }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}
@media (min-width: 860px) {
  .layout { grid-template-columns: 340px 1fr; align-items: start; }
}

form, main > section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
}
main { display: grid; gap: 16px; min-width: 0; }

fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0; }
fieldset:first-child { border-top: 0; }
legend { font-weight: 600; padding: 0; }
label { display: block; margin: 6px 0; }
label.check { display: flex; gap: 8px; align-items: center; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

input[type="number"], input[type="text"], select {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 6px 8px;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

button, .file-button, #download {
  display: inline-block;
  padding: 7px 14px;
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
  text-decoration: none;
}
button:disabled { opacity: 0.5; cursor: default; }
#download { background: transparent; color: var(--accent); }
.file-button input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
#drop-zone.dragging { outline: 2px dashed var(--accent); outline-offset: 4px; }

#file-list { padding-left: 20px; margin: 4px 0; }
#file-list li { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
#file-list .name { flex: 1; overflow-wrap: anywhere; }
#file-list .pages { color: var(--muted); white-space: nowrap; }
#file-list button { padding: 2px 8px; background: transparent; color: var(--accent); }

.error { color: var(--error); white-space: pre-line; margin: 0; }
.error:empty, .warning:empty { display: none; }
.warning { color: var(--warning); padding-left: 20px; }
.limit { color: var(--muted); font-size: 0.8rem; }
.limit.below { color: var(--error); }
input.below { border-color: var(--error); }
input:disabled { opacity: 0.5; }

#summary { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; margin: 0; }
#summary dt { color: var(--muted); }
#summary dd { margin: 0; }
#instructions { padding-left: 20px; margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; margin: 16px 0 0; }

#output { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }

#preview { display: grid; gap: 12px; }
.sheet { display: flex; flex-wrap: wrap; gap: 12px; }
.sheet figure { margin: 0; }
.sheet figcaption { color: var(--muted); font-size: 0.85rem; }
.sheet svg { display: block; width: 300px; max-width: 100%; height: auto; }
.sheet .paper { fill: var(--paper); stroke: var(--muted); stroke-width: 0.6; }
.sheet .content { fill: var(--accent-soft); }
.sheet .cut { stroke: var(--muted); stroke-width: 0.5; }
.sheet .fold { stroke: var(--muted); stroke-width: 0.5; stroke-dasharray: 3 2; }
.sheet text { fill: var(--text); font-family: system-ui, sans-serif; }
.sheet .label { text-anchor: middle; dominant-baseline: central; }
.sheet .ink { fill: none; stroke: var(--accent); stroke-width: 0.6; stroke-dasharray: 2 1.5; }
.sheet .unprintable { fill: var(--error); opacity: 0.3; }
.sheet .discard { fill: var(--muted); }
