/*
 * Cityview Flipbook — Viewer Stylesheet
 * Edit this file to customise the flipbook appearance.
 * Changes take effect on the next Save & Rebuild in the Page Manager,
 * or re-run: python build_flipbook.py <issue-dir> --gui
 *
 * Key variables (edit :root to retheme in seconds):
 *   --bg          Stage / body background
 *   --tb-bg       Toolbar background
 *   --panel-bg    TOC / Thumbnails panel background
 *   --accent      Highlight colour (buttons, active states, TOC page numbers)
 *   --text        Primary text colour
 *   --muted       Secondary / label text colour
 *   --border      Divider / border colour
 *   --tb          Toolbar height
 *   --pw          Panel width (TOC + Thumbs)
 */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --tb:       50px;
  --pw:       260px;
  --bg:       #1c1c1c;
  --tb-bg:    #111;
  --panel-bg: #1e1e1e;
  --accent:   #b00;
  --text:     #e0e0e0;
  --muted:    #888;
  --border:   #2e2e2e;
}

html, body {
  width: 100%; height: 100%; min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
}

#brand-logo {
  display: none;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 12px;
  height: 26px;
  width: auto;
  z-index: 1200;
  opacity: .9;
  pointer-events: none;
}

#tb-brand {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  pointer-events: auto;
  cursor: pointer;
  text-decoration: none;
}

#tb-brand img {
  height: 20px;
  width: auto;
  opacity: .9;
}

/* ── Toolbar ── */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--tb);
  background: var(--tb-bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 2px; padding: 0 10px;
  z-index: 1000; user-select: none;
}
.tb-btn {
  background: none; border: 1px solid transparent; color: var(--text);
  border-radius: 5px; padding: 5px 11px; cursor: pointer; font-size: 13px;
  white-space: nowrap; transition: background .12s, border-color .12s; flex-shrink: 0;
}
.tb-btn:hover  { background: #282828; border-color: #3a3a3a; }
.tb-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-sep  { width: 1px; height: 26px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.tb-flex { flex: 1; min-width: 0; }
#tb-title {
  font-size: 12px; color: var(--muted); text-align: center; padding: 0 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#page-nav { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
#page-input {
  width: 44px; padding: 3px 5px; background: #252525;
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 12px; text-align: center;
}
#page-input:focus { outline: none; border-color: var(--accent); }
#page-total { font-size: 12px; color: var(--muted); }

/* ── Stage ── */
#stage {
  position: fixed; top: var(--tb); left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}

/* Zoom/pinch hardening (runtime-toggle via body.zoom-fix-on / ?zoomfix=off) */
body.zoom-fix-on #stage {
  touch-action: none;
}

/* ── Flipbook wrapper ── */
#flipbook-wrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .35s; pointer-events: none;
}
#flipbook-wrap.visible { opacity: 1; pointer-events: auto; }

/* ── Book-wrap: zoom+pan transform, depth via drop-shadow ── */
#book-wrap {
  display: inline-block; position: relative;
  transform-origin: center center; transition: transform .18s ease;
  cursor: grab;
  filter: none;
  contain: paint;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}
#book-wrap.panning { cursor: grabbing; transition: none; }

#book-wrap #book {
  box-shadow: 0 8px 28px rgba(0,0,0,0.85);
}

body.zoom-fix-on #book-wrap #book {
  position: relative;
  overflow: hidden;
  margin: 0 auto;
  transform-origin: center center;
}

/* Kill every artefact StPageFlip might render */
#book-wrap .stf__parent { background: transparent !important; }
#book-wrap .stf__block  { background: transparent !important; box-shadow: none !important; }
#book-wrap canvas {
  display: block !important;
  background: transparent !important;
  border: none !important; outline: none !important; box-shadow: none !important;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden !important;
  -webkit-backface-visibility: hidden !important;
}

body.zoom-fix-on #book-wrap .stf__parent,
body.zoom-fix-on #book-wrap .stf__block,
body.zoom-fix-on #book-wrap canvas,
body.zoom-fix-on .st-page-flip-container {
  transform-origin: center center !important;
}

/* When the cover page is shown alone, StPageFlip paints the left half of its canvas
   white (canvas 2D API — CSS background:transparent can't override this). The
   ::before pseudo-element covers that half with the stage background colour. */
#book-wrap.at-cover::before {
  content: ''; position: absolute; inset: 0 50% 0 0;
  background: var(--bg); z-index: 5; pointer-events: none;
}

/* Back cover can also be shown solo; mask the opposite half there. */
#book-wrap.at-back-cover::after {
  content: ''; position: absolute; inset: 0 0 0 50%;
  background: var(--bg); z-index: 5; pointer-events: none;
}

/* ── Panels ── */
.panel {
  position: fixed; top: var(--tb); bottom: 0; width: var(--pw);
  background: var(--panel-bg); overflow-y: auto;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  z-index: 900; padding: 18px 14px;
}
#toc-panel   { left: 0;  border-right: 1px solid var(--border); transform: translateX(calc(-1 * var(--pw))); }
#thumb-panel { right: 0; border-left:  1px solid var(--border); transform: translateX(var(--pw)); }
.panel.open  { transform: translateX(0) !important; }
.panel-head {
  font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
#toc-list { list-style: none; }
#toc-list li { margin-bottom: 1px; }
.toc-link {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  background: none; border: none; color: var(--text);
  padding: 8px 10px; border-radius: 4px; font-size: 13px;
  cursor: pointer; text-align: left; transition: background .12s;
}
.toc-link:hover { background: #282828; }
.toc-pg   { font-size: 11px; color: var(--accent); font-weight: 700; min-width: 26px; flex-shrink: 0; padding-top: 1px; }
.toc-body { display: flex; flex-direction: column; gap: 3px; }
.toc-title-text { font-size: 13px; }
.toc-desc { font-size: 11px; color: var(--muted); line-height: 1.35; font-weight: 400; }
.toc-section-header {
  font-size: 9px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); padding: 14px 10px 4px; margin-top: 4px;
  border-top: 1px solid var(--border);
}
#toc-list li:first-child.toc-section-header { border-top: none; margin-top: 0; padding-top: 4px; }
.toc-empty { font-size: 12px; color: var(--muted); padding: 8px 10px; }

/* Thumbnails — rows are spreads (2 pages) or singles (cover / back cover) */
#thumb-grid { display: flex; flex-direction: column; gap: 8px; }
.th-row {
  display: flex; gap: 2px; border-radius: 4px; overflow: hidden;
  border: 2px solid transparent; transition: border-color .12s; cursor: pointer;
}
.th-row:hover  { border-color: #484848; }
.th-row.active { border-color: var(--accent); }
.th { flex: 1; position: relative; overflow: hidden; }
.th img { width: 100%; display: block; pointer-events: none; }
.th-n {
  position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px;
  color: rgba(255,255,255,.75); background: rgba(0,0,0,.55);
  text-align: center; padding: 2px 0;
}

/* Hotlink overlay — transparent <a> elements over page regions */
#hotlink-layer { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
#hotlink-layer a {
  position: absolute; pointer-events: auto; cursor: pointer;
  /* Uncomment to visualise hotlinks during development: */
  /* background: rgba(255,255,0,.2); border: 1px dashed gold; */
}

/* Zoom indicator */
#zoom-level {
  position: fixed; bottom: 14px; right: 14px; z-index: 800;
  font-size: 11px; color: var(--muted); background: rgba(0,0,0,.5);
  border-radius: 4px; padding: 3px 8px;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
#zoom-level.show { opacity: 1; }

/* ── Modern template (keeps classic available) ───────────────────────────── */
body.template-modern #brand-logo {
  display: none;
}

body.template-modern #toolbar {
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  left: 14px;
  right: 14px;
  height: 54px;
  border: 1px solid #303030;
  border-radius: 12px 12px 0 0;
  background: rgba(16, 16, 16, .92);
  backdrop-filter: blur(3px);
  justify-content: center;
  gap: 8px;
}

body.template-modern #stage {
  top: 0;
  bottom: calc(54px + env(safe-area-inset-bottom, 0px));
}

body.template-modern #tb-title,
body.template-modern #page-nav,
body.template-modern .tb-sep,
body.template-modern #btn-zoom-in,
body.template-modern #btn-zoom-out,
body.template-modern #btn-zoom-fit,
body.template-modern #btn-thumbs {
  display: none;
}

#btn-reset-view {
  display: none;
}

body.template-modern #tb-brand {
  display: flex;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  min-width: 0;
  z-index: 1;
}

body.template-modern #tb-brand img {
  height: 22px;
  max-width: min(38vw, 280px);
}

body.template-modern #btn-toc,
body.template-modern #btn-fs,
body.template-modern #btn-reset-view {
  position: relative;
  z-index: 2;
}

body.template-modern #btn-toc,
body.template-modern #btn-fs,
body.template-modern #btn-reset-view {
  min-width: 76px;
  height: 52px;
  padding: 0 16px;
  border-radius: 18px;
  font-size: 0;
}

body.template-modern #btn-reset-view {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  font-size: 12px;
  letter-spacing: .02em;
}

body.template-modern #btn-toc::before {
  content: '☰';
  font-size: 30px;
}

body.template-modern #btn-fs::before {
  content: '⛶';
  font-size: 28px;
}

body.template-modern #btn-prev,
body.template-modern #btn-next {
  position: fixed !important;
  top: 50%;
  transform: translateY(-50%);
  z-index: 999;
  border: none;
  background: transparent;
  font-size: 42px;
  line-height: 1;
  color: rgba(255, 255, 255, .62);
  text-shadow: 0 2px 8px rgba(0, 0, 0, .45);
  padding: 0 6px;
}

body.template-modern #btn-prev,
body.template-modern #btn-next {
  font-size: 0;
}

body.template-modern #btn-prev::before,
body.template-modern #btn-next::before {
  font-size: 42px;
  line-height: 1;
}

body.template-modern #btn-prev::before { content: '‹'; }
body.template-modern #btn-next::before { content: '›'; }

body.template-modern #btn-prev:hover,
body.template-modern #btn-next:hover {
  color: rgba(255, 255, 255, .8);
  background: transparent;
  border: none;
}

body.template-modern #btn-prev { left: 12px; }
body.template-modern #btn-next { right: 12px; }

body.template-modern #thumb-panel {
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(54px + env(safe-area-inset-bottom, 0px));
  width: auto;
  border: none;
  transform: translateY(calc(100% + 54px + env(safe-area-inset-bottom, 0px)));
  background: rgba(24, 32, 60, .8);
  backdrop-filter: blur(2px);
  padding: 16px 18px;
}

body.template-modern #thumb-panel .panel-head {
  text-align: center;
  color: #d8deef;
  border-bottom-color: rgba(255, 255, 255, .18);
}

body.template-modern #thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  align-items: end;
}

body.template-modern .th-row {
  background: rgba(0, 0, 0, .2);
  border-color: rgba(255, 255, 255, .15);
  align-items: flex-end;
  align-self: end;
}

body.template-modern .th {
  flex: 1 1 50%;
  min-width: 0;
}

body.template-modern .th.th-ghost {
  background: rgba(255, 255, 255, .02);
}

body.template-modern .th.th-ghost .th-n {
  display: none;
}

body.template-modern .th-row:hover {
  border-color: rgba(255, 255, 255, .35);
}

body.template-modern .th-row.active {
  border-color: #ff8f45;
  box-shadow: 0 0 0 2px rgba(255, 143, 69, .2) inset;
}

body.template-modern #toc-panel {
  display: none;
}

@media (max-width: 1100px) and (pointer: coarse) {
  body.template-modern #tb-brand {
    display: none;
  }
}

/* ── Navigation Chevrons ── */
.chevron-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 500;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 64px;
  line-height: 1;
  cursor: pointer;
  padding: 20px 15px;
  transition: color 0.2s, transform 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chevron-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  transform: translateY(-50%) scale(1.1);
}

.chevron-btn:active {
  transform: translateY(-50%) scale(0.95);
}

.chevron-prev {
  left: 20px;
}

.chevron-next {
  right: 20px;
}

/* Hide on very small screens where they'd overlap the book */
@media (max-width: 767px) {
  .chevron-btn {
    font-size: 48px;
    padding: 15px 10px;
  }
  .chevron-prev { left: 10px; }
  .chevron-next { right: 10px; }
}

@media (max-width: 480px) {
  .chevron-btn {
    display: none;
  }
}
