/*
 * The Snow Man — Wallace Stevens
 *
 * Design system: "Frozen Glass"
 * The poem is about looking through nothingness and finding nothingness.
 * The page should feel like a cold, still room with one thing written on the wall.
 *
 * Typography: Cormorant Garamond — high-contrast serif with crystalline thin strokes.
 *   Its sharp, elegant hairlines evoke frost. It's a typeface that can feel beautiful
 *   and cold at the same time, which is exactly what Stevens is doing.
 *
 * Color: Near-monochromatic blue-grays. The poem takes place in January.
 *   No warmth. Light mode is overcast daylight; dark mode is a winter evening window.
 *
 * Hook: Stanzas dissolve in opacity as you read — the poem literally fades toward
 *   "the nothing that is." Hovering a stanza restores it. You must attend to read.
 */


/* ── Tokens ─────────────────────────────────────────────────────── */

:root {
  /* Light mode: overcast daylight on cold paper */
  --bg:           #e8ecf0;
  --bg-subtle:    #dce2e8;
  --frost-color:  rgba(180, 200, 220, 0.25);
  --text:         #1c2632;
  --text-muted:   #5a6a7a;
  --text-faint:   #8899aa;
  --rule:         rgba(28, 38, 50, 0.08);

  /* Type scale — generous but not shouting */
  --font-poem:    'Cormorant Garamond', 'Garamond', 'Georgia', serif;
  --size-title:   clamp(1.1rem, 2.5vw, 1.5rem);
  --size-body:    clamp(1.35rem, 3.5vw, 1.85rem);
  --size-attr:    clamp(0.8rem, 1.5vw, 0.95rem);

  --leading:      1.75;
  --stanza-gap:   2.25em;

  /* Opacity dissolve — each stanza loses presence */
  --opacity-1: 1;
  --opacity-2: 0.82;
  --opacity-3: 0.64;
  --opacity-4: 0.46;
  --opacity-5: 0.30;

  /* Motion */
  --duration-hover:  0.5s;
  --duration-breath: 12s;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark mode: deep winter evening, not black — slate blue */
    --bg:           #111820;
    --bg-subtle:    #161e28;
    --frost-color:  rgba(120, 150, 190, 0.08);
    --text:         #c4d0dc;
    --text-muted:   #7a8a9a;
    --text-faint:   #4a5a6a;
    --rule:         rgba(196, 208, 220, 0.06);
  }
}


/* ── Reset & Base ───────────────────────────────────────────────── */

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

html {
  font-size: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-poem);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  transition: background-color 0.6s ease, color 0.6s ease;
}


/* ── Frost — ambient light shift ────────────────────────────────── */
/*
 * A barely-visible radial gradient that slowly breathes,
 * like cold light shifting through a window. You almost
 * don't notice it — but you'd notice if it stopped.
 */

.frost {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      ellipse 80% 60% at 30% 25%,
      var(--frost-color),
      transparent 70%
    );
  animation: frost-breathe var(--duration-breath) ease-in-out infinite alternate;
}

@keyframes frost-breathe {
  0% {
    opacity: 0.4;
    transform: scale(1) translate(0, 0);
  }
  100% {
    opacity: 1;
    transform: scale(1.15) translate(2%, 3%);
  }
}


/* ── Poem Container ─────────────────────────────────────────────── */

main {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 40rem;
  padding: 3rem 2rem;
}

.poem {
  display: flex;
  flex-direction: column;
  gap: var(--stanza-gap);
}


/* ── Title ──────────────────────────────────────────────────────── */
/*
 * Small, quiet, letterspaced. The title isn't the event here —
 * the poem is. The title is a label on the wall next to the painting.
 */

.poem-title {
  font-family: var(--font-poem);
  font-size: var(--size-title);
  font-weight: 300;
  font-style: italic;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  text-transform: none;
  margin-bottom: 0.5em;
  padding-bottom: 1em;
  border-bottom: 1px solid var(--rule);
}


/* ── Stanzas ────────────────────────────────────────────────────── */
/*
 * The dissolve: each stanza is slightly more transparent than the last.
 * The poem moves toward "nothing" — so does the ink. Hovering restores
 * the stanza: you must bring your attention, your "mind of winter."
 */

.poem-body {
  display: flex;
  flex-direction: column;
  gap: var(--stanza-gap);
}

.stanza {
  font-size: var(--size-body);
  font-weight: 300;
  line-height: var(--leading);
  transition: opacity var(--duration-hover) ease;
}

.stanza p {
  /* Each line of verse — no extra spacing between lines in a stanza */
  text-indent: 0;
}

/* The dissolve gradient */
.stanza[data-stanza="1"] { opacity: var(--opacity-1); }
.stanza[data-stanza="2"] { opacity: var(--opacity-2); }
.stanza[data-stanza="3"] { opacity: var(--opacity-3); }
.stanza[data-stanza="4"] { opacity: var(--opacity-4); }
.stanza[data-stanza="5"] { opacity: var(--opacity-5); }

/* Attention restores clarity */
.stanza:hover,
.stanza:focus-within {
  opacity: 1;
}

/*
 * When you hover any stanza, the NON-hovered ones dim further —
 * isolating the one you're reading. The spotlight of attention.
 */
.poem-body:hover .stanza:not(:hover) {
  opacity: calc(var(--opacity-5) * 0.7);
}

/* But restore the dissolve order for non-hovered stanzas cleanly */
.poem-body:hover .stanza[data-stanza="1"]:not(:hover) { opacity: calc(var(--opacity-1) * 0.4); }
.poem-body:hover .stanza[data-stanza="2"]:not(:hover) { opacity: calc(var(--opacity-2) * 0.35); }
.poem-body:hover .stanza[data-stanza="3"]:not(:hover) { opacity: calc(var(--opacity-3) * 0.3); }
.poem-body:hover .stanza[data-stanza="4"]:not(:hover) { opacity: calc(var(--opacity-4) * 0.25); }
.poem-body:hover .stanza[data-stanza="5"]:not(:hover) { opacity: calc(var(--opacity-5) * 0.25); }


/* ── Attribution ────────────────────────────────────────────────── */
/*
 * Quiet. The poet's name and year, separated by a dash.
 * Same weight as the title — these are labels, not headlines.
 */

.poem-attribution {
  display: flex;
  align-items: baseline;
  gap: 0.75em;
  padding-top: 1.5em;
  border-top: 1px solid var(--rule);
  font-size: var(--size-attr);
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.poet-name {
  /* A touch more weight to distinguish from the year */
  font-weight: 500;
}

.poem-year {
  color: var(--text-faint);
}

.poem-attribution .poet-name::after {
  content: "·";
  margin-left: 0.75em;
  color: var(--text-faint);
  font-weight: 300;
}


/* ── Entrance animation ─────────────────────────────────────────── */
/*
 * Stanzas fade in sequentially, as if being written.
 * Each one appears slightly after the last — the poem
 * builds its single sentence in real time.
 */

.stanza {
  animation: emerge 1.8s ease-out both;
}

.stanza[data-stanza="1"] { animation-delay: 0.3s; }
.stanza[data-stanza="2"] { animation-delay: 0.7s; }
.stanza[data-stanza="3"] { animation-delay: 1.1s; }
.stanza[data-stanza="4"] { animation-delay: 1.5s; }
.stanza[data-stanza="5"] { animation-delay: 1.9s; }

@keyframes emerge {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  /* 'to' state is the stanza's own data-stanza opacity — handled by the cascade */
}

.poem-title {
  animation: emerge-title 1.5s ease-out both;
}

@keyframes emerge-title {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
  }
}

.poem-attribution {
  animation: emerge-title 1.2s ease-out 2.4s both;
}


/* ── Reduced Motion ─────────────────────────────────────────────── */
/*
 * Kill all animation and transition. The opacity dissolve stays
 * (it's not motion, it's a static visual treatment) but the
 * frost breathing and entrance animations go away.
 */

@media (prefers-reduced-motion: reduce) {
  .frost {
    animation: none;
    opacity: 0.7;
  }

  .stanza,
  .poem-title,
  .poem-attribution {
    animation: none;
  }

  .stanza {
    transition: none;
  }

  /* Restore static opacities without transition */
  .stanza[data-stanza="1"] { opacity: var(--opacity-1); }
  .stanza[data-stanza="2"] { opacity: var(--opacity-2); }
  .stanza[data-stanza="3"] { opacity: var(--opacity-3); }
  .stanza[data-stanza="4"] { opacity: var(--opacity-4); }
  .stanza[data-stanza="5"] { opacity: var(--opacity-5); }
}


/* ── Mobile adjustments ─────────────────────────────────────────── */

@media (max-width: 480px) {
  main {
    padding: 2.5rem 1.5rem;
  }

  :root {
    --stanza-gap: 1.75em;
  }
}

/* Tall, narrow screens — center a bit more aggressively */
@media (max-height: 680px) and (max-width: 480px) {
  body {
    align-items: flex-start;
    padding-top: 1.5rem;
  }
}


/* ── Touch devices — no hover, so show full poem ────────────────── */
/*
 * On touch-only devices, the hover-to-reveal mechanic doesn't work.
 * We soften the dissolve so it's more of a gentle gradient than
 * a legibility challenge. The poem should be readable without hover.
 */

@media (hover: none) {
  :root {
    --opacity-1: 1;
    --opacity-2: 0.90;
    --opacity-3: 0.78;
    --opacity-4: 0.65;
    --opacity-5: 0.52;
  }

  /* Don't dim siblings on touch */
  .poem-body:hover .stanza:not(:hover) {
    opacity: unset;
  }
  .poem-body:hover .stanza[data-stanza="1"]:not(:hover) { opacity: var(--opacity-1); }
  .poem-body:hover .stanza[data-stanza="2"]:not(:hover) { opacity: var(--opacity-2); }
  .poem-body:hover .stanza[data-stanza="3"]:not(:hover) { opacity: var(--opacity-3); }
  .poem-body:hover .stanza[data-stanza="4"]:not(:hover) { opacity: var(--opacity-4); }
  .poem-body:hover .stanza[data-stanza="5"]:not(:hover) { opacity: var(--opacity-5); }
}


/* ── Print ──────────────────────────────────────────────────────── */

@media print {
  .frost { display: none; }

  body {
    background: white;
    color: black;
  }

  .stanza {
    opacity: 1 !important;
    animation: none;
  }
}
