/* Kingly Clark — see DESIGN.md */

:root {
  --bg:     oklch(0.965 0.004 290);
  --ink:    oklch(0.185 0.012 290);
  --muted:  oklch(0.45  0.010 290);
  --faint:  oklch(0.185 0.012 290 / 0.14);
  --accent: oklch(0.50  0.130 290);

  --serif: "Baskervville", "Iowan Old Style", Georgia, serif;
  --grot:  "Familjen Grotesk", "Avenir Next", "Helvetica Neue", sans-serif;

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);

  /* z scale: field < text < extras/chrome */
  --z-field: 1;
  --z-text: 2;
  --z-extras: 3;
  --z-chrome: 4;
}

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

html {
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  touch-action: manipulation; /* keep scroll + pinch, kill double-tap zoom on tap-bursts */
}

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

:focus-visible {
  outline: 1.5px solid var(--accent);
  outline-offset: 4px;
  border-radius: 1px;
}

/* ---------- Chrome ---------- */

.masthead {
  position: fixed;
  top: clamp(20px, 3.4vh, 34px);
  left: clamp(22px, 3.6vw, 44px);
  z-index: var(--z-chrome);
}

.wordmark {
  font-family: var(--grot);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

/* Scroll cue — the same instrument language as the meter (hairline track,
   traveling ember), stood upright. Retires once the reader takes the hint. */

.cue {
  position: fixed;
  bottom: clamp(20px, 4vh, 40px);
  left: 50%;
  transform: translateX(-50%);
  display: none; /* stage mode only */
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: var(--z-chrome);
  transition: opacity 0.7s var(--ease-out-quart);
  animation: cue-arrive 1.2s var(--ease-out-quart) 1.9s backwards;
}

@keyframes cue-arrive {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.cue-label {
  font-family: var(--grot);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  animation: cue-breathe 2.6s ease-in-out infinite;
}

/* pointer readers scroll; touch readers swipe (the cue is aria-hidden,
   so generated content costs nothing in the accessibility tree) */
.cue-label::after { content: "Scroll"; }

@media (pointer: coarse) {
  .cue-label::after { content: "Swipe"; }
}

@keyframes cue-breathe {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

.cue-track {
  position: relative;
  width: 1px;
  height: 46px;
  background: linear-gradient(
    to bottom,
    var(--faint) 0%,
    var(--faint) 70%,
    transparent 100%
  );
}

.cue-ember {
  position: absolute;
  left: 50%;
  top: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
  animation: cue-fall 2.4s var(--ease-out-quart) infinite;
}

/* the ember falls the length of the track, fading as it goes — the same
   dot the meter uses, telling you which way the page moves */
@keyframes cue-fall {
  0%        { top: 0;    opacity: 0; }
  12%       { opacity: 0.9; }
  62%       { opacity: 0.9; }
  82%, 100% { top: 46px; opacity: 0; }
}

/* reduced motion: no fall, no breathing — a static mark that still points down */
@media (prefers-reduced-motion: reduce) {
  .cue { animation: none; }
  .cue-label { animation: none; opacity: 0.9; }
  .cue-ember { animation: none; top: 46px; opacity: 0.9; }
}

/* ---------- Sequence: document flow (no-JS and reduced-motion) ---------- */

.seq {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 12svh clamp(24px, 7vw, 96px);
  gap: clamp(24px, 5vh, 48px);
}

/* one uniform statement size — no line shouts louder than another */
.statement {
  font-weight: 400;
  font-size: clamp(22px, 3.3vw, 46px);
  line-height: 1.26;
  letter-spacing: -0.005em;
  max-width: 32ch;
  text-wrap: balance;
}

.footnote {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.stamp {
  font-family: var(--grot);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--faint);
  padding: 5px 10px 4px 13px; /* extra left inset balances the tracking */
  transform: rotate(-2deg);
}

.aside {
  font-style: italic;
  font-size: clamp(15px, 1.6vw, 20px);
  color: var(--muted);
}

.marks {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: clamp(22px, 4vw, 52px);
  row-gap: 18px;
  max-width: 900px;
}

.marks li {
  font-family: var(--grot);
  font-weight: 500;
  font-size: clamp(12px, 1.3vw, 15px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.35s var(--ease-out-quart), transform 0.35s var(--ease-out-quart);
  cursor: default;
}

.marks li:hover {
  color: var(--ink);
  transform: translateY(-2px);
}

.colophon {
  font-family: var(--grot);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Stage mode (JS + motion OK): body.stage ---------- */

body.stage { cursor: crosshair; }

/* keep sequence text for assistive tech; visuals move to canvas */
body.stage #sequence {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body.stage .cue { display: flex; }
body.stage .cue.is-done { opacity: 0; }

.spacer { width: 1px; }

.stage-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

canvas.field    { z-index: var(--z-field); }
canvas.textbed  { z-index: var(--z-text); }

.stage-layer, canvas.field, canvas.textbed {
  opacity: 0;
  transition: opacity 1.1s var(--ease-out-quart);
}

body.stage.is-ready .stage-layer,
body.stage.is-ready canvas.field,
body.stage.is-ready canvas.textbed { opacity: 1; }

/* extras cloned into the stage overlay */
.overlay {
  z-index: var(--z-extras);
}

.overlay .extras {
  position: absolute;
  left: 50%;
  top: 66%;
  width: min(88vw, 960px);
  transform: translate(-50%, 14px);
  display: flex;
  justify-content: center;
  opacity: 0;
  filter: blur(6px);
  transition:
    opacity 0.9s var(--ease-out-quart),
    filter 0.9s var(--ease-out-quart),
    transform 0.9s var(--ease-out-expo);
  pointer-events: none;
}

.overlay .extras.is-live {
  opacity: 1;
  filter: blur(0);
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.overlay .extras.is-live .marks li {
  opacity: 0;
  animation: mark-in 0.8s var(--ease-out-quart) forwards;
  animation-delay: calc(var(--i, 0) * 90ms);
}

@keyframes mark-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* the one statement that arrives as real, permanent text */
.overlay .finale {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) translateY(10px);
  width: min(86vw, 880px);
  text-align: center;
  font-size: clamp(19px, 2.6vw, 34px);
  line-height: 1.42;
  letter-spacing: -0.002em;
  text-wrap: balance;
  opacity: 0;
  filter: blur(10px);
  transition:
    opacity 1.4s var(--ease-out-quart),
    filter 1.4s var(--ease-out-quart),
    transform 1.4s var(--ease-out-expo);
  pointer-events: none;
}

.overlay .finale.is-live {
  opacity: 1;
  filter: blur(0);
  transform: translate(-50%, -50%);
}

.overlay .colophon-slot {
  position: absolute;
  left: 50%;
  bottom: clamp(20px, 4vh, 40px);
  transform: translateX(-50%);
  top: auto;
  width: auto;
}

/* ---------- Progress meter (stage mode, built by JS) ----------
   a small instrument at the foot of the page: roman numeral, hairline
   track with a tick per statement, and an ember that travels with the
   scrub. Appears once the scroll cue retires; stands aside at the finale. */

.meter {
  position: fixed;
  bottom: clamp(18px, 3.6vh, 36px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 10px 8px;
  z-index: var(--z-chrome);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.9s var(--ease-out-quart) 0.35s;
}

.meter.is-on { opacity: 1; pointer-events: auto; }
.meter.is-parked { opacity: 0; pointer-events: none; transition-delay: 0s; }

.meter-numeral {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  line-height: 1;
  min-width: 2.6em;
  text-align: right;
  opacity: 0.85;
}

.meter-numeral.swap {
  animation: numeral-in 0.6s var(--ease-out-quart);
}

@keyframes numeral-in {
  from { opacity: 0.1; filter: blur(4px); }
  to   { opacity: 0.85; filter: blur(0); }
}

.meter-track {
  position: relative;
  width: clamp(110px, 16vw, 170px);
  height: 1px;
  background: var(--faint);
}

.meter-tick {
  position: absolute;
  top: 50%;
  width: 1px;
  height: 5px;
  transform: translate(-0.5px, -50%);
  background: var(--ink);
  opacity: 0.22;
  transition: opacity 0.3s;
}

.meter:hover .meter-tick { opacity: 0.4; }

.meter-ember {
  position: absolute;
  top: 50%;
  left: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
  will-change: left;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
