/* Self-hosted Quicksand (OFL) — no external requests, no consent needed. */
@font-face {
  font-family: "Quicksand";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/quicksand-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Quicksand";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/quicksand-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --text: #161615;
  --muted: #55554f;
  --border: #dededb;
  --btn: #161615;
  --btn-text: #ffffff;
  /* Focus ring — used globally via :focus-visible */
  --focus-ring: 0 0 0 3px rgba(22, 22, 21, 0.18);
  /* Shared easing for micro-interactions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Brand-coloured text selection */
::selection {
  background: rgba(22, 22, 21, 0.12);
  color: var(--text);
}

* { box-sizing: border-box; }

/* Global focus-visible ring — replaces the browser default blue outline
 * with a subtle dark ring that matches the palette. Interactive elements
 * that need a different ring (e.g. viewer buttons) override this locally. */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 4px;
}

html {
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox: hide scrollbar, page still scrolls */
  -ms-overflow-style: none; /* legacy Edge/IE */
}

/* Chromium/Safari: hide scrollbar, page still scrolls */
::-webkit-scrollbar { display: none; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text);
  font-family: "Quicksand", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  line-height: 1.6;
  /* Remove the grey tap flash on iOS for all clickable elements */
  -webkit-tap-highlight-color: transparent;
}

/* Entire background is the container — no card for the hero. */
.wrap {
  width: 100%;
  max-width: 620px;
  padding: 96px 24px 72px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 24px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--muted);
}

h1 {
  margin: 0 0 16px;
  font-size: clamp(40px, 7vw, 56px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

h1.error-code {
  font-size: clamp(56px, 10vw, 84px);
}

.sub {
  margin: 0 auto 40px;
  max-width: 34ch;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.65;
  text-wrap: balance;
}

.links {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: block;
  padding: 15px 28px;
  border-radius: 999px;
  background: var(--btn);
  color: var(--btn-text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.18s var(--ease-out), transform 0.18s var(--ease-out);
  cursor: pointer;
  border: none;
}

.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:hover    { opacity: 0.82; }
.btn:active   { transform: scale(0.97); opacity: 0.9; }
.btn:focus-visible {
  box-shadow: var(--focus-ring);
  border-radius: 999px;
}

/* Social/API links sit directly on the background — no container. */
.more {
  margin: 40px 0 8px;
}

.more h2 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.more ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 22px;
}

.more a {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: border-color 0.15s ease, color 0.15s ease;
  border-radius: 2px;
}

.more a:hover       { border-color: var(--text); }
.more a:focus-visible {
  border-bottom-color: transparent;
  box-shadow: var(--focus-ring);
  border-radius: 3px;
}

/* ─── Stories Section ───────────────────────────────────────────────────── */

.stories {
  margin: 40px 0 0;
}

.stories h2 {
  margin: 0 0 24px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Deck container.
 * --card-w is the single source of truth for card size: the deck height is
 * derived from it (card height 16/9 + fan spread + slack), so both scale
 * together on small screens instead of drifting apart.
 *
 * Mobile-first sizing strategy:
 *  - Phone  (<480px): card fills ~60vw — feels like a real story preview
 *  - Tablet (480-620px): fixed 220px — comfortable and prominent
 *  - Desktop (>620px): 200px — balanced within the 620px max-width layout
 *
 * The deck's max-width must accommodate the card plus the rightmost fan cards
 * (3 cards at 10px offset each = +30px) plus some breathing room. */
.story-deck {
  --card-w: 200px;
  position: relative;
  height: calc(var(--card-w) * 16 / 9 + 72px);
  max-width: 460px;
  margin: 0 auto;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Cards ── */
/* Latest story (--i: 0) is on top via z-index. Background cards fan below. */
.story-card {
  position: absolute;
  left: 50%;
  top: 0;
  display: block;
  width: var(--card-w, 200px);
  aspect-ratio: 9 / 16;
  border-radius: 22px;
  overflow: hidden;
  border: 1.5px solid rgba(255,255,255,0.55);
  background: var(--bg);
  /* Layered shadow: soft spread + crisp focus */
  box-shadow:
    0 2px 8px rgba(22, 22, 21, 0.06),
    0 12px 32px rgba(22, 22, 21, 0.16);
  z-index: calc(var(--n, 1) - var(--i, 0));
  transform:
    translateX(-50%)
    translate(
      calc(min(var(--i, 0), 3) * 10px - 15px),
      calc(min(var(--i, 0), 3) * 14px)
    )
    rotate(calc((min(var(--i, 0), 3) - 1.2) * 4.5deg));
  transition:
    transform 0.38s cubic-bezier(.22,.68,0,1.2),
    opacity   0.38s ease,
    box-shadow 0.25s ease;
  cursor: pointer;
  outline: none;
}

/* Top card: lift on hover, focus ring on keyboard focus */
.story-card:first-child {
  outline: none;
}

.story-card:first-child:hover {
  /* Keep the resting fan offset (-15px, -5.4deg) and only add lift + scale,
   * otherwise the card visibly jumps sideways when hovered. */
  transform: translateX(-50%) translate(-15px, -10px) rotate(-5.4deg) scale(1.025);
  box-shadow:
    0 4px 12px rgba(22, 22, 21, 0.08),
    0 20px 48px rgba(22, 22, 21, 0.22);
}

.story-card:first-child:focus-visible {
  transform: translateX(-50%) translate(-15px, -10px) rotate(-5.4deg) scale(1.025);
  box-shadow:
    0 4px 12px rgba(22, 22, 21, 0.08),
    0 20px 48px rgba(22, 22, 21, 0.22),
    var(--focus-ring);
}

.story-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Dragging state — disable transition for 1:1 tracking */
.story-card.dragging {
  transition: none;
  cursor: grabbing;
}

/* Leaving animation — card flies out */
.story-card.leaving {
  transition: transform 0.38s ease, opacity 0.38s ease;
  pointer-events: none;
}

/* ── Auto-advance shimmer on top card ── */
.story-card:first-child::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: var(--adv-pct, 0%);
  height: 3px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0 2px 0 0;
  transition: width 0.1s linear;
  pointer-events: none;
}

/* ── Counter badge ── */
.story-deck__counter {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.story-deck__count {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.story-deck__dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.25s ease, transform 0.25s ease;
}

.story-deck__dot--current {
  background: var(--text);
  transform: scale(1.3);
}

/* Hint text below the counter */
.story-hint {
  margin: 60px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.7;
  letter-spacing: 0.02em;
}

/* ── Mobile: card fills most of the viewport width ──
 * On phones the deck is the hero of the page — give it real estate.
 * clamp(180px, 60vw, 240px) means:
 *   ≤300px wide phone  → 180px card (still comfortable)
 *   375px iPhone       → 225px card
 *   430px iPhone Pro   → 240px card (capped)
 * The deck max-width is removed so it can breathe; the card width already
 * self-limits. Extra bottom space ensures counter + hint never clip. */
@media (max-width: 480px) {
  .story-deck {
    --card-w: clamp(180px, 60vw, 240px);
    max-width: 100%;
  }
  .story-card {
    border-radius: 18px;
  }
  .story-hint {
    margin-top: 56px;
  }
}

/* ── Small tablet / large phone: step up to 220px ── */
@media (min-width: 481px) and (max-width: 620px) {
  .story-deck {
    --card-w: 220px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-card,
  .story-card:first-child::after { transition: none; }
}

/* ─── Story Lightbox Viewer ──────────────────────────────────────────────── */

.story-viewer {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Entry animation */
  animation: sv-in 0.22s ease forwards;
}

@keyframes sv-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.story-viewer[hidden] { display: none !important; }

/* Progress bar */
.story-viewer__progress-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.2);
  z-index: 10;
}

.story-viewer__progress-bar {
  height: 100%;
  width: 0%;
  background: #fff;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* Close button */
.story-viewer__close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top, 16px));
  right: 16px;
  z-index: 10;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s ease;
}

.story-viewer__close:hover { background: rgba(255,255,255,0.25); }
.story-viewer__close:focus-visible {
  background: rgba(255,255,255,0.25);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.5);
  border-radius: 50%;
}

/* Counter chip (e.g. "3 / 6") */
.story-viewer__counter {
  position: absolute;
  top: max(20px, calc(env(safe-area-inset-top, 0px) + 20px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
}

/* Media area — fills the screen (portrait constraint) */
.story-viewer__media {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-viewer__media img,
.story-viewer__media video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 0;
}

/* Contain to story aspect ratio on wider viewports */
@media (min-width: 500px) {
  .story-viewer__media img,
  .story-viewer__media video {
    max-width: min(100vw, calc(100vh * 9 / 16));
    max-height: 100vh;
    border-radius: 12px;
  }
}

/* Navigation arrows — visible on desktop/tablet, hidden on touch-only phones
 * where the tap zones (left 40% / right 40%) handle navigation instead. */
.story-viewer__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s ease, opacity 0.2s ease;
}

.story-viewer__nav:hover { background: rgba(255,255,255,0.25); }
.story-viewer__nav:focus-visible {
  background: rgba(255,255,255,0.25);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.5);
  border-radius: 50%;
}

.story-viewer__nav:disabled {
  opacity: 0.25;
  cursor: default;
}

.story-viewer__nav--prev { left: 12px; }
.story-viewer__nav--next { right: 12px; }

/* On mobile, tap zones handle navigation — hide arrows to keep UI clean */
@media (max-width: 480px) and (pointer: coarse) {
  .story-viewer__nav { display: none; }
}

/* Tap zones (invisible) for full-height prev/next navigation */
.story-viewer__tap-prev,
.story-viewer__tap-next {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  z-index: 5;
  cursor: pointer;
}

.story-viewer__tap-prev { left: 0; }
.story-viewer__tap-next { right: 0; }

/* Volume control row — bottom-centre of viewer */
.story-viewer__volume {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 8px 14px 8px 10px;
}

.story-viewer__vol-btn {
  border: none;
  background: none;
  color: #fff;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.story-viewer__vol-btn:focus-visible {
  outline: 2px solid rgba(255,255,255,0.6);
  border-radius: 4px;
}

/* Range slider — custom cross-browser */
.story-viewer__vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.3);
  outline: none;
  cursor: pointer;
  accent-color: #fff; /* modern browsers */
}

.story-viewer__vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.story-viewer__vol-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* Hide volume row for image stories (controlled via JS .vol-hidden class) */
.story-viewer__volume.vol-hidden {
  display: none;
}

/* The speaker icons are inline <svg> — enforce [hidden] explicitly so a
 * missing/expired UA rule can never leave both icons visible at once
 * (JS toggles the content attribute, see syncVolUI in stories.js). */
.story-viewer__volume [hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .story-viewer { animation: none; }
  .story-viewer__progress-bar { transition: none; }
  .btn { transition: none; }
  .more a { transition: none; }
}


/* ─── Language Switcher ────────────────────────────────────────────────── */

.lang {
  margin-top: 36px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.lang a {
  color: inherit;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
  display: inline-block;
}

.lang a:hover {
  color: var(--text);
  background: rgba(22, 22, 21, 0.06);
}

.lang a[aria-current="true"] {
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
}

.lang a:focus-visible {
  box-shadow: var(--focus-ring);
  color: var(--text);
}

/* ─── Footer ────────────────────────────────────────────────────────────── */

footer {
  margin-top: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

footer p { margin: 5px 0; }

footer .credits {
  font-size: 12px;
  font-weight: 400;
}

footer .credits a,
footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease;
  border-radius: 2px;
}

footer .credits a:hover,
footer a:hover { color: var(--text); }

footer .credits a:focus-visible,
footer a:focus-visible {
  box-shadow: var(--focus-ring);
  border-radius: 3px;
}

/* ─── Responsive tweaks ─────────────────────────────────────────────────── */

@media (min-width: 480px) {
  .links { flex-direction: row; justify-content: center; }
  .btn { min-width: 200px; }
}

/* Tighter top padding on small phones — still generous but not too much */
@media (max-width: 480px) {
  .wrap { padding-top: 64px; padding-bottom: 56px; }
}
