/*
 * Neo-brutalist chrome on a pastel palette. NeoBrutalismCSS (linked before this file) supplies the
 * .nb-button component; everything here either sizes it for this app or applies the same language
 * (black borders, hard offset shadows, flat pastel fills) to the app's own controls.
 */
:root {
  color-scheme: light;
  font-family: 'Public Sans', Arial, Helvetica, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #111111;
  --ink-soft: #3d3a45;
  --paper: #fff7ea;
  --surface: #ffffff;
  --butter: #fff1a8;
  --pink: #ffc9de;
  --pink-deep: #ffadcc;
  --lilac: #ddd0ff;
  --mint: #c4f1d9;
  --sky: #c8e6ff;
  --peach: #ffd9bd;
  --border-w: 3px;
  --border: var(--border-w) solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --shadow-lg: 7px 7px 0 var(--ink);
  --display: 'Lexend Mega', 'Public Sans', Arial, sans-serif;
  --selected-green: #22b45a;
  --stage: #141414;
  --stage-edge: var(--paper);
  --stage-shadow: #b0b0b6;
  --stage-text: var(--paper);
  --stage-muted: #cfc8dc;
  --stage-dot: #4a4a50;
  --stage-drag: #23202b;
  --page-ratio: .647;
  --spread-ratio: 1.294;
}

* { box-sizing: border-box; }

html { min-width: min(320px, 100%); background: var(--paper); font-family: 'Public Sans', Arial, Helvetica, sans-serif; }

body {
  min-width: min(320px, 100%);
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
/* Quiet focus cues: text fields lift with a hard shadow, and buttons get a thin dashed outline that
   only shows for keyboard focus. */
button:focus-visible, a:focus-visible, input[type="range"]:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
input:focus, textarea:focus { outline: none; }
input:not([type="range"]):not([type="file"]):not([type="checkbox"]):focus, textarea:focus { background-color: #fffdf5; box-shadow: var(--shadow); }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }

/* NeoBrutalismCSS buttons, sized for a dense editor. Its own rules grow at 576px and 768px and drop the
   focus outline, so these repeat its two-class selectors to win the cascade at every width. */
.nb-button.default {
  --btn-bg: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 13px;
  color: var(--ink);
  background-color: var(--btn-bg);
  border: 2.5px solid var(--ink);
  border-radius: 0;
  box-shadow: var(--shadow-sm);
  font-family: 'Public Sans', Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1;
  white-space: nowrap;
}
.nb-button.default:hover, .nb-button.default:focus { color: var(--ink); background-color: var(--btn-bg); box-shadow: var(--shadow-sm); transform: none; }
.nb-button.default:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
.nb-button.default:active { box-shadow: none; transform: translate(3px, 3px); }
.nb-button.default:disabled { box-shadow: none; transform: none; }
@media (hover: hover) {
  .nb-button.default:hover { box-shadow: 1px 1px 0 var(--ink); transform: translate(2px, 2px); }
}

.topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto auto;
  align-items: center;
  min-height: 62px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--butter);
  border-bottom: var(--border);
}

.wordmark {
  width: fit-content;
  color: inherit;
  font-family: var(--display);
  font-size: 35px;
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; padding: 10px 0; }
.brand-tagline { margin: 0; color: var(--ink-soft); font-size: 12px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }

.wordmark-dot { color: #e0457b; }
.topbar-right { display: flex; align-items: center; gap: 13px; padding-right: 16px; }
.save-status { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; display: inline-block; border: 2px solid var(--ink); border-radius: 50%; background: #5fd38f; }
.save-status.is-saving .status-dot { background: #ffb347; }

.nb-button.default.install-button { min-height: 32px; padding-inline: 10px; font-size: 10px; }

.toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.paper-switch, .segmented { display: flex; overflow: hidden; background: var(--surface); border: 2.5px solid var(--ink); box-shadow: var(--shadow-sm); }

.paper-switch button {
  min-height: 33px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s ease;
}

.paper-switch button + button { border-left: 2.5px solid var(--ink); }
.paper-switch button[aria-pressed="true"] { background: var(--pink); }
.button-icon { font-size: 14px; line-height: 1; }
.nb-button.default.three-button { --btn-bg: var(--sky); }
.nb-button.default.download-button { --btn-bg: var(--pink); }
/* PDF margin option: a neo-brutalist checkbox drawn with CSS so it matches the other controls. */
.margin-toggle { display: inline-flex; align-items: center; gap: 9px; min-height: 38px; font-size: 11px; font-weight: 800; letter-spacing: .06em; white-space: nowrap; cursor: pointer; user-select: none; }
.margin-toggle input { -webkit-appearance: none; appearance: none; display: grid; place-content: center; flex: 0 0 auto; width: 24px; height: 24px; margin: 0; background: var(--surface); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: pointer; }
.margin-toggle input::after { content: ''; width: 6px; height: 12px; border: solid var(--ink); border-width: 0 3px 3px 0; transform: translateY(-1px) rotate(45deg); opacity: 0; }
.margin-toggle input:checked { background: var(--mint); }
.margin-toggle input:checked::after { opacity: 1; }
.margin-toggle input:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
.download-control { position: relative; min-width: 0; }
.download-caret { font-size: 12px; }
.download-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 10; width: 280px; max-width: calc(100vw - 32px); padding: 4px; background: var(--surface); border: var(--border); box-shadow: var(--shadow); }
.download-menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; width: 100%; min-height: 64px; padding: 12px; color: var(--ink); background: var(--surface); border: 0; text-align: left; cursor: pointer; }
.download-menu button + button { border-top: 2px solid var(--ink); }
.download-menu button:hover, .download-menu button:focus-visible { background: var(--pink); }
.download-menu button span { font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.download-menu button small { color: var(--ink-soft); font-size: 11px; font-weight: 500; line-height: 1.4; }

.studio { width: 100%; }

.workspace {
  display: flex;
  height: calc(100svh - 407px);
  min-height: 375px;
  max-height: 760px;
  background: var(--paper);
  border-bottom: var(--border);
}

.page-rail {
  display: flex;
  flex: 0 0 132px;
  flex-direction: column;
  min-width: 0;
  padding: 12px 12px 10px;
  background: var(--mint);
  border-right: var(--border);
}

.rail-label, .inspector-topline, .control-label, .stage-meta, .stage-bottom, .inspector-foot, .rail-help, .three-hint, .eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.rail-label { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 6px; margin: 0 0 10px; white-space: nowrap; }
.rail-label span { color: var(--ink-soft); font-size: 9px; }
.sheet-list { display: flex; flex: 1; flex-direction: column; gap: 8px; min-height: 0; }
.sheet-thumb.is-draggable { cursor: grab; touch-action: pan-x; }
.sheet-thumb.is-draggable:active { cursor: grabbing; }
.sheet-thumb.dragging { z-index: 3; opacity: .5; transform: scale(.96); }
.sheet-thumb.drag-over { background: var(--butter); box-shadow: var(--shadow); }
.sheet-list.reordering .sheet-thumb { transition: transform .12s ease, opacity .12s ease, background .12s ease; }

.sheet-thumb {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-height: 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 4px 4px;
  background: var(--surface);
  border: 2.5px solid var(--ink);
  border-radius: 0;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  transition: background .12s ease, box-shadow .12s ease, transform .12s ease;
}

.sheet-thumb[aria-pressed="true"] { background: var(--pink); box-shadow: var(--shadow); transform: translate(-1px, -1px); }
.thumb-pages { display: flex; align-items: center; justify-content: center; gap: 2px; width: 100%; min-height: 0; flex: 1; }
.thumb-page { display: block; height: 100%; max-height: 61px; width: auto; max-width: 48%; aspect-ratio: var(--page-ratio); object-fit: cover; border: 1.5px solid var(--ink); background: #f3eee4; }
.thumb-label { color: var(--ink); font-size: 9px; font-weight: 800; letter-spacing: .05em; white-space: nowrap; }
.rail-help { min-height: 32px; padding: 8px 0 0; letter-spacing: .03em; white-space: nowrap; color: var(--ink); background: none; border: 0; text-align: left; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; cursor: pointer; }
.rail-links { display: flex; flex-direction: column; }
.rail-help span { margin-right: 3px; font-size: 12px; }
@media (hover: hover) {
  .sheet-thumb:not([aria-pressed="true"]):hover { background: var(--butter); }
}

.stage {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--stage);
  background-image: radial-gradient(var(--stage-dot) 1.2px, transparent 1.3px);
  background-size: 18px 18px;
}

.stage-meta { position: absolute; z-index: 1; top: 14px; left: 18px; right: 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--stage-text); pointer-events: none; }
.stage-page-label { padding: 4px 8px; color: var(--ink); background: var(--butter); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--stage-shadow); font-family: var(--display); font-size: 9px; }
.stage-tip { min-width: 0; color: var(--stage-muted); font-weight: 600; letter-spacing: .02em; text-transform: none; text-align: right; }
.stage.is-dragover { outline: 3px dashed var(--stage-text); outline-offset: -12px; background-color: var(--stage-drag); }
.stage.is-uploading { cursor: progress; }
.stage-pages { display: flex; align-items: center; justify-content: center; gap: 2px; width: 100%; height: 100%; padding: 46px 30px 54px; }
.stage-pages.is-spread { width: auto; height: 80%; max-width: 88%; aspect-ratio: var(--spread-ratio); padding: 0; gap: 0; border: var(--border-w) solid var(--stage-edge); box-shadow: 7px 7px 0 var(--stage-shadow); background: var(--ink); }

.preview-page-frame {
  position: relative;
  display: block;
  flex: 0 1 auto;
  width: auto;
  height: min(100%, 525px);
  max-width: 48%;
  aspect-ratio: var(--page-ratio);
  overflow: hidden;
  padding: 0;
  background: #111;
  border: var(--border-w) solid var(--stage-edge);
  box-shadow: 7px 7px 0 var(--stage-shadow);
}

.preview-page {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: #111;
  cursor: pointer;
  touch-action: none;
}

.preview-page canvas { display: block; width: 100%; height: 100%; }

.stage-pages.is-spread .preview-page-frame { width: 50%; height: 100%; max-width: none; border: 0; box-shadow: none; }
.stage-pages.is-spread .preview-page-frame + .preview-page-frame { border-left: 1.5px solid var(--ink); }
/* The panel being edited. Drawn inside the frame so it shows on spreads, single pages and every stage background. */
.preview-page-frame.is-selected { outline: 4px solid var(--selected-green); outline-offset: -4px; }
.preview-page:focus-visible { outline: 2px dashed var(--butter); outline-offset: -6px; }
.preview-remove-photo { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 2.5px solid var(--ink); border-radius: 50%; color: var(--ink); background: var(--surface); box-shadow: 2px 2px 0 var(--ink); font-size: 26px; line-height: 1; cursor: pointer; }
/* Add/change photo: same round control as remove, sitting just to its left (or alone on an empty page). */
.preview-change-photo { position: absolute; top: 8px; right: 60px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 2.5px solid var(--ink); border-radius: 50%; color: var(--ink); background: var(--butter); box-shadow: 2px 2px 0 var(--ink); font-size: 24px; font-weight: 700; line-height: 1; cursor: pointer; }
.preview-change-photo.is-empty { right: 8px; font-size: 30px; font-weight: 500; }
.preview-change-photo:active { box-shadow: none; transform: translate(2px, 2px); }
.preview-change-photo:focus-visible { outline: 2px dashed var(--butter); outline-offset: 2px; }
.preview-change-photo:disabled { opacity: .5; cursor: wait; }
.preview-remove-photo:active { box-shadow: none; transform: translate(2px, 2px); }
.preview-remove-photo:focus-visible { outline: 2px dashed var(--butter); outline-offset: 2px; }
.preview-remove-photo:disabled { opacity: .5; cursor: wait; }
.preview-add-second-photo { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 20px); min-height: 44px; padding: 8px 12px; border: 2.5px solid var(--ink); color: var(--ink); background: var(--butter); box-shadow: var(--shadow-sm); font-size: 11px; font-weight: 800; letter-spacing: .04em; cursor: pointer; }
.preview-add-second-photo:active { box-shadow: none; transform: translate(calc(-50% + 3px), 3px); }
.preview-add-second-photo:focus-visible { outline: 2px dashed var(--butter); outline-offset: 2px; }
@media (hover: hover) {
  .preview-remove-photo:hover { background: var(--pink); }
  .preview-change-photo:hover { background: var(--pink); }
  .preview-add-second-photo:hover { background: var(--pink); }
}
.stage-bottom { position: absolute; bottom: 12px; left: 18px; right: 18px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; color: var(--stage-muted); font-size: 9px; }
.stage-size { grid-column: 3; justify-self: end; color: var(--stage-text); }
.stage-bg-picker { grid-column: 2; }

/* Preview background choices, set on .stage by stage-background.js. Light backgrounds switch the page edge
   and shadow to ink, since cream and lilac would wash out. */
.stage[data-bg="grey"] { --stage: #a6a6ac; --stage-edge: var(--ink); --stage-shadow: var(--ink); --stage-text: var(--ink); --stage-muted: #2b2930; --stage-dot: rgba(17, 17, 17, .16); --stage-drag: #b8b4c6; }
.stage[data-bg="white"] { --stage: #ffffff; --stage-edge: var(--ink); --stage-shadow: var(--ink); --stage-text: var(--ink); --stage-muted: var(--ink-soft); --stage-dot: rgba(17, 17, 17, .12); --stage-drag: #f1ecff; }
.stage-bg-picker { display: flex; align-items: center; gap: 9px; }
.stage-bg-label { color: var(--stage-muted); }
.stage-bg-choice { width: 26px; height: 26px; padding: 0; border: 2.5px solid var(--ink); border-radius: 50%; box-shadow: 0 0 0 1.5px var(--stage-text); cursor: pointer; transition: box-shadow .12s ease; }
.stage-bg-choice.is-black { background: #141414; }
.stage-bg-choice.is-grey { background: #a6a6ac; }
.stage-bg-choice.is-white { background: #ffffff; }
.stage-bg-choice[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--stage), 0 0 0 5px var(--stage-text); }
.stage-bg-choice:focus-visible { outline: 2px dashed var(--stage-text); outline-offset: 5px; }

.inspector {
  min-height: 268px;
  padding: 0 18px 10px;
  background: var(--paper);
  border-bottom: var(--border);
}

.inspector-topline { display: flex; align-items: center; justify-content: space-between; height: 40px; }
.inspector-topline > span:first-child { font-family: var(--display); font-size: 10px; }
.inspector-page { color: var(--ink-soft); font-weight: 700; }
.inspector-topline-right, .page-move-controls { display: flex; align-items: center; gap: 8px; }
.page-move-controls { color: var(--ink-soft); font-size: 9px; }
.page-move-controls button { width: 32px; height: 28px; padding: 0; color: var(--ink); background: var(--surface); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); font-size: 13px; font-weight: 800; cursor: pointer; }
.page-move-controls button:active { box-shadow: none; transform: translate(2px, 2px); }
@media (hover: hover) {
  .page-move-controls button:hover { background: var(--butter); }
}
.photo-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.inspector-main { display: grid; grid-template-columns: minmax(255px, 1fr) minmax(470px, 1.55fr); gap: 18px; align-items: stretch; }

.field-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; gap: 12px 10px; min-width: 0; }
.field-panel.single-field { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }
.field > span { color: var(--ink); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.field input, .field textarea { display: block; width: 100%; min-width: 0; min-height: 40px; padding: 0 11px; color: var(--ink); background: var(--surface); border: 2.5px solid var(--ink); border-radius: 0; box-shadow: var(--shadow-sm); font-size: 14px; transition: box-shadow .12s ease, transform .12s ease; }
.field textarea { min-height: 80px; padding: 9px 11px; resize: vertical; line-height: 1.4; }
.field input:focus, .field textarea:focus { background: #fffdf5; box-shadow: var(--shadow); transform: translate(-1px, -1px); }
.field input::placeholder, .field textarea::placeholder { color: #8d8996; }
.caption-field { grid-column: 1 / -1; }
.field-hint { grid-column: 1 / -1; margin: -3px 0 0; color: var(--ink-soft); font-size: 11px; line-height: 1.4; }

/* Groups size to their own controls and wrap, so wide button sets never spill into a neighbour. */
.typography-panel { display: flex; flex-wrap: wrap; align-items: flex-end; align-content: flex-start; gap: 14px 20px; min-width: 0; }
.control-group { display: flex; flex: 0 0 auto; min-width: 0; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 7px; }
.control-label { color: var(--ink); font-size: 9px; white-space: nowrap; }
.font-group { flex: 1 0 100%; grid-column: 1 / -1; justify-content: flex-start; }
.font-list { display: flex; width: 100%; gap: 8px; overflow-x: auto; padding: 0 4px 5px 0; scrollbar-width: thin; scrollbar-color: var(--ink) transparent; }
.font-button { flex: 0 0 auto; min-height: 32px; padding: 0 10px; color: var(--ink); background: var(--surface); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); font-size: 12px; white-space: nowrap; cursor: pointer; }
.font-button[aria-pressed="true"] { background: var(--pink); box-shadow: none; transform: translate(2px, 2px); }
.font-button[data-font="Archivo Black"] { font-family: 'Arial Black', Arial, sans-serif; font-weight: 900; }
.font-button[data-font="Barlow Condensed"], .font-button[data-font="Oswald"] { font-family: 'Arial Narrow', Impact, sans-serif; }
.font-button[data-font="Coda"] { font-family: 'Trebuchet MS', sans-serif; }
.font-button[data-font="Courier Prime"], .font-button[data-font="Special Elite"], .font-button[data-font="Press Start 2P"] { font-family: 'Courier New', monospace; }
.font-button[data-font="Cutive"], .font-button[data-font="Playfair Display"] { font-family: Georgia, serif; }
.font-button[data-font="Syncopate"] { font-family: 'Century Gothic', Arial, sans-serif; }
@media (hover: hover) {
  .font-button:not([aria-pressed="true"]):hover { background: var(--butter); }
}

.segmented { width: fit-content; box-shadow: 2px 2px 0 var(--ink); }
.segmented button { min-width: 30px; min-height: 30px; padding: 0 7px; color: var(--ink); background: var(--surface); border: 0; font-size: 11px; font-weight: 800; cursor: pointer; }
.segmented button + button { border-left: 2px solid var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--pink); }
.small-segmented button { min-width: 32px; font-size: 12px; }
.icon-segmented button { min-width: 32px; font-family: Arial, sans-serif; font-size: 15px; }
.align-group button[data-align="left"] { transform: scaleX(-1); }
.color-choices { display: flex; gap: 10px; align-items: center; min-height: 30px; }
.color-choice { width: 26px; height: 26px; padding: 0; background: var(--surface); border: 2.5px solid var(--ink); border-radius: 50%; cursor: pointer; }
.color-choice.is-black { background: #141414; }
.color-choice[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--ink); }
.overlay-group { flex: 1 1 110px; min-width: 110px; max-width: 260px; }
.overlay-group input { width: 100%; min-height: 30px; margin: 0; accent-color: var(--ink); }
.overlay-group .control-label { display: flex; width: 100%; justify-content: space-between; gap: 5px; }
.fit-segmented button { min-width: 44px; font-size: 10px; }
@media (hover: hover) {
  .paper-switch button:not([aria-pressed="true"]):hover, .segmented button:not([aria-pressed="true"]):hover { background: var(--butter); }
}

.inspector-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin-top: 8px; color: var(--ink-soft); font-size: 10px; }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(40, 24, 64, .55); }
.three-dialog { width: min(100vw, 1200px); height: min(100svh, 900px); max-width: none; max-height: none; padding: 0; overflow: hidden; color: var(--ink); background: #292a2f; border: var(--border); border-radius: 0; box-shadow: var(--shadow-lg); }
.three-dialog[open] { display: flex; flex-direction: column; }
.dialog-top { display: flex; min-height: 58px; align-items: center; justify-content: space-between; padding: 0 16px 0 19px; background: var(--butter); border-bottom: var(--border); font-family: var(--display); font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.dialog-actions { display: flex; align-items: center; gap: 14px; }
.nb-button.default.three-reset { --btn-bg: var(--surface); min-height: 40px; gap: 6px; padding-inline: 12px; font-size: 10px; }
.three-reset span:first-child { font-size: 15px; }
.dialog-kicker { color: var(--ink-soft); font-family: 'Public Sans', Arial, sans-serif; font-weight: 700; }
.nb-button.default.icon-close { width: 40px; min-height: 40px; height: 40px; padding: 0; font-size: 24px; font-weight: 500; }

.three-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #5c5c62; }
.three-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.three-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink); background: var(--lilac); font-family: var(--display); font-size: 10px; letter-spacing: .06em; pointer-events: none; transition: opacity .2s ease; }
.three-loading.is-hidden { opacity: 0; }
.three-controls { display: flex; min-height: 66px; align-items: center; justify-content: center; gap: 22px; background: var(--butter); border-top: var(--border); }
.three-controls .nb-button.default { width: 44px; min-height: 44px; height: 44px; padding: 0; font-size: 18px; }
.three-controls span { min-width: 120px; color: var(--ink); font-family: var(--display); font-size: 9px; letter-spacing: .04em; text-align: center; }
.three-hint { min-height: 30px; margin: 0; padding: 0 10px 9px; color: var(--ink-soft); background: var(--butter); text-align: center; font-size: 9px; }

.info-dialog { width: min(660px, calc(100vw - 32px)); max-height: min(88svh, 840px); padding: 27px clamp(20px, 5vw, 43px) 32px; overflow-y: auto; background: var(--paper); border: var(--border); border-radius: 0; box-shadow: var(--shadow-lg); }
.info-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 23px; }
.settings-dialog p { margin: 16px 0; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.settings-dialog .app-version { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.nb-button.default.update-app-button { min-height: 44px; background: var(--mint); }
.eyebrow { display: inline-block; padding: 4px 8px; color: var(--ink); background: var(--butter); border: 2px solid var(--ink); font-size: 9px; }
.info-heading h2 { margin: 14px 0 0; font-family: var(--display); font-size: clamp(22px, 4.6vw, 34px); font-weight: 900; letter-spacing: -.05em; line-height: 1.08; }
.fold-video { margin: 0 0 22px; }
.fold-video-frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: var(--ink); border: var(--border); box-shadow: var(--shadow); }
.fold-video-frame iframe { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border: 0; }
.fold-video-offline { display: none; position: absolute; inset: 0; margin: 0; padding: 20px; place-content: center; color: var(--paper); font-size: 13px; font-weight: 700; line-height: 1.5; text-align: center; }
.fold-video.is-offline iframe { display: none; }
.fold-video.is-offline .fold-video-offline { display: grid; }
.fold-video figcaption { margin-top: 10px; color: var(--ink-soft); font-size: 12px; font-weight: 600; }
.fold-video figcaption a { color: var(--ink); font-weight: 800; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.fold-steps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.fold-steps article { display: flex; gap: 12px; padding: 12px; background: var(--surface); border: 2.5px solid var(--ink); box-shadow: var(--shadow-sm); }
.fold-steps article:nth-child(3n+1) { background: var(--mint); }
.fold-steps article:nth-child(3n+2) { background: var(--sky); }
.fold-steps article:nth-child(3n) { background: var(--pink); }
.fold-steps article > span { font-family: var(--display); font-size: 11px; font-weight: 900; }
.fold-steps h3 { margin: 0 0 5px; font-size: 15px; font-weight: 800; }
.fold-steps p, .about-dialog > p, .reset-dialog > p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.fold-diagram { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 20px; background: var(--surface); border: var(--border); box-shadow: var(--shadow-sm); }
.fold-diagram span { display: grid; min-height: 51px; place-items: center; color: var(--ink); border: 1.5px dashed var(--ink); font-size: 11px; font-weight: 800; }
.about-dialog > p + p { margin-top: 12px; }
.about-signoff { display: block; margin-top: 30px; font-family: var(--display); font-size: 9px; letter-spacing: .04em; }
.reset-actions { display: flex; justify-content: flex-end; gap: 14px; margin-top: 26px; }
.nb-button.default.reset-cancel, .nb-button.default.reset-confirm { min-height: 44px; }
.nb-button.default.reset-confirm { --btn-bg: var(--pink-deep); }

.toast { position: fixed; z-index: 20; right: 18px; bottom: 18px; max-width: min(340px, calc(100vw - 36px)); padding: 12px 16px; color: var(--ink); background: var(--butter); border: var(--border); box-shadow: var(--shadow); font-size: 13px; font-weight: 700; opacity: 0; transform: translateY(9px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { color: var(--ink); background: #ffb3b8; line-height: 1.5; }

@media (min-width: 1500px) {
  .inspector { padding-inline: 24px; }
  .inspector-main { grid-template-columns: minmax(300px, 1fr) minmax(570px, 1.5fr); gap: 22px; }
  .workspace { height: calc(100svh - 407px); }
}

@media (max-width: 1200px) and (min-width: 761px) {
  .topbar { grid-template-columns: minmax(165px,1fr) auto; padding-inline: 14px; }
  .topbar-right { display: none; }
  .toolbar { gap: 10px; }
  .nb-button.default.toolbar-button { padding-inline: 10px; }
  .toolbar .label-extra { display: none; }
}

@media (max-width: 1020px) and (min-width: 761px) {
  .workspace { height: calc(100svh - 613px); min-height: 330px; }
  .page-rail { flex-basis: 116px; padding-inline: 9px; }
  .inspector { padding-inline: 14px; }
  .inspector-main { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .inspector { min-height: 290px; }
  .inspector-foot { margin-top: 8px; }
}

@media (max-width: 760px) {
  :root { --page-ratio: .647; --border-w: 2.5px; --shadow: 3px 3px 0 var(--ink); --shadow-sm: 2px 2px 0 var(--ink); --shadow-lg: 4px 4px 0 var(--ink); }
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    min-height: 0;
    padding: 0 12px 4px;
  }
  .topbar-right { justify-content: flex-end; gap: 8px; padding: 0; }
  .save-status { gap: 6px; font-size: 11px; }
  .nb-button.default.install-button { min-height: 32px; padding-inline: 8px; font-size: 10px; }
  .toolbar { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; padding: 4px 2px 8px 0; }
  .paper-switch { grid-column: 1; grid-row: 1; }
  .margin-toggle { grid-column: 2; grid-row: 1; justify-content: center; min-height: 44px; }
  .margin-toggle input { width: 28px; height: 28px; }
  .download-control { grid-column: 2; grid-row: 2; }
  .download-control > button { width: 100%; }
  .paper-switch button { flex: 1; min-width: 0; min-height: 44px; padding-inline: 6px; font-size: 11px; letter-spacing: .03em; }
  .paper-switch button:first-child { flex: 1.7; }
  .nb-button.default.toolbar-button { min-width: 0; min-height: 44px; gap: 5px; padding-inline: 10px; font-size: 11px; letter-spacing: .03em; }
  .button-icon { font-size: 13px; }
  .workspace { height: auto; min-height: 0; max-height: none; flex-direction: column; }
  .stage { flex: none; height: min(50svh, 420px); min-height: 330px; }
  .stage { order: 1; }
  .stage-meta { top: 10px; left: 12px; right: 12px; font-size: 10px; }
  .stage-tip { font-size: 11px; }
  .stage-pages { padding: 44px 22px 52px; }
  .preview-page-frame { height: 82%; max-height: 340px; }
  .stage-pages.is-spread { width: auto; height: 62%; max-width: 90%; aspect-ratio: var(--spread-ratio); padding: 0; }
  .stage-pages.is-spread .preview-page-frame { height: 100%; }
  .preview-page-frame, .stage-pages.is-spread { box-shadow: 4px 4px 0 var(--stage-shadow); }
  .stage-pages.is-spread .preview-page-frame { box-shadow: none; }
  .stage-bottom { left: 12px; right: 12px; bottom: 8px; font-size: 9px; }
  .stage-bottom { display: flex; justify-content: space-between; }
  .stage-bg-choice { width: 34px; height: 34px; }
  .page-rail { flex: none; width: 100%; padding: 10px 12px 10px; border-top: var(--border); border-right: 0; }
  .page-rail { order: 2; }
  .rail-label { margin: 0 0 8px; }
  .rail-label span { font-size: 10px; }
  .sheet-list { flex: none; flex-direction: row; gap: 9px; overflow-x: auto; padding: 0 4px 6px 0; scrollbar-width: thin; scrollbar-color: var(--ink) transparent; touch-action: pan-x; }
  .sheet-thumb { flex: 0 0 94px; min-height: 82px; height: 82px; gap: 2px; padding: 4px 3px 3px; }
  .thumb-pages { min-height: 50px; }
  .thumb-page { max-height: 50px; }
  .thumb-label { font-size: 9px; }
  .rail-help { display: block; min-height: 44px; padding: 8px 0; }
  .rail-links { flex-direction: row; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
  .inspector { min-height: 0; padding: 0 12px 12px; }
  .inspector-topline { height: 44px; font-size: 10px; }
  .inspector-topline > span:first-child { font-size: 9px; }
  .inspector-topline-right { gap: 7px; }
  .page-move-controls { gap: 6px; font-size: 9px; }
  .page-move-controls span { display: none; }
  .page-move-controls button { width: 44px; height: 40px; }
  .inspector-main { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .field-panel { grid-template-columns: 1fr; align-content: center; gap: 10px; }
  .field-panel.single-field { grid-template-columns: 1fr; }
  .field { gap: 5px; }
  .field > span { font-size: 10px; }
  /* 16px stops iOS Safari from zooming the page when a field gets focus. */
  .field input { min-height: 46px; padding-inline: 10px; font-size: 16px; }
  .field textarea { min-height: 92px; font-size: 16px; }
  .caption-field { grid-column: auto; }
  .field-hint { grid-column: auto; font-size: 11px; }
  .typography-panel { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto; gap: 14px 12px; padding: 14px 0 6px; border-top: var(--border); }
  .font-group { grid-column: 1 / -1; }
  .font-list { gap: 8px; padding-bottom: 6px; }
  .font-button { min-height: 44px; padding-inline: 12px; font-size: 13px; }
  .control-group { gap: 7px; }
  .control-label { font-size: 10px; letter-spacing: .06em; }
  .segmented button { min-width: 44px; min-height: 44px; }
  .small-segmented button, .icon-segmented button { min-width: 44px; }
  .fit-segmented button { min-width: 56px; font-size: 11px; }
  .overlay-group { grid-column: 1 / -1; max-width: none; }
  .overlay-group input { min-height: 32px; }
  .color-group { align-items: flex-start; }
  .color-choices { gap: 12px; min-height: 44px; }
  .color-choice { width: 34px; height: 34px; }
  .inspector-foot { flex-direction: column; align-items: stretch; gap: 10px; min-height: 0; margin-top: 10px; padding-top: 10px; border-top: 2px dashed var(--ink); font-size: 10px; }
  .inspector-foot > span { line-height: 1.5; }
  .three-dialog { width: 100vw; height: 100svh; border: 0; box-shadow: none; }
  .dialog-top { min-height: 56px; padding-inline: 13px 10px; font-size: 9px; }
  .nb-button.default.icon-close { width: 44px; height: 44px; min-height: 44px; }
  .nb-button.default.three-reset { min-height: 44px; padding-inline: 10px; }
  .dialog-actions { gap: 10px; }
  .three-controls { min-height: 64px; }
  .three-hint { min-height: 30px; font-size: 9px; }
  .info-dialog { width: calc(100vw - 20px); max-height: 90svh; padding: 20px 16px 24px; }
  .info-heading h2 { font-size: clamp(19px, 6.4vw, 26px); }
  .fold-steps { grid-template-columns: 1fr; gap: 10px; }
  .fold-steps article { gap: 11px; padding: 10px; }
  .fold-steps p { font-size: 12px; }
  .fold-diagram span { min-height: 44px; font-size: 9px; }
  .reset-actions { flex-wrap: wrap; }
  .toast { right: 12px; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: none; font-size: 12px; }
}

@media (max-width: 400px) {
  .label-extra { display: none; }
}

/* Small phones: the 35px wordmark needs the row, so the save status shrinks to its dot. Screen readers
   still hear the text. */
@media (max-width: 420px) {
  .save-status > span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@media (max-width: 370px) {
  .toolbar { gap: 6px; }
  .paper-switch button { padding-inline: 7px; font-size: 10px; }
  .nb-button.default.toolbar-button { padding-inline: 8px; font-size: 10px; }
  .button-icon { display: none; }
  .save-status { font-size: 10px; }
  .sheet-thumb { flex-basis: 86px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
  .nb-button.default:hover, .nb-button.default:active, .preview-remove-photo:active, .page-move-controls button:active, .field input:focus, .field textarea:focus { transform: none; }
}
