/* Flipbook reader (docs/features/pageflip.md). Served with the reader page at
   /flip/<publication>/<issue>. Loaded as a file, never inline: the page runs
   under a content policy that allows no inline script. */
:root {
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-elevated: #0f3460;
  --accent: #c41e3a;
  --accent-hover: #e02040;
  --text: #eee;
  --text-muted: #999;
  --toolbar-h: 48px;
  --thumb-h: 80px;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
/* The page head hides the body until this file applies (READER_FIRST_PAINT_CSS
   in reader-html.ts), so a framed reader never lays out unstyled first. */
body { visibility: visible; }

/* ── Toolbar ── */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center;
  padding: 0 10px;
  z-index: 100; gap: 4px;
  transition: opacity .3s, transform .3s;
}
#toolbar.autohide { opacity: 0; transform: translateY(-100%); pointer-events: none; }

.brand {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 14px;
  white-space: nowrap; color: var(--accent);
  margin-right: 4px;
  /* The title gives way before any button does: a long publication name
     used to push Next and Autoplay off the right edge on phones. */
  min-width: 0; flex: 0 1 auto; overflow: hidden;
}
.brand #brand-title { overflow: hidden; text-overflow: ellipsis; }
.brand .issue-date { color: var(--text-muted); font-weight: 400; font-size: 12px; flex-shrink: 0; }

.spacer { flex: 1 0 0; }

.tg { display: flex; align-items: center; gap: 1px; flex-shrink: 0; }

/* Visible keyboard focus on every control */
.tb:focus-visible, .stab:focus-visible, .nav-arrow:focus-visible,
.hs:focus-visible, .vh:focus-visible, .th:focus-visible, .ti:focus-visible,
.sr:focus-visible, #page-ind:focus-visible,
#zoom-close:focus-visible, .zoom-step:focus-visible {
  outline: 2px solid #fff; outline-offset: 1px;
}
.hs:focus-visible .hs-label, .vh:focus-visible .hs-label { display: block; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.tb {
  background: none; border: none; color: var(--text);
  width: 36px; height: 36px;
  border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; position: relative; flex-shrink: 0;
  text-decoration: none;
}
.tb:hover { background: rgba(255,255,255,.1); }
.tb.active { background: var(--accent); color: #fff; }
.tb[disabled] { opacity: .3; cursor: default; }
.tb[disabled]:hover { background: none; }
.tb svg { width: 18px; height: 18px; }

.tb .tip {
  display: none; position: absolute; bottom: -28px; left: 50%;
  transform: translateX(-50%);
  background: #222; color: #fff; font-size: 10px;
  padding: 2px 7px; border-radius: 3px; white-space: nowrap;
  pointer-events: none; z-index: 110;
}
.tb:hover .tip { display: block; }

#page-ind {
  font-size: 12px; color: var(--text-muted);
  min-width: 60px; text-align: center;
  cursor: pointer; padding: 4px 6px;
  border-radius: 4px; font-variant-numeric: tabular-nums;
  background: none; border: none; font-family: inherit; flex-shrink: 0;
}
#page-ind:hover { background: rgba(255,255,255,.08); }

.div { width: 1px; height: 22px; background: rgba(255,255,255,.1); margin: 0 3px; flex-shrink: 0; }

.badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--accent); color: #fff;
  font-size: 8px; min-width: 14px; height: 14px;
  border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; padding: 0 3px;
}

/* ── Section Nav ── */
#secnav {
  position: fixed; top: var(--toolbar-h); left: 0; right: 0;
  height: 34px;
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  padding: 0 10px; gap: 3px;
  z-index: 99; scrollbar-width: none;
  transition: opacity .3s, transform .3s;
}
#secnav::-webkit-scrollbar { display: none; }
#secnav.autohide { opacity: 0; transform: translateY(-100%); pointer-events: none; }

.stab {
  background: none; border: none; color: var(--text-muted);
  padding: 5px 12px; border-radius: 14px;
  font-size: 11px; cursor: pointer;
  white-space: nowrap; transition: all .15s;
  font-weight: 500;
  display: flex; align-items: center; gap: 5px;
}
.stab:hover { color: var(--text); background: rgba(255,255,255,.08); }
.stab.active { color: #fff; background: var(--accent); }
.stab svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Main Container ── */
#main {
  position: fixed;
  top: calc(var(--toolbar-h) + 34px);
  left: 0; right: 0; bottom: 0;
  display: flex; overflow: hidden;
}

/* ── TOC Panel ── */
#toc {
  width: 280px; min-width: 280px;
  background: var(--bg-surface);
  border-right: 1px solid rgba(255,255,255,.08);
  overflow-y: auto; padding: 8px 0;
  transition: margin-left .3s ease; z-index: 50;
}
#toc.hidden { margin-left: -280px; }

.toc-head {
  padding: 6px 14px; font-size: 10px;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted);
}

/* TOC Search */
#toc-search {
  margin: 4px 14px 8px; padding: 6px 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px; color: var(--text); font-size: 12px;
  width: calc(100% - 28px); outline: none;
}
#toc-search:focus { border-color: var(--accent); }
#toc-search::placeholder { color: var(--text-muted); }

.ti {
  display: flex; align-items: center;
  padding: 7px 14px; cursor: pointer;
  font-size: 12px; gap: 8px;
  transition: background .15s;
  border-left: 3px solid transparent;
}
.ti:hover { background: rgba(255,255,255,.05); }
.ti.active { background: rgba(196,30,58,.1); border-left-color: var(--accent); }
.ti.hidden { display: none; }
.ti .tp { color: var(--text-muted); font-size: 10px; min-width: 18px; text-align: right; }
.ti .tb-badge {
  font-size: 9px; padding: 1px 5px;
  border-radius: 6px; background: rgba(255,255,255,.08);
  color: var(--text-muted); white-space: nowrap; margin-left: auto; flex-shrink: 0;
}

/* ── Flipbook Area ── */
#fb-area {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden; background: var(--bg);
}

#fb-wrap {
  position: relative; display: flex;
  align-items: center; justify-content: center;
  flex: 1; width: 100%; padding: 8px;
}

/* ── Pages ── */
.page { background: #fff; position: relative; overflow: hidden; }
.page img {
  width: 100%; height: 100%; object-fit: cover;
  display: block; user-select: none; -webkit-user-drag: none;
}

/* ── Ad Hotspots ── */
.hs {
  position: absolute; cursor: pointer;
  border: 2px solid transparent; border-radius: 3px;
  transition: all .25s; z-index: 5;
}
.hs:hover {
  border-color: var(--accent);
  background: rgba(196,30,58,.12);
  box-shadow: 0 0 10px rgba(196,30,58,.3);
}
.hs .hs-label {
  display: none; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.88); color: #fff; font-size: 10px;
  padding: 3px 8px; border-radius: 3px; white-space: nowrap;
  pointer-events: none; margin-bottom: 3px;
}
.hs .hs-label::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent; border-top-color: rgba(0,0,0,.88);
}
.hs:hover .hs-label { display: block; }
.hs-dot {
  position: absolute; top: 3px; right: 3px;
  width: 6px; height: 6px; background: var(--accent);
  border-radius: 50%; animation: pulse 2s infinite;
}
.hs:not(:hover) .hs-dot { opacity: .6; }
@keyframes pulse { 0%,100%{opacity:.3;transform:scale(1)}50%{opacity:.8;transform:scale(1.4)} }

/* ── Video Hotspots ── */
.vh {
  position: absolute; cursor: pointer;
  border: 2px solid transparent; border-radius: 3px;
  transition: all .25s; z-index: 6;
  display: flex; align-items: center; justify-content: center;
}
.vh:hover {
  border-color: #e02040;
  background: rgba(224,32,64,.15);
  box-shadow: 0 0 12px rgba(224,32,64,.4);
}
.vh .vh-play {
  width: 40px; height: 40px; background: rgba(196,30,58,.9);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); transition: transform .2s;
}
.vh:hover .vh-play { transform: scale(1.1); }
.vh .vh-play svg { width: 18px; height: 18px; fill: #fff; margin-left: 2px; }
.vh .hs-label {
  display: none; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.88); color: #fff; font-size: 10px;
  padding: 3px 8px; border-radius: 3px; white-space: nowrap;
  pointer-events: none; margin-bottom: 3px;
}
.vh .hs-label::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent; border-top-color: rgba(0,0,0,.88);
}
.vh:hover .hs-label { display: block; }

/* ── Video Modal ── */
#video-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.85); z-index: 300;
  align-items: center; justify-content: center;
}
#video-modal.active { display: flex; }
#video-modal .vm-wrap {
  width: 90%; max-width: 900px; position: relative;
}
#video-modal .vm-close {
  position: absolute; top: -36px; right: 0;
  width: 32px; height: 32px;
  background: rgba(255,255,255,.12); border: none; color: #fff;
  font-size: 20px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#video-modal .vm-close:hover { background: rgba(255,255,255,.25); }
#video-modal .vm-frame {
  width: 100%; aspect-ratio: 16/9;
  border-radius: 8px; overflow: hidden;
  background: #000;
}
#video-modal iframe {
  width: 100%; height: 100%; border: none;
}

/* ── Nav Arrows ── */
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 80px;
  background: rgba(0,0,0,.35); backdrop-filter: blur(4px);
  border: none; color: #fff; font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 20; transition: background .2s, opacity .2s;
  border-radius: 4px; opacity: .7;
}
.nav-arrow:hover { background: rgba(0,0,0,.55); opacity: 1; }
.nav-arrow.prev { left: 6px; }
.nav-arrow.next { right: 6px; }

/* ── Page Slider ── */
#page-slider-wrap {
  width: 100%; padding: 0 60px;
  display: flex; align-items: center; gap: 8px;
  height: 28px; flex-shrink: 0;
}
#page-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: rgba(255,255,255,.15);
  border-radius: 2px; outline: none; cursor: pointer;
}
#page-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
#page-slider::-moz-range-thumb {
  width: 16px; height: 16px; background: var(--accent);
  border-radius: 50%; cursor: pointer; border: none;
}
#slider-label {
  font-size: 10px; color: var(--text-muted);
  min-width: 40px; text-align: center;
}

/* ── Thumbnail Strip ── */
#thumbs {
  width: 100%; height: var(--thumb-h);
  background: var(--bg-surface);
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center;
  overflow-x: auto; padding: 6px 10px; gap: 6px;
  scrollbar-width: thin; scrollbar-color: var(--accent) transparent;
  transition: height .3s, padding .3s, opacity .3s;
}
#thumbs.hidden { height: 0; padding: 0; opacity: 0; overflow: hidden; }

.th {
  flex-shrink: 0; width: 42px; height: 65px;
  border-radius: 2px; overflow: hidden; cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, transform .15s; opacity: .6;
}
.th:hover { opacity: 1; transform: scale(1.1); }
.th.active { border-color: var(--accent); opacity: 1; }
.th img { width: 100%; height: 100%; object-fit: cover; }

/* ── Zoom Overlay ── */
#zoom-ov {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.94); z-index: 200;
  cursor: grab; overflow: hidden;
}
#zoom-ov.active { display: flex; align-items: center; justify-content: center; }
/* Our own pinch and drag handlers own gestures inside the zoom view. */
#zoom-ov { touch-action: none; }

@media (prefers-reduced-motion: reduce) {
  .hs-dot, #loading .pf-icon { animation: none !important; }
  #toolbar, #secnav, #toc, #thumbs, .th, #zoom-img { transition: none !important; }
}
#zoom-ov.dragging { cursor: grabbing; }
#zoom-img {
  max-width: none; max-height: none;
  transition: transform .1s; user-select: none; -webkit-user-drag: none;
}
#zoom-close {
  position: fixed; top: 14px; right: 14px;
  width: 40px; height: 40px;
  /* A dark fill with a light ring, not a faint white one: a magnified page is
     usually white, and a white button on it cannot be seen (on a phone this is
     the only way out of the zoom view). */
  background: rgba(17,17,17,.78); border: none; color: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,.4);
  font-size: 22px; border-radius: 50%; cursor: pointer; z-index: 201;
  display: flex; align-items: center; justify-content: center;
}
#zoom-close:hover { background: rgba(60,60,60,.9); }
#zoom-bar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(17,17,17,.82); color: #fff; font-size: 11px;
  padding: 5px 14px; border-radius: 16px; z-index: 201;
  display: flex; gap: 10px; align-items: center; white-space: nowrap;
  max-width: calc(100vw - 24px);
}
#zoom-page { font-weight: 600; }
#zoom-hint { opacity: .8; overflow: hidden; text-overflow: ellipsis; }
.zoom-step {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px;
  background: rgba(17,17,17,.78); border: none; color: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,.4);
  font-size: 20px; border-radius: 8px; cursor: pointer; z-index: 201;
  display: flex; align-items: center; justify-content: center;
}
#zoom-prev { left: 14px; }
#zoom-next { right: 14px; }
.zoom-step:hover:not(:disabled) { background: rgba(60,60,60,.9); }
.zoom-step:disabled { opacity: .3; cursor: default; }

/* ── Page Jump Modal ── */
#jump-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 300;
  align-items: center; justify-content: center;
}
#jump-modal.active { display: flex; }
#jump-modal .mc {
  background: var(--bg-elevated); border-radius: 10px;
  padding: 20px; width: 240px; text-align: center;
}
#jump-modal h4 { margin-bottom: 12px; font-size: 15px; }
#jump-input {
  width: 70px; padding: 7px; font-size: 18px; text-align: center;
  border: 2px solid var(--accent); border-radius: 6px;
  background: var(--bg); color: var(--text); outline: none;
}
#jump-go {
  margin-top: 12px; padding: 7px 20px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 6px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
#jump-go:hover { background: var(--accent-hover); }

/* ── Embed Modal ── */
#embed-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 300;
  align-items: center; justify-content: center;
}
#embed-modal.active { display: flex; }
#embed-modal .mc {
  background: var(--bg-elevated); border-radius: 10px;
  padding: 20px; width: 400px; max-width: 90vw;
}
#embed-modal h4 { margin-bottom: 12px; font-size: 15px; }
#embed-modal .em-tabs {
  display: flex; gap: 4px; margin-bottom: 12px;
}
#embed-modal .em-tab {
  padding: 6px 14px; border-radius: 6px; border: none;
  background: rgba(255,255,255,.08); color: var(--text);
  font-size: 12px; cursor: pointer;
}
#embed-modal .em-tab.active { background: var(--accent); color: #fff; }
#embed-modal .em-opts {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;
}
#embed-modal .em-opt {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
}
#embed-modal .em-opt select, #embed-modal .em-opt input {
  background: var(--bg); border: 1px solid rgba(255,255,255,.15);
  color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 12px;
}
#embed-code {
  width: 100%; height: 80px; padding: 8px;
  background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px; color: var(--text); font-size: 11px;
  font-family: monospace; resize: none; outline: none;
}
#embed-copy {
  margin-top: 8px; padding: 7px 20px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 6px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
#embed-copy:hover { background: var(--accent-hover); }

/* ── Toast ── */
#toast {
  display: none; position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated); color: #fff;
  padding: 10px 20px; border-radius: 8px; font-size: 12px;
  z-index: 300; box-shadow: 0 4px 16px rgba(0,0,0,.4);
  animation: toast-in .3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Search Panel ── */
#search-panel {
  display: none; position: fixed;
  top: var(--toolbar-h); right: 10px;
  width: 300px; max-height: 400px;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; z-index: 110;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  overflow: hidden;
}
#search-panel.active { display: flex; flex-direction: column; }
#search-input {
  padding: 10px 12px; background: none;
  border: none; border-bottom: 1px solid rgba(255,255,255,.1);
  color: var(--text); font-size: 13px; outline: none;
}
#search-input::placeholder { color: var(--text-muted); }
#search-results {
  overflow-y: auto; max-height: 340px; padding: 4px 0;
}
.sr {
  padding: 8px 12px; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; gap: 8px;
  transition: background .15s;
}
.sr:hover { background: rgba(255,255,255,.06); }
.sr .sr-page { color: var(--accent); font-weight: 600; min-width: 20px; }
.sr .sr-type { color: var(--text-muted); font-size: 10px; margin-left: auto; }
#search-empty {
  padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px;
}

/* ── Print ── */
@media print {
  body { background: #fff; }
  #toolbar, #secnav, #toc, #thumbs, #page-slider-wrap,
  .nav-arrow, .hs, .vh, #zoom-ov { display: none !important; }
  #main { position: static; }
  #fb-area { position: static; }
  .page { page-break-after: always; }
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .brand .issue-date { display: none; }
  .desk { display: none !important; }
  /* Phones turn pages by swiping, the side arrows, or the slider, so the
     toolbar keeps its room for Contents, Search, Zoom and Share. */
  .mob-hide { display: none !important; }
  .tb { width: 40px; height: 40px; }
  .tb .tip { display: none !important; }
  #toc {
    width: 260px; min-width: 260px;
    position: fixed; top: calc(var(--toolbar-h) + 34px);
    bottom: 0; left: 0; z-index: 90;
    box-shadow: 4px 0 20px rgba(0,0,0,.5);
  }
  #toc.hidden { margin-left: -260px; }
  .nav-arrow { width: 36px; height: 60px; font-size: 16px; }
  #thumbs { --thumb-h: 60px; }
  /* A phone starts with the strip closed (reader.js adds .hidden, then drops
     .pf-start). Closed here from the first layout, with no transition, so the
     book is not pushed down by a 0.3s collapse after load. */
  #thumbs.pf-start { height: 0; padding: 0; opacity: 0; overflow: hidden; transition: none; }
  .th { width: 32px; height: 50px; }
  #search-panel { width: calc(100% - 20px); right: 10px; }
  #page-slider-wrap { padding: 0 40px; }
}

/* ── Loading ── */
#loading {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 500; transition: opacity .4s;
}
#loading.done { opacity: 0; pointer-events: none; }
#loading .pf-icon { fill: var(--accent); width: 48px; height: 48px; animation: bob 1.5s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0)}50%{transform:translateY(-8px)} }
#loading p { margin-top: 14px; color: var(--text-muted); font-size: 13px; }

/* Embedded in another site, and signed-in preview: no embed button. */
body.pf-embed #btn-embed, body.pf-preview #btn-embed, body.pf-preview #btn-share { display: none; }
