/* For Luddites page only. Everything else comes from site.css.
   The timeline has a plant stem down its left side. The resting state is the
   finished plant: stem fully grown, every leaf open. Growth with scroll is
   switched on only when luddites.js adds .is-growing (scripts on, motion
   allowed). It is driven by a CSS scroll timeline where supported, otherwise
   luddites.js sets --lud-grow and .is-open itself. Text never waits for it. */

@property --lud-grow {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

.lud-timeline {
  --lud-stem: var(--forest);
  --lud-leaf: var(--leaf);
  --lud-node: var(--accent);
  --lud-ring: var(--paper);
  --lud-col: 2.5rem;      /* room left of the entries */
  --lud-x: 1.05rem;       /* stem centre, from the left edge */
  --lud-grow: 1;
  position: relative;
  max-width: 46rem;
  padding-left: var(--lud-col);
  margin-top: var(--space-6);
}
:root[data-theme="dark"] .lud-timeline {
  --lud-stem: var(--mark-leaf);
  --lud-leaf: var(--leaf);
  --lud-ring: var(--paper);
}
@media (min-width: 40rem) {
  .lud-timeline { --lud-col: 4rem; --lud-x: 1.6rem; }
}

/* The stem: a calm flat line that grows downward from the first node to the bud. */
.lud-stem {
  position: absolute;
  left: calc(var(--lud-x) - 1.5px);
  top: 0.95rem;
  bottom: 2rem;
  width: 3px;
  pointer-events: none;
}
.lud-stem__line {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: var(--lud-stem);
  transform-origin: 50% 0;
  transform: scaleY(var(--lud-grow));
}

.lud-list { list-style: none; padding: 0; margin: 0; }
.lud-list > li + li { margin-top: var(--space-7); }
.lud-entry { position: relative; }
.lud-entry > * + * { margin-top: var(--space-2); }
.lud-entry > .source-line { margin-top: var(--space-3); }
.lud-entry__date {
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}
.lud-entry h3 { margin-top: var(--space-1); }

/* Each entry hangs off a marigold node on the stem, with one leaf beside it.
   Leaves alternate sides. Both are decoration and carry aria-hidden. */
.lud-sprig {
  position: absolute;
  top: 0.95rem;
  left: calc(var(--lud-x) - var(--lud-col));
  width: 0; height: 0;
  pointer-events: none;
}
.lud-sprig__node {
  position: absolute;
  left: -0.4rem; top: -0.4rem;
  width: 0.8rem; height: 0.8rem;
  border-radius: 50%;
  background: var(--lud-node);
  box-shadow: 0 0 0 3px var(--lud-ring);
}
.lud-sprig__leaf {
  position: absolute;
  bottom: 0.1rem;
  width: 0.95rem; height: 0.95rem;
  background: var(--lud-leaf);
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s ease;
}
/* Right-hand leaf: base at the bottom left corner, tip up and to the right. */
.lud-sprig__leaf--r {
  left: 0.15rem;
  border-radius: 100% 0;
  transform-origin: 0 100%;
  background-image: linear-gradient(to bottom right, transparent calc(50% - 0.6px), var(--lud-ring) calc(50% - 0.6px) calc(50% + 0.6px), transparent calc(50% + 0.6px));
}
/* Left-hand leaf: the mirror image. */
.lud-sprig__leaf--l {
  right: 0.15rem;
  border-radius: 0 100%;
  transform-origin: 100% 100%;
  background-image: linear-gradient(to top right, transparent calc(50% - 0.6px), var(--lud-ring) calc(50% - 0.6px) calc(50% + 0.6px), transparent calc(50% + 0.6px));
}
@media (min-width: 40rem) {
  .lud-sprig__leaf { width: 1.15rem; height: 1.15rem; }
}

/* The bud at the end of the stem: the site's own leaf mark. */
.lud-bud {
  position: relative;
  height: 2.6rem;
  margin-top: var(--space-5);
  pointer-events: none;
}
.lud-bud .mark {
  position: absolute;
  left: calc(var(--lud-x) - var(--lud-col) - 1rem);
  top: 0.3rem;
  width: 2rem; height: 2rem;
  transform-origin: 50% 0;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease;
}

/* ---------- Growing (only with .is-growing, set by luddites.js) ---------- */

/* Script fallback: luddites.js sets --lud-grow on the timeline and .is-open on
   each entry once the stem reaches it. */
.lud-timeline.is-growing .lud-sprig__leaf--r { transform: rotate(-42deg) scale(0.2); opacity: 0; }
.lud-timeline.is-growing .lud-sprig__leaf--l { transform: rotate(42deg) scale(0.2); opacity: 0; }
.lud-timeline.is-growing .lud-sprig__node { transform: scale(0.4); transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.lud-timeline.is-growing .lud-bud .mark { transform: scale(0.3) rotate(-20deg); opacity: 0; }
.lud-timeline.is-growing .is-open .lud-sprig__leaf,
.lud-timeline.is-growing .is-open .lud-sprig__node,
.lud-timeline.is-growing .lud-bud.is-open .mark { transform: none; opacity: 1; }

/* Scroll-driven version. The stem tip tracks a line about 60% of the way
   down the window; each leaf opens as that line passes it. */
@supports (animation-timeline: view()) {
  .lud-timeline.is-growing.is-scroll-driven .lud-stem {
    animation: lud-grow linear both;
    animation-timeline: view();
    animation-range: cover 40vh cover calc(100% - 60vh);
  }
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__leaf,
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__node,
  .lud-timeline.is-growing.is-scroll-driven .lud-bud .mark { transition: none; }
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__leaf--r { animation: lud-unfurl-r linear both; }
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__leaf--l { animation: lud-unfurl-l linear both; }
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__node { animation: lud-node linear both; }
  .lud-timeline.is-growing.is-scroll-driven .lud-bud .mark { animation: lud-bud linear both; }
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__leaf,
  .lud-timeline.is-growing.is-scroll-driven .lud-sprig__node,
  .lud-timeline.is-growing.is-scroll-driven .lud-bud .mark {
    animation-timeline: view();
    animation-range: cover 38vh cover 50vh;
  }
}
@keyframes lud-grow { from { --lud-grow: 0; } to { --lud-grow: 1; } }
@keyframes lud-unfurl-r { from { transform: rotate(-42deg) scale(0.2); opacity: 0; } 40% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes lud-unfurl-l { from { transform: rotate(42deg) scale(0.2); opacity: 0; } 40% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes lud-node { from { transform: scale(0.4); } to { transform: none; } }
@keyframes lud-bud { from { transform: scale(0.3) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* Reduced motion: the finished plant, whatever the script did. */
@media (prefers-reduced-motion: reduce) {
  .lud-timeline { --lud-grow: 1 !important; }
  .lud-timeline .lud-sprig__leaf,
  .lud-timeline .lud-sprig__node,
  .lud-timeline .lud-bud .mark { transform: none !important; opacity: 1 !important; }
}

/* ---------- The rest of the page ---------- */
.lud-letter {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-left: 3px solid var(--accent-line);
  background: var(--surface-2);
  border-radius: 0 var(--radius-m) var(--radius-m) 0;
  max-width: var(--measure);
}
.lud-letter p { font-family: var(--font-display); font-size: var(--step-1); line-height: 1.45; }
.lud-letter .source-line { font-family: var(--font-body); font-size: var(--step--1); }
.lud-reading { padding-left: 1.2em; }
.lud-reading li + li { margin-top: var(--space-3); }
