:root {
  --bg: #111111;
  --panel: #1a1a1a;
  --panel-2: #222222;
  --paper: #f2efe7;
  --ink: #f5f5f5;
  --muted: #9c9c9c;
  --line: #333333;
  --accent: #f5f5f5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }

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

.topbar {
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #151515;
}

.topbar h1 { margin: 2px 0 0; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.eyebrow, .section-kicker { font-size: 10px; letter-spacing: .16em; color: #7e7e7e; font-weight: 700; }
.version { font-size: 12px; color: var(--muted); }

.setup-view { flex: 1; display: grid; place-items: center; padding: 40px 20px; }
.setup-card {
  width: min(520px, 100%);
  padding: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
}
.setup-card h2 { margin: 8px 0 6px; font-size: 30px; letter-spacing: -.04em; }
.muted { color: var(--muted); line-height: 1.5; margin: 0 0 28px; }
.spec-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 28px; }
.spec-row > div { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.spec-row strong { font-size: 14px; font-weight: 600; }

.page-count-block { margin-bottom: 24px; }
.page-count-block > label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 650; }
.stepper { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; }
.stepper button, .stepper input {
  height: 48px;
  border: 1px solid #3b3b3b;
  background: #202020;
  color: var(--ink);
  border-radius: 10px;
}
.stepper button { font-size: 24px; }
.stepper input { text-align: center; font-size: 18px; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.hint { color: #777; font-size: 12px; margin: 8px 0 0; }
.hint.error { color: #d9a0a0; }

.primary-btn {
  width: 100%; height: 50px; border: 0; border-radius: 11px;
  background: var(--accent); color: #111; font-weight: 750;
}

.document-view { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr; }
.hidden { display: none !important; }
.sidebar { border-right: 1px solid var(--line); background: #151515; min-height: 0; display: flex; flex-direction: column; }
.sidebar-head { padding: 20px 18px 16px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); }
.sidebar-head h2 { font-size: 15px; margin: 6px 0 0; }
.ghost-btn { border: 1px solid #3a3a3a; background: transparent; color: #bbb; border-radius: 8px; padding: 6px 9px; font-size: 12px; }
.thumbnail-grid { overflow: auto; padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-content: start; }
.thumb-wrap { display: flex; flex-direction: column; gap: 6px; }
.thumb {
  aspect-ratio: 148 / 210;
  background: #e9e6df;
  border: 2px solid transparent;
  border-radius: 2px;
  position: relative;
  display: grid;
  place-items: center;
  color: #aaa;
  font-size: 16px;
}
.thumb:hover { border-color: #666; }
.thumb.active { border-color: #f4f4f4; }
.thumb-label { font-size: 10px; color: #7e7e7e; text-align: center; }

.workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.workspace-toolbar { height: 58px; padding: 0 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; background: #181818; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; color: #888; border-radius: 7px; padding: 8px 12px; font-size: 12px; }
.tab.active { background: #2a2a2a; color: #fff; }
.tab.disabled { opacity: .4; cursor: default; }
.status { font-size: 12px; color: #777; }

.canvas-area { flex: 1; min-height: 0; overflow: auto; display: grid; justify-items: center; align-content: start; padding: 32px 44px 44px; background-image: radial-gradient(#2b2b2b 1px, transparent 1px); background-size: 22px 22px; }
.page-canvas {
  width: min(48vh, 420px);
  aspect-ratio: 148 / 210;
  background: var(--paper);
  color: #111;
  position: relative;
  container-type: inline-size;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.safe-area { position: absolute; inset: 6.75%; border: 1px dashed rgba(0,0,0,.18); }
.page-number { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(48px, 7vw, 84px); color: #c2beb4; font-weight: 750; }
.cover-badge { position: absolute; top: 16px; left: 16px; font-size: 9px; letter-spacing: .13em; font-weight: 800; color: #9c978c; }
.canvas-meta { margin-top: 12px; width: min(48vh, 420px); display: flex; justify-content: space-between; font-size: 12px; color: #777; }
.canvas-meta strong { color: #bdbdbd; }

@media (max-width: 760px) {
  .document-view { grid-template-columns: 110px 1fr; }
  .thumbnail-grid { grid-template-columns: 1fr; padding: 10px; }
  .sidebar-head { padding: 14px 10px; }
  .sidebar-head h2 { display: none; }
  .workspace-toolbar { padding: 0 12px; }
  .status { display: none; }
  .canvas-area { padding: 20px; }
  .spec-row { grid-template-columns: 1fr; }
}

/* Book preview */
.book-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: block;
  padding: 28px 36px 36px;
  background-image: radial-gradient(#2b2b2b 1px, transparent 1px);
  background-size: 22px 22px;
}

.book-preview-shell {
  width: min(100%, 960px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.book-preview-header,
.book-preview-footer {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
}

.book-preview-header > div {
  text-align: center;
}

.book-preview-header strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  font-weight: 650;
}

.book-preview-footer {
  grid-template-columns: 1fr 1fr;
  color: #777;
  font-size: 12px;
}

.book-preview-footer span:last-child {
  text-align: right;
}

.preview-nav {
  width: 42px;
  height: 42px;
  border: 1px solid #3b3b3b;
  border-radius: 10px;
  background: #1d1d1d;
  color: #d8d8d8;
  font-size: 18px;
}

.preview-nav:last-child {
  justify-self: end;
}

.preview-nav:disabled {
  opacity: .28;
  cursor: default;
}

.book-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
  min-height: 0;
}

.book-page {
  width: min(31vw, 320px);
  aspect-ratio: 148 / 210;
  background: var(--paper);
  color: #111;
  position: relative;
  box-shadow: 0 18px 48px rgba(0,0,0,.32);
}

.book-page:first-child:not(.single) {
  box-shadow: -10px 18px 48px rgba(0,0,0,.26);
}

.book-page:last-child:not(.single) {
  box-shadow: 10px 18px 48px rgba(0,0,0,.26);
}

.book-page-safe {
  position: absolute;
  inset: 6.75%;
  border: 1px dashed rgba(0,0,0,.14);
}

.book-page-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c2beb4;
  font-size: clamp(46px, 7vw, 78px);
  font-weight: 750;
}

.book-page-role {
  position: absolute;
  left: 16px;
  bottom: 14px;
  color: #9c978c;
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 800;
}

.single-page-stage .book-page {
  width: min(31vw, 320px);
}

@media (max-width: 760px) {
  .book-view {
    padding: 20px 12px;
  }

  .book-stage {
    min-height: 320px;
  }

  .book-page,
  .single-page-stage .book-page {
    width: min(38vw, 240px);
  }

  .book-preview-header,
  .book-preview-footer {
    grid-template-columns: 46px 1fr 46px;
  }

  .book-preview-footer {
    grid-template-columns: 1fr 1fr;
  }
}

/* Print preview */
.print-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: block;
  padding: 28px 36px 36px;
  background-image: radial-gradient(#2b2b2b 1px, transparent 1px);
  background-size: 22px 22px;
}

.print-preview-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.print-preview-header {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
}

.print-heading {
  text-align: center;
}

.print-heading strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  font-weight: 650;
}

.side-toggle {
  display: inline-flex;
  gap: 3px;
  margin-top: 10px;
  padding: 3px;
  border: 1px solid #343434;
  border-radius: 9px;
  background: #181818;
}

.side-btn {
  border: 0;
  border-radius: 6px;
  padding: 6px 12px;
  background: transparent;
  color: #777;
  font-size: 11px;
}

.side-btn.active {
  background: #303030;
  color: #fff;
}

.print-stage {
  width: min(78vw, 900px);
  aspect-ratio: 297 / 210;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #ddd9d0;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 18px 50px rgba(0,0,0,.32);
}

.print-page {
  min-width: 0;
  background: var(--paper);
  color: #111;
  position: relative;
}

.print-page + .print-page {
  border-left: 1px dashed rgba(0,0,0,.28);
}

.print-page-safe {
  position: absolute;
  inset: 6.75%;
  border: 1px dashed rgba(0,0,0,.14);
}

.print-page-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c2beb4;
  font-size: clamp(44px, 7vw, 82px);
  font-weight: 750;
}

.print-page-role {
  position: absolute;
  left: 16px;
  bottom: 14px;
  color: #9c978c;
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 800;
}

.print-preview-footer {
  display: flex;
  justify-content: space-between;
  color: #777;
  font-size: 12px;
}

.print-note {
  padding: 12px 14px;
  border: 1px solid #2f2f2f;
  border-radius: 10px;
  background: #171717;
  color: #757575;
  font-size: 11px;
  line-height: 1.45;
}

@media (max-width: 760px) {
  .print-view {
    padding: 20px 12px;
  }

  .print-preview-header {
    grid-template-columns: 46px 1fr 46px;
  }

  .print-stage {
    width: min(82vw, 620px);
  }
}



/* Page artwork placement */
.design-toolbar {
  width: min(76vw, 760px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
  padding: 7px;
  border: 1px solid #303030;
  border-radius: 10px;
  background: #181818;
}

.tool-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid #383838;
  border-radius: 7px;
  background: #222;
  color: #d4d4d4;
  font-size: 11px;
}

.tool-btn:hover:not(:disabled),
.tool-btn.active {
  background: #333;
  color: #fff;
  border-color: #505050;
}

.tool-btn.compact {
  width: 30px;
  padding: 0;
  font-size: 16px;
}

.tool-btn.danger {
  margin-left: 2px;
}

.tool-btn:disabled {
  opacity: .35;
  cursor: default;
}

.tool-divider {
  width: 1px;
  height: 20px;
  background: #333;
}

.zoom-controls {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.zoom-label {
  width: 48px;
  text-align: center;
  color: #aaa;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.placement-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(76vw, 760px);
  min-height: 650px;
  padding: 28px 110px;
  overflow: visible;
}

.page-canvas {
  z-index: 2;
  flex: none;
  outline: 1px solid rgba(255,255,255,.28);
  outline-offset: 0;
  touch-action: none;
  user-select: none;
}

.page-canvas.has-artwork {
  cursor: grab;
}

.page-canvas.dragging-artwork {
  cursor: grabbing;
}

.artwork-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: visible;
  pointer-events: none;
}

.artwork-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.editor-artwork,
.preview-artwork,
.thumb-artwork {
  position: absolute;
  max-width: none;
  max-height: none;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}

.editor-artwork.ghost {
  opacity: .24;
  filter: saturate(.85);
}

.editor-artwork.solid {
  opacity: 1;
}

.drop-hint {
  position: absolute;
  inset: auto 18px 18px;
  z-index: 5;
  padding: 8px 10px;
  border: 1px dashed rgba(0,0,0,.22);
  border-radius: 7px;
  background: rgba(245,245,245,.86);
  color: #858078;
  font-size: 10px;
  text-align: center;
  pointer-events: none;
}

.page-canvas.has-artwork .page-number,
.page-canvas.has-artwork .cover-badge,
.page-canvas.has-artwork .safe-area {
  opacity: 0;
}

.page-canvas.has-artwork .drop-hint {
  opacity: 0;
}

.page-canvas.dragging-artwork .drop-hint {
  opacity: 1;
  background: rgba(20,20,20,.72);
  border-color: rgba(255,255,255,.25);
  color: #ddd;
}

.page-canvas.drag-over {
  outline: 3px solid rgba(255,255,255,.72);
  outline-offset: 5px;
}

.page-canvas.drag-over .drop-hint {
  opacity: 1;
  inset: 20px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(0,0,0,.35);
  background: rgba(245,245,245,.9);
  font-size: 13px;
}

.thumb {
  overflow: hidden;
}

.thumb > span {
  position: relative;
  z-index: 2;
}

.thumb-artwork {
  z-index: 1;
}

.thumb.has-artwork > span {
  opacity: 0;
}

.book-page,
.print-page {
  overflow: hidden;
}

.preview-artwork {
  z-index: 2;
}

.book-page.has-artwork .book-page-number,
.book-page.has-artwork .book-page-role,
.print-page.has-artwork .print-page-number,
.print-page.has-artwork .print-page-role {
  opacity: 0;
}

@media (max-width: 900px) {
  .design-toolbar {
    width: min(86vw, 620px);
  }

  .placement-stage {
    width: min(86vw, 620px);
    min-height: 520px;
    padding: 20px 70px;
  }
}

@media (max-width: 760px) {
  .design-toolbar {
    width: 100%;
  }

  .placement-stage {
    width: 100%;
    min-height: 440px;
    padding: 18px 38px;
  }
}

.import-status {
  min-height: 18px;
  margin: -3px 0 2px;
  color: #777;
  font-size: 10px;
  text-align: center;
}

.import-status:empty {
  min-height: 0;
  margin: 0;
}


.reorder-hint {
  padding: 10px 16px 0;
  color: #5f5f5f;
  font-size: 10px;
  text-align: center;
}

.thumb-wrap {
  cursor: grab;
  transition: opacity .12s ease, transform .12s ease;
}

.thumb-wrap:active {
  cursor: grabbing;
}

.thumb-wrap.dragging-page {
  opacity: .35;
}

.thumb-wrap.reorder-target {
  transform: translateY(2px);
}

.thumb-wrap.reorder-target .thumb {
  border-color: #f4f4f4;
  box-shadow: 0 0 0 2px rgba(255,255,255,.18);
}

.thumb-wrap.reorder-target::before {
  content: '';
  display: block;
  height: 2px;
  margin-bottom: -2px;
  border-radius: 999px;
  background: #f4f4f4;
}


.toolbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-status {
  padding-right: 12px;
  border-right: 1px solid #303030;
  color: #656565;
  font-size: 11px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .save-status {
    display: none;
  }
}


.tool-btn.pdf-importing {
  min-width: 84px;
}


.print-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.export-btn {
  min-width: 150px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: #f1f1f1;
  color: #111;
  font-size: 12px;
  font-weight: 750;
}

.export-btn:hover:not(:disabled) {
  background: #ffffff;
}

.export-btn:disabled {
  opacity: .45;
  cursor: default;
}

.export-status {
  color: #727272;
  font-size: 11px;
  text-align: right;
}

@media (max-width: 760px) {
  .print-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .export-status {
    text-align: left;
  }
}


.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ghost-btn.danger-ghost {
  color: #a97979;
  border-color: #463232;
}

.ghost-btn.danger-ghost:hover {
  color: #d4a4a4;
  border-color: #6a4444;
  background: #211919;
}

@media (max-width: 760px) {
  .sidebar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ghost-btn.danger-ghost {
    font-size: 10px;
    padding: 5px 6px;
  }
}
