:root {
  --bg: #efebe2;
  --bg-deep: #e8e2d6;
  --panel: #fbf9f3;
  --panel-2: #f5f1e7;
  --paper: #fffefb;
  --border: #e2dccc;
  --border-strong: #cec5b1;
  --ink: #26231d;
  --ink-soft: #3f3a30;
  --muted: #766f61;
  --faint: #a49b8a;
  --accent: #9a4a2f;
  --accent-dark: #7d3822;
  --accent-soft: #f2e2d7;
  --green: #4c6d5b;
  --yellow-soft: #f6edd5;
  --yellow-border: #e3d3a7;
  --red: #9c3d2c;
  --serif: Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --hand: "hand-kalam", "Segoe Print", "Bradley Hand", cursive;
  --shadow-page: 0 1px 1px rgba(42, 35, 24, .07), 0 14px 34px -14px rgba(42, 35, 24, .32);
  --shadow-pop: 0 18px 60px -18px rgba(38, 31, 21, .45);
  --radius: 10px;
  --settings-w: 312px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% -10%, rgba(255, 255, 255, .75), transparent 36%),
    linear-gradient(180deg, #f2eee6 0%, var(--bg) 55%, #eae4d8 100%);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
::selection { background: #e9d3c2; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ boot */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 255, 255, .75), transparent 36%),
    var(--bg);
  transition: opacity .45s ease, visibility .45s ease;
}
.boot.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-mark {
  font-family: "hand-caveat", var(--serif);
  font-size: 58px;
  line-height: 1;
  letter-spacing: .01em;
  color: var(--ink);
}
.boot-sub { color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.boot-line { width: 86px; height: 2px; margin-top: 12px; background: var(--border-strong); overflow: hidden; border-radius: 2px; }
.boot-line::after {
  content: "";
  display: block;
  width: 36px;
  height: 100%;
  background: var(--accent);
  animation: boot-slide 1.1s ease-in-out infinite;
}
@keyframes boot-slide { 0% { transform: translateX(-38px); } 100% { transform: translateX(90px); } }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: relative;
  z-index: 50;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(251, 249, 243, .86);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #f8f3e7;
  flex: none;
  box-shadow: 0 2px 7px rgba(38, 35, 29, .18);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.wordmark {
  font-family: "hand-caveat", var(--serif);
  font-size: 27px;
  line-height: .86;
  color: var(--ink);
  letter-spacing: .005em;
}
.tagline {
  font-size: 8.5px;
  color: var(--faint);
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex: none; }
.status.loading .status-dot { background: #b9862f; animation: pulse 1s ease-in-out infinite; }
.status.error .status-dot { background: var(--red); }
.status.waiting .status-dot { background: var(--faint); }
@keyframes pulse { 50% { opacity: .28; transform: scale(.8); } }
.btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .005em;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--ink); color: #fbf7ee; box-shadow: 0 1px 2px rgba(38, 35, 29, .16); }
.btn-primary:hover { background: #3b362d; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--panel-2); }
.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover { background: rgba(38, 35, 29, .07); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.mobile-only { display: none; }

/* ------------------------------------------------------------------ workspace */
.workspace {
  display: grid;
  grid-template-columns: var(--settings-w) minmax(330px, .92fr) minmax(0, 1.08fr);
  height: calc(100vh - 64px);
  min-height: 0;
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.pane-head {
  height: 49px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(251, 249, 243, .74);
}
.pane-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.pane-tools { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pane-meta {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.text-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em;
  text-decoration: underline;
  text-decoration-color: rgba(118, 111, 97, .3);
  text-underline-offset: 3px;
}
.text-btn:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ------------------------------------------------------------------ settings */
.settings-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
}
.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  height: auto;
  min-height: 72px;
  padding: 15px 18px 12px;
}
.settings-head h1 {
  margin: 1px 0 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 400;
  letter-spacing: -.02em;
}
.eyebrow {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
}
.settings-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 18px; scrollbar-gutter: stable; }
.setting-group { padding: 15px 0 16px; border-bottom: 1px solid var(--border); }
.setting-group:last-child { border-bottom: 0; }
.group-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.group-tools { display: flex; align-items: center; gap: 6px; }
.mini-btn {
  height: 20px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}
.mini-btn:hover { background: #ebd4c4; }
.group-heading h3 {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.count-badge {
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #eae4d7;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
}
.value-label { font-family: var(--mono); font-size: 9.5px; color: var(--faint); white-space: nowrap; }
.hint { margin: 7px 0 0; color: var(--faint); font-size: 10.5px; line-height: 1.5; }

.preset-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.preset {
  min-width: 0;
  padding: 8px 8px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink-soft);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  transition: border-color .15s ease, background .15s ease;
}
.preset small { display: block; margin-top: 3px; font-size: 8.5px; font-weight: 400; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset:hover { border-color: var(--border-strong); background: #fdfbf6; }
.preset.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.preset.active small { color: #9b6c57; }

.specimen {
  position: relative;
  margin-bottom: 9px;
  padding: 11px 12px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .6), transparent 70%),
    var(--panel);
  overflow: hidden;
}
.specimen::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 28px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border) 8%, var(--border) 92%, transparent);
}
.specimen-text {
  min-height: 31px;
  font-family: var(--hand);
  font-size: 22px;
  line-height: 1.38;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.specimen-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 9px; color: var(--faint); }
.specimen-meta span:first-child { color: var(--muted); font-weight: 600; font-size: 9.5px; }
.specimen-meta span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.font-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.font-card {
  position: relative;
  min-width: 0;
  height: 62px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
  overflow: hidden;
  transition: border-color .14s ease, background .14s ease, transform .14s ease;
}
.font-card:hover { border-color: var(--border-strong); background: #fdfbf6; transform: translateY(-1px); }
.font-card.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px rgba(154, 74, 47, .16) inset; }
.font-aa { display: block; height: 26px; width: auto; max-width: 100%; object-fit: contain; object-position: left center; }
.font-name { max-width: 100%; font-size: 8.5px; line-height: 1.2; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-card.selected .font-name { color: var(--accent-dark); }
.font-source {
  position: absolute;
  top: 5px;
  right: 5px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff7ef;
  font-size: 6.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.upload-button {
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}
.upload-button:hover { border-color: var(--accent); background: rgba(242, 226, 215, .35); }
.upload-plus { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-dark); font-size: 15px; flex: none; }
.upload-button strong { display: block; font-size: 10.5px; font-weight: 600; }
.upload-button small { display: block; margin-top: 1px; color: var(--faint); font-size: 8.5px; }

.swatches { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatch {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), inset 0 0 0 2px rgba(0, 0, 0, .06);
  transition: transform .13s ease, box-shadow .13s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch.selected { box-shadow: 0 0 0 2px var(--panel-2), 0 0 0 4px var(--accent); }
.swatch-custom { display: grid; place-items: center; background: #fffdf8; border: 1px dashed var(--border-strong); box-shadow: none; color: var(--faint); font-size: 14px; overflow: hidden; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.swatch-custom span { pointer-events: none; }

.margin-grid, .cs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.margin-grid label, .cs-grid label, .wide-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
}
input[type="number"], input[type="text"], input[type="password"], input[type="file"] {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fffdf8;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  outline: none;
  transition: border-color .14s ease, box-shadow .14s ease;
}
input[type="number"]:focus, input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(154, 74, 47, .09);
}
.wide-field { margin-top: 7px; }
.wide-field input { max-width: 110px; }

.range-row, .noise-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1px 8px;
  margin-top: 10px;
}
.range-row:first-of-type, .noise-row:first-of-type { margin-top: 4px; }
.range-row label, .noise-row label { font-size: 10.5px; color: var(--ink-soft); }
.range-row output, .noise-row output { font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.range-row input, .noise-row input { grid-column: 1 / -1; }
.auto-note { grid-column: 1 / -1; display: none; margin-top: 2px; color: var(--accent); font-size: 8.5px; font-weight: 600; letter-spacing: .03em; }
.range-row.is-disabled { opacity: .45; }
.range-row.is-disabled .auto-note { display: block; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: #ddd5c4; }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: #ddd5c4; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 1px 2px rgba(38, 35, 29, .18);
}
input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fffdf8;
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(154, 74, 47, .16); }

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  margin-bottom: 9px;
  border-radius: 8px;
  background: #eae4d7;
}
.segmented button {
  flex: 1;
  height: 27px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--ink); color: #fbf7ee; box-shadow: 0 1px 2px rgba(38, 35, 29, .15); }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 10.5px; line-height: 1.4; color: var(--ink-soft); cursor: pointer; }
.check-row input[type="checkbox"] { width: 14px; height: 14px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.heading-preview {
  margin-top: 11px;
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: rgba(255, 253, 248, .5);
  font-family: var(--hand);
  line-height: 1.25;
  color: var(--ink);
}
.hp-row { margin: 2px 0; }
.hp-h1, .hp-h2, .hp-h3 { display: inline-block; }
.heading-preview.compact .hp-h1 { font-size: 15px; font-weight: 700; }
.heading-preview.compact .hp-h2 { font-size: 13px; font-weight: 700; border-bottom: 2px double currentColor; }
.heading-preview.compact .hp-h3 { font-size: 11.5px; font-weight: 700; border-bottom: 1px solid currentColor; }
.heading-preview.compact.boxed .hp-h1 { padding: 1px 5px; border: 1px solid currentColor; }
.heading-preview.classic .hp-h1 { font-size: 21px; font-weight: 700; }
.heading-preview.classic .hp-h2 { font-size: 17px; font-weight: 700; }
.heading-preview.classic .hp-h3 { font-size: 13.5px; font-weight: 700; }

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track { width: 34px; height: 19px; border-radius: 20px; background: #d9d1c0; transition: background .16s ease; display: block; }
.switch-knob { display: block; width: 15px; height: 15px; margin: 2px; border-radius: 50%; background: #fffdf8; box-shadow: 0 1px 2px rgba(38, 35, 29, .2); transition: transform .16s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-knob { transform: translateX(15px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.cs-fields { margin-top: 10px; transition: opacity .16s ease; }
.cs-fields.disabled { opacity: .38; pointer-events: none; filter: saturate(.5); }
.cs-result {
  margin-top: 9px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 253, 248, .55);
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.45;
}
.cs-result strong { color: var(--ink-soft); font-weight: 600; }
.cs-result.warn { border-color: var(--yellow-border); background: var(--yellow-soft); color: #725c2d; }
.sidebar-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 18px;
  border-top: 1px solid var(--border);
  background: rgba(245, 241, 231, .82);
}
.sidebar-foot .text-btn { font-size: 9.5px; }
.privacy-note { font-size: 8.5px; color: var(--faint); white-space: nowrap; }

/* ------------------------------------------------------------------ editor */
.editor-pane { border-right: 1px solid var(--border); }
#editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 21px 24px 30px;
  border: 0;
  outline: none;
  resize: none;
  background:
    linear-gradient(90deg, transparent 0, transparent calc(100% - 1px), rgba(226, 220, 204, .24) calc(100% - 1px)),
    #fcfaf5;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 12.75px;
  line-height: 1.78;
  tab-size: 2;
  caret-color: var(--accent);
}
#editor::placeholder { color: #b8ae9c; }
#editor::selection { background: #ecdbcd; }
.editor-foot {
  flex: none;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px 0 24px;
  border-top: 1px solid var(--border);
  background: rgba(251, 249, 243, .74);
  color: var(--faint);
  font-size: 8.5px;
  letter-spacing: .02em;
}
.editor-foot kbd {
  display: inline-block;
  min-width: 15px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-bottom-color: var(--border-strong);
  border-radius: 3px;
  background: #fffdf8;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 14px;
  text-align: center;
}

/* ------------------------------------------------------------------ preview */
.preview-pane {
  background:
    radial-gradient(circle at 75% 2%, rgba(255, 255, 255, .55), transparent 30%),
    linear-gradient(180deg, #ece7dc 0%, #e8e2d5 100%);
}
.preview-head { background: rgba(245, 241, 232, .7); }
.preview-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 26px 48px; scrollbar-gutter: stable; }
.render-spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid rgba(118, 111, 97, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.warnings {
  width: min(100%, 720px);
  margin: 0 auto 18px;
  padding: 9px 12px;
  border: 1px solid var(--yellow-border);
  border-radius: 8px;
  background: rgba(246, 237, 213, .82);
  color: #6f592c;
  font-size: 10px;
  line-height: 1.5;
}
.warnings summary { cursor: pointer; font-weight: 600; }
.warnings ul { margin: 6px 0 0; padding-left: 16px; }
.warnings li { margin: 3px 0; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.page-figure { margin: 0; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 7px; }
.page-sheet {
  width: min(100%, 720px);
  position: relative;
  background: var(--paper);
  border-radius: 2px;
  box-shadow: var(--shadow-page);
  overflow: hidden;
  cursor: zoom-in;
  transition: transform .18s ease, box-shadow .18s ease;
}
.page-sheet:hover { transform: translateY(-2px); box-shadow: 0 2px 2px rgba(42, 35, 24, .07), 0 20px 44px -16px rgba(42, 35, 24, .38); }
.page-sheet img { display: block; width: 100%; height: auto; }
.page-number { font-family: var(--mono); font-size: 8.5px; letter-spacing: .12em; color: #968c7a; text-transform: uppercase; }
.page-placeholder { width: 100%; display: flex; justify-content: center; }
.placeholder-sheet {
  width: min(100%, 680px);
  aspect-ratio: 210 / 297;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px dashed #c9bfab;
  border-radius: 3px;
  background:
    repeating-linear-gradient(180deg, transparent 0, transparent 31px, rgba(214, 205, 187, .20) 31px, rgba(214, 205, 187, .20) 32px),
    rgba(255, 254, 251, .55);
  color: #9e9482;
  box-shadow: 0 10px 30px -20px rgba(42, 35, 24, .3);
}
.placeholder-scribble { font-family: "hand-caveat", var(--serif); font-size: 42px; color: #b6a993; transform: rotate(-2deg); }
.placeholder-sheet p { margin: 0; font-size: 10px; letter-spacing: .04em; }

/* ------------------------------------------------------------------ mobile tabs / scrim */
.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: 46px;
  padding: 5px;
  gap: 4px;
  border-top: 1px solid var(--border);
  background: rgba(251, 249, 243, .94);
  backdrop-filter: blur(12px);
}
.mobile-tabs button {
  flex: 1;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.mobile-tabs button.active { background: var(--ink); color: #fbf7ee; }
.scrim { position: fixed; inset: 64px 0 0; z-index: 35; background: rgba(34, 29, 21, .28); backdrop-filter: blur(2px); }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 120;
  max-width: min(92vw, 540px);
  padding: 10px 14px;
  border-radius: 9px;
  background: #2e2a23;
  color: #faf5e9;
  font-size: 11.5px;
  line-height: 1.45;
  box-shadow: 0 12px 32px -10px rgba(20, 16, 10, .5);
  transform: translate(-50%, 10px);
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #5b2b21; }

/* ------------------------------------------------------------------ dialogs */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(33, 28, 20, .42); backdrop-filter: blur(3px); }
.lightbox {
  inset: 0;
  width: 100vw;
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(25, 22, 17, .93);
  color: #f4eee1;
}
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox-bar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 22px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #c5bcaa;
}
.lightbox-actions { display: flex; gap: 3px; }
.lightbox .icon-btn { color: #cfc6b3; }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.lightbox-stage { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 0 18px 22px; }
.lightbox-stage img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; box-shadow: 0 22px 70px rgba(0, 0, 0, .5); transform-origin: top center; transition: transform .16s ease; }
.zoom-label { min-width: 38px; text-align: center; font-family: var(--mono); font-size: 9px; color: #bdb3a0; align-self: center; }

.modal {
  width: min(94vw, 478px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--panel);
  box-shadow: var(--shadow-pop);
}
.modal form { padding: 20px 22px 18px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.modal-head h2 { margin: 2px 0 0; font-family: var(--serif); font-size: 22px; font-weight: 400; letter-spacing: -.02em; }
.modal-copy { margin: 0 0 14px; color: var(--muted); font-size: 10.5px; line-height: 1.55; }
.file-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px dashed var(--border-strong);
  border-radius: 9px;
  background: #fffdf8;
  cursor: pointer;
}
.file-field:hover, .file-field.dragging { border-color: var(--accent); background: #fdf7f0; }
.file-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); flex: none; }
.file-icon svg { width: 17px; height: 17px; }
.file-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-copy strong { font-size: 10.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 330px; }
.file-copy small { color: var(--faint); font-size: 9px; }
.field-label { display: flex; flex-direction: column; gap: 5px; margin-top: 12px; font-size: 8.5px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; color: var(--faint); }
.field-label span { font-weight: 400; text-transform: none; letter-spacing: 0; }
.token-field { margin-top: 10px; }
.license-row { margin-top: 13px; font-size: 9.5px; line-height: 1.45; }
.upload-error { margin: 10px 0 0; padding: 8px 10px; border-radius: 7px; background: #f7e3dd; color: #7a2f22; font-size: 10px; line-height: 1.45; }
.upload-result { margin-top: 13px; padding: 11px 12px; border: 1px solid #cddbc4; border-radius: 9px; background: #f0f5e9; color: #3d5235; font-size: 10px; line-height: 1.5; }
.upload-result h4 { margin: 0 0 5px; font-size: 10.5px; font-weight: 700; }
.coverage-row { display: grid; grid-template-columns: 76px 1fr 32px; align-items: center; gap: 7px; margin: 4px 0; }
.coverage-track { height: 4px; border-radius: 4px; background: #dce5d3; overflow: hidden; }
.coverage-fill { height: 100%; background: #64805a; border-radius: 4px; }
.coverage-row span { font-family: var(--mono); font-size: 8px; color: #6c7d5e; }
.upload-result ul { margin: 6px 0 0; padding-left: 15px; color: #725c2d; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 17px; }
.modal-actions .btn { height: 34px; font-size: 11px; }
#upload-submit.loading { opacity: .7; pointer-events: none; }

/* ------------------------------------------------------------------ scrollbars */
.settings-scroll::-webkit-scrollbar, .preview-scroll::-webkit-scrollbar { width: 9px; }
.settings-scroll::-webkit-scrollbar-thumb, .preview-scroll::-webkit-scrollbar-thumb { background: #d3c9b7; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
.settings-scroll::-webkit-scrollbar-thumb:hover, .preview-scroll::-webkit-scrollbar-thumb:hover { background: #bdb19c; border: 3px solid transparent; background-clip: padding-box; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  :root { --settings-w: 288px; }
  .font-card { height: 58px; }
  .font-aa { font-size: 19px; }
}

@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(320px, .92fr) minmax(0, 1.08fr); }
  .settings-panel {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(340px, 88vw);
    transform: translateX(-105%);
    transition: transform .22s cubic-bezier(.2, .75, .3, 1);
    box-shadow: 18px 0 46px -22px rgba(38, 31, 21, .45);
  }
  .settings-panel.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .settings-head { min-height: 66px; }
}

@media (max-width: 760px) {
  .topbar { height: 60px; padding: 0 12px; }
  .brand { gap: 8px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-mark svg { width: 18px; height: 18px; }
  .wordmark { font-size: 24px; }
  .tagline { display: none; }
  .status { display: none; }
  .top-actions { gap: 7px; }
  .btn { height: 34px; padding: 0 10px; font-size: 11px; }
  .btn-primary { gap: 6px; }
  .download-label { display: none; }
  .workspace { display: block; height: calc(100vh - 60px - 46px); }
  .pane { display: none; height: 100%; border-right: 0; }
  body.view-editor .editor-pane,
  body.view-preview .preview-pane { display: flex; }
  .settings-panel { top: 60px; bottom: 0; }
  .scrim { inset: 60px 0 0; }
  .pane-head { height: 44px; padding: 0 13px; }
  .pane-title { font-size: 9px; }
  .pane-tools { gap: 8px; }
  .pane-meta { font-size: 8.5px; }
  #editor { padding: 16px 16px 24px; font-size: 12.5px; }
  .editor-foot { padding: 0 12px; font-size: 8px; height: 30px; }
  .editor-foot span:last-child { display: none; }
  .preview-scroll { padding: 14px 12px 34px; }
  .pages { gap: 18px; }
  .page-sheet { width: 100%; }
  .warnings { margin-bottom: 12px; }
  .mobile-tabs { display: flex; }
  .footer, .toast { bottom: 58px; }
  .lightbox-bar { height: 46px; padding: 0 10px 0 16px; }
  .lightbox-stage { padding: 0 8px 12px; }
  .placeholder-scribble { font-size: 34px; }
  .placeholder-sheet { width: 100%; }
}

@media (max-width: 420px) {
  .preset small { display: none; }
  .preset { padding: 8px 6px; text-align: center; }
  .font-grid { gap: 5px; }
  .font-card { height: 54px; padding: 5px 7px; }
  .font-aa { font-size: 18px; }
  .font-name { font-size: 8px; }
  .modal form { padding: 16px; }
  .file-copy strong { max-width: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
