/* ==========================================================================
   OptometryIQ — design tokens, base reset, scroll-stage + editorial shell
   ========================================================================== */

:root {
  /* parchment / paper */
  --paper: #F5F1E8;
  --paper-hi: #FAF7F0;
  --paper-lo: #EDE7D8;

  /* ink + neutrals */
  --ink: #1F1F1F;
  --muted: #6B6358;
  --hint: #A89F90;

  /* borders */
  --line: #E8E0D0;
  --line-strong: #D6CCB8;

  /* earth trio */
  --sage: #4A6B4F;
  --brass: #B8893D;
  --terra: #8B3A2F;

  /* night family (warm brown-black — never blue-black) */
  --night: #1A1612;
  --night-2: #221C16;
  --night-3: #2E2620;

  /* product accents (only inside their own blocks) */
  --cyan: #0E7C9D;
  --forest: #2D4A3E;
}

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

body {
  background: var(--night);
  color: #FAF7F0;
  font-family: 'DM Sans', sans-serif;
}

img {
  max-width: 100%;
}

/* ============ wordmark ============ */

.wordmark {
  position: fixed;
  top: 40px;
  left: 5.5vw;
  z-index: 10;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: #FAF7F0;
  /* difference blend renders the cream mark dark over the light interior
     scenes (2–4) and cream over the night scenes — per-pixel, so it stays
     legible through every crossfade (a fixed shadow could not) */
  mix-blend-mode: difference;
  transition: opacity 0.4s ease;
}

@media (min-width: 900px) {
  .wordmark { left: 80px; }
}

/* toggled by js/main.js once the world hands off to the editorial band */
.wordmark.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* the editorial half carries its own static wordmark (ink, not fixed) so
   branding survives once the fixed wordmark fades out at the handoff */
.editorial__wordmark {
  padding: 40px 5.5vw 0;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--ink);
}

@media (min-width: 900px) {
  .editorial__wordmark { padding-left: 80px; }
}

/* ============ scroll stage ============ */

.world {
  position: relative;
}

.world__sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.world__track {
  height: calc(var(--world-scroll, 8) * 100vh);
}

.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.scene.is-active {
  opacity: 1;
}

.scene__art {
  position: absolute;
  inset: 0;
}

.scene__art svg {
  width: 100%;
  height: 100%;
  display: block;
}

.scene__copy {
  position: absolute;
  left: 5.5vw;
  bottom: 12vh;
  max-width: 560px;
}

.scene__copy .eyebrow {
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--brass);
  margin-bottom: 18px;
}

.scene__copy h1,
.scene__copy h2 {
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: clamp(34px, 4.2vw, 54px);
  line-height: 1.1;
  color: var(--paper-hi);
  margin-bottom: 22px;
}

.scene__copy p {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  font-size: 16.5px;
  line-height: 1.6;
  color: var(--hint);
  max-width: 500px;
}

/* mobile: copy blocks become full-width bottom sheets — a translucent paper
   panel so the text never fights the recomposed art behind it. Night scenes
   (1 + 5) get a night sheet; cream interiors (2–4) get a parchment sheet. */
@media (max-width: 600px) {
  .scene__copy {
    left: 6vw;
    right: 6vw;
    bottom: 8vh;
    max-width: none;
    padding: 20px 22px;
    border-radius: 14px;
    background: rgba(26, 22, 18, 0.78);
  }

  [data-scene="table"] .scene__copy,
  [data-scene="board"] .scene__copy,
  [data-scene="office"] .scene__copy {
    background: rgba(245, 241, 232, 0.9);
  }

  .scene__copy .eyebrow { margin-bottom: 12px; }

  .scene__copy h1,
  .scene__copy h2 {
    font-size: clamp(27px, 7.2vw, 34px);
    margin-bottom: 14px;
  }

  .scene__copy p { font-size: 15px; }
}

/* ============ scene 1 — "the practice at 9pm" ============
   Ported from docs/design-reference/scene1-cut-paper.html (approved
   variant A). CSS animations live on nodes the engine never transforms:
   the engine drives #cam-street + .scene__copy/.scene__hint, these drive
   inner children only. */

/* scroll hint — outer node is engine-driven (opacity/translateY), so the
   pulse animation sits on the inner wrapper */
.scene__hint {
  position: absolute;
  bottom: 26px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.scene__hint-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0.75;
  animation: hint 3.5s ease-in-out infinite;
}

.scene__hint span {
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #FAF7F0;
}

.scene__hint .line {
  width: 1px;
  height: 34px;
  background: #FAF7F0;
}

/* trough stays >= 0.55 so the cream-on-night hint keeps AA contrast (4.5:1)
   at every point of the pulse */
@keyframes hint {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 0.55; }
}

/* star twinkle */
[data-scene="street"] .tw  { animation: twinkle 4s ease-in-out infinite; }
[data-scene="street"] .tw2 { animation: twinkle 5s ease-in-out infinite; animation-delay: 1.6s; }
[data-scene="street"] .tw3 { animation: twinkle 4.5s ease-in-out infinite; animation-delay: 2.8s; }

@keyframes twinkle {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}

/* window glow flicker */
[data-scene="street"] .glow-mid { animation: flick 7s ease-in-out infinite; }

@keyframes flick {
  0%, 100% { opacity: 0.13; }
  44% { opacity: 0.105; }
  58% { opacity: 0.145; }
}

/* moths around the streetlamp */
[data-scene="street"] .moth {
  transform-box: fill-box;
  transform-origin: center;
  animation: moth 5s ease-in-out infinite;
}

[data-scene="street"] .moth.m2 {
  animation-duration: 6.5s;
  animation-delay: 1.2s;
}

@keyframes moth {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(4px, -5px); }
  65% { transform: translate(-3px, -2px); }
}

/* ============ scene 2 — "the dispensing table" ============
   The interior is cream, so the copy flips to ink. Chip bob + lamp breathe
   sit on inner art nodes the engine never writes (it only transforms
   #cam-table); chips carry their rotation on an outer attribute group so
   the CSS transform animation doesn't clobber it. */

[data-scene="table"] .scene__copy h2 { color: var(--ink); }
[data-scene="table"] .scene__copy p { color: var(--muted); }

[data-scene="table"] .chip {
  transform-box: fill-box;
  transform-origin: center;
  animation: chip-bob 3.4s ease-in-out infinite;
}

[data-scene="table"] .chip.c2 { animation-duration: 4s; animation-delay: 0.6s; }
[data-scene="table"] .chip.c3 { animation-duration: 3.6s; animation-delay: 1.2s; }
[data-scene="table"] .chip.c4 { animation-duration: 4.3s; animation-delay: 1.8s; }

@keyframes chip-bob {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(2px, -6px); }
}

/* pendant glow breathe */
[data-scene="table"] .lamp-glow { animation: lamp-breathe 7s ease-in-out infinite; }

@keyframes lamp-breathe {
  0%, 100% { opacity: 0.12; }
  46% { opacity: 0.095; }
  60% { opacity: 0.135; }
}

/* ============ scene 3 — "the frame board" ============
   Cream interior again, so the copy flips to ink. Glow breathe sits on the
   A-player chip wrapper groups (group opacity, so the two stacked chip
   rects keep their relative layering); motes drift like scene 1's moths.
   All animated nodes are inner art — the engine only writes #cam-board. */

[data-scene="board"] .scene__copy h2 { color: var(--ink); }
[data-scene="board"] .scene__copy p { color: var(--muted); }

[data-scene="board"] .glow-a { animation: glow-breathe 5.5s ease-in-out infinite; }
[data-scene="board"] .glow-a.g2 { animation-duration: 6.4s; animation-delay: 1.3s; }
[data-scene="board"] .glow-a.g3 { animation-duration: 4.8s; animation-delay: 2.5s; }

@keyframes glow-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.62; }
}

[data-scene="board"] .mote {
  transform-box: fill-box;
  transform-origin: center;
  animation: mote 9s ease-in-out infinite;
}

[data-scene="board"] .mote.m2 { animation-duration: 11s; animation-delay: 2s; }
[data-scene="board"] .mote.m3 { animation-duration: 8s; animation-delay: 4s; }

@keyframes mote {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(3px, -4px); }
  70% { transform: translate(-2px, -1px); }
}

/* ============ scene 4 — "the back office, reading itself" ============
   Cream interior again, so the copy flips to ink. Sheet drift sits on the
   inner .off-sheet groups (rotation + skew live on the outer attribute
   group, scene 2 chip pattern); the lamp glow reuses scene 2's
   lamp-breathe keyframes. All animated nodes are inner art — the engine
   only writes #cam-office. */

[data-scene="office"] .scene__copy h2 { color: var(--ink); }
[data-scene="office"] .scene__copy p { color: var(--muted); }

[data-scene="office"] .off-sheet {
  transform-box: fill-box;
  transform-origin: center;
  animation: sheet-drift 4.5s ease-in-out infinite;
}

[data-scene="office"] .off-sheet.s2 { animation-duration: 5.2s; animation-delay: 0.5s; }
[data-scene="office"] .off-sheet.s3 { animation-duration: 4.1s; animation-delay: 1.1s; }
[data-scene="office"] .off-sheet.s4 { animation-duration: 5.6s; animation-delay: 1.7s; }
[data-scene="office"] .off-sheet.s5 { animation-duration: 4.7s; animation-delay: 2.3s; }
[data-scene="office"] .off-sheet.s6 { animation-duration: 5s; animation-delay: 2.9s; }
[data-scene="office"] .off-sheet.s7 { animation-duration: 4.3s; animation-delay: 3.4s; }

@keyframes sheet-drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(2px, -6px); }
}

/* desk-lamp glow breathe (reuses scene 2's lamp-breathe keyframes) */
[data-scene="office"] .off-glow { animation: lamp-breathe 6.5s ease-in-out infinite; }

/* ============ scene 5 — "home" ============
   Night exterior again, so the copy stays cream (no flip). Twinkle and
   the window-glow flicker reuse scene 1's keyframes (`flick` animates
   absolute opacity — the mid glow layer sits at .13 to match); chimney
   smoke drifts like the moths; one moth circles the porch light. All
   animated nodes are inner art — the engine only writes #cam-home. */

/* the payoff copy HOLDS through the settled frame (out:1.2), so it must
   compose against the final framing: raised above the fence/cat rows,
   clear of the lit window (which the end keyframe keeps right of x 620) */
[data-scene="home"] .scene__copy { bottom: 30vh; }

/* mobile: the bottom sheet carries its own scrim, so it drops back down with
   the others and clears the lit dinner window (must follow the 30vh rule —
   equal specificity, source order decides) */
@media (max-width: 600px) {
  [data-scene="home"] .scene__copy { bottom: 8vh; }
}

[data-scene="home"] .hm-tw  { animation: twinkle 4s ease-in-out infinite; }
[data-scene="home"] .hm-tw2 { animation: twinkle 5s ease-in-out infinite; animation-delay: 1.6s; }
[data-scene="home"] .hm-tw3 { animation: twinkle 4.5s ease-in-out infinite; animation-delay: 2.8s; }

[data-scene="home"] .hm-glow-mid { animation: flick 7s ease-in-out infinite; }

[data-scene="home"] .hm-smoke {
  transform-box: fill-box;
  transform-origin: center;
  animation: smoke-drift 6s ease-in-out infinite;
}

[data-scene="home"] .hm-smoke.s2 { animation-duration: 7.5s; animation-delay: 1.4s; }
[data-scene="home"] .hm-smoke.s3 { animation-duration: 9s; animation-delay: 2.8s; }

@keyframes smoke-drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(4px, -7px); }
}

[data-scene="home"] .hm-moth {
  transform-box: fill-box;
  transform-origin: center;
  animation: moth 5.5s ease-in-out infinite;
}

/* ============ editorial ============ */

.editorial {
  background: var(--paper);
  color: var(--ink);
}

/* ---- fade-up reveals (js/main.js observes .reveal inside .editorial) ---- */

.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---- shared editorial layout ---- */

.edt-section {
  padding: 120px 0;
}

.edt-section--tint {
  background: var(--paper-lo);
}

.edt-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 5.5vw;
}

.edt-container--narrow {
  max-width: 720px;
}

.edt-h2 {
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: clamp(36px, 4.5vw, 58px);
  line-height: 1.12;
  color: var(--ink);
  margin-bottom: 20px;
  max-width: 800px;
}

.edt-lede,
.edt-body {
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--muted);
  max-width: 680px;
}

.edt-body {
  color: var(--ink);
  font-size: 19px;
}

@media (max-width: 700px) {
  .edt-section { padding: 72px 0; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- #products ---- */

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  margin-top: 64px;
}

@media (max-width: 860px) {
  .product-grid { grid-template-columns: 1fr; gap: 56px; }
}

.product__rule {
  width: 56px;
  height: 3px;
  background: var(--cyan);
  margin-bottom: 24px;
}

.product--frameiq .product__rule { background: var(--forest); }

.product__name {
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: clamp(26px, 2.6vw, 32px);
  color: var(--ink);
  margin-bottom: 14px;
}

.product__line {
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 24px;
}

.product__stats {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  margin-bottom: 22px;
}

.product__stats li {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  padding-left: 16px;
  position: relative;
}

.product__stats li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
}

.product--frameiq .product__stats li::before { background: var(--forest); }

.product__limits {
  font-size: 14px;
  line-height: 1.6;
  color: var(--hint);
  margin-bottom: 28px;
}

.product__shot {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  margin-bottom: 24px;
}

.product__link {
  display: inline-block;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--cyan);
  text-decoration: none;
}

.product--frameiq .product__link { color: var(--forest); }

.product__link:hover { text-decoration: underline; }

/* ---- #philosophy ---- */

.philosophy__manifesto {
  font-family: 'DM Sans', sans-serif;
  font-size: 19px;
  line-height: 1.75;
  color: var(--ink);
  max-width: 740px;
  margin-top: 8px;
}

.trust-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin-top: 64px;
}

@media (max-width: 860px) {
  .trust-grid { grid-template-columns: 1fr; }
}

.trust-card {
  background: var(--paper-hi);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
}

.trust-card h3 {
  font-family: 'Instrument Serif', serif;
  font-weight: 400;
  font-size: 23px;
  color: var(--ink);
  margin-bottom: 12px;
}

.trust-card p {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--muted);
}

/* ---- #story ---- */

.story-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 64px;
  margin-top: 48px;
  align-items: start;
}

@media (max-width: 860px) {
  .story-grid { grid-template-columns: 1fr; gap: 40px; }
}

.story__text p {
  font-family: 'DM Sans', sans-serif;
  font-size: 17px;
  line-height: 1.75;
  color: var(--ink);
  margin-bottom: 20px;
}

.story__sig {
  color: var(--muted);
  font-style: italic;
}

.story__sidebar {
  background: var(--paper-hi);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
}

.story__stat {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.story__stat:first-child { padding-top: 0; }
.story__stat:last-child { border-bottom: none; padding-bottom: 0; }

/* ---- #follow ---- */

.subscribe {
  margin: 40px 0 20px;
  max-width: 480px;
}

.subscribe__field {
  display: flex;
  gap: 12px;
}

.subscribe__field input[type="email"] {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper-hi);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
}

.subscribe__field input[type="email"]:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.subscribe__field button {
  padding: 14px 24px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper-hi);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}

.subscribe__field button:hover { opacity: 0.85; }

.hp {
  position: absolute;
  left: -9999px;
}

.subscribe__msg {
  margin-top: 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--muted);
  min-height: 1em;
}

.subscribe__msg.is-hidden { display: none; }

@media (max-width: 520px) {
  .subscribe__field { flex-direction: column; }
  /* 16px floor stops iOS Safari's focus auto-zoom */
  .subscribe__field input[type="email"] { font-size: 16px; }
}

.follow__quiet {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

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

.site-footer {
  background: var(--paper);
  color: var(--ink);
  padding: 48px 5.5vw;
  border-top: 1px solid var(--line);
}

.site-footer .footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin-bottom: 16px;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

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

.site-footer p {
  color: var(--muted); /* --hint fails AA contrast on parchment */
  font-size: 13px;
}

/* ============ reduced motion: scenes stack as stills ============ */

@media (prefers-reduced-motion: reduce) {
  .world__track { height: auto; }
  .scene { position: relative; opacity: 1; height: 100vh; }
  .world__sticky { position: relative; height: auto; overflow: visible; }
  .world *, .world *::before, .world *::after { animation: none !important; }
}

/* .world--still is added by the engine when it takes the reduced path
   (prefers-reduced-motion OR the __forceReducedMotion QA hook) — identical
   declarations to the media query above so both routes render the same. */
.world--still .world__track { height: auto; }
.world--still .scene { position: relative; opacity: 1; height: 100vh; }
.world--still .world__sticky { position: relative; height: auto; overflow: visible; }
.world--still *, .world--still *::before, .world--still *::after { animation: none !important; }
