/* ============ Font Faces ============ */
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/Fraunces-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/DMSans-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/DMSans-Medium.woff2') format('woff2');
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/DMSans-SemiBold.woff2') format('woff2');
}

/**
 * Bookletter — app styles
 * Editorial UI matching the mini-zine-maker reference.
 * Three-rail shell: 275px | fluid | 270px
 */

/* ============ Design Tokens ============ */
:root {
  /* -------- Palette: Candy Pink -------- */
  --candy-pink-750: #DE505B;
  --candy-pink-500: #E4717A;
  --candy-pink-250: #EA9299;
  --candy-pink-100: #F4C3C7;
  --candy-pink-50:  #FDF5F5;
  
  /* -------- Palette: Cornflower Blue -------- */
  --cornflower-blue-750: #505BDE;
  --cornflower-blue-500: #717AE4;
  --cornflower-blue-250: #9299EA;
  --cornflower-blue-100: #C3C7F4;
  --cornflower-blue-50:  #F5F5FD;
  
  /* -------- Palette: Neutrals -------- */
  --a800: #161719;
  --a500: #565A62;
  --a70:  #B0B3B9;
  --a30:  #D9DBDE;
  --a0:   #FFFFFF;
  
  /* -------- Semantic tokens -------- */
  --surface: var(--a0);                    /* cards, rails, panels, page canvas */
  --desk: var(--candy-pink-50);            /* app background, canvas surround */
  --ink: var(--a800);                      /* primary text */
  --ink-muted: var(--a500);                /* secondary text, labels, captions */
  --line: var(--a30);                      /* hairline borders */
  --line-strong: var(--a70);               /* emphasised rules, inactive edges */
  --accent: var(--candy-pink-750);         /* primary buttons, active states, serif headlines */
  --accent-hover: var(--candy-pink-500);   /* hover state for accent buttons */
  --accent-on: #FFFFFF;                    /* text ON accent bg (white on Candy Pink 750) */
  --accent-tint-wash: var(--candy-pink-50);  /* alert/notice panel background */
  --accent-tint-rule: var(--candy-pink-250); /* alert/notice panel rule */
  --guide: var(--cornflower-blue-500);     /* fold lines, snap guides, margin guide */
  --focus: var(--cornflower-blue-750);     /* focus ring */
  --info: var(--cornflower-blue-750);      /* informational states, links */
  --info-tint: var(--cornflower-blue-50);  /* info panel background */
  --info-wash: var(--cornflower-blue-100); /* info panel rule/wash */
  
  /* -------- Page content colors (print output — DO NOT CHANGE) -------- */
  --paper: #fff;
  
  /* -------- Geometry -------- */
  --mm: 1px;
  --pw: 148;
  --ph: 210;
  
  /* -------- Typography - UI only -------- */
  --f-serif: 'Fraunces', Georgia, serif;
  --f-sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  
  /* Page content fonts (deterministic print) */
  --f-ui: system-ui, -apple-system, sans-serif;
  
  /* -------- Sizes -------- */
  --header-h: 68px;
  --rail-left: 275px;
  --rail-right: 270px;
  --border-w: 0.8px;
  --radius: 0;
}

/* ============ Reset ============ */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--desk);
  color: var(--ink);
  font: 13px/1.5 var(--f-sans);
}

button {
  font: inherit;
  font-size: 12px;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  border-radius: var(--radius);
}

input {
  font: inherit;
  border-radius: var(--radius);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ============ App Shell ============ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;            /* Fallback for browsers without dvh */
  height: 100dvh;           /* Dynamic viewport height - iOS Safari safe */
  overflow: hidden;
}

/* ============ Header ============ */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: var(--border-w) solid var(--line);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-name {
  font: 20px var(--f-serif);
  color: var(--ink);
  line-height: 1.1;
}

.header-title {
  flex: 0 1 auto;
  min-width: 120px;
  max-width: 200px;
}

.header-title input {
  width: 100%;
  padding: 6px 10px;
  border: var(--border-w) solid var(--line);
  background: var(--desk);
  font-size: 12px;
  color: var(--ink);
}

.header-status {
  font-size: 11px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ Preview Button ============ */
.btn-preview {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  min-height: 36px;
}

.btn-preview:hover {
  color: var(--ink);
}

.preview-icon {
  font-size: 16px;
}

/* ============ Dropdown Menus ============ */
.dropdown {
  position: relative;
}

.dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dropdown-caret {
  font-size: 8px;
  opacity: 0.7;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 180px;
  background: var(--surface);
  border: var(--border-w) solid var(--line-strong);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
}

.dropdown-menu-right {
  left: auto;
  right: 0;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 12px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.dropdown-item:hover {
  background: var(--desk);
}

.dropdown-item:focus-visible {
  outline: 2px solid var(--focus) inset;
}

/* ============ Split Button (Save) ============ */
.btn-split {
  display: inline-flex;
}

.btn-split-main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 1px solid rgba(0,0,0,0.15);
}

.btn-split-caret {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 0 8px;
  min-width: 28px;
}

.btn-split-caret .dropdown-caret,
.btn-split-caret .icon {
  opacity: 0.8;
}

.dropdown-caret-icon {
  margin-left: 2px;
  opacity: 0.6;
}

/* ============ Main Three-Rail Layout ============ */
.main {
  display: grid;
  grid-template-columns: var(--rail-left) 1fr var(--rail-right);
  flex: 1;
  overflow: hidden;
}

/* ============ Rails ============ */
.rail {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
}

.rail-left {
  background: var(--surface);
  border-right: var(--border-w) solid var(--line);
}

.rail-center {
  background: var(--desk);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.rail-right {
  background: var(--surface);
  border-left: var(--border-w) solid var(--line);
}

.rail-section {
  margin-bottom: 24px;
}

.rail-section:last-child {
  margin-bottom: 0;
}

/* ============ Typography ============ */
.micro-label {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.helper-text {
  font-size: 11px;
  color: var(--ink-muted);
  margin: 8px 0 0 0;
  line-height: 1.4;
}

.display-headline {
  font: 28px/1.15 var(--f-serif);
  color: var(--accent);
  margin: 0 0 12px 0;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 10px 0;
}

.explainer {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 0 0 16px 0;
  line-height: 1.45;
}

.hint {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 4px 0;
}

/* ============ Buttons ============ */
.btn-s {
  font-size: 12px;
  font-weight: 500;
  padding: 10px 14px;
  border: var(--border-w) solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-s:hover {
  background: var(--desk);
}

.btn-primary {
  font-size: 12px;
  font-weight: 600;
  padding: 10px 18px;
  background: var(--accent);
  color: var(--accent-on);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-accent {
  font-size: 12px;
  font-weight: 600;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--accent-on);
  min-height: 44px;
  width: 100%;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

/* ============ Project Name Input ============ */
.project-name-input {
  width: 100%;
  padding: 10px 12px;
  border: var(--border-w) solid var(--line-strong);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.project-name-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============ Button with Icon ============ */
.btn-icon {
  gap: 6px;
}

/* Inline SVG icons */
.icon {
  flex-shrink: 0;
  vertical-align: middle;
}

.btn-icon .icon {
  opacity: 0.8;
}

/* ============ Chips ============ */
.chip {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  border: var(--border-w) solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-muted);
  min-height: 32px;
}

.chip[aria-pressed="true"],
.chip.active {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-with-input {
  display: flex;
  align-items: center;
  gap: 6px;
}

.safe-input-wrap {
  position: relative;
  display: flex;
  width: 56px;
}

.safe-input-wrap input {
  width: 100%;
  height: 36px;
  padding: 0 24px 0 8px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  font-size: 12px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.safe-input-wrap input::-webkit-outer-spin-button,
.safe-input-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.safe-unit {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--ink-muted);
  pointer-events: none;
}

.chip-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip-icon .icon {
  opacity: 0.7;
}

.seg button .icon {
  opacity: 0.7;
}

.seg-view button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ============ Segmented Controls ============ */
.seg {
  display: inline-flex;
  flex-wrap: nowrap;
  border: var(--border-w) solid var(--line-strong);
  overflow: hidden;
}

.seg button {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface);
  color: var(--ink-muted);
  border-right: var(--border-w) solid var(--line-strong);
  min-height: 36px;
}

.seg button:last-child {
  border-right: none;
}

.seg button[aria-pressed="true"],
.seg button.active {
  background: var(--accent);
  color: var(--accent-on);
}

.seg button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.seg-view {
  margin-right: auto;
}

.seg-vertical {
  flex-direction: column;
}

.seg-vertical button {
  border-right: none;
  border-bottom: var(--border-w) solid var(--line-strong);
}

.seg-vertical button:last-child {
  border-bottom: none;
}

/* Number of Sheets - horizontal row with equal-width touch targets */
#segPages {
  display: flex;
  width: 100%;
}
#segPages button {
  flex: 1;
  min-height: 44px;
  padding: 8px 0;
}

/* ============ Sheet Controls ============ */
.sheet-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sheet-controls .seg {
  flex-shrink: 0;
}

.bleed-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bleed-control .micro-label {
  margin-bottom: 0;
}

/* ============ Paper Swatches ============ */
.paper-swatches {
  display: flex;
  gap: 8px;
  align-items: center;
}

.paper-swatches button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: var(--border-w) solid var(--line);
  padding: 0;
  min-height: 32px;
  flex-shrink: 0;
}

.paper-swatches button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--accent);
}

.paper-swatches button[data-c="custom"] {
  position: relative;
  overflow: hidden;
  background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
}

.paper-swatches button[data-c="custom"]::after {
  content: '+';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ink-muted);
}

/* ============ Swatches ============ */
.sw {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sw button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: var(--border-w) solid var(--line);
  padding: 0;
  min-height: 28px;
}

.sw button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--accent);
}

.sw button[data-c="custom"] {
  position: relative;
  overflow: hidden;
}

.sw button[data-c="custom"]::after {
  content: '+';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ink-muted);
}

/* ============ Layouts Grid ============ */
.layouts-scroll {
  /* No scrolling - tiles wrap onto multiple rows */
  margin: 0 -20px;
  padding: 0 20px;
}

.layouts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
}

.layouts .lay {
  /* Aspect ratio from page orientation via CSS vars */
  aspect-ratio: var(--pw, 148) / var(--ph, 210);
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0; /* Allow grid to shrink tiles */
}

.layouts .lay:hover {
  border-color: var(--accent);
}

.layouts .lay[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(222, 80, 91, 0.08);
}

/* Layout template icons */
.ico {
  display: block;
  width: 100%;
  aspect-ratio: var(--pw, 148) / var(--ph, 210);
  position: relative;
}

.ico .in {
  position: absolute;
  inset: 8%;
  background: var(--desk);
  border: 1px solid var(--line);
}

.ico .in.b {
  inset: 0;
}

.ico .in i {
  position: absolute;
  background: var(--ink-muted);
  opacity: 0.35;
}

.ico .in i.text {
  background: var(--line);
  opacity: 0.6;
}
/* ============ Add Layer Buttons ============ */
.add-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.add-btns .btn-s {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

/* ============ Center Rail ============ */
.center-header {
  padding: 0 0 12px 0;
  flex-shrink: 0;
}

.page-heading {
  margin-bottom: 4px;
}

.clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  background: transparent;
  border: none;
  opacity: 0.7;
  cursor: pointer;
}

.clear-btn:hover {
  opacity: 1;
  color: var(--danger, #c53030);
}

.clear-btn .icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.center-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .center-toolbar {
    gap: 6px;
    flex-wrap: wrap;
  }
  .toolbar-left {
    flex: 0 0 auto;
    gap: 6px;
  }
  .toolbar-right {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 6px;
    margin-left: 0;
  }
  /* Hide all text labels in toolbar at narrow widths */
  .center-toolbar .seg button span,
  .center-toolbar #snapToggle span {
    display: none !important;
  }
  .center-toolbar .seg button {
    padding: 6px 10px;
    min-width: auto;
  }
  .center-toolbar #snapToggle {
    padding: 6px 8px;
    min-width: auto;
  }
}

/* ============ Canvas Area ============ */
.canvas-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
}

.canvas-stage {
  position: relative;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.canvas-footer {
  display: flex;
  justify-content: flex-start;
  padding: 8px 0 0 0;
  flex-shrink: 0;
}

.zoom-ctrl {
  display: inline-flex;
  height: 32px;
  border: var(--border-w) solid var(--line-strong);
  background: var(--surface);
  overflow: hidden;
}

.zoom-ctrl button {
  width: 32px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-right: var(--border-w) solid var(--line);
  background: transparent;
  color: var(--ink-muted);
}

.zoom-ctrl button:last-child {
  border-right: none;
}

.zoom-ctrl button:hover {
  background: var(--desk);
}

.zoom-ctrl button .icon {
  opacity: 0.7;
}

.center-toolbar #snapToggle {
  height: 32px;
  min-height: 32px;
  padding: 0 10px;
}

.pagecap {
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
  margin-top: 12px;
  flex-shrink: 0;
}

/* ============ Sheet Tabs ============ */
.sheet-tabs-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px 0;
  border-top: var(--border-w) solid var(--line);
  margin-top: 16px;
  flex-shrink: 0;
}

.sheet-tabs {
  display: flex;
  gap: 4px;
}

.sheet-tab {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  border: var(--border-w) solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-muted);
  min-height: 36px;
}

.sheet-tab:hover {
  border-color: var(--accent);
}

.sheet-tab.active {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

/* ============ Filmstrip ============ */
.filmstrip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  flex-shrink: 0;
}

.filmstrip-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.filmstrip-arrow {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 18px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.filmstrip-arrow:hover:not([hidden]) {
  background: var(--desk);
  color: var(--ink);
}

.filmstrip-arrow[hidden] {
  visibility: hidden;
}

.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  flex-shrink: 0;
}

.strip .thumb {
  flex-shrink: 0;
  width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 8px 4px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
}

.strip .thumb:hover {
  border-color: var(--accent);
}

.strip .thumb.sel {
  border-color: var(--accent);
  background: rgba(222, 80, 91, 0.05);
}

.strip .thumb-pg {
  width: 100%;
  aspect-ratio: var(--pw, 148) / var(--ph, 210);
  background: var(--paper);
  border: var(--border-w) solid var(--line);
  position: relative;
  overflow: hidden;
  margin-bottom: 6px;
}

.strip .thumb-num {
  font: 20px var(--f-serif);
  color: var(--accent);
  line-height: 1;
}

.strip .thumb-label {
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: center;
  line-height: 1.3;
  margin-top: 4px;
}

/* ============ Right Rail Cards ============ */
.card {
  background: var(--desk);
  padding: 16px;
  border: var(--border-w) solid var(--line);
}

.card-title {
  font: 18px/1.2 var(--f-serif);
  color: var(--ink);
  margin: 0 0 12px 0;
}

.card-title .accent {
  color: var(--accent);
}

/* ============ Layers Panel ============ */
.layers-panel {
  font-size: 12px;
}

.layers-list {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.layers-list:empty + .layers-order {
  display: none;
}

/* Layer row - minimum 44px tall for touch, actual height depends on thumbnail */
.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  min-height: 44px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.1s;
}

.layer-row:hover {
  background: var(--desk);
}

.layer-row.selected {
  background: var(--accent-tint);
}

.layer-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Grip handle - 40px wide touch target */
.layer-grip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 100%;
  cursor: grab;
  color: var(--ink-muted);
  touch-action: none;
}

.layer-grip:active {
  cursor: grabbing;
}

.layer-grip:hover {
  color: var(--ink);
}

/* Thumbnail ~40x52 for A5-ish proportion */
.layer-thumb {
  width: 40px;
  height: 52px;
  min-width: 40px;
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layer-thumb-text {
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}

/* Layer info */
.layer-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.layer-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.layer-type {
  font-size: 11px;
  color: var(--ink-muted);
}

/* Drag preview */
.layer-row.dragging {
  opacity: 0.5;
}

.layer-row.drag-over-top::before,
.layer-row.drag-over-bottom::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.layer-row.drag-over-top::before {
  top: -1px;
}

.layer-row.drag-over-bottom::after {
  bottom: -1px;
}

.layer-row {
  position: relative;
}

/* Layer order buttons - moved from inspector */
.layers-order {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 8px;
}

.layers-order button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  min-height: 36px;
  color: var(--ink-muted);
}

.layers-order button:hover {
  background: var(--desk);
  color: var(--ink);
}

.layers-order button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Empty state */
.layers-empty {
  padding: 16px 0;
  text-align: center;
  color: var(--ink-muted);
}

.layers-empty-text {
  margin-bottom: 12px;
}

.layers-empty-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.layers-empty-actions button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  font-size: 12px;
  color: var(--ink);
}

.layers-empty-actions button:hover {
  background: var(--desk);
}

/* ============ Inspector ============ */
#inspector {
  font-size: 12px;
}

/* Sections with consistent spacing */
#inspector .insp-section {
  margin-bottom: 16px;
}

#inspector .insp-section:last-child {
  margin-bottom: 0;
}

/* Grid row for geometry fields: 2 equal columns */
#inspector .insp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

#inspector .insp-grid:last-child {
  margin-bottom: 0;
}

/* Field wrapper with label above input */
#inspector .insp-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#inspector .insp-field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Input with unit suffix container */
#inspector .insp-input-wrap {
  position: relative;
  display: flex;
}

#inspector .insp-input-wrap input {
  width: 100%;
  padding: 8px 28px 8px 8px; /* room for suffix */
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  font-size: 12px;
  min-height: 36px;
  -moz-appearance: textfield;
  appearance: textfield;
}

#inspector .insp-input-wrap input::-webkit-outer-spin-button,
#inspector .insp-input-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#inspector .insp-unit {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--ink-muted);
  pointer-events: none;
}

/* Simple row for labels + controls (Font, Align, etc.) */
#inspector .insp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

#inspector .insp-row:last-child {
  margin-bottom: 0;
}

#inspector .insp-row > span {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  min-width: 60px;
  flex-shrink: 0;
}

/* Layer order buttons - 4 equal icon buttons */
#inspector .insp-order {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

#inspector .insp-order button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  min-height: 36px;
  color: var(--ink-muted);
}

#inspector .insp-order button:hover {
  background: var(--desk);
  color: var(--ink);
}

/* Actions row - equal width buttons */
#inspector .insp-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#inspector .insp-actions.single {
  grid-template-columns: 1fr;
}

#inspector .insp-actions button {
  padding: 10px 12px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  font-size: 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#inspector .insp-actions button:hover {
  background: var(--desk);
}

#inspector .insp-actions button.danger {
  color: var(--accent);
  border-color: var(--accent-tint-rule);
}

#inspector .insp-actions button.danger:hover {
  background: var(--accent-tint-wash);
}

#inspector .insp-actions button.primary {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

#inspector .insp-actions button.primary:hover {
  background: var(--accent-hover);
}

/* Segmented 2-button controls */
#inspector .seg2 {
  display: flex;
  flex: 1;
  border: var(--border-w) solid var(--line);
  overflow: hidden;
}

#inspector .seg2 button {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  border: none;
  border-right: var(--border-w) solid var(--line);
  background: var(--surface);
  min-height: 32px;
}

#inspector .seg2 button:last-child {
  border-right: none;
}

#inspector .seg2 button:hover {
  background: var(--desk);
}

#inspector .seg2 button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-on);
}

/* Hint text */
#inspector .hint {
  font-size: 11px;
  color: var(--ink-muted);
  margin: 8px 0 0 0;
  line-height: 1.4;
}

/* Ghost button for secondary actions */
#inspector button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-muted);
  padding: 6px 0;
  min-height: auto;
}

#inspector button.ghost:hover {
  color: var(--ink);
  background: transparent;
}

/* Color button */
#inspector .insp-color-btn {
  width: 36px;
  height: 36px;
  border: var(--border-w) solid var(--line);
  flex-shrink: 0;
}

#inspector .insp-color-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Text layer size input inline with row */
#inspector .insp-row input[type="number"] {
  width: 70px;
  flex-shrink: 0;
  padding: 6px 8px;
  border: var(--border-w) solid var(--line);
  background: var(--surface);
  font-size: 12px;
  min-height: 32px;
  -moz-appearance: textfield;
  appearance: textfield;
}

#inspector .insp-row input::-webkit-outer-spin-button,
#inspector .insp-row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ============ Safety Panel ============ */
.safety-panel {
  font-size: 11px;
  padding: 8px;
  background: var(--surface);
  min-height: 32px;
}

.safety-panel.has-issues {
  background: var(--accent-tint-wash);
  border: 1px solid var(--accent-tint-rule);
}

.safety-panel.no-issues {
  background: var(--info-tint);
  border: 1px solid var(--info-wash);
}

.check-ok {
  color: var(--info);
  font-weight: 500;
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.check-warn {
  color: var(--ink);
  padding: 2px 0;
  line-height: 1.35;
}

.check-warn::before {
  content: '⚠ ';
  color: var(--accent);
}

/* ============ Imposition Diagram ============ */
.imposition-diagram {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 12px;
  background: var(--surface);
  margin-bottom: 12px;
}

.imposition-diagram .cell {
  aspect-ratio: 148 / 210;
  border: var(--border-w) solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 14px var(--f-serif);
  color: var(--ink-muted);
  position: relative;
}

.imposition-diagram .cell.rot {
  transform: rotate(180deg);
}

.imposition-diagram .cell.rot::after {
  content: '↻';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 8px;
  transform: rotate(180deg);
}

/* ============ Steps ============ */
.steps {
  margin: 0;
  padding: 0 0 0 18px;
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.6;
}

.steps li {
  margin-bottom: 4px;
}

.note {
  font-size: 11px;
  color: var(--ink-muted);
  margin: 12px 0 0 0;
  line-height: 1.45;
}

.flip-backs-control {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: var(--border-w) solid var(--line);
}

.flip-backs-control .chip {
  min-height: 40px;
}

.flip-backs-control .helper-text {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 8px 0 0 0;
  line-height: 1.4;
}

/* ============ Export Buttons ============ */
.export-btns {
  margin-top: 16px;
  padding-top: 12px;
  border-top: var(--border-w) solid var(--line);
}

.export-btns .seg {
  margin-top: 8px;
  width: 100%;
}

.export-btns .seg button {
  flex: 1;
}

/* ============ Sheets Overlay ============ */
.sheets-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 23, 25, 0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.sheets-overlay[hidden] {
  display: none;
}

.sheets-overlay-content {
  background: var(--desk);
  max-width: 1200px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  width: 100%;
}

.sheets-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.sheets-overlay .sub {
  font-size: 13px;
  color: var(--ink-muted);
  margin: 0 0 24px 0;
  line-height: 1.5;
}

.sheets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.sheets figure {
  margin: 0;
}

.sheets figcaption {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 12px;
}

.sheets figcaption small {
  color: var(--ink-muted);
  font-weight: 400;
}

.sheets .sheet {
  background: var(--paper);
  position: relative;
  width: calc(var(--mm) * var(--sw));
  height: calc(var(--mm) * var(--sh));
  max-width: 100%;
}

/* ============ Shared Page Rendering ============ */
/* These rules apply in ALL contexts: editor, thumbnails, sheet previews, print area */
.pg {
  position: relative;
  width: calc(var(--mm) * var(--pw, 148));
  height: calc(var(--mm) * var(--ph, 210));
  background: var(--paper);
  overflow: hidden;
}

.layer {
  position: absolute;
}

.layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
}

.layer svg {
  width: 100%;
  height: 100%;
  display: block;
}

.layer .tx {
  width: 100%;
  height: 100%;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.layer .tx:empty::before {
  content: attr(data-ph);
  color: var(--ink-muted);
  opacity: 0.6;
}

.layer .ph {
  width: 100%;
  height: 100%;
  border: 1px dashed var(--line);
  background: rgba(0,0,0,0.02);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--ink-muted);
}

/* Safe margin guide - individual lines per unsafe side */
.guide {
  position: absolute;
  pointer-events: none;
  border: none;
}

.guide-top {
  top: calc(var(--mm) * var(--band, 0));
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed var(--guide);
  opacity: 0.4;
}

.guide-right {
  top: 0;
  right: calc(var(--mm) * var(--band, 0));
  bottom: 0;
  width: 0;
  border-right: 1px dashed var(--guide);
  opacity: 0.4;
}

.guide-bottom {
  bottom: calc(var(--mm) * var(--band, 0));
  left: 0;
  right: 0;
  height: 0;
  border-bottom: 1px dashed var(--guide);
  opacity: 0.4;
}

.guide-left {
  top: 0;
  left: calc(var(--mm) * var(--band, 0));
  bottom: 0;
  width: 0;
  border-left: 1px dashed var(--guide);
  opacity: 0.4;
}

/* ============ Layer Handles ============ */
.layer-handles {
  position: absolute;
  pointer-events: none;
  z-index: 10;
}

.handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border: 2px solid var(--accent);
  pointer-events: auto;
  cursor: text;
}

.resize-handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.resize-handle.n { left: calc(50% - 5px); top: -5px; cursor: ns-resize; }
.resize-handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.resize-handle.e { right: -5px; top: calc(50% - 5px); cursor: ew-resize; }
.resize-handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.resize-handle.s { left: calc(50% - 5px); bottom: -5px; cursor: ns-resize; }
.resize-handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.resize-handle.w { left: -5px; top: calc(50% - 5px); cursor: ew-resize; }

.rotate-handle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  left: calc(50% - 6px);
  top: -24px;
  cursor: grab;
}

/* ============ Snap guides ============ */
.snapToggle[aria-pressed="false"] ~ #editorPage .snap-guide {
  display: none;
}

/* ============ Hidden inputs ============ */
/* Safari requires inputs to be rendered (not display:none/visibility:hidden)
   to show native pickers from programmatic clicks. Keep in layout but invisible. */
.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
  clip-path: inset(50%);
}

/* ============ Toast ============ */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--a0);
  padding: 12px 20px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
}

/* ============ Print Styles ============ */
@media print {
  html, body {
    background: #fff;
    margin: 0;
    padding: 0;
  }
  
  #app, #toast {
    display: none !important;
  }
  
  #printArea {
    display: block !important;
    --mm: 1mm;
  }
  
  #printArea .sheet {
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
  
  #printArea .sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  
  #printArea .foldline,
  #printArea .tag {
    display: none !important;
  }
}

#printArea {
  display: none;
}

/* ============ Sheet Styling (shared preview + print) ============ */
.sheet {
  position: relative;
  background: var(--paper);
  width: calc(var(--mm) * var(--sw, 297));
  height: calc(var(--mm) * var(--sh, 420));
}

.sheet .cell {
  position: absolute;
  overflow: hidden;
}

.sheet .cell.rot {
  transform: rotate(180deg);
}

.sheet .cell .pg {
  width: calc(var(--mm) * var(--pw, 148));
  height: calc(var(--mm) * var(--ph, 210));
}

.sheet .tag {
  position: absolute;
  font-size: 10px;
  color: var(--accent);
  background: var(--surface);
  padding: 2px 6px;
  pointer-events: none;
}

.sheet .foldline {
  position: absolute;
  border: 1px dashed var(--guide);
  opacity: 0.6;
  pointer-events: none;
}

.sheet .foldline.h {
  width: 100%;
  height: 0;
  left: 0;
  top: calc(var(--mm) * var(--sh) / 2);
}

.sheet .foldline.v {
  width: 0;
  height: 100%;
  left: calc(var(--mm) * var(--sw) / 2);
  top: 0;
}

/* Cut/slit line - solid pink */
.sheet .cutline {
  position: absolute;
  border: 1px solid var(--candy-pink-750);
  opacity: 0.6;
  pointer-events: none;
}

.sheet .cutline.v {
  width: 0;
  height: 100%;
  left: calc(var(--mm) * var(--sw) / 2);
  top: 0;
}

.sheet .cutline.h {
  width: 100%;
  height: 0;
  left: 0;
  top: calc(var(--mm) * var(--sh) / 2);
}

/* Crop and fold marks */
.sheet .mk {
  position: absolute;
  background: #000;
}

.sheet .mk.fold {
  background: #666;
}

/* ============ Responsive: Tablet (834px) ============ */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(400px, 1fr) auto;
    overflow-y: auto;
  }
  
  .rail-left {
    order: 1;
    border-right: none;
    border-bottom: var(--border-w) solid var(--line);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 16px;
    overflow: visible;
  }
  
  .rail-left .rail-section {
    margin-bottom: 0;
  }
  
  .rail-left .rail-section:first-child {
    grid-column: 1 / -1;
  }
  
  .rail-center {
    order: 2;
    padding: 16px;
    overflow-y: auto;       /* Constrain canvas so it doesn't escape grid cell */
  }
  
  .rail-right {
    order: 3;
    border-left: none;
    border-top: var(--border-w) solid var(--line);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    padding: 16px;
  }
  
  .rail-right .rail-section {
    margin-bottom: 0;
  }
  
  .header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding: 12px 16px;
  }
  
  .header-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .sheets-overlay {
    padding: 20px;
  }
  
  .sheets {
    grid-template-columns: 1fr;
  }
}

/* ============ Spread View ============ */
.canvas-stage.spread-view {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: flex-start;
}

/* Partner page (read-only half of spread) */
.canvas-stage.spread-view .spread-partner {
  cursor: pointer;
  transition: opacity 0.15s;
  opacity: 0.85;
  flex-shrink: 0;
}

.canvas-stage.spread-view .spread-partner:hover {
  opacity: 1;
}

/* Blank placeholder for cover spreads */
.canvas-stage.spread-view .spread-blank {
  background: var(--bg);
  border: 1px dashed var(--line);
  flex-shrink: 0;
}

/* ============ In-App Color Picker (Wheel) ============ */
/* Hue ring + saturation/brightness square, presets, recents */
.color-picker {
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 14px;
  width: 240px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  display: none;
}

.color-picker.open {
  display: block;
}

.cp-header {
  margin-bottom: 12px;
}

/* Hue ring container */
.cp-wheel-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.cp-ring {
  position: relative;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, 
    hsl(0, 100%, 50%),
    hsl(60, 100%, 50%),
    hsl(120, 100%, 50%),
    hsl(180, 100%, 50%),
    hsl(240, 100%, 50%),
    hsl(300, 100%, 50%),
    hsl(360, 100%, 50%)
  );
  cursor: pointer;
  touch-action: none;
}

.cp-ring:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.cp-ring-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--ink), 0 2px 4px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cp-ring-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 3px solid var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none;
}

/* Saturation/Brightness square */
.cp-square-wrap {
  position: relative;
  margin-bottom: 12px;
}

.cp-square {
  display: block;
  width: 100%;
  height: 120px;
  border: 1px solid var(--line);
  cursor: crosshair;
  touch-action: none;
}

.cp-square:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.cp-square-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--ink), 0 1px 3px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Preview and hex input */
.cp-preview-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: stretch;
}

.cp-preview {
  width: 48px;
  min-height: 40px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.cp-hex {
  flex: 1;
  font-family: monospace;
  font-size: 14px;
  padding: 8px 10px;
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-transform: uppercase;
  box-sizing: border-box;
}

.cp-hex:focus {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* Section labels */
.cp-section-label {
  margin-bottom: 6px;
  margin-top: 4px;
}

/* Recents row */
.cp-recents {
  margin-bottom: 8px;
}

.cp-recents-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.cp-recents-row .cp-swatch {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  flex: 0 0 40px;
}

/* Swatch grid */
.cp-swatches {
  display: grid;
  grid-template-columns: repeat(5, minmax(40px, 1fr));
  gap: 3px;
  margin-bottom: 12px;
}

.cp-swatch {
  width: 100%;
  aspect-ratio: 1;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  position: relative;
}

.cp-swatch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  z-index: 1;
}

.cp-swatch.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--ink);
}

.cp-swatch.dark.active::after {
  color: var(--a0);
}

/* Print note */
.cp-note {
  font-size: 11px;
  color: var(--ink-muted);
  margin-bottom: 12px;
  line-height: 1.3;
}

/* Actions */
.cp-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.cp-actions .btn {
  min-width: 70px;
  min-height: 40px;
}

/* Inspector color button */
.insp-color-btn {
  width: 40px;
  height: 36px;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.insp-color-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Responsive: smaller ring on narrow viewports */
@media (max-width: 520px) {
  .color-picker {
    width: calc(100vw - 24px);
    padding: 10px;
    max-height: calc(100vh - 80px);
  }
  
  .cp-header {
    margin-bottom: 8px;
  }
  
  .cp-ring {
    width: 140px;
    height: 140px;
  }
  
  .cp-ring-center {
    width: 60px;
    height: 60px;
  }
  
  .cp-wheel-wrap {
    margin-bottom: 8px;
  }
  
  .cp-square {
    height: 80px;
  }
  
  .cp-square-wrap {
    margin-bottom: 8px;
  }
  
  .cp-swatches {
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 8px;
  }
  
  .cp-swatch {
    min-width: 40px;
    min-height: 40px;
  }
  
  .cp-recents {
    margin-bottom: 6px;
  }
  
  .cp-note {
    margin-bottom: 8px;
    font-size: 10px;
  }
  
  .cp-section-label {
    margin-bottom: 4px;
    margin-top: 2px;
  }
}

/* ============ Setup Panel ============ */
.setup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 23, 25, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.setup-overlay[hidden] {
  display: none;
}

.setup-panel {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.setup-title {
  font-family: var(--f-head);
  font-size: 24px;
  font-weight: 400;
  margin: 0 0 24px 0;
  color: var(--ink);
}

.setup-section {
  margin-bottom: 20px;
}

.setup-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.setup-helper {
  display: block;
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 6px;
}

.setup-helper[hidden] {
  display: none;
}

.setup-summary {
  font-size: 14px;
  color: var(--ink-muted);
  margin: 20px 0 24px 0;
  padding: 12px;
  background: var(--desk);
  border-radius: 6px;
  line-height: 1.5;
}

/* Setup panel body - two-column at wide widths */
.setup-body {
  display: flex;
  gap: 24px;
}

.setup-controls {
  flex: 0 0 auto;
  min-width: 180px;
}

/* Schematic container */
.setup-schematic {
  flex: 1 1 auto;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.setup-schematic-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.setup-schematic-side svg {
  display: block;
}

.setup-schematic-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

/* Stack controls and schematic on narrow screens */
@media (max-width: 540px) {
  .setup-panel {
    max-width: 400px;
  }
  
  .setup-body {
    flex-direction: column;
  }
  
  .setup-controls {
    min-width: auto;
  }
  
  .setup-schematic {
    justify-content: center;
    margin-top: 8px;
  }
}

.setup-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setup-buttons button {
  width: 100%;
  min-height: 44px;
  padding: 12px 24px;
  font-size: 13px;
}

/* Credit line in rail */
.rail-credit {
  font-size: 11px;
  color: var(--ink-muted);
  margin: auto 0 0 0;
  padding: 12px 0;
}

.rail-credit a {
  color: var(--ink-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.rail-credit a:hover {
  color: var(--ink);
}

/* Format display in rail */
.format-section {
  padding-top: 8px;
  padding-bottom: 8px;
}

.format-display {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.format-text {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.4;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  color: var(--candy-pink-750);
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover {
  color: var(--candy-pink-500);
}

@media (max-width: 520px) {
  .setup-panel {
    padding: 24px;
  }
  
  .setup-title {
    font-size: 20px;
  }
}

/* Clear confirmation panel (smaller) */
.setup-panel-sm {
  max-width: 340px;
  text-align: center;
}

.setup-panel-sm .setup-summary {
  margin: 12px 0 24px 0;
}

/* Danger button */
.btn-danger {
  background: var(--candy-pink-750);
}

.btn-danger:hover {
  background: var(--candy-pink-500);
}

/* Danger dropdown item */
.dropdown-item-danger {
  color: var(--candy-pink-750);
}

.dropdown-item-danger:hover {
  background: rgba(222, 80, 91, 0.1);
  color: var(--candy-pink-750);
}

/* ============ Empty State ============ */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
}

.empty-state[hidden] {
  display: none;
}

.empty-card {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: 12px;
  padding: 40px 48px;
  text-align: center;
  max-width: 320px;
}

.empty-text {
  font-size: 15px;
  color: var(--ink-muted);
  margin: 0 0 24px 0;
  line-height: 1.5;
}

.btn-create-new {
  min-width: 140px;
  padding: 14px 28px;
}

/* Editor content wrapper */
.editor-content[hidden] {
  display: none;
}

/* Disabled header buttons */
.header-actions .btn-preview:disabled,
.header-actions .btn-split-main:disabled,
.header-actions .btn-split-caret:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Center toolbar hidden state */
.center-toolbar[hidden] {
  display: none;
}

/* Rail sections hidden state */
.rail-section[hidden] {
  display: none;
}

.rail-credit[hidden] {
  display: none;
}

/* ============ Page Settings ============ */
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.settings-row:last-child {
  margin-bottom: 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--candy-pink-500);
  cursor: pointer;
}

/* Sheet helper text */
#sheetHelper {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 8px 0 0 0;
  line-height: 1.4;
}

/* ============ Selected Page Add Buttons ============ */
.add-btns-compact {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.add-btns-compact .btn-s {
  flex: 1;
  min-height: 44px;
  font-size: 12px;
}

.inspector-content {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
