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

/* ─── DESIGN TOKENS ─────────────────────────────────────────────────────── */
:root {
  /* Palette: the actual colours.
     Edit a hex here to change one swatch wherever it's used. */
  --black:   #0d0c0b;
  --teal:    #1aada0;
  --torrent: #04555d;
  --bone:    #c6c5b9;
  --kraft:   #c4a97a;
  --ink:     #1a1208;
  --carbon:  #1a191c;
  --cream:   #e8d9b8;
  --error:   #d97b6c;
  --white:   #fff;
  --shadow:  #000;

  /* RGB triplets for rgba() alpha variants — keep in sync with the hex values above. */
  --black-rgb:   13, 12, 11;
  --teal-rgb:    26, 173, 160;
  --torrent-rgb: 4, 85, 93;
  --bone-rgb:    198, 197, 185;
  --kraft-rgb:   196, 169, 122;
  --cream-rgb:   232, 217, 184;
  --white-rgb:   255, 255, 255;
  --shadow-rgb:  0, 0, 0;

  /* Semantic roles: what each colour MEANS in the design.
     Re-point a role at a different palette swatch to retheme. */
  --bg:              var(--black);    /* page / stage / body background */
  --bg-rgb:          var(--black-rgb);
  --surface:         var(--carbon);   /* booking-page surface */
  --paper:           var(--bone);     /* zine page-face / leaf */
  --paper-rgb:       var(--bone-rgb);
  --primary:         var(--bone);     /* button bgs + body copy on dark */
  --primary-rgb:     var(--bone-rgb);
  --on-primary:      var(--carbon);   /* text/icons on top of --primary */
  --accent:          var(--torrent);  /* links, focus, success, active dot */
  --accent-rgb:      var(--torrent-rgb);
  --text-strong:     var(--white);    /* high-contrast text/icons */
  --text-strong-rgb: var(--white-rgb);
  --gutter:          var(--black);    /* gutter shadow */
  --danger:          var(--error);    /* error messages */
  /* --shadow / --shadow-rgb already read as semantic; reused as-is. */
}

/* ─── PAGE / DOCUMENT ───────────────────────────────────────────────────── */
html {
  height: 100%;
}

/* Mobile browsers: stable visible height (address bar); safe areas for notch devices */
body {
  min-height: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  width: 100%;
  margin: 0;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Special Elite', courier;
}

/* Grain overlay over everything */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E");
  opacity: 0.4;
}

#root {
  width: 100%;
  min-height: 100dvh;
  min-height: 100svh;
}

/* Links: inherit surrounding text colour; teal on hover */
a:where(:link, :visited) { color: inherit; }
a:where(:hover)          { color: var(--accent); }

/* ─── PRELOAD SCREEN ────────────────────────────────────────────────────── */
.zine-preload-root {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Special Elite', system-ui;
  color: rgba(var(--text-strong-rgb), 0.25);
  letter-spacing: 0.15em;
  font-size: 12px;
}

/* Fallback page when a ZinePage receives an unexpected null src (mid-flip transition). */
.zine-page-placeholder {
  width: 100%;
  height: 100%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.zine-page-placeholder svg {
  width: 60px;
  height: 60px;
  opacity: 0.06;
}

/* ─── STAGE ─────────────────────────────────────────────────────────────── */
/* Spread aspect width:height ≈ 1.54 — size from the tighter of viewport height vs width */
.zine-stage {
  --zine-pad: clamp(12px, 4vw, 35px);
  --book-height: min(
    90vh,
    90dvh,
    90svh,
    700px,
    calc((100vw - var(--zine-pad) * 2) / 1.54)
  );
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2400px;
  perspective: min(2400px, 200vw);
  background: var(--bg);
  position: relative;
  padding: var(--zine-pad);
}

/* ─── BOOK ──────────────────────────────────────────────────────────────── */
.zine-book {
  position: relative;
  display: flex;
  align-items: stretch;
  aspect-ratio: 1.54 / 1;
  width: min(100%, calc(var(--book-height) * 1.54));
  max-height: var(--book-height);
  height: auto;
  flex-shrink: 0;
  transform-style: preserve-3d;
}

/* Spine shadow — on the book so it tracks width/height when the spread is clamped */
.zine-book::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  transform: translateX(-50%);
  width: 4px;
  background: linear-gradient(to right, var(--shadow) 0%, var(--gutter) 40%, var(--shadow) 100%);
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 0 30px 8px rgba(var(--shadow-rgb), 0.9);
}

/* Let the turning page move in 3D without clipping (restored after animation) */
.zine-book.zine-book--flipping .page-half {
  overflow: visible;
}

/* During a turn, the active half must paint above its sibling or the flip is hidden (prev was broken). */
.zine-book.zine-book--flipping .page-half:has(.flip-panel) {
  z-index: 2;
}

/* ─── PAGE HALF ─────────────────────────────────────────────────────────── */
.page-half {
  flex: 1;
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
}

.page-half.left  { border-radius: 4px 0 0 4px; }
.page-half.right { border-radius: 0 4px 4px 0; }

/* Static (visible) face of each half */
.page-face {
  position: absolute;
  inset: 0;
  background: var(--paper);
  overflow: hidden;
}

.page-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* Tap / click targets for turning pages (landscape) */
.page-face.zine-page-face--turn {
  cursor: pointer;
}

/* Page curl shadow */
.page-half.left .page-face::after,
.page-half.right .page-face::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.page-half.left .page-face::after {
  background: linear-gradient(to right, transparent 85%, rgba(var(--shadow-rgb), 0.25) 100%);
}

.page-half.right .page-face::after {
  background: linear-gradient(to left, transparent 85%, rgba(var(--shadow-rgb), 0.25) 100%);
}

/* ─── FLIP PANEL ────── covers whichever half is turning ────────────────── */
.flip-panel {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  /* Keyframed only — transitioning to ±180° interpolates ambiguously */
  transition: none;
  z-index: 10;
  pointer-events: none;
}

/* Forward leaf: lives in the right half; hinge = spine (left edge) */
.flip-panel.flip-leaf--next {
  transform-origin: left center;
  transform: rotateY(0deg);
}

/* Backward leaf: lives in the left half; hinge = spine (right edge) */
.flip-panel.flip-leaf--prev {
  transform-origin: right center;
  transform: rotateY(0deg);
}

/* Must stay in sync with FLIP_MS in zine-app.jsx */
.flip-panel.flip-leaf--next.flip-run {
  animation: zineFlipNext 750ms cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

.flip-panel.flip-leaf--prev.flip-run {
  animation: zineFlipPrev 750ms cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

@keyframes zineFlipNext {
  from { transform: rotateY(0deg); }
  50%  { transform: rotateY(-90deg); }
  to   { transform: rotateY(-180deg); }
}

@keyframes zineFlipPrev {
  from { transform: rotateY(0deg); }
  50%  { transform: rotateY(90deg); }
  to   { transform: rotateY(180deg); }
}

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
}

.flip-face.back {
  transform: rotateY(180deg);
}

.flip-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  pointer-events: none;
}

/* Flip shadow during animation */
.flip-panel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(var(--shadow-rgb), 0.15) 0%, transparent 30%);
  pointer-events: none;
  z-index: 1;
}

/* ─── EDGE ARROWS ───────────────────────────────────────────────────────── */
.edge-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 80px;
  background: rgba(10, 8, 4, 0.7);
  border: 1px solid rgba(var(--text-strong-rgb), 0.08);
  transition: background 0.2s, transform 0.15s;
  user-select: none;
}

.edge-arrow:hover {
  background: rgba(var(--accent-rgb), 0.25);
  transform: translateY(-50%) scale(1.06);
}

.edge-arrow.prev { left: -56px;  border-radius: 4px 0 0 4px; }
.edge-arrow.next { right: -56px; border-radius: 0 4px 4px 0; }

.edge-arrow svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--text-strong);
  stroke-width: 2;
}

/* ─── NAV DOTS ──────────────────────────────────────────────────────────── */
.nav-dots {
  position: fixed;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 500;
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(var(--text-strong-rgb), 0.2);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  border: 1px solid rgba(var(--text-strong-rgb), 0.1);
}

.nav-dot.active {
  background: var(--accent);
  transform: scale(1.4);
}

/* ─── PAGE COUNTER ──────────────────────────────────────────────────────── */
.page-counter {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Special Elite', courier;
  font-size: 13px;
  color: rgba(var(--text-strong-rgb), 0.35);
  letter-spacing: 0.12em;
  z-index: 500;
  pointer-events: none;
}

/* ─── ZINE LABEL ────────────────────────────────────────────────────────── */
.zine-label {
  position: fixed;
  top: calc(18px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Special Elite', courier;
  font-size: 13px;
  color: rgba(var(--text-strong-rgb), 0.2);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 500;
}

/* ─── BOOKING PAGE (last page) ──────────────────────────────────────────── */
.booking-page {
  width: 100%;
  height: 100%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vh, 28px);
  padding: clamp(16px, 4vh, 40px) clamp(16px, 5vw, 30px);
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.booking-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
  opacity: 0.5;
  pointer-events: none;
}

.booking-title {
  font-family: 'Manufacturing Consent', courier;
  font-size: clamp(28px, 2.2vw, 22px);
  background: var(--primary);
  color: var(--on-primary);
  text-transform: lowercase;
  letter-spacing: 0.05em;
  padding: 4px 12px;
  display: inline-block;
  transform: rotate(-1deg);
  text-decoration: none;
  cursor: pointer;
  border: none;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.booking-title:hover,
.booking-title:focus-visible {
  transform: rotate(-1deg) translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--shadow);
  outline: none;
}

.booking-btn {
  font-family: 'Manufacturing Consent', courier;
  font-size: clamp(28px, 1.8vw, 18px);
  background: var(--primary);
  color: var(--shadow);
  border: none;
  padding: 4px 12px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-decoration: none;
  display: inline-block;
  transform: rotate(0.5deg);
  transition: transform 0.15s, background 0.15s;
  box-shadow: 3px 3px 0 var(--shadow);
}

.booking-btn:hover {
  transform: rotate(0.5deg) translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--shadow);
}

.booking-info {
  font-family: 'Special Elite', courier;
  font-size: clamp(11px, 1.5vw, 14px);
  color: var(--primary);
  text-align: center;
  line-height: 2;
}

/* ─── MAILING LIST SIGNUP (sender.net) ──────────────────────────────────── */
.mailing-list {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.mailing-list__title {
  font-family: 'Special Elite', courier;
  font-size: clamp(16px, 1.6vw, 15px);
  color: var(--primary);
  padding: 3px 10px;
  align-self: center;
  letter-spacing: 0.05em;
  transform: rotate(0.8deg);
}

.mailing-list__lede {
  font-family: 'Special Elite', courier;
  font-size: clamp(10px, 1.2vw, 12px);
  color: var(--primary);
  letter-spacing: 0.04em;
  line-height: 1.5;
  margin: 0 auto;
  max-width: 57ch;
}

.mailing-list__input {
  width: 100%;
  flex: 0 0 auto;
  min-width: 0;
  font-family: 'Special Elite', courier;
  font-size: clamp(12px, 1.5vw, 14px);
  color: var(--primary);
  background: rgba(var(--bg-rgb), 0.55);
  border: 1px dashed rgba(var(--paper-rgb), 0.55);
  border-radius: 0;
  padding: 10px 12px;
  letter-spacing: 0.04em;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.mailing-list__input::placeholder {
  color: rgba(var(--primary-rgb), 0.4);
  font-style: italic;
}

.mailing-list__input:focus {
  border-color: var(--accent);
  background: rgba(var(--bg-rgb), 0.75);
}

.mailing-list__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.mailing-list__btn {
  align-self: center;
  font-family: 'Manufacturing Consent', courier;
  font-size: clamp(28px, 1.5vw, 14px);
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  letter-spacing: 0.08em;
  transform: rotate(-0.5deg);
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  box-shadow: 2px 2px 0 var(--shadow);
  margin-top: 4px;
}

.mailing-list__btn:hover:not(:disabled) {
  transform: rotate(-0.5deg) translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--shadow);
}

.mailing-list__btn:disabled {
  cursor: default;
  opacity: 0.7;
}

.mailing-list__msg {
  font-family: 'Special Elite', courier;
  font-size: clamp(10px, 1.2vw, 12px);
  letter-spacing: 0.04em;
  line-height: 1.4;
  min-height: 1em;
  margin-top: 2px;
}

.mailing-list__msg--success    { color: var(--accent); }
.mailing-list__msg--error      { color: var(--danger); }
.mailing-list__msg--submitting { color: rgba(var(--primary-rgb), 0.6); }

/* ─── PORTRAIT / PHONE SINGLE-PAGE ──────────────────────────────────────── */
/* Fixed viewport height so extra content (CTA) scrolls inside this pane */
.zine-mobile {
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* First screen: zine carousel; scroll reveals CTA below */
.zine-mobile__viewport {
  position: relative;
  flex: 0 0 auto;
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.zine-mobile__cta {
  flex: 0 0 auto;
  width: 100%;
  padding: clamp(28px, 8vw, 48px) clamp(16px, 5vw, 24px)
    clamp(32px + env(safe-area-inset-bottom, 0px), 10vw, 64px);
}

.zine-mobile__cta .booking-page {
  border-radius: 6px;
  min-height: min(85dvh, 85svh, 560px);
  max-height: none;
  justify-content: center;
}

/* Keep chrome on the zine screen only — not fixed over the CTA when scrolled */
.zine-mobile__viewport .nav-dots,
.zine-mobile__viewport .page-counter {
  position: absolute;
}

.zine-mobile__viewport .zine-label {
  position: absolute;
  top: 18px;
}

.zine-mobile__frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: clamp(40px, 10vh, 64px);
  overflow: hidden;
}

.zine-mobile__slide {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.zine-mobile__slide.zine-mobile__slide--last {
  cursor: default;
}

/* Height cap lives on the <img> itself: percentage max-height resolves
   unreliably against a flex-sized parent, so portrait images would
   overflow vertically when the viewport was wider than it was tall
   (e.g. small phones in landscape). vh/dvh/svh resolve against the
   viewport directly, guaranteeing the page always fits in frame. */
.zine-mobile__media {
  display: block;
  max-width: 100%;
  max-height: min(80svh, 80dvh, 80vh, calc(100dvh - 108px));
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center center;
}

/* ─── RESPONSIVE OVERRIDES ──────────────────────────────────────────────── */
@media (max-width: 840px), (max-height: 520px) {
  .edge-arrow {
    top: calc(45% + env(safe-area-inset-top, 0px));
  }
  .nav-dots {
    right: calc(6px + env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 720px), (orientation: portrait) {
  .zine-book::before {
    display: none;
  }
  .edge-arrow.prev { left:  max(8px, env(safe-area-inset-left, 12px)); }
  .edge-arrow.next { right: max(8px, env(safe-area-inset-right, 12px)); }
}
