:root {
  --charcoal:      #1d1d1a;   /* exact match to catalogue cover/back cover */
  --charcoal-deep: #131311;   /* slightly darker for vignette/depth */
  --charcoal-btn:  #262622;   /* button resting surface */
  --red:           #C8102E;
  --red-dark:      #a80d25;
  --white:         #FFFFFF;
  --border:        rgba(255,255,255,0.07); /* universal subtle separator */
  --header-h:      52px;
  --thumb-h:       68px;
}

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

html {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--charcoal);
  font-family: 'Georgia', serif;
  display: flex;
  flex-direction: column;
  height: 100vh;    /* fallback */
  height: 100dvh;   /* dynamic — accounts for iOS Safari toolbar */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── HEADER ─────────────────────────────────────────────────────── */
.header {
  background: var(--charcoal);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 30;
  gap: 8px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #fff;
  flex-shrink: 0;
  min-width: 0;
}

.brand-dot {
  width: 28px;
  height: 28px;
  background: var(--red);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.brand-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff;
  white-space: nowrap;
}
.brand-sub {
  font-size: 9px;
  color: rgba(255,255,255,0.3);
  font-style: italic;
  white-space: nowrap;
  margin-top: 1px;
}

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

/* ── BUTTONS ─────────────────────────────────────────────────────── */
.ctrl-btn {
  background: var(--charcoal-btn);
  border: 1px solid var(--border);
  color: rgba(255,255,255,0.55);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'Georgia', serif;
  white-space: nowrap;
  text-decoration: none;
  min-height: 34px;
  min-width: 34px;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  letter-spacing: 0.02em;
}
.ctrl-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-color: rgba(255,255,255,0.15);
}
.ctrl-btn:active {
  background: rgba(255,255,255,0.07);
}
.ctrl-btn:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
.ctrl-btn:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

/* Red download button */
.ctrl-btn.red {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.ctrl-btn.red:hover  { background: var(--red-dark); border-color: var(--red-dark); }
.ctrl-btn.red:active { background: #8f0b1e; }

/* Zoom active — show user they're in zoom mode */
.ctrl-btn.zoom-active {
  background: rgba(68,102,170,0.2);
  border-color: rgba(68,102,170,0.4);
  color: #88aaee;
}

.page-counter {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  min-width: 44px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* Zoom level badge — inline inside zoom-in button */
.zoom-badge {
  font-size: 9px;
  font-style: normal;
  background: var(--red);
  color: #fff;
  border-radius: 3px;
  padding: 1px 4px;
  font-weight: 700;
  letter-spacing: 0.03em;
  /* Use opacity so button width never jumps */
  opacity: 0;
  transition: opacity 0.15s;
}
.zoom-badge.visible { opacity: 1; }

/* ── STAGE ───────────────────────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  /* Soft vignette that stays within the charcoal family */
  background: radial-gradient(ellipse at center, #222220 0%, var(--charcoal-deep) 100%);
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

/* Grab cursor when zoomed */
.stage.zoomed         { cursor: grab; }
.stage.zoomed:active  { cursor: grabbing; }

/* ── FLIPBOOK CONTAINER ──────────────────────────────────────────── */
#flipbook-container {
  position: relative;
  /* Promote the book (not the whole stage) to its own compositor layer */
  will-change: transform;
  transform-origin: center center;
  transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Neutralise StPageFlip's pan-y so our pinch/pan handlers own touch */
.stf__parent {
  touch-action: none !important;
  outline: none;
}
.stf__parent canvas {
  outline: none;
  display: block;
}

/* ── ZOOM OVERLAY ────────────────────────────────────────────────── */
/* Transparent intercept layer — blocks StPageFlip from seeing touches
   when zoomed; events still bubble up to .stage for our pan handlers */
#zoom-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;   /* above book (0), below nav arrows (20) */
  display: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  outline: none;
}
#zoom-overlay:active { cursor: grabbing; }

/* ── NAV ARROWS ──────────────────────────────────────────────────── */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  background: rgba(29,29,26,0.75);
  border: 1px solid var(--border);
  color: rgba(255,255,255,0.4);
  width: 36px;
  height: 56px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, opacity 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  outline: none;
}
.nav-arrow:hover  { background: rgba(200,16,46,0.8); color: #fff; border-color: rgba(200,16,46,0.5); }
.nav-arrow:active { background: rgba(168,13,37,0.9); }
.nav-arrow:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.nav-arrow.left  { left: 8px; }
.nav-arrow.right { right: 8px; }

/* Hide arrows when zoomed — user pans instead */
.stage.zoomed .nav-arrow { opacity: 0; pointer-events: none; }

/* ── THUMBNAILS ──────────────────────────────────────────────────── */
.thumb-strip {
  height: var(--thumb-h);
  background: var(--charcoal);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.thumb-strip::-webkit-scrollbar       { height: 3px; }
.thumb-strip::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.thumb {
  height: 46px;
  aspect-ratio: 612 / 792;
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  /* Use box-shadow for the active ring — never border — so layout never shifts */
  box-shadow: 0 0 0 2px transparent;
  flex-shrink: 0;
  opacity: 0.4;
  transition: opacity 0.15s, box-shadow 0.15s;
  outline: none;
}
.thumb img   { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { opacity: 0.75; }
.thumb.active {
  box-shadow: 0 0 0 2px var(--red);
  opacity: 1;
}

/* ── LOADING SCREEN ──────────────────────────────────────────────── */
.loading-screen {
  position: absolute;
  inset: 0;
  background: var(--charcoal);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  gap: 16px;
  transition: opacity 0.5s ease;
}
.loading-screen.done { opacity: 0; pointer-events: none; }

.loading-logo {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.loading-logo span { color: var(--red); }

.loading-bar-wrap {
  width: 140px;
  height: 2px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  width: 0;
  transition: width 0.15s ease;
}
.loading-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.25);
  font-style: italic;
  letter-spacing: 0.05em;
}

/* ── RESPONSIVE ──────────────────────────────────────────────────── */

/* Tablet / large phone — swipe handles navigation */
@media (max-width: 680px) {
  .nav-arrow { display: none; }
}

/* Phone */
@media (max-width: 480px) {
  :root { --header-h: 46px; --thumb-h: 54px; }

  .brand-sub     { display: none; }
  .page-counter  { display: none; }
  .ctrl-btn span { display: none; }
  .ctrl-btn { padding: 5px 7px; min-height: 32px; min-width: 32px; }

  .thumb { height: 38px; }
}

/* Very small phones */
@media (max-width: 360px) {
  .brand-name { display: none; }
  .header { padding: 0 10px; gap: 3px; }
}

/* ── SAFE AREA (notched phones / Dynamic Island) ─────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .thumb-strip {
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
    height: calc(var(--thumb-h) + env(safe-area-inset-bottom));
  }
  .header {
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* ── FULLSCREEN ──────────────────────────────────────────────────── */
:fullscreen .thumb-strip,
:-webkit-full-screen .thumb-strip { height: var(--thumb-h); padding-bottom: 0; }
