:root {
  --bg: #081018;
  --bg-soft: #0d1721;
  --panel: rgba(12, 18, 25, 0.96);
  --panel-2: rgba(17, 24, 34, 0.96);
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.16);
  --text: #eef4fb;
  --muted: #8f9db1;
  --accent: #d2a060;
  --accent-soft: rgba(210,160,96,.16);
  --shadow: 0 18px 44px rgba(0,0,0,.22);
  --paper: #fffdf7;
  --ink: #151515;
  --ok-bg: rgba(125, 215, 166, .12);
  --ok-line: rgba(125, 215, 166, .28);
  --warn-bg: rgba(255, 206, 118, .12);
  --warn-line: rgba(255, 206, 118, .28);
  --bad-bg: rgba(255, 142, 142, .12);
  --bad-line: rgba(255, 142, 142, .28);
}

body[data-theme="light"] {
  --bg: #eef2f6;
  --bg-soft: #f7f9fc;
  --panel: rgba(255,255,255,.92);
  --panel-2: rgba(248,250,253,.96);
  --line: rgba(17,24,34,.10);
  --line-strong: rgba(17,24,34,.18);
  --text: #18212c;
  --muted: #5f6f84;
  --accent: #b9792d;
  --accent-soft: rgba(185,121,45,.12);
  --shadow: 0 16px 34px rgba(24,33,44,.10);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(210,160,96,.08), transparent 22%),
    radial-gradient(circle at top right, rgba(112,151,255,.07), transparent 22%),
    var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  outline: none;
}
body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] textarea {
  background: rgba(24,33,44,.03);
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(210,160,96,.48);
  box-shadow: 0 0 0 3px rgba(210,160,96,.12);
}
textarea { resize: vertical; }
input[type="color"] { height: 38px; padding: 4px; }
label { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
label > span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.012)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.app-shell {
  min-height: 100vh;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  position: sticky;
  top: 10px;
  z-index: 30;
}
.topbar-left, .topbar-center, .topbar-right, .segmented, .metrics-row, .chip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.topbar-center { justify-content: center; }
.topbar-right { flex-wrap: wrap; justify-content: flex-end; }
.page-nav { flex-wrap: wrap; }

.ghost, .primary, .seg-btn, .chip, .thumb-btn, .toolbar-menu > summary, .menu-panel button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.04);
  border-radius: 12px;
  padding: 7px 10px;
}
.primary, .toolbar-menu > summary.primary {
  background: linear-gradient(180deg, rgba(210,160,96,.30), rgba(210,160,96,.14));
  border-color: rgba(210,160,96,.28);
}
.seg-btn.active, .chip.active, .thumb-btn.active {
  background: var(--accent-soft);
  border-color: rgba(210,160,96,.34);
}
.icon-btn { width: 38px; padding-inline: 0; }
#pageNumberInput { width: 66px; text-align: center; }
#pageJumpSelect { width: auto; min-width: 170px; max-width: 250px; }
.count-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 38px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.toolbar-menu { position: relative; }
.toolbar-menu > summary { list-style: none; }
.toolbar-menu > summary::-webkit-details-marker { display: none; }
.toolbar-menu[open] > summary {
  background: var(--accent-soft);
  border-color: rgba(210,160,96,.34);
}
.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 162px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: var(--shadow);
}
.menu-panel button { text-align: left; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(188px, 212px) minmax(0, 1fr) minmax(196px, 220px);
  gap: 10px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 74px;
  height: calc(100vh - 84px);
  padding: 7px;
  overflow: hidden;
  min-height: 0;
}
.sidebar-scroll {
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.08);
  border-radius: 999px;
}

.section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.022), rgba(255,255,255,.009));
  overflow: hidden;
}
.section > summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after {
  content: "+";
  font-size: 15px;
  line-height: 1;
}
.section[open] > summary::after { content: "−"; }
.section-body { padding: 0 8px 8px; }
.stack-gap { display: flex; flex-direction: column; gap: 8px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.form-grid .wide { grid-column: 1 / -1; }
.toggle {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
}
.toggle > span { margin: 0; }
.chip-row { flex-wrap: wrap; }
.chip { padding: 6px 9px; font-size: 11px; }
#manuscriptInput {
  min-height: 112px;
  line-height: 1.45;
  font-size: 14px;
}
#backBlurb { min-height: 86px; }
.mini-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.center {
  min-height: calc(100vh - 84px);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.center-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.metrics-row { flex-wrap: wrap; }
.metric-chip {
  min-width: 84px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.metric-chip span {
  display: block;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.metric-chip strong { font-size: 13px; }

.stage-wrap {
  flex: 1;
  min-height: 700px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,.022), rgba(255,255,255,.009)),
    var(--bg-soft);
  padding: 10px;
  overflow: auto;
}
.view { display: none; min-height: 100%; }
.view.active { display: block; }
.page-stage, .cover-stage {
  min-height: 580px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-workspace, .cover-workspace {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.page-meta, .cover-caption {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
}
.page-paper, .cover-paper {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 56px rgba(0,0,0,.22);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
  max-width: 100%;
}
.cover-paper { border-radius: 12px; }
.sheet-guide,
.safe-guide,
.header-guide,
.folio-guide,
.barcode-box,
.spine-guide,
.trim-guide,
.preview-folio,
.preview-header { position: absolute; }
.trim-guide { border: 1px solid rgba(25,25,25,.10); }
.safe-guide { border: 1px dashed rgba(190,130,59,.75); }
.header-guide { border-top: 1px dashed rgba(92,116,170,.56); }
.folio-guide { border-top: 1px dashed rgba(44,153,124,.66); }
.page-inner {
  position: absolute;
  overflow: visible;
}
.preview-header, .preview-folio { color: #535353; }

.page-block,
.title-edit,
.cover-edit,
.blurb-edit,
.dedication-edit {
  outline: none;
  border-radius: 6px;
  padding: 2px 4px;
}
.page-block[contenteditable="true"]:focus,
.title-edit[contenteditable="true"]:focus,
.cover-edit[contenteditable="true"]:focus,
.blurb-edit[contenteditable="true"]:focus,
.dedication-edit[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 2px rgba(210,160,96,.42);
  background: rgba(210,160,96,.08);
}
.blank-tag {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #777064;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .18em;
}
.thumb-strip {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.thumb-strip::-webkit-scrollbar { height: 8px; }
.thumb-strip::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.08);
  border-radius: 999px;
}
.thumb-btn {
  flex: 0 0 86px;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  min-height: 56px;
  text-align: left;
}
.thumb-btn small {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 10px;
}

.cover-paper .panel-face,
.cover-paper .panel-spine,
.title-treatment-band,
.title-treatment-box {
  position: absolute;
}
.cover-paper .panel-face,
.cover-paper .panel-spine {
  top: 0;
  bottom: 0;
  overflow: hidden;
}
.cover-paper .panel-spine {
  border-left: 1px solid rgba(255,255,255,.16);
  border-right: 1px solid rgba(255,255,255,.16);
}
.cover-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}
.cover-copy,
.back-copy,
.spine-copy,
.title-treatment-band,
.title-treatment-box {
  position: absolute;
}
.cover-copy, .back-copy { color: inherit; }
.title-treatment-band {
  background: rgba(0,0,0,.18);
  backdrop-filter: blur(3px);
  border-radius: 14px;
}
.title-treatment-box {
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 14px;
  background: rgba(255,255,255,.04);
}

.is-draggable { cursor: grab; user-select: none; }
.is-dragging { cursor: grabbing; }
.selected-node {
  box-shadow: 0 0 0 2px rgba(210,160,96,.38), 0 0 0 6px rgba(210,160,96,.08);
  border-radius: 10px;
}
.title-curve {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.title-curve span {
  display: inline-block;
  transform-origin: center bottom;
}

.move-handle {
  position: absolute;
  left: 50%;
  top: -20px;
  transform: translateX(-50%);
  width: 24px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(210,160,96,.34);
  background: rgba(10,14,20,.82);
  color: #f4d7ac;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  cursor: grab;
  user-select: none;
}
body[data-theme="light"] .move-handle {
  background: rgba(255,255,255,.94);
  color: #8b5f2b;
}
.cover-copy .move-handle { top: -22px; }
.title-page-group .move-handle { top: -22px; }

.checks-wrap { display: grid; gap: 10px; }
.check-card {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
}
.check-card.ok { background: var(--ok-bg); border-color: var(--ok-line); }
.check-card.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.check-card.bad { background: var(--bad-bg); border-color: var(--bad-line); }
.check-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.site-link-wrap {
  margin-top: auto;
  padding: 4px 6px 0;
}
.site-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.site-link:hover { color: var(--text); }
.measure-root {
  position: absolute;
  left: -99999px;
  top: -99999px;
  visibility: hidden;
  pointer-events: none;
}
.hidden { display: none !important; }

@media (max-width: 1440px) {
  .workspace-grid {
    grid-template-columns: minmax(196px, 216px) minmax(0, 1fr) minmax(206px, 226px);
  }
}
@media (max-width: 1180px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    max-height: none;
  }
  .center { min-height: auto; }
  .stage-wrap { min-height: 620px; }
}
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr; }
  .topbar-left, .topbar-center, .topbar-right { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  #pageJumpSelect { max-width: 100%; }
  .menu-panel { right: auto; left: 0; }
}

.compact-grid input, .compact-grid select { padding-block: 7px; }
.metric-chip { min-width: 0; }
.metric-chip strong { white-space: nowrap; }
.site-link-wrap { padding: 0 2px 4px; }
.site-link { font-size: 12px; letter-spacing: .08em; }
@media (max-width: 1280px) { .workspace-grid { grid-template-columns: minmax(176px, 200px) minmax(0, 1fr) minmax(186px, 208px); } }


.preflight-strip {
  flex: 1 1 260px;
  min-width: 0;
}
.preflight-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.035);
}
.preflight-compact.ok {
  border-color: rgba(110, 231, 183, .28);
}
.preflight-compact.warn {
  border-color: rgba(209, 154, 88, .34);
}
.preflight-compact.bad {
  border-color: rgba(255, 107, 107, .34);
}
.preflight-status {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}
.preflight-status strong {
  font-size: 15px;
  line-height: 1;
}
.preflight-status span,
.preflight-facts span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
}
.preflight-facts {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  white-space: nowrap;
}
.preflight-facts span + span::before {
  content: '•';
  margin-right: 10px;
  color: rgba(255,255,255,.2);
}
.center-topbar {
  align-items: stretch;
}
.metrics-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.metric-chip {
  min-width: 74px;
  padding: 6px 9px;
  border-radius: 12px;
}
.metric-chip span {
  margin-bottom: 3px;
}
@media (max-width: 1200px) {
  .preflight-compact {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .preflight-facts {
    width: 100%;
    overflow: auto;
    padding-bottom: 2px;
  }
}

.text-blocks-wrap { gap: 10px; }
.block-editor-grid { display: grid; gap: 10px; }
.block-card { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: rgba(255,255,255,.03); }
.block-card-head { display:flex; align-items:center; justify-content:space-between; gap:8px; font-size:12px; text-transform:uppercase; letter-spacing:.12em; color:var(--muted); margin-bottom:8px; }
.inline-toggle { gap: 6px; }
.tiny-grid label span { font-size:10px; }
.cover-text-block { position:absolute; color:inherit; border-radius:8px; }
.cover-text-block .cover-edit { display:block; min-height:1em; line-height:1.35; }
.cover-text-block .move-handle { top:-20px; }
