/* Flipbook reader — generic reader chrome, zero issue-specific values.
   Everything issue-specific (title, page images, publication name) is
   injected at runtime by app.js from window.ISSUE (issue.js). Do not add
   any brand-specific strings or colors here — this file ships to every
   business/professional that uses the magazine-publisher skill.

   Breakpoint contract: single-page mode at <=820px, matching the
   MOBILE_BREAKPOINT constant in app.js. Keep both in sync if this changes. */

:root {
  --bg: #0b0b0c;
  --bg-elevated: #17181b;
  --panel-bg: #111214;
  --text: #f3f3f0;
  --muted: #a7abb6;
  --accent: #abe1e4;
  --accent-ink: #111111;
  --border: rgba(255, 255, 255, 0.12);
  --focus-ring: #abe1e4;
  --page-bg: #ffffff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --toolbar-h: 60px;
  --turn-duration: 850ms;
  --turn-ease: cubic-bezier(0.45, 0.05, 0.15, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px; top: -48px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
  z-index: 100;
}
.skip-link:focus { top: 8px; }

/* Focus-visible treatment applied broadly. Buttons/links/inputs get a
   clear ring only for keyboard focus, not mouse clicks. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Toolbar ---------- */

.toolbar {
  height: var(--toolbar-h);
  min-height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  /* No flex-wrap: the bar is fixed-height, so a wrapped row would clip.
     Narrow widths are handled by the media queries below instead. */
}

.toolbar-group { display: flex; align-items: center; gap: 8px; }
/* overflow:hidden so shrunken nowrap content clips inside its own box
   instead of spilling under the right-side buttons (mobile overlap bug). */
.toolbar-center { flex: 1; justify-content: center; min-width: 0; overflow: hidden; }

.toolbar button,
.pdf-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 44px;
  min-width: 44px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.toolbar button:hover,
.pdf-download:hover { background: rgba(255, 255, 255, 0.08); }
.toolbar button .icon { font-size: 16px; }

.nav-btn { font-size: 20px; padding: 8px 14px; }

.page-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.page-indicator input[type="range"] {
  width: clamp(90px, 22vw, 240px);
  accent-color: var(--accent);
}
.page-count-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* Below ~640px, hide text labels on buttons to save space; icons remain. */
@media (max-width: 640px) {
  .btn-label { display: none; }
  .toolbar { gap: 6px; padding: 0 8px; }
  .toolbar-group { gap: 4px; }
  .page-indicator input[type="range"] { width: clamp(70px, 16vw, 240px); }
}

/* Below ~480px there is no honest room for the slider next to five 44px tap
   targets. Drop it (buttons, swipe, and TOC still navigate) rather than let
   anything overlap — measured overlap at 375px was the bug this fixes. */
@media (max-width: 480px) {
  .page-indicator input[type="range"] { display: none; }
}

/* ---------- Viewer / stage ---------- */

.viewer {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: radial-gradient(ellipse at center, var(--bg-elevated) 0%, var(--bg) 70%);
  overflow: hidden;
}

.stage-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 64px;
  perspective: 2400px;
}

@media (max-width: 820px) {
  .stage-wrap { padding: 12px 44px; }
}

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  max-height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}

/* The "leaving" stage during a page turn is stacked exactly on top of the
   incoming stage and rotated away. See app.js turnTo(). */
.stage.leaving {
  position: absolute;
  inset: 0;
  z-index: 2;
  transition: transform var(--turn-duration) var(--turn-ease),
              opacity var(--turn-duration) var(--turn-ease);
  backface-visibility: hidden;
}
.stage.leaving.turn-forward {
  transform-origin: right center;
  transform: rotateY(-115deg);
  opacity: 0;
}
.stage.leaving.turn-backward {
  transform-origin: left center;
  transform: rotateY(115deg);
  opacity: 0;
}

.page-frame {
  height: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  box-shadow: var(--shadow);
}

.page-frame img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  background: var(--page-bg);
}

/* Cover / single-page frames get a touch more shadow presence since
   there's no facing page to visually anchor them. */
.page-frame.single { box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55); }

/* prefers-reduced-motion: the CSS-side backstop. app.js also skips
   creating the .leaving overlay entirely when reduced motion is set, so
   under normal operation this rule never has anything to zero out — it
   exists as defense in depth in case a leaving node is ever present. */
@media (prefers-reduced-motion: reduce) {
  .stage.leaving {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

.edge-tap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12%;
  min-width: 32px;
  max-width: 90px;
  background: transparent;
  border: 0;
  cursor: pointer;
  z-index: 3;
}
.edge-tap-left { left: 0; }
.edge-tap-right { right: 0; }
.edge-tap:hover { background: rgba(255, 255, 255, 0.03); }
.edge-tap:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 0.01ms linear; }
}

/* ---------- Contents overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 9, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 24px;
}
.overlay[hidden] { display: none; }

.contents-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.contents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.contents-header h2 { margin: 0; font-size: 16px; }
.contents-header button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
}

.contents-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
}
.contents-list li { margin: 0; }
.contents-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  padding: 12px 10px;
  min-height: 44px;
  font-size: 14px;
  cursor: pointer;
}
.contents-list button:hover { background: rgba(255, 255, 255, 0.07); }
.contents-list button[aria-current="true"] {
  background: rgba(208, 151, 58, 0.16);
  color: var(--accent);
  font-weight: 600;
}
.contents-list .contents-num {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 24px;
}
.contents-list button[aria-current="true"] .contents-num { color: var(--accent); }

/* First Key Pacific additions */
body, button, input { font-family: "Poppins", system-ui, sans-serif; }
.back-home { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; color: var(--text); text-decoration: none; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.back-home:hover { background: rgba(255, 255, 255, 0.08); }
/* Clickable lines on the contents page. Sized by app.js to the drawn page. */
.page-frame { position: relative; }
.page-links { position: absolute; z-index: 6; }
.page-links a { position: absolute; display: block; border-radius: 4px; }
.page-links a:hover, .page-links a:focus-visible { background: rgba(171, 225, 228, 0.28); outline: 2px solid #abe1e4; }
.reader-legal { flex: none; margin: 0; padding: 6px 12px; text-align: center; font-size: 11px; line-height: 1.4; color: var(--muted); background: var(--panel-bg); border-top: 1px solid var(--border); }
@media (max-width: 820px) {
  #btn-fullscreen, #pdf-download { display: none; }
  #page-count-label { white-space: nowrap; font-size: 13px; }
  .page-frame, .page-frame.single { background: transparent; box-shadow: none; }
  .page-frame img { height: auto; max-height: 100%; width: 100%; }
  .reader-legal { font-size: 10px; padding: 4px 10px; }
}
/* Inside the magazine page: that page carries the way back and the license line. */
.embed .back-home, .embed .reader-legal { display: none; }
.embed body, .embed .viewer { background: #0b0b0c; }
/* No white bars when the page is shorter than its space. */
.page-frame, .page-frame.single, .page-frame img { background: transparent; box-shadow: none; }
/* A real page turn: the page swings on its own edge like a page in a book,
   instead of the whole stage rotating. */
.stage.leaving, .stage.leaving.turn-forward, .stage.leaving.turn-backward {
  transform: none; opacity: 1; transition: none; backface-visibility: visible;
}
.stage.leaving .page-frame {
  transition: transform var(--turn-duration) var(--turn-ease), opacity var(--turn-duration) ease-in;
  backface-visibility: hidden;
  opacity: 0.2;
}
.stage.leaving.turn-forward .page-frame { transform-origin: left center; transform: rotateY(-130deg); }
.stage.leaving.turn-backward .page-frame { transform-origin: right center; transform: rotateY(130deg); }
.stage-wrap { padding: 8px 56px; }
@media (max-width: 820px) { .stage-wrap { padding: 8px 36px; } }
/* Bigger and smaller */
.zoom-btn { min-width: 40px; min-height: 40px; padding: 0; font-size: 20px; line-height: 1; color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.zoom-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.zoom-btn:disabled { opacity: 0.35; cursor: default; }
.stage-wrap.zoomed { display: block; overflow: auto; padding: 8px; }
.stage-wrap.zoomed .stage { display: block; height: auto; max-height: none; }
.stage-wrap.zoomed .page-frame { display: block; width: var(--zoom-w); height: auto; max-height: none; margin: 0 auto; }
.stage-wrap.zoomed .page-frame img { width: 100%; height: auto; max-width: none; max-height: none; }
/* The side arrows stay out of the way of a scrolling page. */
.viewer:has(.stage-wrap.zoomed) .edge-tap { display: none; }
@media (max-width: 820px) { #btn-share { display: none; } }
/* Phone: the page fills the width. Readers swipe or use the arrows up top, so
   the side tap strips go, which also keeps them off the links near the edges. */
@media (max-width: 640px) {
  .stage-wrap { padding: 6px; }
  .edge-tap { display: none; }
}
