:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --border: #dcdcd7;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --accent: #2f5fd6;
  --accent-text: #ffffff;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 16px; }
.topbar-stats { color: var(--muted); font-variant-numeric: tabular-nums; }

.layout { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.panel { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--border); padding: 12px 14px 40px; }
.group { padding: 10px 0 14px; border-bottom: 1px solid var(--border); }
.group:last-child { border-bottom: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select { color: var(--text); }
input[type=number], input[type=text], select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font: inherit;
}
input[type=color] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
input[type=range] { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; align-items: end; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.slider { margin-bottom: 6px; }
.slider.inline { flex-direction: row; align-items: center; gap: 8px; }
.slider.inline input { width: 160px; }
.check { flex-direction: row; align-items: center; gap: 8px; margin: 6px 0; color: var(--text); }
.hint { color: var(--muted); margin: 6px 0 0; font-size: 12px; line-height: 1.4; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
  color: var(--text); font: inherit; cursor: pointer; text-align: center;
}
.btn:hover { background: #f5f5f3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: #2751b8; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.file-btn { cursor: pointer; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 110px; border: 1px dashed var(--border); border-radius: var(--radius);
  background: #fafaf8; cursor: pointer; text-align: center; padding: 8px; color: var(--muted);
}
.dropzone.over { border-color: var(--accent); background: #eef2fc; }
.dropzone img { max-width: 100%; max-height: 140px; border-radius: 4px; }

.colors { list-style: none; margin: 8px 0; padding: 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.colors li { display: grid; grid-template-columns: 22px 30px 34px 1fr 52px 24px; align-items: center; gap: 6px; padding: 4px 6px; border-bottom: 1px solid #eeeeea; }
.colors li:last-child { border-bottom: 0; }
.colors li.off { opacity: .45; }
.colors .num { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.colors input[type=color] { width: 30px; height: 24px; padding: 1px; }
.colors input[type=text] { padding: 3px 6px; font-size: 12px; }
.colors .count { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.colors .remove { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
.colors .remove:hover { color: #b3261e; }
.addcolor { display: grid; grid-template-columns: 44px 1fr auto; gap: 6px; margin-bottom: 8px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.hover { color: var(--muted); font-variant-numeric: tabular-nums; }
.viewport { position: relative; flex: 1; overflow: auto; background: #e9e9e6; }
.viewport .spacer { position: absolute; top: 0; left: 0; width: 1px; height: 1px; }
.viewport canvas { position: sticky; top: 0; left: 0; display: block; }

#print { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh; }
  .panel { border-right: 0; border-bottom: 1px solid var(--border); }
}

@media print {
  body > *:not(#print) { display: none !important; }
  html, body { height: auto; background: #fff; }
  #print { display: block; }
  .print-page { break-after: page; padding: 0; }
  .print-page:last-child { break-after: auto; }
  .print-page h1 { font-size: 20px; margin: 0 0 6px; }
  .print-page h2 { font-size: 15px; margin: 0 0 8px; color: #333; text-transform: none; letter-spacing: 0; }
  .print-page p { margin: 0 0 8px; }
  .print-page canvas { max-width: 100%; height: auto; }
  .print-legend { width: 100%; border-collapse: collapse; font-size: 12px; }
  .print-legend td, .print-legend th { border: 1px solid #bbb; padding: 3px 6px; text-align: left; }
  .print-legend .sw { width: 28px; height: 16px; border: 1px solid #666; display: inline-block; vertical-align: middle; }
  .sheet-counts { font-size: 12px; color: #333; margin-top: 6px; }
}

.slider > span:first-child { display: flex; justify-content: space-between; }
.slider > span:first-child > span { color: var(--text); font-variant-numeric: tabular-nums; }
