/* Serendip — the final site.
   Type from v2 (serif display + mono legend). Palette a mix of v2's warm paper
   and v3's cool slate, landing on an elegant neutral: Stone (light) / Charcoal
   (dark). The background is v3's "Transit" interchange on a faint graticule.
   Monochrome, hairline, no glow. */

:root {
  --radius: 6px;
  --gutter: clamp(20px, 5vw, 56px);
  --col: 720px;
  --measure: 660px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
    Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Stone — warm paper (v2) tempered toward cool chalk (v3). The default. */
  --bg: #efeeea;
  --bg-2: #e7e5de;
  --ink: #17171b;
  --ink-strong: #000000;
  --muted: #5e5a52;
  --faint: #938d80;
  --line: rgba(23, 23, 27, 0.14);
  --line-soft: rgba(23, 23, 27, 0.08);
  --grid: rgba(23, 23, 27, 0.05);
  --grid-bold: rgba(23, 23, 27, 0.08);
  --hover: rgba(23, 23, 27, 0.05);
  --header-bg: rgba(239, 238, 234, 0.82);
  --theme-color: #efeeea;
  --cv-bg: 239, 238, 234;
  --cv-ink: 23, 23, 27;
}

:root[data-theme="dark"] {
  /* Charcoal — v2's espresso warmth and v3's slate depth, blended neutral. */
  --bg: #121116;
  --bg-2: #1a191f;
  --ink: #eae7df;
  --ink-strong: #fffaf2;
  --muted: #a7a094;
  --faint: #6f6a60;
  --line: rgba(234, 231, 223, 0.14);
  --line-soft: rgba(234, 231, 223, 0.07);
  --grid: rgba(234, 231, 223, 0.05);
  --grid-bold: rgba(234, 231, 223, 0.08);
  --hover: rgba(234, 231, 223, 0.06);
  --header-bg: rgba(18, 17, 22, 0.78);
  --theme-color: #121116;
  --cv-bg: 18, 17, 22;
  --cv-ink: 234, 231, 223;
}

html {
  color-scheme: light dark;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--ink);
  color: var(--bg);
}

:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 3px;
  border-radius: 3px;
}

/* The map-legend voice — mono, tracked, technical. */
.eyebrow,
.kicker,
.counter,
.scroll-cue,
.header__cta,
.doc__updated,
.doc__back {
  font-family: var(--mono);
}

/* The Serendip brand mark — the "S" stencil (shared #brandmark symbol).
   Taller than wide; the box matches its 418:640 aspect so it sits tight. */
.glyph {
  width: 0.72em;
  height: 1.1em;
  flex: none;
  color: currentColor;
}

/* ───────────────────────── Graticule (page 1) ───────────────────────── */

#grid {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-bold) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-bold) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 256px 256px, 256px 256px;
}

main {
  position: relative;
  z-index: 1;
}

/* ───────────────────────── Header ───────────────────────── */

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--gutter);
  padding-right: calc(var(--gutter) + 52px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--header-bg);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line-soft);
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.5s var(--ease), opacity 0.4s ease;
}

.header.is-shown {
  transform: none;
  opacity: 1;
}

.header__mark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.005em;
}

.header__cta {
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.header__cta:hover {
  background: var(--hover);
  border-color: var(--ink);
}

/* ───────────────────────── Theme toggle ───────────────────────── */

.theme-toggle {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: var(--gutter);
  z-index: 30;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s var(--ease);
}

.theme-toggle:hover {
  background: var(--hover);
  border-color: var(--ink);
  transform: translateY(-1px);
}

.theme-toggle .ic {
  display: none;
  width: 18px;
  height: 18px;
}

:root[data-theme="dark"] .theme-toggle .ic--sun {
  display: block;
}

:root:not([data-theme="dark"]) .theme-toggle .ic--moon {
  display: block;
}

/* ───────────────────────── Hero (left-aligned) ───────────────────────── */

.hero {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: 132px var(--gutter) 132px;
}

.hero__inner {
  position: relative;
  z-index: 1;
  max-width: var(--col);
  /* Let the field show through, but keep links/the counter clickable. */
  pointer-events: none;
}

.hero__inner a,
.hero__inner .counter {
  pointer-events: auto;
}

/* Serendip — the first thing, and the loudest. The leading "S" is the
   brandmark itself (an abstract S stencil), set to the serif cap height and
   sitting on the baseline so the word reads as one. */
.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(64px, 15vw, 184px);
  line-height: 0.9;
  letter-spacing: -0.02em;
  white-space: nowrap; /* keep the brandmark welded to "erendip" */
}

.wordmark__glyph {
  display: inline-block;
  width: auto;
  height: 0.985em;          /* 30% taller than the tallest letter (the "d" ascender ≈ 0.757em) */
  vertical-align: baseline; /* box bottom rides the baseline, like the S */
  margin-right: 0.02em;     /* optical space into the lowercase run */
  color: currentColor;
}

/* Make serendipity last. — clearly visible, elegant, never shouting. */
.tagline {
  margin: 0.18em 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(23px, 4.6vw, 46px);
  line-height: 1.05;
  letter-spacing: -0.012em;
  color: var(--ink);
}

.lede {
  margin: 28px 0 0;
  max-width: 40ch;
  font-size: clamp(16px, 2.2vw, 19px);
  line-height: 1.6;
  color: var(--muted);
  text-wrap: balance;
}

.cta {
  margin-top: 36px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 48px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease,
    transform 0.2s var(--ease);
}

.btn:hover {
  background: var(--hover);
  border-color: var(--ink);
  transform: translateY(-1px);
}

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.btn--primary:hover {
  background: var(--ink-strong);
  border-color: var(--ink-strong);
  color: var(--bg);
}

.btn__glyph {
  width: 16px;
  height: 16px;
}

.counter {
  position: absolute;
  left: var(--gutter);
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 1;
  margin: 0;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.hero.is-stirred .counter {
  opacity: 1;
}

.counter #count {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.scroll-cue {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(26px, env(safe-area-inset-bottom));
  z-index: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--faint);
  transition: color 0.2s ease;
}

.scroll-cue:hover {
  color: var(--ink);
}

.scroll-cue svg {
  width: 12px;
  height: 18px;
  animation: nudge 2.2s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50% { transform: translateY(4px); opacity: 1; }
}

/* ─────────────── Content plates (the rule / how it works / control) ───────────
   Opaque pages that sit over the fixed field — the map's "legend". Editorial,
   monochrome, hairline; no cards, no icons, no glow. */

.plate {
  position: relative;
  z-index: 1;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: clamp(80px, 13vh, 148px) var(--gutter);
}

.plate__inner {
  max-width: var(--col);
  margin: 0 auto;
}

/* Mono "map legend" label, prefixed with a short tick. */
.plate__kicker {
  margin: 0 0 clamp(26px, 4.5vh, 44px);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.plate__kicker::before {
  content: "";
  width: 26px;
  height: 1px;
  background: var(--ink);
}

.plate__lead {
  margin: 0;
  max-width: 20ch;
  font-family: var(--serif);
  font-size: clamp(28px, 5.2vw, 54px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.plate__body {
  margin: 26px 0 0;
  max-width: 52ch;
  font-size: clamp(16px, 2.1vw, 18px);
  line-height: 1.65;
  color: var(--muted);
  text-wrap: pretty;
}

/* Legend — numbered (how it works) or keyed (control) rows on hairlines. */
.legend {
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(18px, 4vw, 40px);
  align-items: start;
  padding: clamp(22px, 3.4vh, 34px) 0;
  border-top: 1px solid var(--line-soft);
}

.legend__item:first-child {
  border-top: none;
  padding-top: 0;
}

/* Let the text column shrink inside the grid track (avoids overflow on phones). */
.legend__text {
  min-width: 0;
}

.legend__n {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  padding-top: 0.5em;
}

/* The control rows are marked with the interchange "station" square. */
.legend__mark {
  width: 8px;
  height: 8px;
  margin-top: 0.72em;
  background: var(--ink);
}

.legend__term {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(20px, 3.2vw, 28px);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.012em;
}

.legend__desc {
  margin: 8px 0 0;
  max-width: 54ch;
  font-size: clamp(15px, 2vw, 17px);
  line-height: 1.6;
  color: var(--muted);
  text-wrap: pretty;
}

/* ───────────────────── Get the app (centered) ───────────────────── */

.get {
  position: relative;
  z-index: 1;
  background: var(--bg);
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(120px, 16vh, 168px) var(--gutter);
  border-top: 1px solid var(--line);
}

.get__inner {
  max-width: var(--col);
  margin: 0 auto;
}

.get__glyph {
  width: clamp(104px, 16vw, 180px);
  height: clamp(104px, 16vw, 180px);
  margin: 0 auto 40px;
  display: block;
  color: var(--ink);
}

.get__title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  /* Always on a single line — scales with the viewport so it never wraps,
     down to the narrowest phones. */
  font-size: clamp(18px, 6vw, 90px);
  white-space: nowrap;
  line-height: 1;
  letter-spacing: -0.018em;
}

/* Official store badges (real artwork, no invented icons). */
.store {
  margin-top: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: center;
}

.store__badge {
  display: inline-flex;
  border-radius: 9px;
  transition: transform 0.2s var(--ease), opacity 0.2s ease;
}

.store__badge:hover {
  transform: translateY(-2px);
}

.store__badge img {
  display: block;
  height: 52px;
  width: auto;
}

/* Apple's badge carries extra internal padding — nudge it to match Google's. */
.store__badge--play img {
  height: 53px;
}

/* On the dark theme the near-black badges meet a near-black page; a hairline
   ring keeps them crisp without altering the official artwork. */
:root[data-theme="dark"] .store__badge {
  outline: 1px solid var(--line);
  outline-offset: 0;
}

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

/* A single, quiet row. */
.foot {
  position: relative;
  z-index: 1;
  background: var(--bg);
  padding: 26px var(--gutter) max(26px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
}

.foot__mark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 16px;
}

.foot__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 22px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.foot__nav a {
  transition: color 0.2s ease;
}

.foot__nav a:hover {
  color: var(--ink);
}

.foot__fine {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--faint);
}

/* ───────────────────── Legal pages (privacy / terms) ───────────────────── */

.legal {
  position: relative;
  z-index: 1;
  background: var(--bg);
  min-height: 100vh;
  min-height: 100svh;
  padding: 132px var(--gutter) clamp(72px, 12vh, 120px);
}

.doc {
  max-width: var(--col);
  margin: 0 auto;
}

.doc__kicker {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.doc__title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.018em;
}

.doc__updated {
  margin: 14px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.doc__body {
  margin-top: clamp(36px, 6vh, 56px);
}

.doc h2 {
  margin: 2.2em 0 0.6em;
  font-family: var(--serif);
  font-size: clamp(20px, 3vw, 26px);
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--ink);
}

.doc h2:first-child {
  margin-top: 0;
}

.doc p,
.doc li {
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--muted);
  max-width: var(--measure);
  margin-left: auto;
  margin-right: auto;
}

.doc p {
  margin: 0 0 1em;
}

.doc ul {
  margin: 0 auto 1em;
  padding-left: 1.1em;
  max-width: var(--measure);
}

.doc li {
  margin: 0 0 0.5em;
  padding-left: 0.2em;
}

.doc li::marker {
  color: var(--faint);
}

.doc strong {
  color: var(--ink);
  font-weight: 600;
}

.doc a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--line);
  transition: text-decoration-color 0.2s ease;
}

.doc a:hover {
  text-decoration-color: var(--ink);
}

.doc__foot {
  max-width: var(--measure);
  margin: clamp(48px, 8vh, 72px) auto 0;
  padding-top: clamp(28px, 5vh, 40px);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
}

.doc__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  transition: color 0.2s ease;
}

.doc__back:hover {
  color: var(--ink);
}

/* ───────────────────────── Reveal ───────────────────────── */

[data-reveal] {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
  will-change: opacity, transform;
}

[data-reveal].is-in {
  opacity: 1;
  transform: none;
}

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

@media (max-width: 720px) {
  .scroll-cue {
    display: none;
  }
}

/* Stack the store badges on narrow phones so neither is clipped. */
@media (max-width: 400px) {
  .store {
    flex-direction: column;
  }
}

/* On the narrowest phones the wordmark is pinned at the clamp floor (64px),
   which can clip the nowrap "Serendip". Let it scale down so it always fits. */
@media (max-width: 360px) {
  .wordmark {
    font-size: clamp(48px, 14.5vw, 64px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .scroll-cue svg {
    animation: none;
  }
  [data-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }
}
