:root {
  color-scheme: dark;
  --ink: #f4f6f8;
  --muted: #959ca6;
  --panel: #202329;
  --panel-2: #292d34;
  --panel-3: #333840;
  --line: #3a4049;
  --line-hot: #66717d;
  --paper: #fff;
  --amber: #f0b429;
  --amber-dark: #1d1708;
  --cyan: #53b7d1;
  --danger: #ff6b5e;
  --shadow: 0 22px 70px rgba(0, 0, 0, .46);
  --ui-font: Inter, "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: #17191d;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 14px;
  overflow: hidden;
}

button, input, select { font: inherit; }
button, label[for], select, input[type="color"], input[type="range"] { cursor: pointer; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
label[for]:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 22px;
  background: #1b1e22;
  border-bottom: 1px solid #30343b;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 245px; }
.brand h1 { display: block; margin: 0; font-size: 17px; line-height: 1.15; letter-spacing: -.2px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.brand-mark { width: 34px; height: 34px; display: flex; align-items: end; gap: 3px; padding: 6px; background: var(--amber); }
.brand-mark i { display: block; width: 4px; background: var(--amber-dark); }
.brand-mark i:nth-child(1) { height: 12px; }
.brand-mark i:nth-child(2) { height: 20px; }
.brand-mark i:nth-child(3) { height: 8px; }
.brand-mark i:nth-child(4) { height: 16px; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.language-switcher {
  display: inline-flex;
  padding: 3px;
  border: 1px solid #414750;
  border-radius: 4px;
  background: #15171a;
}
.language-switcher button {
  min-width: 32px;
  min-height: 28px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .4px;
}
.language-switcher button:hover { color: #fff; }
.language-switcher button.active { background: var(--amber); color: var(--amber-dark); }
.button {
  min-height: 36px;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  padding: 8px 13px;
  background: var(--panel-3);
  color: var(--ink);
  font-weight: 650;
  line-height: 1;
}
.button:hover { border-color: #8a96a2; background: #3b414a; }
.button.ghost { background: transparent; color: #cbd0d6; border-color: #414750; }
.button.ghost:hover { background: #292d33; color: #fff; }
.button.primary { border-color: var(--amber); background: var(--amber); color: var(--amber-dark); }
.button.primary:hover { background: #ffc13e; }
.button.small { min-height: 34px; padding: 7px 12px; }
.file-button { display: inline-flex; align-items: center; }
.icon-button { width: 31px; height: 31px; border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 3px; font-size: 20px; line-height: 1; }
.icon-button:hover { color: #fff; border-color: var(--line-hot); }
.text-button { border: 0; padding: 0; background: transparent; color: var(--cyan); font-size: 12px; }
.text-button:hover { text-decoration: underline; }
.danger-quiet { width: 100%; margin-top: 14px; color: #ffaaa2; border-color: #60413f; background: transparent; }
.danger-quiet:hover { border-color: #92504b; background: #392624; }

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
}

.editor {
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  scrollbar-color: #4d545f transparent;
}

.editor-section { padding: 20px 22px 22px; border-bottom: 1px solid var(--line); }
.editor-section:last-child { border-bottom: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 15px; }
.section-heading h1, .section-heading h2 { margin: 0; font-size: 16px; font-weight: 720; letter-spacing: -.15px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

.about-section { color: #c7ccd2; }
.about-section h2 { margin: 0 0 10px; color: #f4f6f8; font-size: 15px; line-height: 1.35; }
.about-section p, .about-section li { font-size: 12px; line-height: 1.55; }
.about-section p { margin: 0 0 10px; }
.about-section ol { margin: 0 0 13px; padding-left: 20px; }
.about-section li + li { margin-top: 4px; }
.about-links { display: flex; flex-wrap: wrap; gap: 7px 14px; }
.about-links a { color: var(--cyan); text-underline-offset: 2px; }
.about-section .disclaimer { margin: 13px 0 0; color: var(--muted); font-size: 10px; }

.channel-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.channel-button {
  aspect-ratio: 1;
  border: 1px solid #48505a;
  border-radius: 2px;
  background: #2a2e34;
  color: #c5cad0;
  font-size: 12px;
  font-weight: 750;
}
.channel-button:hover { border-color: #7a8590; color: #fff; }
.channel-button.active { border-color: var(--amber); background: var(--amber); color: #17130a; }
.channel-button.linked { box-shadow: inset -3px 0 0 var(--channel-color, #777); }
.channel-button.consumed { color: #737b84; background: #24272c; }

.selected-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.selected-heading h2 { margin: 0; font-size: 19px; line-height: 1.1; letter-spacing: -.25px; }
.selected-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.channel-badge { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--amber); color: var(--amber); font-size: 16px; font-weight: 800; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 10px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > span, .color-field > span, .field-label-row > span { color: #b7bdc5; font-size: 11px; font-weight: 650; }
.field input[type="text"], .field input[type="search"], .field select, .icon-search input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #48505a;
  border-radius: 3px;
  padding: 7px 9px;
  background: #181a1e;
  color: #f5f7f8;
}
.field input::placeholder, .icon-search input::placeholder { color: #69717b; }
.field input:hover, .field select:hover, .icon-search input:hover { border-color: #68737f; }
.field input:focus, .field select:focus, .icon-search input:focus { border-color: var(--cyan); }

.range-field > span { display: flex; justify-content: space-between; }
.range-field output { color: var(--amber); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--amber); }
.geometry-note {
  margin: -5px 0 1px;
  padding-left: 9px;
  border-left: 2px solid #69737e;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.color-row { margin-top: 15px; display: grid; gap: 9px; }
.color-field { display: flex; align-items: center; justify-content: space-between; }
.color-field input { width: 44px; height: 28px; border: 1px solid #59616c; border-radius: 2px; padding: 2px; background: transparent; }
.swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.swatch { height: 23px; border: 1px solid rgba(255,255,255,.16); border-radius: 2px; background: var(--swatch); }
.swatch:hover, .swatch.active { outline: 2px solid #fff; outline-offset: 1px; }

.icon-editor { margin-top: 17px; padding-top: 16px; border-top: 1px solid var(--line); }
.field-label-row { display: flex; justify-content: space-between; margin-bottom: 9px; }
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.icon-choice {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 6px;
  border: 1px solid #48505a;
  border-radius: 2px;
  background: #292d33;
  color: #d8dce1;
}
.icon-choice:hover { border-color: #7e8994; background: #333840; }
.icon-choice.active { border-color: var(--amber); color: var(--amber); }
.icon-choice svg, .icon-choice img { width: 100%; height: 100%; object-fit: contain; }
.icon-search { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 10px; }
.search-status { min-height: 17px; margin: 7px 0 8px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.search-results:empty { display: none; }

.switch-list { display: grid; gap: 10px; margin-top: 16px; }
.switch { display: flex; align-items: center; gap: 9px; color: #c5cad0; font-size: 12px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 33px; height: 19px; border-radius: 20px; background: #4a515b; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s ease; }
.switch-copy { min-width: 0; }
.switch input:checked + .switch-track { background: var(--amber); }
.switch input:checked + .switch-track::after { transform: translateX(14px); background: #211b0b; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--cyan); outline-offset: 2px; }

.canvas { min-width: 0; display: grid; grid-template-rows: auto 1fr; background: #121417; }
.canvas-toolbar { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 11px 20px; border-bottom: 1px solid #2a2e34; background: #191b1f; }
.canvas-toolbar strong { display: block; font-size: 13px; }
.canvas-toolbar span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.save-state { display: flex; align-items: center; gap: 7px; color: #9098a2; font-size: 11px; white-space: nowrap; }
.save-state > .save-dot { width: 7px; height: 7px; margin: 0; border-radius: 50%; background: #55bd74; }
.save-state > #saveStateText { margin: 0; }
.save-state.saving > .save-dot { background: var(--amber); }

.sheet-stage {
  min-width: 0;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 28px;
  background-color: #141619;
  background-image: linear-gradient(#1b1e22 1px, transparent 1px), linear-gradient(90deg, #1b1e22 1px, transparent 1px);
  background-size: 22px 22px;
  scrollbar-color: #4d545f transparent;
}

.sheet {
  position: relative;
  width: 297mm;
  height: 210mm;
  flex: none;
  padding-top: 7mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1mm;
  background: var(--paper);
  color: #111;
  box-shadow: var(--shadow);
  zoom: .72;
}

.strip-cut {
  position: relative;
  width: var(--cut-width, 231mm);
  height: var(--cut-height, 22mm);
  flex: none;
}
.strip-cut > .label-strip { position: absolute; left: 2mm; top: 2mm; width: var(--strip-width, 227mm); height: var(--strip-height, 18mm); overflow: visible; }
.strip-cut > .crop-layer { position: absolute; inset: 0; width: var(--cut-width, 231mm); height: var(--cut-height, 22mm); pointer-events: none; }
.label-hit { cursor: pointer; }
.label-hit:hover .label-frame { stroke: #008db3 !important; stroke-width: .45 !important; }
.label-hit.selected .label-frame { stroke: #d88a00 !important; stroke-width: .55 !important; }

.calibration {
  position: absolute;
  left: 34.5mm;
  bottom: 7mm;
  display: flex;
  align-items: center;
  gap: 5mm;
  font: 2.35mm/1 Arial, sans-serif;
  color: #333;
}
.calibration-line { position: relative; width: 50mm; height: 4mm; border-bottom: .25mm solid #222; }
.calibration-line::before, .calibration-line::after { content: ""; position: absolute; bottom: -2mm; width: .25mm; height: 4mm; background: #222; }
.calibration-line::before { left: 0; }
.calibration-line::after { right: 0; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 360px;
  padding: 11px 14px;
  border-left: 3px solid var(--amber);
  background: #2b3036;
  color: #fff;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .top-actions .ghost { display: none; }
  .workspace { grid-template-columns: 340px minmax(0, 1fr); }
  .sheet { zoom: .58; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { height: auto; min-height: 66px; padding: 10px 14px; }
  .brand small { display: none; }
  .top-actions { margin-left: auto; }
  .top-actions .button { display: none; }
  .top-actions .primary { display: inline-flex; }
  .workspace { height: auto; grid-template-columns: 1fr; }
  .editor { overflow: visible; border-right: 0; }
  .canvas { min-height: 540px; }
  .canvas-toolbar { align-items: start; }
  .save-state { display: none; }
  .sheet-stage { padding: 18px 8px; justify-items: center; }
  .sheet { zoom: .42; }
}

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

@page { size: A4 landscape; margin: 0; }

@media print {
  :root { color-scheme: light; }
  html, body { width: 297mm; height: 210mm; margin: 0; overflow: visible; background: #fff; }
  .topbar, .editor, .canvas-toolbar, .toast { display: none !important; }
  .workspace, .canvas, .sheet-stage {
    display: block;
    width: 297mm;
    height: auto;
    min-height: 210mm;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #fff;
  }
  .sheet {
    display: block;
    width: 297mm;
    height: 210mm;
    margin: 0;
    padding-top: 7mm;
    overflow: hidden;
    box-shadow: none;
    zoom: 1;
    transform: none;
  }
  .strip-cut {
    margin: 0 auto 1mm;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .strip-cut:last-of-type { margin-bottom: 0; }
  .label-hit { cursor: default; }
  .label-hit:hover .label-frame, .label-hit.selected .label-frame { stroke: #8a8a8a !important; stroke-width: .18 !important; }
}
