/* 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: #121317;
  --bg-elevated: #1b1d22;
  --panel-bg: #1e2026;
  --text: #f3f3f0;
  --muted: #a7abb6;
  --accent: #d0973a;
  --accent-ink: #2a1c05;
  --border: rgba(255, 255, 255, 0.12);
  --focus-ring: #6fb7ff;
  --page-bg: #ffffff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --toolbar-h: 60px;
  --turn-duration: 660ms;
  --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); }

/* Phones: the page is width-limited, so size the frame from the page's own
   shape instead of filling the full height (which left white bands above
   and below every page). */
@media (max-width: 820px) {
  .stage { height: auto; width: 100%; }
  .page-frame { height: auto; width: 100%; background: transparent; box-shadow: none; }
  .page-frame img { width: 100%; height: auto; max-height: calc(100dvh - 120px); background: transparent; box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55); }
}

.contents-more { list-style: none; margin: 16px 0 0; padding: 16px 0 0; border-top: 1px solid rgba(255,255,255,0.15); }
.contents-more li { margin: 0 0 10px; }
.contents-more a { color: #d6b56d; text-decoration: none; font-size: 15px; }
.contents-more a:hover, .contents-more a:focus { text-decoration: underline; }
