/* ═══════════════════════════════════════════════════════════
   iridesuwa — Artbook Stylesheet  v2
   Museum classic white · A4 page layout · DM Sans body font
═══════════════════════════════════════════════════════════ */

/* ─── TOKENS ─────────────────────────────────────────────── */
:root {
  --bg:           #f7f5f2;
  --bg-2:         #efede9;
  --surface:      #ffffff;
  --surface-2:    #fafaf8;
  --text:         #1a1814;
  --text-mid:     #5c5852;
  --text-faint:   #a09c95;
  --border:       #ddd9d3;
  --border-light: #e8e5e0;
  --accent:       #1a1814;
  --danger:       #b84040;
  --success:      #3a7a52;

  --shadow-sm:    0 1px 3px rgba(0,0,0,0.07);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.09);
  --shadow-lg:    0 12px 48px rgba(0,0,0,0.13);
  --shadow-page:  0 8px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);

  --font-display: 'Cormorant Garamond', 'Georgia', serif;
  --font-body:    'DM Sans', 'Helvetica Neue', sans-serif;

  --header-h:    60px;
  --nav-h:       52px;
  --section-bar-h: 0px;  /* Set to 39px by JS when section bar is visible */
  --radius:      3px;
  --radius-md:   6px;
  --transition:  240ms cubic-bezier(0.4, 0, 0.2, 1);

  /* A4 ratio: 210×297mm → 1:√2 */
  --a4-ratio:    1.4142;
}

[data-theme="dark"] {
  --bg:           #121110;
  --bg-2:         #1a1916;
  --surface:      #1e1c19;
  --surface-2:    #232118;
  --text:         #edeae3;
  --text-mid:     #9a968f;
  --text-faint:   #5a5650;
  --border:       #2c2a26;
  --border-light: #232120;
  --accent:       #edeae3;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.35);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.55);
  --shadow-lg:    0 12px 48px rgba(0,0,0,0.75);
  --shadow-page:  0 8px 40px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.3);
}

/* ─── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-weight: 300;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
  -webkit-user-select: none;
  user-select: none;
  /* A5: disable double-tap zoom on all non-interactive areas;
     pinch-zoom still works via JS handlers in the viewer */
  touch-action: manipulation;
}

/* A5: Re-enable pan+pinch-zoom in the viewer area so our JS handlers fire */
.a4-viewport,
.multi-view-wrap,
.fs-overlay,
.fs-content,
.multi-cell-viewport {
  touch-action: pan-x pan-y pinch-zoom;
}

img {
  display: block;
  max-width: 100%;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

button { cursor: pointer; font-family: var(--font-body); }
input, textarea, select { font-family: var(--font-body); }

/* ─── HEADER ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  transition: background var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 20px;
  gap: 12px;
}

.site-tagline {
  font-family: var(--font-body);
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-faint);
  transition: color var(--transition);
  white-space: nowrap;
}

.logo-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.site-logo {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--text);
  cursor: default;
  transition: color var(--transition);
  text-align: center;
  user-select: none;
}

.header-rule {
  height: 1px;
  background: var(--border);
  transition: background var(--transition);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* Theme toggle */
.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mid);
  transition: all var(--transition);
}
.theme-btn:hover { border-color: var(--text-mid); color: var(--text); }
.theme-icon { width: 14px; height: 14px; }

.settings-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mid);
  transition: all var(--transition);
}
.settings-btn:hover { border-color: var(--text-mid); color: var(--text); }

/* ─── MAIN AREA ───────────────────────────────────────────── */
.artbook-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 24px 16px;
  min-height: 0;
  overflow: hidden;
}

/* ─── STATES ─────────────────────────────────────────────── */
.loading-state, .empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.loading-ring {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--border);
  border-top-color: var(--text-mid);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-text {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  color: var(--text-faint);
}

/* ─── A4 PAGE LAYOUT ─────────────────────────────────────── */
.page-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
}

.page-label-row {
  width: 100%;
  max-width: var(--a4-max, 680px);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-left: 2px;
}

.page-label-num {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.14em;
  color: var(--text-faint);
}

/* a4-viewport — fixed display box, scrollable for zoom/pan */
.a4-viewport {
  position: relative;
  /* Fills the same space the old a4-frame used to */
  width: 100%;
  aspect-ratio: 1 / 1.4142;
  max-height: calc(100dvh - var(--header-h) - var(--nav-h) - var(--section-bar-h) - 80px);
  max-width: calc((100dvh - var(--header-h) - var(--nav-h) - var(--section-bar-h) - 80px) / 1.4142);
  /* Use auto so the a4Frame can expand beyond the viewport when zoomed */
  overflow: auto;
  cursor: default;
  /* Smooth scroll for programmatic pan */
  scroll-behavior: auto;
  /* Hide scrollbars — panning is done via drag */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.a4-viewport::-webkit-scrollbar { display: none; }
.a4-viewport.can-pan    { cursor: grab; }
.a4-viewport.is-panning { cursor: grabbing !important; }

/* a4-frame — real rendered size, grows with zoom level */
.a4-frame {
  background: var(--surface);
  box-shadow: var(--shadow-page);
  position: relative;
  /* Size is set by JS via --zoom-scale; default 100% of viewport */
  width: 100%;
  height: 100%;
  transition: background var(--transition), box-shadow var(--transition);
  /* No overflow: hidden — page-stage fills it completely */
  overflow: hidden;
  /* A2: Prevent blurry scaling */
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
/* Default smooth scaling (blurry on upscale, not pixelated) */
.a4-frame img,
.fs-page-wrap img,
.fs-multi-cell img,
.multi-cell-frame img {
  image-rendering: auto;
  will-change: transform;
  /* Subpixel anti-aliasing */
  -webkit-font-smoothing: antialiased;
}

/* When zoomed in, claw back some perceived sharpness with a gentle
   unsharp mask instead of switching to blocky nearest-neighbor scaling. */
.can-pan img,
.fs-page-wrap.is-zoomed img {
  filter: url(#zoom-unsharp);
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  z-index: 10;
  transition: opacity var(--transition);
}
.zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-mid);
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
  line-height: 0;
}
.zoom-btn:hover { background: var(--bg-2); color: var(--text); }
.zoom-btn svg { display: block; }
.zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}
.zoom-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  cursor: pointer;
}
.zoom-pct {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  min-width: 34px;
  text-align: right;
}

/* Page is always sized to fill the A4 frame */
.page-stage {
  position: absolute;
  inset: 0;
}

/* ─── PAGE COMPONENT ─────────────────────────────────────── */
.art-page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  transition: background var(--transition);
}

.art-page.entering-forward { animation: slideInR 0.42s cubic-bezier(0.4,0,0.2,1) forwards; }
.art-page.leaving-forward  { animation: slideOutL 0.42s cubic-bezier(0.4,0,0.2,1) forwards; }
.art-page.entering-back    { animation: slideInL 0.42s cubic-bezier(0.4,0,0.2,1) forwards; }
.art-page.leaving-back     { animation: slideOutR 0.42s cubic-bezier(0.4,0,0.2,1) forwards; }

@keyframes slideOutL { from{transform:translateX(0);opacity:1} to{transform:translateX(-32px);opacity:0} }
@keyframes slideInR  { from{transform:translateX(32px);opacity:0} to{transform:translateX(0);opacity:1} }
@keyframes slideOutR { from{transform:translateX(0);opacity:1} to{transform:translateX(32px);opacity:0} }
@keyframes slideInL  { from{transform:translateX(-32px);opacity:0} to{transform:translateX(0);opacity:1} }


/* ═══════════════════════════════════════════════════════════
   A4-ANCHORED LAYOUT SIZES
   --a4-w and --a4-h are set by viewer.js ResizeObserver on
   the .a4-frame element. All font sizes and spacing inside
   the page use calc(var(--a4-w) * ratio) so they are
   completely consistent regardless of browser window size.
═══════════════════════════════════════════════════════════ */

/* ─── LAYOUT: FLOOD ─────────────────────────────────────── */
.layout-flood { padding: 0; }
.layout-flood .artwork-flood {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.layout-flood .artwork-flood img {
  width: 100%;
  height: 100%;
  object-fit: var(--flood-img-fit, cover);
}

/* Caption box: position anchored by corner class.
   Height is controlled by --flood-h-ratio (fraction of A4 height).
   Text scale by --flood-text-scale. */
.flood-caption {
  position: absolute;
  display: flex;
  align-items: center;
  gap: calc(var(--a4-w, 400px) * 0.018);
  /* Height as fraction of A4 height */
  min-height: calc(var(--a4-h, 566px) * var(--flood-h-ratio, 0.18));
  padding: calc(var(--a4-w, 400px) * 0.04) calc(var(--a4-w, 400px) * 0.05);
  box-sizing: border-box;
}

/* Corner positioning */
.flood-caption--bl { bottom: 0; left: 0; align-items: flex-end; }
.flood-caption--br { bottom: 0; right: 0; align-items: flex-end; flex-direction: row-reverse; }
.flood-caption--tl { top: 0; left: 0; align-items: flex-start; }
.flood-caption--tr { top: 0; right: 0; align-items: flex-start; flex-direction: row-reverse; }

.flood-caption-text {
  display: flex;
  flex-direction: column;
  gap: calc(var(--a4-w, 400px) * 0.01);
}

/* Title and meta: each line gets its own background box */
.flood-title,
.flood-meta {
  display: inline;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  line-height: 1.55;
  background-color: var(--flood-bg, rgba(255,255,255,0.92));
  color:            var(--flood-fg, #1a1814);
  transition: background-color 0.25s, color 0.25s;
}

.flood-caption .flood-title {
  font-family: var(--font-body);
  /* Base ~3.8% of A4 width, scaled by --flood-text-scale */
  font-size: calc(var(--a4-w, 400px) * 0.038 * var(--flood-text-scale, 1));
  font-weight: 400;
  padding: calc(var(--a4-w, 400px) * 0.006) calc(var(--a4-w, 400px) * 0.018);
}
.flood-caption .flood-meta {
  font-size: calc(var(--a4-w, 400px) * 0.022 * var(--flood-text-scale, 1));
  font-weight: 400;
  letter-spacing: 0.12em;
  padding: calc(var(--a4-w, 400px) * 0.003) calc(var(--a4-w, 400px) * 0.014);
}

/* Info icon button */
.flood-info-btn {
  background: var(--flood-bg, rgba(255,255,255,0.92));
  color:      var(--flood-fg, #1a1814);
  border: none;
  border-radius: 50%;
  width:  calc(var(--a4-w, 400px) * 0.065);
  height: calc(var(--a4-w, 400px) * 0.065);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
  pointer-events: all;
}
.flood-info-btn:hover, .flood-info-btn.active { opacity: 0.75; }
.flood-info-btn svg {
  width:  calc(var(--a4-w, 400px) * 0.032);
  height: calc(var(--a4-w, 400px) * 0.032);
}

/* Info popup card — floats above caption */
.flood-info-popup {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: calc(var(--a4-w, 400px) * 0.018);
  background: var(--flood-bg, rgba(255,255,255,0.96));
  color:      var(--flood-fg, #1a1814);
  backdrop-filter: blur(8px);
  padding: calc(var(--a4-w, 400px) * 0.04) calc(var(--a4-w, 400px) * 0.05);
  min-width: calc(var(--a4-w, 400px) * 0.42);
  max-width: calc(var(--a4-w, 400px) * 0.65);
  border-radius: 2px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  z-index: 10;
  pointer-events: none;
}
/* Position relative to corner */
.flood-info-popup--bl { bottom: calc(var(--a4-h, 566px) * var(--flood-h-ratio, 0.18) + calc(var(--a4-w, 400px) * 0.02)); left: calc(var(--a4-w, 400px) * 0.05); }
.flood-info-popup--br { bottom: calc(var(--a4-h, 566px) * var(--flood-h-ratio, 0.18) + calc(var(--a4-w, 400px) * 0.02)); right: calc(var(--a4-w, 400px) * 0.05); }
.flood-info-popup--tl { top: calc(var(--a4-h, 566px) * var(--flood-h-ratio, 0.18) + calc(var(--a4-w, 400px) * 0.02)); left: calc(var(--a4-w, 400px) * 0.05); }
.flood-info-popup--tr { top: calc(var(--a4-h, 566px) * var(--flood-h-ratio, 0.18) + calc(var(--a4-w, 400px) * 0.02)); right: calc(var(--a4-w, 400px) * 0.05); }

.flood-info-row {
  display: flex;
  flex-direction: column;
  gap: calc(var(--a4-w, 400px) * 0.006);
}
.flood-info-label {
  font-size: calc(var(--a4-w, 400px) * 0.019);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.55;
}
.flood-info-value {
  font-size: calc(var(--a4-w, 400px) * 0.026);
  font-weight: 300;
  line-height: 1.4;
}
.flood-info-empty {
  font-size: calc(var(--a4-w, 400px) * 0.024);
  font-style: italic;
  opacity: 0.5;
}

/* ─── LAYOUT: LARGE ─────────────────────────────────────── */
.layout-large {
  align-items: center;
  justify-content: center;
  padding: calc(var(--a4-w, 400px) * 0.08);
  gap: calc(var(--a4-w, 400px) * 0.04);
}
.layout-large .artwork-large {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--a4-w, 400px) * 0.032);
  max-height: 100%;
  width: 100%;
  min-height: 0;
}

/* Text-align variants */
.layout-large .artwork-large[data-text-align="left"]  { align-items: flex-start; }
.layout-large .artwork-large[data-text-align="right"] { align-items: flex-end; }
.layout-large .artwork-large[data-text-align="center"]{ align-items: center; }

.layout-large .artwork-large .img-shield {
  flex: 1;
  min-height: 0;
  /* Image height = remaining space after text block */
  max-height: calc(100% - var(--a4-h, 566px) * var(--large-text-ratio, 0.22) - calc(var(--a4-w, 400px) * 0.04));
  display: flex;
  align-items: center;
  justify-content: center;
}
.layout-large .artwork-large img {
  max-height: 100%;
  max-width:  100%;
  object-fit: contain;
  box-shadow: var(--shadow-md);
}
.layout-large .art-caption-block {
  flex-shrink: 0;
  /* Width = same as whatever img-shield consumed — achieved via align-self stretch in column flex */
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: calc(var(--a4-w, 400px) * 0.012);
  /* Reserve the text-ratio height */
  min-height: calc(var(--a4-h, 566px) * var(--large-text-ratio, 0.22));
}

/* ─── LAYOUT: MEDIUM ────────────────────────────────────── */
.layout-medium {
  padding: calc(var(--a4-w, 400px) * 0.07) calc(var(--a4-w, 400px) * 0.09);
  gap: calc(var(--a4-w, 400px) * 0.045);
  justify-content: center;
}
.artwork-medium {
  display: grid;
  grid-template-columns: var(--split-img, 50%) var(--split-txt, 50%);
  gap: calc(var(--a4-w, 400px) * 0.04);
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}
/* text-left: swap column order cleanly without direction trick */
.artwork-medium.text-left {
  grid-template-columns: var(--split-txt, 50%) var(--split-img, 50%);
}
.artwork-medium.text-left .img-col { order: 2; }
.artwork-medium.text-left .text-col { order: 1; text-align: right; }
.artwork-medium .img-col {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.artwork-medium .img-col img {
  width: 100%;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.artwork-medium .text-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: calc(var(--a4-w, 400px) * 0.022);
  padding: calc(var(--a4-w, 400px) * 0.01) 0;
  text-align: left;
}

/* ─── LAYOUT: SMALL ─────────────────────────────────────
   Identical structure to medium, tighter spacing to fit 4 rows.
   Page gap / row gap / text-col gap all scaled down proportionally. */
.layout-small {
  padding: calc(var(--a4-w, 400px) * 0.07) calc(var(--a4-w, 400px) * 0.09);
  gap: calc(var(--a4-w, 400px) * 0.025);
  justify-content: center;
}
.artwork-small {
  display: grid;
  grid-template-columns: var(--split-img, 50%) var(--split-txt, 50%);
  gap: calc(var(--a4-w, 400px) * 0.04);
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}
.artwork-small.text-left {
  grid-template-columns: var(--split-txt, 50%) var(--split-img, 50%);
}
.artwork-small.text-left .img-col { order: 2; }
.artwork-small.text-left .text-col { order: 1; text-align: right; }
.artwork-small .img-col {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.artwork-small .img-col img {
  width: 100%;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.artwork-small .text-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: calc(var(--a4-w, 400px) * 0.022);
  padding: calc(var(--a4-w, 400px) * 0.01) 0;
  text-align: left;
}

/* ─── CAPTION / META — A4-anchored sizes ────────────────── */
/* All text sizes are fractions of --a4-w so they scale with
   the A4 page, not the browser window. */

.art-title {
  font-family: var(--font-body);
  font-size: calc(var(--a4-w, 400px) * 0.038);
  font-weight: 400;
  color: var(--text);
  line-height: 1.2;
  transition: color var(--transition);
}
/* Large layout title: slightly larger */
.large-title {
  font-size: calc(var(--a4-w, 400px) * 0.042);
}
/* Smaller title for medium/small label under image */
.art-title--small {
  font-size: calc(var(--a4-w, 400px) * 0.028);
}
.art-meta {
  font-size: calc(var(--a4-w, 400px) * 0.021);
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  transition: color var(--transition);
}
.art-desc {
  font-size: calc(var(--a4-w, 400px) * 0.026);
  font-weight: 300;
  line-height: 1.75;
  color: var(--text-mid);
  transition: color var(--transition);
}
.art-caption-block { display: flex; flex-direction: column; gap: calc(var(--a4-w, 400px) * 0.012); }

/* Caption under image in medium/small */
.img-col { flex-direction: column; }
.img-col-caption {
  display: flex;
  flex-direction: column;
  gap: calc(var(--a4-w, 400px) * 0.006);
  padding-top: calc(var(--a4-w, 400px) * 0.014);
  text-align: center;
}

.img-shield { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.img-shield::after { content: ''; position: absolute; inset: 0; z-index: 2; cursor: default; }

/* ─── ART CONCEPT LINE — A4-anchored ───────────────────── */
.art-concept-line {
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 300;
  color: var(--text-faint);
  line-height: 1.4;
  transition: color var(--transition);
}
.art-concept-line--full {
  font-size: calc(var(--a4-w, 400px) * 0.028);
  letter-spacing: 0.01em;
  margin-bottom: 1px;
}
.art-concept-line--short {
  font-size: calc(var(--a4-w, 400px) * 0.022);
  letter-spacing: 0.01em;
  margin-bottom: 3px;
}

/* ─── NAVIGATION ─────────────────────────────────────────── */
.book-nav {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}

.nav-arrow {
  background: none;
  border: none;
  color: var(--text-mid);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.nav-arrow:hover { color: var(--text); background: var(--bg-2); }
.nav-arrow:disabled { color: var(--border); cursor: not-allowed; background: none; }

.page-counter {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 64px;
  justify-content: center;
}
.counter-sep { opacity: 0.4; }

/* A1: Jump-to-start / jump-to-end nav buttons */
.nav-jump-btn {
  color: var(--text-faint);
}
.nav-jump-btn:disabled { color: var(--border); cursor: not-allowed; background: none; }

/* A4: Page slider row — sits below the book-nav bar */
.nav-slider-row {
  position: relative;
  display: none; /* shown by JS once nav extras are built */
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 4px 20px 6px;
  background: var(--bg);
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}
.nav-page-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 480px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  transition: background var(--transition);
}
.nav-page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  transition: transform 0.15s;
}
.nav-page-slider::-webkit-slider-thumb:active {
  transform: scale(1.25);
}
.nav-page-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  cursor: pointer;
}

/* A4: Slider preview thumbnail — floats above thumb */
.nav-slider-preview {
  position: absolute;
  bottom: calc(100% + 2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 200;
  min-width: 70px;
  width: 90px;
}
.nav-slider-preview-img {
  width: 80px;
  height: auto;
  max-height: 60px;
  object-fit: contain;
  border-radius: 2px;
  display: block;
}
.nav-slider-preview-label {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}

/* ─── ADMIN OVERLAY ──────────────────────────────────────── */
.admin-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.2s ease;
}
.admin-overlay.open { display: flex; align-items: flex-start; justify-content: flex-end; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

.admin-panel {
  width: min(440px, 96vw);
  height: 100dvh;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.28s cubic-bezier(0.4,0,0.2,1);
  transition: background var(--transition);
  overflow: hidden;
}
@keyframes slideInRight { from{transform:translateX(100%)} to{transform:translateX(0)} }

.admin-screen { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* ─── PANEL HEADER ───────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 400;
  font-style: italic;
  color: var(--text);
}
.panel-header-right { display: flex; align-items: center; gap: 8px; }

.panel-close-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.panel-close-btn:hover { background: var(--bg-2); color: var(--text); }

.icon-tool-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-tool-btn:hover { border-color: var(--text-mid); color: var(--text); background: var(--bg-2); }
.icon-tool-btn.ml4 { margin-left: 4px; }

/* ─── AUTOSAVE BAR ───────────────────────────────────────── */
.autosave-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  min-height: 34px;
}
.autosave-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.3s;
}
.autosave-dot.saving { background: #c08840; animation: pulse 1s ease-in-out infinite; }
.autosave-dot.saved  { background: var(--success); }
.autosave-dot.error  { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.autosave-label {
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

/* ─── AUTH BODY ──────────────────────────────────────────── */
.auth-body {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-intro {
  font-size: 13px;
  font-weight: 300;
  color: var(--text-mid);
  line-height: 1.6;
}
.field-group { display: flex; flex-direction: column; gap: 12px; }

.auth-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 16px;
  text-align: center;
  font-weight: 400;
}

/* ─── EDITOR BODY ────────────────────────────────────────── */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.editor-body::-webkit-scrollbar { width: 4px; }
.editor-body::-webkit-scrollbar-track { background: transparent; }
.editor-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.pages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.section-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ─── PAGES ACCORDION ────────────────────────────────────── */
.pages-accordion {
  flex: 1;
}

/* ─── PAGES SECTION GROUPING BARS ────────────────────────── */
.pages-section-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px 5px;
  margin-top: 6px;
  border-bottom: 1px solid var(--border-light);
  background: transparent;
  flex-shrink: 0;
}
.pages-section-bar:first-child { margin-top: 0; }

.pages-section-bar-letter {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent, #b08060);
  background: color-mix(in srgb, var(--accent, #b08060) 12%, transparent);
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.5;
  flex-shrink: 0;
}
.pages-section-bar-name {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pages-section-bar--unassigned .pages-section-bar-name {
  font-style: italic;
}

.pages-section-child {
  /* slight indent to show hierarchy */
  margin-left: 0;
  border-left: 2px solid transparent;
}

.pages-section-child + .pages-section-child {
  /* no extra top gap between sibling page folders */
}

.pages-subsection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px 4px 22px;
  border-bottom: 1px solid var(--border-light);
  background: transparent;
}
.pages-subsection-bar-name {
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-style: italic;
}

.pages-section-empty {
  padding: 7px 14px 7px 14px;
  font-size: 10.5px;
  color: var(--text-faint);
  font-style: italic;
}


.page-folder {
  border-bottom: 1px solid var(--border-light);
}

.page-folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 11px 16px 11px 14px;
  background: var(--bg-2);
  cursor: pointer;
  transition: background var(--transition);
  gap: 8px;
  user-select: none;
}
.page-folder-header:hover { background: var(--bg); }
.page-folder.open .page-folder-header { background: var(--surface-2); }

.pf-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.pf-chevron { color: var(--text-faint); transition: transform var(--transition); flex-shrink: 0; }
.page-folder.open .pf-chevron { transform: rotate(90deg); }
.pf-num {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text-mid);
  white-space: nowrap;
}
.pf-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.page-folder-body { display: none; padding: 0; }
.page-folder.open .page-folder-body { display: block; }

/* Layout select inside page folder header */
.layout-select {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  padding: 4px 6px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  max-width: 120px;
}
.layout-select:focus { border-color: var(--text-mid); }

/* Artwork rows inside folder */
.page-artworks-list {
  padding: 8px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.artwork-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--border-light);
  transition: background var(--transition);
}
.artwork-row:hover { background: var(--bg); }
.artwork-row-thumb {
  width: 38px;
  height: 30px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--border-light);
}
.artwork-row-info { flex: 1; min-width: 0; overflow: hidden; }
.artwork-row-title {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.artwork-row-sub {
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.add-artwork-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% - 28px);
  margin: 6px 14px 12px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.06em;
  padding: 7px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.add-artwork-btn:hover { border-color: var(--text-mid); color: var(--text-mid); background: var(--bg-2); }
.add-artwork-btn svg { color: inherit; }

/* ─── PANEL INPUTS ───────────────────────────────────────── */
.panel-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 300;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.panel-input:focus { border-color: var(--text-mid); background: var(--surface); }
.panel-input.textarea { resize: vertical; min-height: 72px; }
select.panel-input { cursor: pointer; }

/* ─── FIELD LABEL ────────────────────────────────────────── */
.field-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ─── INPUT ROW (password eye) ───────────────────────────── */
.input-row { display: flex; align-items: center; gap: 6px; }
.input-row .panel-input { flex: 1; }

.eye-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.eye-btn:hover { color: var(--text-mid); border-color: var(--text-faint); }
.eye-icon { width: 15px; height: 15px; }

/* ─── PANEL BUTTONS ──────────────────────────────────────── */
.panel-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  padding: 9px 18px;
  transition: all var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.panel-btn:hover { border-color: var(--text-mid); background: var(--bg); }
.panel-btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.panel-btn.primary:hover { opacity: 0.82; }
.panel-btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.panel-btn.danger:hover { opacity: 0.85; }
.panel-btn.sm { font-size: 11px; padding: 6px 12px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-mid);
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); }

/* ─── MODAL OVERLAY ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}

/* Picker modals open on top of form modals — must be higher z-index
   regardless of DOM order */
#artworkPickerOverlay,
#characterPickerOverlay { z-index: 1200; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.22s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  max-height: 90dvh;
  overflow: hidden;
}
@keyframes scaleIn { from{transform:scale(0.96);opacity:0} to{transform:scale(1);opacity:1} }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── UPLOAD MODAL ───────────────────────────────────────── */
.upload-modal { width: min(500px, 96vw); }
.upload-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.upload-fields { display: flex; flex-direction: column; gap: 12px; }

/* Drop zone */
.drop-zone {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  min-height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--text-mid); background: var(--bg-2); }
.drop-inner { text-align: center; pointer-events: none; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-icon { color: var(--text-faint); }
.drop-label { font-size: 12.5px; font-weight: 300; color: var(--text-mid); }
.upload-preview { width: 100%; height: 160px; object-fit: contain; background: var(--bg-2); }

/* Filename row */
.filename-row {
  display: flex;
  align-items: center;
}
.filename-row .panel-input {
  border-radius: var(--radius) 0 0 var(--radius);
  flex: 1;
  border-right: none;
}
.filename-ext {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-faint);
  height: 38px;
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
  border-right: none;
}
.filename-row .icon-tool-btn {
  border-radius: 0 var(--radius) var(--radius) 0;
  width: 38px;
  height: 38px;
  border-left: none;
  flex-shrink: 0;
}

/* Upload progress */
.upload-progress { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.progress-track { height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--text); border-radius: 2px; width: 0%; transition: width 0.3s ease; }
.progress-label { font-size: 11px; color: var(--text-faint); letter-spacing: 0.08em; }

/* ─── FILE VIEWER MODAL ──────────────────────────────────── */
.file-viewer-modal { width: min(680px, 96vw); }
.file-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.fv-count { font-size: 11px; color: var(--text-faint); letter-spacing: 0.06em; }
.file-viewer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  overflow-y: auto;
  max-height: calc(90dvh - 140px);
}
.fv-loading { grid-column: 1/-1; display: flex; justify-content: center; padding: 40px; }

.fv-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 8px;
  border: 1px solid var(--border-light);
  background: var(--surface-2);
  transition: all var(--transition);
}
.fv-item:hover { border-color: var(--border); background: var(--bg-2); }
.fv-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 2px;
  background: var(--bg-2);
  pointer-events: none;
}
.fv-name {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-mid);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.fv-actions {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.fv-action-btn {
  font-size: 10px;
  font-family: var(--font-body);
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-mid);
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.04em;
}
.fv-action-btn:hover { border-color: var(--text-mid); color: var(--text); background: var(--bg); }
.fv-action-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* ─── EDIT ARTWORK MODAL ─────────────────────────────────── */
.edit-art-modal { width: min(420px, 96vw); }
.edit-art-body { display: flex; flex-direction: column; gap: 12px; }

/* ─── CONFIRM MODAL ──────────────────────────────────────── */
.confirm-modal { width: min(380px, 96vw); }
.confirm-text { font-size: 13.5px; font-weight: 300; line-height: 1.6; color: var(--text-mid); }
.confirm-text strong { font-weight: 500; color: var(--text); }

/* ─── EMPTY PAGE PLACEHOLDER ─────────────────────────────── */
.page-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  height: 100%;
  color: var(--text-faint);
  border: 1.5px dashed var(--border);
  margin: clamp(16px, 5%, 40px);
  width: calc(100% - clamp(32px, 10%, 80px));
  height: calc(100% - clamp(32px, 10%, 80px));
  border-radius: 2px;
  transition: border-color var(--transition), color var(--transition);
}
.page-placeholder span {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}


/* ─── ART CONCEPT LINE ───────────────────────────────────── */
/* Inline comma-separated concept subtitle, styled like a secondary
   title — display font, italic, faint. Sits under the title on large
   layouts, and leads the text column on medium/small layouts. */
.art-concept-line {
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 300;
  color: var(--text-faint);
  line-height: 1.4;
  transition: color var(--transition);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
/* art-concept-line sizes are A4-anchored — see the layout block above */

/* ─── SPLIT RATIO SLIDER ─────────────────────────────────── */
.split-ratio-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0 2px;
  border-top: 1px solid var(--border-light);
  margin-top: 2px;
}
.split-ratio-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.split-ratio-label {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-mid);
  letter-spacing: 0.04em;
}
.split-ratio-pct {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.split-ratio-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: ew-resize;
  transition: background var(--transition);
}
.split-ratio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
  transition: background var(--transition);
}
.split-ratio-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
}

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --header-h: 52px;
    --nav-h: 46px;
  }
  .header-inner { padding: 0 14px; }
  .site-tagline { display: none; }
  .site-logo { font-size: 20px; }

  .artbook-wrap { padding: 12px 12px 8px; }

  /* Layout padding is A4-anchored — no mobile override needed */

  .admin-panel { width: 100vw; }
  .file-viewer-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}


/* ─── FLOOD POSITION MODAL ───────────────────────────────── */
.flood-pos-modal {
  width: min(520px, 96vw);
}

.flood-pos-body {
  padding: 18px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.flood-pos-hint {
  font-size: 12px;
  font-weight: 300;
  color: var(--text-faint);
  line-height: 1.6;
  text-align: center;
}

/* A4 preview stage — centres the A4 frame */
.flood-pos-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* A4 aspect-ratio frame (1 : √2) */
.flood-pos-a4 {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1.4142;
  overflow: hidden;
  border-radius: 2px;
  box-shadow: var(--shadow-md);
  cursor: ew-resize;
  user-select: none;
  touch-action: none;
}

.flood-pos-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  pointer-events: none;
  transition: object-position 0s; /* instant while dragging */
}

/* Gradient caption replica */
.flood-pos-caption {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 14px 14px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.flood-pos-caption-title {
  display: inline;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 400;
  font-style: italic;
  padding: 2px 6px;
  line-height: 1.55;
  background-color: var(--flood-bg, rgba(255,255,255,0.92));
  color: var(--flood-fg, #1a1814);
}

/* Draggable handle — a vertical line + grip */
.flood-pos-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  left: 50%;                     /* JS updates this */
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.flood-pos-handle-line {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.7);
  box-shadow: 0 0 6px rgba(0,0,0,0.35);
}
.flood-pos-handle-grip {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border-radius: 20px;
  width: 32px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.28);
  color: #444;
}

/* Scrubber track below the preview */
.flood-pos-readout {
  display: flex;
  align-items: center;
  gap: 10px;
}
.flood-pos-label {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}
.flood-pos-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 3px;
  position: relative;
  cursor: ew-resize;
}
.flood-pos-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 50%;
  background: var(--text);
  border-radius: 3px;
  transition: width 0s;
}
.flood-pos-knob {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  left: 50%;
  width: 14px;
  height: 14px;
  background: var(--text);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
  transition: left 0s;
}

.flood-pos-pct-row {
  text-align: center;
}
.flood-pos-pct {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* Edit-position button on flood artwork rows */
.artwork-row-edit-pos {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
  white-space: nowrap;
}
.artwork-row-edit-pos:hover {
  border-color: var(--text-mid);
  color: var(--text-mid);
  background: var(--bg-2);
}

@media (max-width: 380px) {
  .site-tagline { display: none; }
}

/* All font sizes are now A4-anchored via calc(var(--a4-w) * ratio).
   No viewport-relative overrides needed. */

/* ─── PAGE SETTINGS PANEL (admin) ──────────────────────── */
.page-settings-wrap {
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.page-setting-label {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  flex: 0 0 110px;
  white-space: nowrap;
}

.page-setting-select {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mid);
  padding: 4px 7px;
  cursor: pointer;
  outline: none;
  flex: 1;
  transition: border-color var(--transition);
}
.page-setting-select:focus { border-color: var(--text-mid); }

.page-setting-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.page-setting-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 3px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: ew-resize;
}
.page-setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
}
.page-setting-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
}

.page-setting-readout {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  min-width: 34px;
  text-align: right;
}

/* ─── Section G: Page Background Colour picker ─────────────── */
.page-bg-row {
  align-items: flex-start;
  padding-top: 4px;
}
.page-bg-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
}
.page-bg-swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1.5px solid transparent;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: border-color 0.15s, transform 0.12s;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-bg-swatch:hover { transform: scale(1.15); }
.page-bg-swatch.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.page-bg-swatch--clear {
  background: var(--bg-2);
  color: var(--text-faint);
  box-shadow: 0 0 0 1px var(--border);
}
.page-bg-swatch--clear svg { display: block; }
.page-bg-custom {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1.5px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}
.page-bg-custom::-webkit-color-swatch-wrapper { padding: 0; }
.page-bg-custom::-webkit-color-swatch { border: none; border-radius: 2px; }

/* ─── Section F: Inline split ratio field in artwork modals ─── */
.split-ratio-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.split-ratio-slider-inline {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  padding: 0;
  border: none;
}
.split-ratio-slider-inline::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}
.split-ratio-slider-inline::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  cursor: pointer;
}
.split-ratio-readout {
  font-size: 10px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}

/* ─── SECTION BAR ────────────────────────────────────────── */

.section-bar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
  position: sticky;
  top: calc(var(--header-h) + 1px);
  z-index: 200;
}

.section-bar-inner {
  display: flex;
  align-items: center;
  gap: 0;
  height: 38px;
  padding: 0 16px;
  max-width: 100%;
  /* overflow: hidden clips the tooltip that drops below the bar.
     clip only horizontally so tabs still can't spill sideways. */
  overflow-x: clip;
  overflow-y: visible;
}

.section-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: clip;
  overflow-y: visible;
}

.section-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: none;
  padding: 5px 10px;
  border-radius: 20px;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  flex-shrink: 0;
}
.section-tab:hover {
  color: var(--text);
  background: var(--bg-2);
}
.section-tab.active {
  color: var(--text);
  background: var(--bg-2);
  font-weight: 500;
}

/* Info icon next to section name */
.section-tab-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.45;
  transition: opacity 0.15s;
  flex-shrink: 0;
  position: relative;
  pointer-events: all;
}
.section-tab-info:hover { opacity: 1; }
.section-tab-info svg { display: block; }

/* Info tooltip */
.section-tab-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 300;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  white-space: normal;
  width: max-content;
  max-width: 220px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.section-tab-info:hover .section-tab-tooltip { opacity: 1; }

/* Overflow button */
.section-overflow-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  margin-left: 4px;
}
.section-overflow-btn:hover {
  border-color: var(--text-mid);
  color: var(--text);
  background: var(--bg-2);
}

/* Landscape: up to 6 tabs; portrait: up to 3 */
@media (orientation: portrait) {
  .section-tab:nth-child(n+4) { display: none; }
}
@media (orientation: landscape) {
  .section-tab:nth-child(n+7) { display: none; }
}

/* Section overflow overlay */
.section-overflow-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.section-overflow-panel {
  background: var(--surface);
  width: min(320px, 90vw);
  max-height: 80vh;
  margin: calc(var(--header-h) + 38px + 8px) 16px 0;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
}

.section-overflow-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.section-overflow-title {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.section-overflow-list {
  overflow-y: auto;
  padding: 8px 0;
  flex: 1;
}

.section-overflow-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.section-overflow-item:hover { background: var(--bg-2); }
.section-overflow-item.active { background: var(--bg-2); }

.section-overflow-item-name {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
}
.section-overflow-item-desc {
  font-size: 10.5px;
  font-weight: 300;
  color: var(--text-faint);
  line-height: 1.45;
}

/* ─── SUBSECTION CHEVRON (on active section tab) ─────────── */
.section-tab-subsec-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  color: var(--text-faint);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), transform 0.18s;
  margin-left: 1px;
}
.section-tab-subsec-chevron:hover {
  background: var(--border);
  color: var(--text);
}
.section-tab-subsec-chevron.open {
  background: var(--border);
  color: var(--text);
}
.section-tab-subsec-chevron.open svg {
  transform: rotate(180deg);
}

/* ─── SUBSECTION INLINE DROPDOWN ─────────────────────────── */
.subsec-dropdown {
  position: fixed;
  z-index: 350;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  max-width: 260px;
  overflow: hidden;
}
.subsec-dropdown-list {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}
.subsec-dropdown-item {
  display: block;
  width: 100%;
  padding: 7px 14px;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subsec-dropdown-item:hover { background: var(--bg-2); }
.subsec-dropdown-item.active {
  color: var(--text);
  font-weight: 500;
  background: var(--bg-2);
}
.subsec-dropdown-item.active::before {
  content: '·';
  margin-right: 6px;
  color: var(--text-mid);
}
.subsec-dropdown-more {
  color: var(--text-faint);
  font-size: 11px;
  border-top: 1px solid var(--border-light);
  margin-top: 2px;
  padding-top: 8px;
}
.subsec-dropdown-more:hover { color: var(--text); }

/* ─── SUBSECTION FULL-SCREEN SEARCH OVERLAY ──────────────── */
.subsec-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(var(--header-h) + var(--section-bar-h) + 20px);
}
.subsec-search-panel {
  background: var(--surface);
  width: min(460px, 92vw);
  max-height: 72vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.subsec-search-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.subsec-search-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 300;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
}
.subsec-search-input::placeholder { color: var(--text-faint); }
.subsec-search-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}
.subsec-search-list::-webkit-scrollbar { width: 4px; }
.subsec-search-list::-webkit-scrollbar-track { background: transparent; }
.subsec-search-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.subsec-search-item {
  display: block;
  width: 100%;
  padding: 9px 18px;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
}
.subsec-search-item:hover { background: var(--bg-2); }
.subsec-search-item.active {
  font-weight: 500;
  background: var(--bg-2);
}
.subsec-search-empty {
  padding: 20px 18px;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  text-align: center;
}

/* ─── SECTION EDITOR (inside admin panel) ───────────────── */
/* Section assign row — sits at top of page folder body */
.section-assign-row {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 5px 8px;
  margin-bottom: 2px;
}
.section-assign-select {
  font-size: 10.5px;
  max-width: 130px;
}

.sections-accordion {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.section-folder {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  transition: border-color var(--transition);
}

.section-folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  cursor: pointer;
  gap: 6px;
}
.section-folder-header:hover { background: var(--bg-2); }

.sf-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.sf-chevron {
  flex-shrink: 0;
  color: var(--text-faint);
  transition: transform 0.18s;
}
.section-folder.open .sf-chevron { transform: rotate(90deg); }

.sf-name {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sf-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.section-folder-body {
  display: none;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border-light);
  gap: 6px;
  flex-direction: column;
}
.section-folder.open .section-folder-body { display: flex; }

.pages-subsection-child {
  padding-left: 8px;
  border-left: 2px solid var(--border-light);
  margin-left: 0;
}

/* ─── SECTION FOLDER SUBSECTIONS ─────────────────────────── */
.sf-subsections-wrap {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sf-subsections-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sf-subsections-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.sf-subsections-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sf-subsection-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ─── MULTI-PAGE VIEW ─────────────────────────────────────── */

/* Toggle button in page-label-row — hidden on mobile/portrait */
.multi-view-btn {
  display: none; /* hidden by default; shown in landscape */
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.06em;
  padding: 4px 10px 4px 8px;
  cursor: pointer;
  transition: all var(--transition);
  margin-left: auto;
  white-space: nowrap;
}
.multi-view-btn:hover {
  border-color: var(--text-mid);
  color: var(--text);
  background: var(--bg-2);
}
.multi-view-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.multi-view-btn svg { flex-shrink: 0; }

/* Only show in landscape (wider than it is tall) on non-mobile */
@media (orientation: landscape) and (min-width: 700px) {
  .multi-view-btn { display: flex; }
}

/* Single-view wrapper — matches old a4-viewport + zoom-controls layout */
.single-view-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* Multi-view wrapper */
.multi-view-wrap {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  /* B: Allow vertical scroll if pages exceed viewport height */
  overflow-y: auto;
  overflow-x: hidden;
}

/* Grid of page cells: 4 columns in one row (portrait/default) */
.multi-page-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  /* B: Constrain so cells fit within the viewport width; vertical scroll if needed */
  max-width: 100%;
  align-items: start;
  overflow: visible;
}

/* B: When viewport is landscape (wider than tall), switch to 2×2 grid
   so cells aren't squeezed too small */
@media (orientation: landscape) and (max-height: 700px) {
  .multi-page-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 10px;
  }
}

/* B: Also switch to 2×2 when in a very wide viewport where 4-across would be tiny */
@media (min-aspect-ratio: 2/1) {
  .multi-page-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 10px;
  }
}

/* Individual page cell */
.multi-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 0;
}

.multi-cell--ghost {
  visibility: hidden;
  pointer-events: none;
}

/* Page number label above each cell */
.multi-cell-label {
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  align-self: flex-start;
  padding-left: 2px;
}

/* The viewport inside each cell — scrollable for zoom/pan */
.multi-cell-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.4142;
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: default;
}
.multi-cell-viewport::-webkit-scrollbar { display: none; }
.multi-cell-viewport.can-pan    { cursor: grab; }
.multi-cell-viewport.is-panning { cursor: grabbing !important; }

/* The A4 frame inside each cell */
.multi-cell-frame {
  background: var(--surface);
  box-shadow: var(--shadow-page);
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: background var(--transition), box-shadow var(--transition);
}

/* Zoom bar per cell — smaller than main zoom controls */
.multi-cell-zoom {
  padding: 3px 8px;
  gap: 5px;
  margin-top: 0;
}
.multi-cell-zoom .zoom-slider {
  width: 60px;
}
.multi-cell-zoom .zoom-pct {
  font-size: 9.5px;
  min-width: 28px;
}
.multi-cell-zoom .zoom-btn {
  width: 20px;
  height: 20px;
}

/* ── Padding wrapper inside multi-cell frame ──────────────────
   Sits between .multi-cell-frame and .art-page. Normal flow,
   fills the frame via width/height:100%, padding creates the A4
   margin. The .art-page inside is switched to position:relative
   so it fills the content box (inside padding), not the padding box.
   The .art-page inside is switched to position:relative so it fills
   the content box (inside the padding), not the padding box. */
.multi-cell-pad {
  width: 100%;
  height: 100%;
  padding: calc(var(--a4-w, 400px) * 0.07);
  box-sizing: border-box;
  position: relative;
}
.multi-cell-pad.is-flood {
  padding: 0;
}
/* Inside multi-cell, override art-page to be relative so it respects padWrap's padding */
.multi-cell-pad > .art-page {
  position: relative;
  inset: unset;
  width: 100%;
  height: 100%;
}

/* ═══════════════════════════════════════════════════════════
   FULLSCREEN VIEWER
═══════════════════════════════════════════════════════════ */
.fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: #0d0d0d;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
[data-theme="light"] .fs-overlay {
  background: #1a1a1a;
}
body.fs-open { overflow: hidden; }

/* Exit button */
.fs-exit-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.15s;
}
.fs-exit-btn:hover { background: rgba(255,255,255,0.22); }

/* Mode toggle button */
.fs-mode-btn {
  position: absolute;
  top: 16px;
  right: 68px;
  z-index: 10;
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  color: rgba(255,255,255,0.75);
  font-size: 12px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.fs-mode-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.fs-mode-btn.active {
  background: rgba(255,255,255,0.22);
  color: #fff;
  border-color: rgba(255,255,255,0.35);
}
.fs-mode-btn svg { flex-shrink: 0; }

/* Page counter */
.fs-counter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  letter-spacing: 0.03em;
  pointer-events: none;
  z-index: 10;
  font-family: inherit;
}

/* Navigation arrows */
.fs-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 56px;
  height: 96px;
  background: rgba(255,255,255,0.08);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.55);
  transition: background 0.15s, color 0.15s;
  border-radius: 4px;
}
.fs-arrow:hover { background: rgba(255,255,255,0.18); color: #fff; }
.fs-arrow:disabled { opacity: 0.2; pointer-events: none; }
.fs-arrow--prev { left: 12px; }
.fs-arrow--next { right: 12px; }

/* Content area */
.fs-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 80px;
  box-sizing: border-box;
}

/* Single-page fullscreen wrap — A4 ratio, fits viewport */
.fs-page-wrap {
  position: relative;
  background: #fff;
  /* Default: fit by width */
  width: min(calc((100vh - 96px) / 1.4142), calc(100vw - 160px));
  aspect-ratio: 1 / 1.4142;
  overflow: hidden;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}
/* The art-page inside fills the wrap */
.fs-page-wrap .art-page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Multi-page fullscreen grid */
.fs-content--multi {
  padding: 56px 80px;
  align-items: center;
}.fs-multi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  width: 100%;
  max-height: calc(100vh - 112px);
  /* A2: Center cells vertically */
  align-items: center;
  align-content: center;
  justify-content: center;
  /* Let height be auto so cells are properly A4-sized */
  height: auto;
}
.fs-multi-cell {
  position: relative;
  background: #fff;
  aspect-ratio: 1 / 1.4142;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  border-radius: 2px;
}
.fs-multi-cell--ghost {
  background: transparent;
  box-shadow: none;
}
.fs-multi-cell-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.fs-multi-cell-frame .art-page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Inject fullscreen button next to multi-page button */
.fs-btn-inject {
  margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════════
   PAGE REORDER BUTTONS
═══════════════════════════════════════════════════════════ */
.move-page-up-btn,
.move-page-dn-btn {
  color: var(--text-faint);
  transition: color 0.15s;
}
.move-page-up-btn:hover,
.move-page-dn-btn:hover {
  color: var(--text-main);
}
.move-page-up-btn:disabled,
.move-page-dn-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Add-page-here button inside each page folder */
.add-page-here-btn {
  margin-top: 12px;
  width: 100%;
  justify-content: center;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  background: transparent;
}
.add-page-here-btn:hover {
  color: var(--text-main);
  border-color: var(--text-faint);
  background: var(--bg-hover, rgba(0,0,0,0.04));
}

/* A4: Fullscreen page slider */
.fs-page-slider-wrap {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(480px, 80vw);
  gap: 0;
}
.fs-page-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.25);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  accent-color: rgba(255,255,255,0.8);
}
.fs-page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  transition: transform 0.15s;
}
.fs-page-slider::-webkit-slider-thumb:active {
  transform: scale(1.3);
}
.fs-page-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
}
.fs-slider-preview {
  position: absolute;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(30,30,30,0.92);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 5px;
  pointer-events: none;
  z-index: 20;
  min-width: 70px;
  width: 90px;
}
.fs-slider-preview-img {
  width: 80px;
  height: auto;
  max-height: 60px;
  object-fit: contain;
  border-radius: 2px;
  display: block;
}
.fs-slider-preview-label {
  font-family: inherit;
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.1em;
}

/* ─── Fullscreen hover zoom bar ─────────────────────────────── */
.fs-zoom-bar {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20,20,20,0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 100px;
  padding: 8px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.fs-zoom-bar.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.fs-zoom-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  padding: 0;
}
.fs-zoom-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.fs-zoom-btn:disabled { opacity: 0.3; cursor: default; }
.fs-zoom-slider {
  width: 110px;
  accent-color: rgba(255,255,255,0.7);
  cursor: pointer;
}
.fs-zoom-pct {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  min-width: 34px;
  text-align: right;
  font-family: inherit;
}
.fs-zoom-reset {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: rgba(255,255,255,0.55);
  font-size: 10.5px;
  font-family: inherit;
  padding: 3px 9px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.fs-zoom-reset:hover { border-color: rgba(255,255,255,0.45); color: #fff; }

/* Hint zone — invisible touch target at bottom of overlay on mobile */
@media (pointer: coarse) {
  .fs-zoom-bar {
    bottom: 28px;
  }
  .fs-zoom-bar.visible::before {
    content: 'Tap bottom edge to dismiss';
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255,255,255,0.3);
    white-space: nowrap;
    pointer-events: none;
  }
}

/* ─── Zoom + Pan ─────────────────────────────────────────────── */
/* Clip zoomed content to overlay bounds */
.fs-content {
  overflow: hidden;
}
/* Smooth transform for zoom (not pan, which should be instant) */
.fs-page-wrap {
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}
/* Disable pointer events on nav arrows while cursor is a grabbing hand */
.fs-overlay:has(.fs-page-wrap[style*="grabbing"]) .fs-arrow {
  pointer-events: none;
}

/* ─── B: Fullscreen multi-grid — landscape 2×2 layout ───────── */
/* When the screen is wider than tall (landscape) the 4-across grid
   squashes cells. Switch to 2×2 so they're big enough to read.    */
@media (orientation: landscape) {
  .fs-multi-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 12px;
    /* Constrain total width so 2 portrait pages fit comfortably */
    max-width: min(100%, calc((100vh - 120px) / 1.4142 * 2 + 12px));
    max-height: calc(100vh - 120px);
  }
  .fs-content--multi {
    padding: 56px 40px;
  }
}

/* Portrait / tall screen: keep 4-across but constrain height */
@media (orientation: portrait) {
  .fs-multi-grid {
    grid-template-columns: repeat(4, 1fr);
    /* Each cell has aspect-ratio 1/√2; cap total height */
    max-height: calc(100vh - 130px);
  }
}

/* B: Regular (non-fullscreen) multi-page wrap — vertical scroll when needed */
.multi-view-wrap {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.multi-view-wrap::-webkit-scrollbar { width: 4px; }
.multi-view-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
