:root {
  --bg: #f2ece2;
  --bg-deep: #e9e0d2;
  --surface: #fffdf8;
  --surface-2: #f7f1e7;
  --ink: #26211b;
  --ink-soft: #50473c;
  --muted: #8b7f71;
  --faint: #aa9d8d;
  --line: #e6dccb;
  --line-strong: #d3c5b1;
  --accent: #b65a33;
  --accent-deep: #9c4827;
  --accent-soft: #f6e3d6;
  --sage: #6c7e5d;
  --shadow-card: 0 1px 0 rgba(38, 33, 27, .025), 0 16px 34px -24px rgba(60, 42, 24, .35);
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --chart-ink: #211d18;
  --chart-paper: #fffdf9;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 88% -14%, #fbf7ee 0%, rgba(251, 247, 238, 0) 62%),
    linear-gradient(180deg, #f4eee4 0%, var(--bg) 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

::selection { background: var(--accent-soft); color: var(--accent-deep); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 241, 232, .82);
  backdrop-filter: blur(14px) saturate(1.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-mark { flex: none; filter: drop-shadow(0 3px 5px rgba(38, 33, 27, .16)); }
.brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: -.035em; line-height: 1.1; }
.brand-sub {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.top-actions { display: flex; align-items: center; gap: 8px; }

.top-meta {
  display: none;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding-right: 6px;
}

.btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .005em;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-deep);
  color: #fff9f3;
  box-shadow: 0 2px 5px rgba(140, 66, 32, .2), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-primary:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
  box-shadow: 0 7px 16px -4px rgba(140, 66, 32, .38);
}
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- layout ---------- */

.layout {
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 358px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.sidebar {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 5px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }

.card {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.step {
  flex: none;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.panel-titles { min-width: 0; }
.panel-head h2 { margin: 0; font-size: 13.5px; font-weight: 800; letter-spacing: -.015em; line-height: 1.2; }
.panel-head p { margin: 2px 0 0; font-size: 10.5px; color: var(--muted); line-height: 1.2; }
.panel-head > .link-btn { margin-left: auto; align-self: flex-start; margin-top: 2px; }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  transition: color .15s ease;
}
.link-btn:hover { color: var(--accent-deep); }
.link-btn:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 3px; border-radius: 3px; }

/* ---------- upload ---------- */

.dropzone {
  position: relative;
  border: 1.5px dashed var(--line-strong);
  border-radius: 14px;
  background: linear-gradient(180deg, #faf5ec 0%, #f7f0e4 100%);
  display: grid;
  place-items: center;
  min-height: 152px;
  overflow: hidden;
  outline: none;
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.dropzone:hover,
.dropzone.dragover { border-color: var(--accent); background: #f8eadf; }
.dropzone.dragover { box-shadow: inset 0 0 0 2px rgba(182, 90, 51, .18); }
.dropzone:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dropzone.has-image { min-height: 0; border-style: solid; border-color: var(--line); background: var(--bg-deep); padding: 0; }

.dz-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  padding: 20px 16px;
  pointer-events: none;
}
.dz-icon {
  width: 37px;
  height: 37px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px -4px rgba(70, 46, 24, .2);
  margin-bottom: 6px;
}
.dz-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dz-empty strong { font-size: 12px; font-weight: 800; letter-spacing: -.01em; }
.dz-empty > span:not(.dz-icon) { font-size: 11px; color: var(--muted); }
.dz-empty small { margin-top: 5px; font-size: 9.5px; color: var(--faint); }

.dz-filled { position: relative; width: 100%; line-height: 0; }
.dz-filled img { display: block; width: 100%; height: 170px; object-fit: contain; background: var(--surface-2); }
.dz-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: linear-gradient(180deg, rgba(28, 22, 15, .02) 20%, rgba(28, 22, 15, .58) 100%);
  opacity: 0;
  transition: opacity .18s ease;
}
.dz-overlay span {
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 8px;
  background: rgba(255, 255, 255, .13);
  backdrop-filter: blur(5px);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}
.dropzone:hover .dz-overlay,
.dropzone:focus-visible .dz-overlay { opacity: 1; }
.dz-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 7px;
  border-radius: 5px;
  background: rgba(25, 19, 13, .55);
  backdrop-filter: blur(5px);
  color: #fff;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  line-height: 1.3;
}

.file-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  min-height: 14px;
}
.file-meta {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-dims { flex: none; font-size: 9.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.samples { margin-top: 13px; display: flex; flex-direction: column; gap: 7px; }
.samples-label {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--faint);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 10.5px;
  font-weight: 650;
  transition: .15s ease;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-2); }
.chip.active { border-color: #ddb49d; background: var(--accent-soft); color: var(--accent-deep); }
.chip:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- controls ---------- */

.control { margin-bottom: 13px; }
.control:last-child { margin-bottom: 0; }
.control-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  min-height: 24px;
}
.control label,
.control-label { font-size: 11.5px; font-weight: 650; color: var(--ink-soft); }

.control output {
  min-width: 34px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.split .control { min-width: 0; }

.num {
  width: 56px;
  height: 26px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 750;
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
  -moz-appearance: textfield;
}
.num::-webkit-outer-spin-button,
.num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num:hover { border-color: var(--line-strong); }
.num:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.num:disabled { opacity: .55; cursor: not-allowed; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill), #ece3d5 var(--fill) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(50, 34, 18, .22);
  transition: transform .12s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.08); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(.97); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 99px; background: #ece3d5; }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(50, 34, 18, .22);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
input[type="range"]:disabled { opacity: .48; cursor: not-allowed; }
input[type="range"]:disabled::-webkit-slider-thumb { transform: none; }

.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 650;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
  margin-top: 9px;
  line-height: 1.3;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch-track {
  flex: none;
  width: 33px;
  height: 19px;
  border-radius: 99px;
  background: #e8dfd1;
  box-shadow: inset 0 1px 2px rgba(60, 44, 28, .12);
  position: relative;
  transition: background .18s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(50, 34, 18, .28);
  transition: transform .18s cubic-bezier(.4, .1, .2, 1);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch.small { margin-top: 1px; margin-bottom: 12px; font-size: 10.5px; color: var(--muted); }

.switch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 10px 0 11px; }
.switch-grid .switch { margin-top: 4px; }

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.segmented button {
  flex: 1;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
  transition: .15s ease;
}
.segmented button:hover:not(.active) { color: var(--ink-soft); }
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(56, 38, 20, .13), 0 0 0 1px rgba(56, 38, 20, .03);
}
.segmented button:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 1px; }
.segmented.is-disabled { opacity: .55; }
.segmented button:disabled { cursor: not-allowed; }

.crop-control { margin-top: 12px; }
.field-note { margin: 6px 0 0; font-size: 9.5px; line-height: 1.4; color: var(--faint); }

.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 2px; }
.color-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 10.5px;
  font-weight: 650;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color .15s;
}
.color-field:hover { border-color: var(--line-strong); }
.color-field input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  flex: none;
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.color-field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }

.inline-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 10px;
}
.inline-control label { font-size: 11px; font-weight: 650; color: var(--ink-soft); }
select {
  height: 29px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 650;
  padding: 0 8px;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select:disabled { opacity: .5; cursor: not-allowed; }

.title-control { margin-top: 13px; }
.soft { font-size: 9px; color: var(--faint); white-space: nowrap; }

.yarn-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.yarn-row { display: flex; align-items: center; gap: 9px; }
.yarn-dot {
  width: 12px;
  height: 12px;
  flex: none;
  border: 1px solid rgba(63, 45, 26, .18);
  border-radius: 3px;
  background: var(--chart-ink);
}
.yarn-dot.yarn-paper { background: var(--chart-paper); }
.yarn-info { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 1px; }
.yarn-name { font-size: 11px; font-weight: 750; color: var(--ink-soft); }
.yarn-count {
  overflow: hidden;
  color: var(--faint);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.yarn-meters {
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.yarn-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 1px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.yarn-total strong { color: var(--ink); font-size: 15px; font-weight: 850; font-variant-numeric: tabular-nums; }
.text-input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 550;
  outline: none;
  transition: .15s ease;
}
.text-input::placeholder { color: var(--faint); font-weight: 500; }
.text-input:hover { border-color: var(--line-strong); }
.text-input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- silhouette ---------- */

.sil-preview { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.sil-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 9.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sil-head span:first-child {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--faint);
}
.sil-wrap {
  height: 132px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background-color: #f4ede1;
  background-image: radial-gradient(rgba(70, 54, 36, .11) .8px, transparent .8px);
  background-size: 10px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#silCanvas {
  display: block;
  image-rendering: pixelated;
  border-radius: 2px;
  box-shadow: 0 1px 6px rgba(48, 33, 18, .2);
  background: #fff;
}

/* ---------- tip ---------- */

.tip-card {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 13px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 15px;
  background: linear-gradient(140deg, #f0e7d8 0%, #f8f2e8 100%);
  color: var(--ink-soft);
}
.tip-icon {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
}
.tip-icon svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tip-card p { margin: 0; font-size: 10px; line-height: 1.55; }
.tip-card b { color: var(--ink); }

/* ---------- stage ---------- */

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.stage-bar {
  flex: none;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, .78);
}
.stage-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stage-heading h2 { margin: 0; font-size: 12.5px; font-weight: 800; letter-spacing: -.01em; }
.stage-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.stage-upload {
  display: none;
  height: 31px;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 700;
}
.stage-upload svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.stage-upload:hover { background: var(--surface-2); border-color: var(--line-strong); }
.stage-upload:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 3px rgba(108, 126, 93, .14);
  flex: none;
}
.pill {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  flex: none;
}
.zoom-btn {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1;
}
.zoom-btn:hover, .zoom-value:hover, .zoom-fit:hover { background: var(--surface); box-shadow: 0 1px 2px rgba(56, 38, 20, .1); }
.zoom-btn:focus-visible, .zoom-value:focus-visible, .zoom-fit:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 0; }
.zoom-value {
  min-width: 46px;
  height: 25px;
  padding: 0 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 10.5px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.zoom-fit {
  height: 25px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}
.zoom-sep { width: 1px; height: 15px; background: var(--line); margin: 0 2px; flex: none; }

.stage-body {
  flex: 1;
  min-height: 0;
  position: relative;
  --ruler-h: 40px;
  --ruler-w: 36px;
}

.ruler-corner {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--ruler-w);
  height: var(--ruler-h);
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  z-index: 4;
}
.ruler-corner::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  transform: translate(-50%, -50%);
}

.ruler-top,
.ruler-left {
  position: absolute;
  overflow: hidden;
  background: var(--surface);
  pointer-events: auto;
  touch-action: none;
}
.ruler-top {
  top: 0;
  left: var(--ruler-w);
  right: 0;
  height: var(--ruler-h);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}
.ruler-left {
  top: var(--ruler-h);
  left: 0;
  bottom: 0;
  width: var(--ruler-w);
  border-right: 1px solid var(--line);
  z-index: 2;
}

.ruler-track {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}
.ruler-top .ruler-track { height: 100%; }
.ruler-left .ruler-track { width: 100%; }

.ruler-col {
  position: absolute;
  top: 0;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 3px;
  border-left: 1px solid rgba(63, 45, 26, .07);
  cursor: pointer;
}
.ruler-num {
  font-size: var(--ruler-font, 8px);
  line-height: 1;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.ruler-col.is-done { background: rgba(182, 90, 51, .07); }
.ruler-col.is-done .ruler-num { color: var(--accent-deep); }
.ruler-check {
  position: relative;
  flex: none;
  width: var(--check-size, 10px);
  height: var(--check-size, 10px);
  margin-top: 3px;
  padding: 0;
  display: block;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--surface-2);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.ruler-check:hover { border-color: var(--accent); }
.ruler-check:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 1px; }
.ruler-check[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent-deep);
}
.ruler-top.no-checks .ruler-check { display: none; }
.ruler-top.no-checks .ruler-col { justify-content: center; padding-top: 0; }
.ruler-top.hide-numbers .ruler-num { display: none; }
.ruler-top.hide-numbers .ruler-col { justify-content: center; padding-top: 0; }
.ruler-col.is-hidden { display: none; }

.ruler-row {
  position: absolute;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 5px;
  border-top: 1px solid rgba(63, 45, 26, .07);
  color: var(--muted);
  font-size: var(--ruler-font, 8px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ruler-left.hide-numbers .ruler-row span { display: none; }
.ruler-row.is-hidden { display: none; }

.stage-canvas {
  position: absolute;
  top: var(--ruler-h);
  left: var(--ruler-w);
  right: 0;
  bottom: 0;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  background-color: #eae2d5;
  background-image: radial-gradient(rgba(60, 46, 30, .1) .9px, transparent .9px);
  background-size: 14px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 70, 48, .4) transparent;
}
.stage-canvas::-webkit-scrollbar { width: 12px; height: 12px; }
.stage-canvas::-webkit-scrollbar-track { background: transparent; }
.stage-canvas::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 99px;
  background: rgba(90, 70, 48, .35);
  background-clip: padding-box;
}
.stage-canvas::-webkit-scrollbar-corner { background: transparent; }

.stage-inner {
  min-width: 100%;
  min-height: 100%;
  display: flex;
  padding: 28px;
}
.paper-wrap {
  margin: auto;
  line-height: 0;
  border-radius: 2px;
  background: #fff;
  box-shadow:
    0 0 0 1px rgba(63, 45, 26, .07),
    0 2px 3px rgba(48, 36, 22, .1),
    0 24px 50px -18px rgba(48, 36, 22, .42);
}
.paper-wrap svg { display: block; max-width: none; height: auto; }
.paper-wrap .chart-numbers { opacity: 0; }

.empty-chart {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}
.empty-chart p { margin: 0; font-size: 11.5px; font-weight: 600; }
.empty-chart.is-error .loader { display: none; }
.loader {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(182, 90, 51, .18);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-foot {
  flex: none;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.legend { display: flex; align-items: center; gap: 14px; font-size: 10px; color: var(--muted); min-width: 0; }
.foot-actions { display: flex; align-items: center; gap: 14px; flex: none; }
.foot-actions .link-btn[hidden] { display: none; }
.legend-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--chart-paper);
  flex: none;
}
.legend-dot.filled { background: var(--chart-ink); border-color: var(--chart-ink); }
.legend-counts { padding-left: 14px; border-left: 1px solid var(--line); color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 24, 16, .48);
  backdrop-filter: blur(6px);
  animation: fade-in .18s ease both;
}
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(84vh, 760px);
  overflow: auto;
  padding: 28px 28px 24px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .5);
  box-shadow: 0 40px 100px -20px rgba(25, 16, 8, .55);
  animation: modal-in .24s cubic-bezier(.2, .8, .2, 1) both;
  scrollbar-width: thin;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
}
.modal-close:hover { background: var(--bg-deep); color: var(--ink); }
.modal-close:focus-visible { outline: 2px solid var(--accent-soft); }
.modal-kicker {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.modal-card h2 { margin: 0 0 8px; font-size: 24px; font-weight: 800; letter-spacing: -.04em; }
.modal-lead { margin: 0 0 18px; font-size: 12px; line-height: 1.6; color: var(--ink-soft); max-width: 46ch; }

.help-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 22px;
}
.help-legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}
.help-swatch {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: var(--chart-paper);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.help-swatch.filled { background: var(--chart-ink); border-color: var(--chart-ink); box-shadow: none; }
.help-legend-item div { display: flex; flex-direction: column; gap: 1px; }
.help-legend-item b { font-size: 10.5px; font-weight: 750; }
.help-legend-item span { font-size: 9.5px; color: var(--muted); }

.modal-card h3 {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--faint);
}
.help-steps { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.help-steps li { display: flex; gap: 11px; }
.help-steps li > span {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 800;
}
.help-steps p { margin: 1px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--ink-soft); }
.help-steps b { color: var(--ink); }
.modal-note {
  margin: 0 0 20px;
  padding: 11px 13px;
  border-left: 2px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--surface-2);
  font-size: 10px;
  line-height: 1.55;
  color: var(--muted);
}
.modal-ok { width: 100%; height: 40px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(92vw, 480px);
  padding: 10px 15px;
  border-radius: 10px;
  background: #26211b;
  color: #fbf6ec;
  font-size: 11.5px;
  font-weight: 600;
  box-shadow: 0 16px 40px -8px rgba(20, 12, 5, .45);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-icon {
  width: 17px;
  height: 17px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sage);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}
.toast.is-error .toast-icon { background: var(--accent); }

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #26211b;
  color: #fff;
  font-size: 12px;
  z-index: 200;
}

/* ---------- responsive ---------- */

@media (min-width: 1340px) {
  .top-meta { display: inline-block; }
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 330px minmax(0, 1fr); gap: 12px; padding: 12px; }
  .sidebar { gap: 10px; }
  .card { padding: 14px; }
}

@media (max-width: 880px) {
  html, body { height: auto; }
  body { min-height: 100%; }
  .topbar { height: 64px; padding: 0 14px; }
  .brand-sub { display: none; }
  .layout {
    height: auto;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
  }
  .stage { order: -1; height: 66vh; min-height: 460px; }
  .stage-upload { display: inline-flex; }
  .sidebar { overflow: visible; padding-right: 0; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .tip-card { grid-column: 1 / -1; }
  .stage-inner { padding: 20px; }
}

@media (max-width: 720px) {
  .top-actions .btn-ghost span { display: none; }
  .top-actions .btn-ghost { width: 38px; padding: 0; }
  .top-actions .btn-primary { padding: 0 12px; }
  .top-actions .btn-primary span { font-size: 10.5px; }
  .sidebar { grid-template-columns: 1fr; }
  .stage { height: 62vh; min-height: 400px; }
}

@media (max-width: 520px) {
  .topbar { gap: 8px; }
  .brand-mark svg { width: 38px; height: 38px; }
  .brand-title { font-size: 15px; }
  .top-actions { gap: 6px; }
  .btn { height: 36px; }
  .stage { min-height: 360px; }
  .stage-bar { height: 50px; padding: 0 12px; }
  .stage-heading h2 { font-size: 11.5px; }
  .zoom-fit { display: none; }
  .zoom-sep { display: none; }
  .stage-foot { height: auto; min-height: 40px; padding: 8px 12px; flex-wrap: wrap; row-gap: 4px; }
  .legend { gap: 9px; font-size: 9px; flex-wrap: wrap; }
  .legend-counts { display: none; }
  .foot-actions { gap: 10px; }
  .stage-body { --ruler-h: 36px; --ruler-w: 32px; }
  .stage-inner { padding: 14px; }
  .layout { padding: 10px; }
}

@media (max-width: 380px) {
  .brand-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  @page { margin: 12mm; }
  body { background: #fff !important; }
  .topbar, .sidebar, .stage-bar, .stage-foot, .toast, .modal { display: none !important; }
  .layout { display: block; height: auto; padding: 0; max-width: none; }
  .stage { border: 0; box-shadow: none; border-radius: 0; height: auto; }
  .stage-body { display: block; }
  .ruler-corner, .ruler-top, .ruler-left { display: none !important; }
  .stage-canvas { position: static; top: auto; right: auto; bottom: auto; left: auto; overflow: visible; background: #fff !important; }
  .stage-inner { display: block; padding: 0; min-height: 0; }
  .paper-wrap { box-shadow: none; margin: 0 auto; }
  .paper-wrap svg { width: 100% !important; height: auto !important; max-height: calc(100vh - 24mm); }
  .paper-wrap .chart-numbers { opacity: 1 !important; }
}
