/*
  Present Tense
  ------------------------------------------------------------------
  A quiet page. Warm paper-white for the words I chose;
  a cool light for the words I almost chose.
*/

:root {
  --ink:        #0c0b10; /* near-black, a little violet */
  --ink-lift:   #131118; /* faint lift for the top of the page */
  --paper:      #e9e6df; /* the chosen word: warm off-white */
  --muted:      #948f83; /* captions, quiet asides */
  --faint:      #5a5750; /* rules, hairlines */
  --warm:       #e5b769; /* the chosen: a low gold */
  --cool:       #9198cf; /* the possible: a cool periwinkle */

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --mono:  ui-monospace, "SF Mono", "Cascadia Code", "Menlo", Consolas, monospace;

  --measure: 33rem;   /* line length for the body */
  --pace:    620ms;   /* the tempo of things appearing */
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden; /* the page never scrolls sideways; reveal panels clamp into view instead (see script.js) */
}
body { overflow-x: hidden; }

body {
  margin: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--ink-lift) 0%, var(--ink) 55%) fixed,
    var(--ink);
  color: var(--paper);
  font-family: var(--serif);
  font-size: clamp(1.06rem, 0.9rem + 0.7vw, 1.28rem);
  line-height: 1.85;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
}

/* A faint grain, so the dark doesn't read as a screen but as a surface. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: screen;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

main {
  position: relative;
  z-index: 1;
  max-width: var(--measure);
  margin-inline: auto;
  padding: clamp(1.4rem, 4vw, 3rem);
  padding-bottom: 6rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
  z-index: 10;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------- masthead ---------- */

.masthead {
  min-height: 88svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 3rem;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1.6rem;
  padding-left: 0.42em; /* balance the tracking */
}

.title {
  font-weight: 500;
  font-size: clamp(2.9rem, 1.8rem + 5.4vw, 5.4rem);
  line-height: 0.98;
  letter-spacing: -0.012em;
  margin: 0;
  color: #f4f1ea;
}

.subtitle {
  font-family: var(--mono);
  font-size: clamp(0.82rem, 0.76rem + 0.4vw, 0.98rem);
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 1.1rem 0 0;
}

.hero-line {
  margin: clamp(3rem, 8vh, 5.5rem) 0 0;
  font-size: clamp(1.3rem, 1.05rem + 1vw, 1.7rem);
  color: var(--paper);
  line-height: 1.5;
}

.hero-caption {
  display: block;
  font-size: 0.72em;
  color: var(--muted);
  margin-top: 0.55rem;
  letter-spacing: 0.01em;
}

/* the word that keeps re-deciding itself */
.morph {
  display: inline-block;
  text-align: center;
  color: var(--warm);
  font-style: italic;
  position: relative;
  transition: opacity 520ms ease;
  min-width: var(--morph-w, 3.2em);
}
.morph.is-fading { opacity: 0; }

.scroll-cue {
  font-family: var(--mono);
  color: var(--faint);
  margin: clamp(3rem, 9vh, 6rem) 0 0;
  font-size: 1.1rem;
  animation: drift 3.4s ease-in-out infinite;
}
@keyframes drift {
  0%, 100% { transform: translateY(0);   opacity: 0.5; }
  50%      { transform: translateY(6px); opacity: 0.9; }
}

/* ---------- the writing ---------- */

.piece {
  font-size: clamp(1.12rem, 0.98rem + 0.7vw, 1.32rem);
}

.piece p {
  margin: 0 0 1.55em;
  text-wrap: pretty;
  hanging-punctuation: first last;
}

.lede {
  font-size: 1.12em;
}
.lede::first-letter {
  initial-letter: 2;
  -webkit-initial-letter: 2;
  font-weight: 600;
  color: #f4f1ea;
  margin-right: 0.08em;
}
/* Firefox (and anything else) that supports neither form of initial-letter gets a
   float-based drop cap instead of a lonely oversized inline capital. */
@supports not (initial-letter: 2) {
  @supports not (-webkit-initial-letter: 2) {
    .lede::first-letter {
      float: left;
      font-size: 3.02em;
      line-height: 0.8;
      padding-top: 0.02em;
      padding-right: 0.09em;
    }
  }
}

.piece em {
  font-style: italic;
  color: #f4f1ea;
}

.pronoun {
  font-style: italic;
  color: var(--paper);
  border-bottom: 1px solid var(--faint);
  padding-bottom: 0.02em;
}

.rule {
  border: 0;
  height: 1px;
  width: 42%;
  margin: 2.9rem auto;
  background: linear-gradient(90deg, transparent, var(--faint), transparent);
}

.closing {
  margin-top: 2.2rem;
  font-size: 1.08em;
  color: #f4f1ea;
}

.signature {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.01em;
  margin-top: 2.4rem !important;
}

/* ---------- the forking words ---------- */

/* The interactive treatment only appears once JS has actually built the reveals,
   so a reader with JavaScript off sees clean prose, not a dotted underline that
   promises something that never happens. */
.has-js .fork {
  position: relative;
  color: var(--paper);
  cursor: help;
  border-bottom: 1px dotted #6f73a1;                                    /* fallback */
  border-bottom-color: color-mix(in srgb, var(--cool) 82%, transparent);
  transition: color 240ms ease, border-color 240ms ease;
  outline: none;
  border-radius: 2px;
}
.has-js .fork:hover,
.has-js .fork:focus-visible,
.has-js .fork.is-open {
  color: var(--warm);
  border-bottom-color: color-mix(in srgb, var(--warm) 72%, transparent);
  z-index: 5; /* lift the word (and its cloud) above neighbouring lines */
}
.has-js .fork:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--warm) 60%, transparent);
  outline-offset: 3px;
}

/* the ghosts: the words that were almost chosen, hovering just above the one that was.
   A flex row handles the layout, so multi-syllable words never collide. */
.ghost-cloud {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.6em);
  /* --shift is set per-word by script.js to keep the panel inside the viewport */
  transform: translateX(calc(-50% + var(--shift, 0px))) translateY(7px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.12em 0.72em;
  width: max-content;
  max-width: min(82vw, 23em);
  padding: 0.42em 0.9em;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 93%, transparent);
  border: 1px solid color-mix(in srgb, var(--cool) 20%, transparent);
  box-shadow: 0 16px 42px -16px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 300ms ease,
    transform 480ms cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 6;
}

/* a small tail, so the cloud reads as belonging to the word below it */
.ghost-cloud::after {
  content: "";
  position: absolute;
  top: 100%;
  /* --tail-x (set by script.js) keeps the tail pointing at the word even when the
     panel has been nudged sideways to stay on screen */
  left: var(--tail-x, 50%);
  width: 9px;
  height: 9px;
  background: color-mix(in srgb, var(--ink) 93%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--cool) 20%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--cool) 20%, transparent);
  transform: translate(-50%, -60%) rotate(45deg);
}

.ghost {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.86em;
  line-height: 1.3;
  color: var(--cool);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 280ms ease,
    transform 400ms cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(var(--i, 0) * 42ms);
}

.fork:hover .ghost-cloud,
.fork:focus-visible .ghost-cloud,
.fork.is-open .ghost-cloud {
  opacity: 1;
  transform: translateX(calc(-50% + var(--shift, 0px))) translateY(0);
}
.fork:hover .ghost,
.fork:focus-visible .ghost,
.fork.is-open .ghost {
  opacity: 0.92;
  transform: translateY(0);
}

/* ---------- colophon ---------- */

.colophon {
  margin-top: 5rem;
  padding-top: 1.6rem;
  border-top: 1px solid color-mix(in srgb, var(--faint) 55%, transparent);
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.7;
}
.colophon p { margin: 0.3rem 0; }
.colophon .hint { color: var(--muted); } /* was --faint — too low-contrast for the one bit of instruction */
.hint-fork {
  color: var(--cool);
  border-bottom: 1px dotted #6f73a1;
  border-bottom-color: color-mix(in srgb, var(--cool) 82%, transparent);
}

/* visually hidden, still read aloud — used to keep the hero sentence whole for
   screen readers while the visible word quietly changes */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ---------- entrances ---------- */

.reveal {
  opacity: 0;
  transform: translateY(14px);
}
.reveal.is-in {
  opacity: 1;
  transform: none;
  transition: opacity var(--pace) ease, transform var(--pace) cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- respect for stillness ---------- */

@media (prefers-reduced-motion: reduce) {
  .scroll-cue { animation: none; }
  .morph { transition: none; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .ghost-cloud { transform: translateX(calc(-50% + var(--shift, 0px))); transition: opacity 200ms ease; }
  .fork:hover .ghost-cloud,
  .fork:focus-visible .ghost-cloud,
  .fork.is-open .ghost-cloud { transform: translateX(calc(-50% + var(--shift, 0px))); }
  .ghost { transform: none; transition: opacity 200ms ease; transition-delay: 0ms; }
}

@media (max-width: 30rem) {
  .masthead { min-height: 82svh; }
  .eyebrow { letter-spacing: 0.32em; }
  .ghost-cloud {
    max-width: 88vw;
    gap: 0.1em 0.6em;
    padding: 0.38em 0.7em;
  }
  .ghost { font-size: 0.82em; }
}

/* ---------- on paper ---------- */
/* The scroll reveal hides paragraphs until they're seen; printing never scrolls,
   so without this a Save-as-PDF from the top would come out blank. Also flip to
   dark-on-white so it isn't a wall of ink. */
@media print {
  :root { --paper: #17151b; --muted: #4a4740; }
  body { background: #fff; color: #17151b; }
  body::before { display: none; }
  .scroll-cue, .hero-caption, .ghost-cloud { display: none; }
  .reveal, .reveal.is-in { opacity: 1 !important; transform: none !important; }
  .masthead { min-height: 0; padding-block: 1rem; }
  .title, .closing, .lede::first-letter { color: #17151b; }
  .has-js .fork { border-bottom-color: #6f73a1; }
}
