:root {
  --paper: #f5f0e8;
  --ink: #2a2a2a;
  --panel: #ffffff;
  --line: #d9d1c4;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --chrome: #f1eee9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #242424;
  background: #e9e3da;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.app-header p {
  margin: 5px 0 0;
  color: #66605a;
}

.export-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

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

.secondary {
  border: 1px solid #bdb4a8;
  border-radius: 8px;
  padding: 10px 15px;
  color: #34302c;
  background: #fff;
  cursor: pointer;
}

.secondary:hover {
  background: #f7f4ef;
}

.primary:disabled,
.secondary:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 77px);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--chrome);
  overflow: auto;
}

.controls section {
  display: grid;
  gap: 9px;
}

.controls label,
.breaks h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #514b45;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 126px;
  padding: 18px;
  border: 2px dashed #bcb2a5;
  border-radius: 8px;
  background: #fbfaf7;
  text-align: center;
  cursor: pointer;
}

.drop-zone.active {
  border-color: var(--accent);
  background: #edf7f5;
}

.drop-zone input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.slider-wrap {
  position: relative;
  padding-bottom: 24px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.ticks {
  position: absolute;
  inset: 22px 0 auto;
  height: 22px;
  font-size: 11px;
  color: #716a62;
}

.ticks span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.ticks span::before {
  content: "";
  display: block;
  width: 1px;
  height: 7px;
  margin: 0 auto 2px;
  background: #9a9187;
}

output {
  font-size: 13px;
  color: #5d5751;
}

.two-col {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.two-col label {
  display: grid;
  gap: 7px;
}

input[type="number"],
input[type="color"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cfc6ba;
  border-radius: 7px;
  padding: 8px;
  background: #fff;
}

.preview-area {
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.measure-stage {
  position: fixed;
  left: -100000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 22px;
  align-items: start;
}

.page-card {
  display: grid;
  gap: 9px;
}

.page-shell {
  border: 1px solid rgba(76, 65, 53, 0.18);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 12px 28px rgba(43, 35, 25, 0.12);
  cursor: zoom-in;
}

.render-page {
  position: relative;
  width: var(--page-width);
  height: var(--page-height);
  padding: var(--page-margin);
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  transform-origin: top left;
}

.page-content {
  font-family: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  font-size: var(--export-font-size);
  font-weight: 600;
  height: 100%;
  line-height: var(--line-height, 1.8);
  overflow: hidden;
}

.page-content h1,
.page-content h2,
.page-content h3 {
  margin: 0 0 0.85em;
  font-weight: 700;
  line-height: 1.25;
}

.page-content h1 {
  font-size: 1.55em;
}

.page-content h2 {
  font-size: 1.35em;
}

.page-content h3 {
  font-size: 1.15em;
}

.page-content p {
  margin: 0 0 1.05em;
  overflow-wrap: anywhere;
}

.page-content .unit {
  display: flow-root;
}

.page-content .unit > :last-child {
  margin-bottom: 1.05em;
}

.page-content .unit.continues > :last-child {
  margin-bottom: 0;
}

.page-content .unit.continuation > :first-child {
  text-indent: 0;
}

.page-content .unit.continuation > :last-child {
  margin-bottom: 1.05em;
}

.break-handle {
  display: block;
  width: 100%;
  height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: row-resize;
  position: relative;
  z-index: 2;
}

.break-handle::before {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  top: -7px;
  height: 1px;
  background: transparent;
}

.break-handle:hover::before,
.break-handle.active::before {
  background: var(--accent);
}

.break-handle.active::after {
  content: "page break";
  display: block;
  position: absolute;
  left: 50%;
  top: -16px;
  transform: translateX(-50%);
  width: max-content;
  padding: 1px 7px 2px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  line-height: 1.4;
}

.page-content strong {
  font-weight: 700;
}

.page-content hr {
  border: 0;
  height: 1px;
  margin: 1.55em 0;
  background: color-mix(in srgb, var(--ink) 22%, transparent);
}

.page-content hr.section-divider {
  height: 1px;
  margin: 1.05em 0;
  background: color-mix(in srgb, var(--ink) 26%, transparent);
}

.page-content .unit.before-section-divider > :last-child {
  margin-bottom: 0;
}

.page-content .unit.after-section-divider > h1:first-child,
.page-content .unit.after-section-divider > h2:first-child,
.page-content .unit.after-section-divider > h3:first-child,
.page-content .unit.section-divider-unit > h1:first-child,
.page-content .unit.section-divider-unit > h2:first-child,
.page-content .unit.section-divider-unit > h3:first-child {
  margin-top: 0;
}

.page-content blockquote {
  margin: 0 0 1.15em;
  padding-left: 1em;
  border-left: 3px solid color-mix(in srgb, var(--ink) 28%, transparent);
}

.page-content ul,
.page-content ol {
  margin: 0 0 1.05em 1.3em;
  padding: 0;
}

.page-content li + li {
  margin-top: 0.35em;
}

.page-content code,
.page-content pre {
  font-family: inherit;
  white-space: pre-wrap;
}

.page-label {
  font-size: 12px;
  color: #67605a;
  text-align: center;
}

.break-list {
  display: grid;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d8d0c4;
  border-radius: 8px;
  background: #fff;
}

.break-item {
  border: 0;
  border-bottom: 1px solid #eee8df;
  padding: 9px 10px;
  background: #fff;
  color: #4a433d;
  text-align: left;
  cursor: pointer;
}

.break-item:last-child {
  border-bottom: 0;
}

.break-item.active {
  color: #fff;
  background: var(--accent);
}

dialog {
  width: min(96vw, 980px);
  height: min(94vh, 1220px);
  padding: 18px;
  border: 0;
  border-radius: 8px;
  background: #ece6dd;
}

dialog::backdrop {
  background: rgba(18, 16, 14, 0.62);
}

dialog form {
  display: flex;
  justify-content: flex-end;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid #cfc6ba;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.large-preview {
  display: grid;
  place-items: start center;
  height: calc(100% - 42px);
  overflow: auto;
}

.large-preview .render-page {
  transform-origin: top center;
  box-shadow: 0 16px 38px rgba(43, 35, 25, 0.2);
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.92rem;
}

.check-row input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

/* Print-to-PDF: render every page full-size, one per sheet, as true vector
   text (browser's native print engine — same as the old Puppeteer page.pdf). */
#printRoot {
  display: none;
}

@media print {
  body > *:not(#printRoot) {
    display: none !important;
  }

  #printRoot {
    display: block !important;
  }

  #printRoot .render-page {
    transform: none !important;
    box-shadow: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    break-after: page;
    /* Force the paper background colour to print (Chrome omits backgrounds otherwise). */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #printRoot .render-page:last-child {
    break-after: auto;
  }
}
