/* Motion levels: <html data-motion="full|calm"> is set by an inline script before first paint.
   full  — everything moves.
   calm  — the visitor asked for less motion: no travel, tilt, parallax or loops;
           fades and colour changes stay so state changes are still visible.
   none  — no JavaScript: no attribute, the page is static and complete. */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
  -webkit-text-size-adjust: 100%;
}
[data-motion="calm"] { scroll-behavior: auto; }

body {
  margin: 0;
  background: var(--day);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--body);
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

h1, h2, h3, p, ol, ul, figure { margin: 0; padding: 0; }
ol, ul { list-style: none; }
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }
button, input { font: inherit; color: inherit; }
h1, h2, .brand, .menu a { overflow-wrap: break-word; hyphens: auto; }

:focus-visible { outline: 3px solid var(--pen); outline-offset: 3px; }
::selection { background: color-mix(in srgb, var(--pen) 22%, transparent); }

.skip {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 40;
  padding: 0.85rem 1.1rem;
  background: var(--ink);
  color: var(--noon);
  text-decoration: none;
}
.skip:focus { top: 1rem; }

/* One light source for the whole page: a window up and to the right. */
.light {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: radial-gradient(120vmax 90vmax at var(--lx, 88%) var(--ly, -10%), var(--noon), transparent 62%);
  pointer-events: none;
}
.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  opacity: 0.07;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.wrap {
  max-width: 78rem;
  margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
}
.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
}

/* ---------- Header and menu ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--day);
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 70%, transparent);
}
.top .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.75rem;
}
.brand {
  font: 800 1.7rem/1 var(--display);
  letter-spacing: 0.01em;
  text-decoration: none;
}
.brand i { font-style: normal; color: var(--pen); }

.menu-btn {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 30;
  min-width: 5.5rem;
  min-height: 3.25rem;
  padding: 0 1.25rem;
  border: 0;
  border-radius: 2px;
  background: var(--ink);
  color: var(--noon);
  font: 600 1rem/1 var(--body);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--fast) var(--ease);
}
.menu-btn:active { transform: scale(0.96); }

.menu {
  inset: auto 0 0 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 1.25rem var(--gutter) calc(5.5rem + env(safe-area-inset-bottom));
  border: 0;
  border-top: 3px solid var(--ink);
  background: var(--noon);
  color: var(--ink);
  opacity: 0;
  transition: translate var(--base) var(--ease), opacity var(--base), display var(--base) allow-discrete, overlay var(--base) allow-discrete;
}
[data-motion="full"] .menu { translate: 0 1.5rem; }
.menu:popover-open { translate: 0 0; opacity: 1; }
@starting-style { .menu:popover-open { opacity: 0; } }
@starting-style { [data-motion="full"] .menu:popover-open { translate: 0 1.5rem; } }
.menu::backdrop { background: color-mix(in srgb, var(--ink) 35%, transparent); }

.menu a {
  display: flex;
  align-items: center;
  min-height: 3.5rem;
  border-bottom: 1px solid var(--rule);
  font: 700 2rem/1 var(--display);
  text-decoration: none;
}
.menu a[aria-current="true"] { color: var(--pen); }

@media (min-width: 60rem) {
  .menu-btn { display: none; }
  .menu {
    display: flex;
    gap: 2rem;
    position: static;
    width: auto;
    padding: 0;
    border: 0;
    background: none;
    overflow: visible;
    opacity: 1;
  }
  .menu, [data-motion="full"] .menu { translate: none; }
  .menu a {
    min-height: 3.75rem;
    border: 0;
    font: 500 var(--step--1)/1 var(--body);
    background: linear-gradient(var(--pen), var(--pen)) no-repeat 0 calc(100% - 1rem) / 0 2px;
    transition: background-size var(--base) var(--ease);
  }
  .menu a:hover, .menu a[aria-current="true"] { background-size: 100% 2px; }
  .menu a[aria-current="true"] { color: var(--ink); }
}

/* ---------- Opening story ---------- */

.story { position: relative; }

.stage {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  margin-top: -3.75rem; /* slide under the sticky header */
  padding-block: 5rem 3.5rem;
  overflow: clip;
  isolation: isolate;
}
.stage > .wrap { width: 100%; }

/* Photograph of morning light on paper; the window light grows as the visitor scrolls on. */
.stage-bg {
  position: absolute;
  inset: -2%;
  z-index: -1;
  background: var(--day) url("../img/dawn.webp") 70% 0 / cover no-repeat;
}
.stage-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(110vmax 80vmax at 86% -8%, var(--noon), transparent 64%),
    linear-gradient(transparent 70%, var(--day));
  opacity: 0.5;
}

.stage h1 {
  grid-column: 1 / -1;
  font: 800 var(--step-3)/0.9 var(--display);
  letter-spacing: -0.005em;
  text-wrap: balance;
}
.stage h1 em { font-style: normal; color: var(--pen); }

.pad-wrap {
  grid-column: 1 / -1;
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 1.1rem;
  margin-top: 2rem;
}
.pad {
  position: relative;
  width: clamp(9rem, 5rem + 15vw, 15.5rem);
  aspect-ratio: 4 / 4.5;
  rotate: -2deg;
  perspective: 700px;
}
/* binding strip along the top of the pad */
.pad::before {
  content: "";
  position: absolute;
  left: -5%;
  right: -5%;
  top: -8%;
  height: 11%;
  z-index: 3;
  border-radius: 3px 3px 1px 1px;
  background: var(--ink);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--noon) 14%, transparent);
}
.pad-stack {
  position: absolute;
  inset: 0;
  background: var(--noon);
  box-shadow:
    0 2px 0 -1px var(--noon), 0 3px 0 -1px var(--rule),
    0 5px 0 -2px var(--noon), 0 6px 0 -2px var(--rule),
    0 8px 0 -3px var(--noon), 0 9px 0 -3px var(--rule),
    0 28px 40px -22px color-mix(in srgb, var(--ink) 65%, transparent);
}

.leaf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2em;
  padding: 1rem 0.75rem;
  background: var(--noon);
  color: var(--ink);
  text-align: center;
  /* perforated top edge, where the leaf was torn from the binding */
  -webkit-mask: radial-gradient(circle 4px at 8px 0, transparent 97%, #000) -8px 0 / 16px 100%;
  mask: radial-gradient(circle 4px at 8px 0, transparent 97%, #000) -8px 0 / 16px 100%;
  transition: background-color var(--base), color var(--base);
}
.pad .leaf {
  position: absolute;
  inset: 0;
  transform-origin: 100% 0;
}
.leaf span { display: block; }
.leaf-month, .leaf-week {
  font: 400 0.78rem/1.2 var(--data);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: color var(--base);
}
.leaf-day {
  font: 800 clamp(4.6rem, 2.4rem + 7vw, 9rem)/0.92 var(--display);
  font-variant-numeric: tabular-nums;
}
.leaf.is-last { background: var(--deadline); color: var(--noon); }
.leaf.is-last .leaf-month, .leaf.is-last .leaf-week { color: color-mix(in srgb, var(--noon) 82%, transparent); }

/* after the last leaf the pad starts over from today: a fresh leaf settles onto the stack */
[data-motion="full"] .pad .leaf.refill { animation: refill 520ms var(--ease) both; }
@keyframes refill { from { opacity: 0; translate: 0 -12%; } }

.leaf.torn { z-index: 2; pointer-events: none; }
[data-motion="full"] .leaf.torn { animation: tear 720ms cubic-bezier(0.55, 0, 0.75, 0.45) forwards; }
[data-motion="calm"] .leaf.torn { animation: fade 200ms linear forwards; }
@keyframes tear {
  0%   { transform: rotate(0) translate(0, 0); }
  22%  { transform: rotate(-7deg) translate(-1%, 1%); }
  100% { transform: rotate(-34deg) translate(-38%, 150%); opacity: 0; }
}
@keyframes fade { to { opacity: 0; } }

/* the current leaf lifts its corner under the pointer, as paper would */
[data-motion="full"] .pad .leaf.is-current { transition: transform var(--base) var(--ease), background-color var(--base), color var(--base); }
@media (hover: hover) {
  [data-motion="full"] .pad:hover .leaf.is-current { transform: rotateX(8deg) rotate(-1.5deg); }
}

.count {
  min-height: 1.3em;
  font: 400 var(--step--1)/1.3 var(--data);
  color: var(--ink-soft);
}
.count b { font-weight: 400; color: var(--pen); }

/* stops the looping calendar (moving content longer than 5 s needs a way to stop it) */
.pad-toggle {
  min-height: 3rem;
  padding: 0 1rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: color-mix(in srgb, var(--noon) 70%, transparent);
  font: 400 var(--step--1)/1 var(--data);
  color: var(--ink-soft);
  cursor: pointer;
  touch-action: manipulation;
  transition: color var(--fast), border-color var(--fast);
}
.pad-toggle:hover { color: var(--ink); border-color: var(--ink); }

.lead {
  grid-column: 1 / -1;
  max-width: 27ch;
  margin-top: 1.5rem;
  font-size: var(--step-1);
  line-height: 1.35;
}
.lead b { font-weight: 600; color: var(--pen); }

.cta, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 3.5rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: 2px;
  background: var(--ink);
  color: var(--noon);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--fast) var(--ease), background-color var(--fast);
}
.cta:hover, .btn:hover { background: var(--pen); }
.cta:active, .btn:active { transform: translateY(2px); }
.cta span { transition: translate var(--base) var(--ease); }
[data-motion="full"] .cta:hover span { translate: 0 3px; }
.stage .cta {
  grid-column: 1 / -1;
  justify-self: start;
  margin-top: 1.5rem;
}

/* Legend strip: one cell per torn leaf, red cell at the end. */
.legend { grid-column: 1 / -1; margin-top: 2rem; }
.strip { display: flex; gap: 3px; }
.strip li {
  flex: 1 1 0;
  height: 2.25rem;
  background: color-mix(in srgb, var(--noon) 62%, transparent);
  border-top: 2px solid var(--rule);
  transition: background-color var(--base), border-color var(--base);
}
.strip li.is-past { background: color-mix(in srgb, var(--pen) 22%, var(--noon)); border-top-color: var(--pen); }
.strip li.is-now { border-top-color: var(--pen); background: var(--noon); }
.strip li.is-end { flex-grow: 1.6; background: var(--deadline); border-top-color: var(--deadline); }
.legend-keys {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.6rem;
  font-size: var(--step--1);
  line-height: 1.35;
  color: var(--ink-soft);
}
.legend-keys b { font-weight: 600; }
.legend-keys .k-pen { color: var(--pen); }
.legend-keys .k-end { color: var(--ink); text-align: right; }

.cue {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  translate: -50% 0;
  font: 400 0.75rem/1 var(--data);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cue i {
  display: block;
  width: 1px;
  height: 2.25rem;
  background: var(--ink-soft);
  transform-origin: top;
}
[data-motion="full"] .cue i { animation: cue 1.8s var(--ease) infinite; }
@keyframes cue {
  0%   { scale: 1 0; transform-origin: top; }
  50%  { scale: 1 1; transform-origin: top; }
  51%  { transform-origin: bottom; }
  100% { scale: 1 0; transform-origin: bottom; }
}

@media (min-width: 60rem) {
  .stage { padding-block: 6rem 5rem; }
  .stage h1 { grid-column: 1 / span 8; grid-row: 1; }
  .lead { grid-column: 1 / span 5; grid-row: 2; margin-top: 2.5rem; }
  .stage .cta { grid-column: 1 / span 5; grid-row: 3; margin-top: 2rem; }
  .pad-wrap { grid-column: 9 / span 4; grid-row: 1 / span 3; align-self: center; margin-top: 0; }
  .legend { grid-column: 1 / -1; grid-row: 4; margin-top: 3.5rem; }
  .strip li { height: 3rem; }
  [data-motion] .cue { display: flex; }
}

/* load sequence */
[data-motion="full"] .stage h1 { animation: rise 800ms var(--ease) both; }
[data-motion="full"] .lead, [data-motion="full"] .stage .cta { animation: rise 800ms var(--ease) 160ms both; }
[data-motion="full"] .pad { animation: drop 900ms cubic-bezier(0.3, 1.35, 0.5, 1) 220ms both; }
[data-motion="calm"] .stage h1, [data-motion="calm"] .pad { animation: fade-in 500ms linear both; }
@keyframes rise { from { opacity: 0; translate: 0 1.5rem; } }
@keyframes drop { from { opacity: 0; translate: 0 -3rem; rotate: 8deg; } }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- Sections ---------- */

.section { padding-block: var(--space-section) 0; }
.section:last-of-type { padding-bottom: var(--space-section); }
.section h2 {
  grid-column: 1 / -1;
  padding-top: 1.25rem;
  border-top: 3px solid var(--ink);
  font: 800 var(--step-2)/0.95 var(--display);
  text-wrap: balance;
}
.section-note {
  grid-column: 1 / -1;
  margin-top: 1rem;
  max-width: 34ch;
  color: var(--ink-soft);
}

@media (min-width: 60rem) {
  .section h2 {
    grid-column: 1 / span 4;
    grid-row: 1;
    position: sticky;
    top: 5rem;
    align-self: start;
    padding-top: 0;
    border-top: 0;
  }
  .section-note {
    grid-column: 1 / span 3;
    grid-row: 2;
    position: sticky;
    top: 13rem;
    align-self: start;
  }
}

/* reveal on entering the viewport (class "in" is added by ui.js) */
[data-motion] [data-reveal] { opacity: 0; transition: opacity 700ms var(--ease), translate 800ms var(--ease); }
[data-motion="full"] [data-reveal] { translate: 0 2rem; }
[data-motion] [data-reveal].in { opacity: 1; translate: 0 0; }

/* section 1: norms with marginal citations */
.norms { grid-column: 1 / -1; margin-top: 2.5rem; border-top: 3px solid var(--ink); }
.norm {
  display: grid;
  gap: 0.75rem;
  padding-block: 1.5rem;
  border-top: 1px solid var(--rule);
}
.norm:first-child { border-top: 0; }
.norm h3 { font: 600 var(--step-1)/1.25 var(--body); text-wrap: balance; }
.norm p { max-width: 62ch; }

.cite {
  justify-self: start;
  display: inline-block;
  padding: 0.75rem 0.9rem;
  border-top: 1px solid var(--pen);
  background: color-mix(in srgb, var(--noon) 75%, transparent);
  font: 400 var(--step--1)/1.45 var(--data);
  color: var(--ink-soft);
  transition: background-color var(--base);
}
.cite:hover { background: var(--noon); }
.cite b { display: block; font-weight: 400; color: var(--ink); }
.cite a, .foot a { text-decoration-color: var(--pen); text-underline-offset: 0.2em; transition: color var(--fast); }
.cite a:hover, .foot a:hover { color: var(--pen); }

.unverified {
  padding: 0.45em 0.75em;
  background: repeating-linear-gradient(-45deg, transparent 0 5px, color-mix(in srgb, var(--ink) 12%, transparent) 5px 6px);
  outline: 1px dashed var(--ink-soft);
  font-family: var(--data);
  font-size: 0.86em;
  white-space: nowrap;
}

@media (min-width: 60rem) {
  .norms { grid-column: 5 / span 8; grid-row: 1 / span 3; margin-top: 0; }
  .norm { grid-template-columns: 5fr 3fr; column-gap: var(--col-gap); padding-block: 2rem; }
  .norm h3, .norm p { grid-column: 1; }
  .norm .cite { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
}

/* section 2: timeline */
.timeline {
  grid-column: 1 / -1;
  position: relative;
  display: grid;
  gap: 2.25rem;
  margin-top: 2.5rem;
  padding-left: 2rem;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 0.6rem;
  bottom: 0.6rem;
  width: 2px;
  background: var(--ink);
  transform-origin: top;
}
[data-motion="full"] .timeline::before { scale: 1 0; transition: scale 1.3s var(--ease) 150ms; }
[data-motion="full"] .timeline.in::before { scale: 1 1; }
.tl { position: relative; display: grid; gap: 0.5rem; align-content: start; }
.tl::before {
  content: "";
  position: absolute;
  left: -2rem;
  top: 0.3rem;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--day);
}
.tl-start::before { border-color: var(--pen); }
.tl-run::before { border-style: dashed; }
.tl-end::before { border-color: var(--deadline); background: var(--deadline); }
[data-motion="full"] .tl::before { scale: 0; transition: scale 420ms cubic-bezier(0.3, 1.6, 0.5, 1) calc(350ms + var(--i) * 300ms); }
[data-motion="full"] .timeline.in .tl::before { scale: 1; }
.tl h3 { font: 600 var(--step-1)/1.2 var(--body); }
.tl-figure { font: 800 var(--step-2)/1 var(--display); }
.tl-figure .unverified { font-size: 1rem; vertical-align: middle; }
.tl-start .tl-figure { color: var(--pen); }
.tl-end .tl-figure { color: var(--deadline); }

/* Month sheet: a torn-out page where days are crossed out in pen, one by one, up to a red «?» */
.sheet-card {
  grid-column: 1 / -1;
  position: relative;
  margin-top: 3.5rem;
  padding: 1.75rem 1.25rem 1.5rem;
  background: var(--noon);
  rotate: -0.8deg;
  box-shadow: 0 30px 44px -30px color-mix(in srgb, var(--ink) 60%, transparent);
}
.sheet-card:has(.sheet:empty) { display: none; }
/* binding strip, the same as on the pad above */
.sheet-card::before {
  content: "";
  position: absolute;
  left: -0.6rem;
  right: -0.6rem;
  top: -0.7rem;
  height: 1.1rem;
  border-radius: 3px 3px 1px 1px;
  background: var(--ink);
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
  font: 800 var(--step-2)/1 var(--display);
}
.sheet-head small { font: 400 var(--step--1)/1 var(--data); color: var(--ink-soft); }
.sheet { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.sheet .wd {
  padding-bottom: 0.4rem;
  font: 400 0.72rem/1 var(--data);
  text-align: center;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.sheet .d {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1.25;
  border-top: 1px solid var(--rule);
  font: 700 clamp(1rem, 0.6rem + 1.6vw, 1.9rem)/1 var(--display);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color 200ms;
}
.sheet .d.off { color: color-mix(in srgb, var(--ink-soft) 45%, transparent); }
.sheet .d small {
  position: absolute;
  top: 4px;
  left: 3px;
  font: 400 0.58rem/1 var(--data);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
/* a pen stroke through each passed day */
.sheet .d.run::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 3px;
  border-radius: 2px;
  background: var(--pen);
  rotate: -32deg;
  scale: 0 1;
  transform-origin: left;
}
.sheet .d.start { color: var(--pen); }
.sheet .d.start::after {
  content: "";
  position: absolute;
  inset: 10% 16%;
  border: 2px solid var(--pen);
  border-radius: 48% 52% 55% 45% / 55% 45% 52% 48%;
  rotate: -8deg;
}
.sheet .d.q { color: var(--deadline); font-weight: 800; }
.sheet .d.q::after {
  content: "";
  position: absolute;
  inset: 8% 14%;
  border: 2.5px solid var(--deadline);
  border-radius: 48% 52% 55% 45% / 55% 45% 52% 48%;
  rotate: -6deg;
  opacity: 0;
}
/* ui.js adds "go" when the sheet comes into view and removes it when it leaves, so it replays */
[data-motion="full"] .sheet.go .d.run::after { scale: 1 1; transition: scale 200ms var(--ease) calc(300ms + var(--s) * 190ms); }
[data-motion="full"] .sheet.go .d.run { color: var(--ink-soft); transition: color 200ms calc(300ms + var(--s) * 190ms); }
[data-motion="full"] .sheet.go .d.q::after { opacity: 1; scale: 1; transition: opacity 160ms, scale 420ms cubic-bezier(0.3, 1.6, 0.5, 1); transition-delay: 3300ms; }
[data-motion="full"] .sheet .d.q::after { scale: 1.5; }
/* calm and no-motion: the finished page, drawn at once */
[data-motion="calm"] .sheet .d.run::after { scale: 1 1; }
[data-motion="calm"] .sheet .d.run { color: var(--ink-soft); }
[data-motion="calm"] .sheet .d.q::after { opacity: 1; }

.photo { grid-column: 1 / -1; margin-top: 3rem; }
.photo img { width: 100%; object-fit: cover; }
[data-motion="full"] .photo img { clip-path: inset(0 0 100% 0); transition: clip-path 1.2s var(--ease) 100ms; }
[data-motion="full"] .photo.in img { clip-path: inset(0); }

@media (min-width: 60rem) {
  .timeline {
    grid-column: 5 / span 8;
    grid-row: 1 / span 2;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: var(--col-gap);
    margin-top: 0;
    padding: 2.75rem 0 0;
  }
  .timeline::before {
    left: 0;
    right: 0;
    top: 0.95rem;
    bottom: auto;
    width: auto;
    height: 2px;
    transform-origin: left;
  }
  [data-motion="full"] .timeline::before { scale: 0 1; }
  .tl::before { left: 0; top: -2.75rem; }
  .sheet-card { grid-column: 5 / span 7; grid-row: 3; margin-top: 4.5rem; padding: 2.25rem 2rem 2rem; }
}

/* section 3: calculator */
.calc-in {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.75rem;
  margin-top: 2.25rem;
}
.calc-in label { font-weight: 600; }
.field { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.field input {
  flex: 1 1 12rem;
  min-width: 0;
  min-height: 3.5rem;
  padding: 0 1rem;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: var(--noon);
  font: 400 1.125rem/1 var(--data);
  color: var(--pen);
  transition: border-color var(--fast);
}
.field input[aria-invalid="true"] { border-color: var(--ink); border-style: dashed; }
.chip {
  min-height: 3.5rem;
  padding: 0 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
.chip:hover { background: var(--ink); color: var(--noon); }
.chip:active { transform: translateY(2px); }
.calc-in .btn { justify-self: start; }
.msg { min-height: 1.55em; color: var(--ink); font-weight: 600; }
[data-motion="full"] .field.shake { animation: shake 340ms var(--ease); }
@keyframes shake { 20% { translate: -4px; } 40% { translate: 4px; } 60% { translate: -3px; } 80% { translate: 2px; } }

.calc-out {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr);
  gap: 1.25rem 1.25rem;
  align-items: start;
  margin-top: 2rem;
}
.out-leaf {
  aspect-ratio: 4 / 4.5;
  rotate: 2deg;
  box-shadow: 0 24px 34px -22px color-mix(in srgb, var(--ink) 60%, transparent);
}
.out-leaf .leaf-day { font-size: clamp(3.6rem, 2rem + 5vw, 6.5rem); }
.calc-out[data-state="empty"] .out-leaf { background: var(--noon); color: var(--rule); }
.calc-out[data-state="empty"] .out-leaf .leaf-month,
.calc-out[data-state="empty"] .out-leaf .leaf-week { color: var(--ink-soft); }
[data-motion="full"] .out-leaf.stamp { animation: stamp 560ms cubic-bezier(0.3, 1.5, 0.5, 1) both; }
[data-motion="calm"] .out-leaf.stamp { animation: fade-in 300ms linear both; }
@keyframes stamp { from { opacity: 0; scale: 1.35; rotate: 9deg; } }
.out-leaf.stamp .leaf-day { animation: roll 520ms var(--ease) 120ms both; }
[data-motion="calm"] .out-leaf.stamp .leaf-day { animation: fade-in 300ms linear both; }
@keyframes roll { from { opacity: 0; translate: 0 40%; } }

.out-text { display: grid; gap: 0.4rem; align-content: start; }
.out-date { font: 600 var(--step-1)/1.3 var(--body); text-wrap: balance; }
.out-days { font: 400 var(--step-0)/1.4 var(--data); color: var(--pen); }
.out-off { font-size: var(--step--1); line-height: 1.5; }
.out-off:empty { display: none; }
.out-basis { font-size: var(--step--1); line-height: 1.5; color: var(--ink-soft); }

.month {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}
.month:empty { display: none; }
.month .wd {
  padding-bottom: 0.35rem;
  font: 400 0.72rem/1 var(--data);
  text-align: center;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.month .d {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-height: 3.5rem;
  font: 400 0.9rem/1 var(--data);
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--noon) 40%, transparent);
}
.month .d small {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.month .d.in { background: color-mix(in srgb, var(--pen) 14%, var(--noon)); color: var(--ink); }
.month .d.start { color: var(--pen); font-weight: 700; }
.month .d.start::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 2px solid var(--pen);
  border-radius: 48% 52% 55% 45% / 55% 45% 52% 48%;
  rotate: -8deg;
}
.month .d.end { background: var(--deadline); color: var(--noon); font-weight: 700; }
[data-motion] .month .d.in { animation: fade-in 260ms var(--ease) both; animation-delay: calc(var(--i) * 16ms); }
[data-motion="full"] .month .d.end { animation: stamp 480ms cubic-bezier(0.3, 1.5, 0.5, 1) both; animation-delay: calc(var(--i) * 16ms + 140ms); }
[data-motion="calm"] .month .d.end { animation: fade-in 260ms linear both; }

@media (min-width: 40rem) {
  .calc-out { grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 1.75rem 2rem; }
}
@media (min-width: 60rem) {
  .check .case { grid-column: 5 / span 8; grid-row: 1; margin-top: 0; }
  .calc-in { grid-column: 5 / span 8; grid-row: 2; margin-top: 2.5rem; grid-template-columns: minmax(0, 1fr) auto; align-items: end; column-gap: 0.75rem; }
  .calc-in label { grid-column: 1 / -1; }
  .calc-in .msg { grid-column: 1 / -1; }
  .calc-out { grid-column: 5 / span 8; grid-row: 3; grid-template-columns: 12rem minmax(0, 1fr); margin-top: 1.5rem; }
  .month { grid-column: 2; }
}

[hidden] { display: none !important; }

/* section 3: which situation; the chosen one is underlined in pen */
.case { grid-column: 1 / -1; min-width: 0; margin: 2.25rem 0 0; padding: 0; border: 0; border-top: 3px solid var(--ink); }
.case legend { float: left; width: 100%; padding: 0.9rem 0 0.25rem; font: 400 var(--step--1)/1 var(--data); color: var(--ink-soft); }
.case label {
  clear: both;
  display: flex;
  align-items: center;
  min-height: 3.25rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  font: 800 var(--step-1)/1.1 var(--display);
}
.case input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.case span { position: relative; padding-block: 0.65rem; transition: color var(--fast); }
.case span::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.3rem;
  height: 3px;
  background: var(--pen);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--base) var(--ease);
}
.case input:checked + span { color: var(--pen); }
.case input:checked + span::after { transform: scaleX(1); }
.case input:focus-visible + span { outline: 3px solid var(--pen); outline-offset: 4px; }
@media (hover: hover) { .case label:hover span { color: var(--pen); } }
@media (min-width: 40rem) {
  .case { display: flex; flex-wrap: wrap; column-gap: 2.25rem; }
  .case label { border-bottom: 0; }
}

/* section 2: the numbers table, one figure per ruled line */
.terms { grid-column: 1 / -1; margin-top: 3.5rem; border-top: 3px solid var(--ink); }
.terms > div { display: grid; gap: 0.35rem; padding-block: 1.1rem; border-bottom: 1px solid var(--rule); }
.terms dt { font: 800 var(--step-2)/1 var(--display); }
.terms dd { max-width: 60ch; }
.terms small { display: block; margin-top: 0.35rem; font: 400 var(--step--1)/1.4 var(--data); color: var(--ink-soft); }
@media (min-width: 40rem) {
  .terms > div { grid-template-columns: 10rem minmax(0, 1fr); column-gap: 1.5rem; align-items: baseline; }
}
@media (min-width: 60rem) {
  .terms { grid-column: 5 / span 8; grid-row: 4; margin-top: 4.5rem; }
}

/* section 3: steps */
.steps { grid-column: 1 / -1; margin-top: 2.25rem; border-top: 3px solid var(--ink); }
.step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  min-height: 3.5rem;
  padding-block: 1.1rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.step input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.box {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: var(--noon);
  transition: border-color var(--fast);
}
.box svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: var(--pen);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  transition: stroke-dashoffset 380ms var(--ease);
}
.step input:checked + .box { border-color: var(--pen); }
.step input:checked + .box svg { stroke-dashoffset: 0; }
.step input:focus-visible + .box { outline: 3px solid var(--pen); outline-offset: 3px; }
.step-text { padding-top: 0.1rem; transition: color var(--base); }
.step-cite { display: block; margin-top: 0.3rem; font: 400 var(--step--1)/1.4 var(--data); color: var(--ink-soft); }
.step input:checked ~ .step-text {
  color: var(--ink-soft);
  text-decoration: line-through;
  text-decoration-color: var(--pen);
  text-decoration-thickness: 2px;
}
@media (hover: hover) { .step:hover .box { border-color: var(--pen); } }

.steps-sum { grid-column: 1 / -1; margin-top: 1.25rem; }
.meter { display: flex; gap: 4px; }
.meter li { flex: 1; height: 0.5rem; background: var(--rule); transition: background-color var(--base); }
.meter li.on { background: var(--pen); }
.steps-left { margin-top: 0.75rem; color: var(--ink-soft); }

/* section 4: what the law sets out after a refusal, one stop per line */
.route { grid-column: 1 / -1; margin-top: 2.25rem; border-top: 3px solid var(--ink); }
.route li {
  display: grid;
  gap: 0.6rem;
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--rule);
}
.route-when { font: 800 var(--step-1)/1 var(--display); color: var(--pen); }
.route h3 { font: 600 var(--step-1)/1.25 var(--body); text-wrap: balance; }
.route p { max-width: 60ch; }

.photo-side img { aspect-ratio: 4 / 3; object-position: 75% 60%; }

/* section 4: official addresses, opened by a pen rule */
.where { grid-column: 1 / -1; display: grid; gap: 0.75rem; margin-top: 2.5rem; padding-top: 1.25rem; border-top: 3px solid var(--pen); }
.where h3 { font: 800 var(--step-2)/1 var(--display); }
.where p { max-width: 60ch; }
.where a { text-decoration-color: var(--pen); text-underline-offset: 0.2em; }
.where a:hover { color: var(--pen); }
@media (min-width: 60rem) { .where { grid-column: 5 / span 6; grid-row: 4; margin-top: 3.5rem; } }

@media (min-width: 40rem) {
  .route li { grid-template-columns: 7.5rem minmax(0, 1fr); column-gap: 1.5rem; }
  .route li > * { grid-column: 2; }
  .route .route-when { grid-column: 1; grid-row: 1 / span 3; padding-top: 0.15rem; }
}
@media (min-width: 60rem) {
  .check .steps { grid-column: 5 / span 8; grid-row: 4; margin-top: 3.5rem; }
  .check:has(.calc-in[hidden]) .steps { margin-top: 2.5rem; }
  .check .steps-sum { grid-column: 5 / span 8; grid-row: 5; }
  .route { grid-column: 5 / span 6; grid-row: 1 / span 3; margin-top: 0; }
  .photo-side { grid-column: 11 / span 2; grid-row: 1 / span 3; margin-top: 0; align-self: start; }
  .photo-side img { aspect-ratio: 3 / 4; }
}

/* ---------- Footer ---------- */

.foot {
  padding-block: 2.5rem calc(6rem + env(safe-area-inset-bottom));
  border-top: 3px solid var(--ink);
  font-size: var(--step--1);
  color: var(--ink-soft);
}
.foot p { max-width: 70ch; }
.foot p + p { margin-top: 0.75rem; }
@media (min-width: 60rem) { .foot { padding-bottom: 3rem; } }

/* Scroll progress as a rule in the margin; absent where unsupported. */
@supports (animation-timeline: scroll()) {
  [data-motion] .progress {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    z-index: 25;
    background: var(--pen);
    transform-origin: top;
    animation: grow linear both;
    animation-timeline: scroll(root);
  }
  @keyframes grow { from { scale: 1 0; } to { scale: 1 1; } }
}

/* ---------- Text that reacts to scrolling (full motion, browsers with scroll timelines) ---------- */
@supports (animation-timeline: view()) {
  /* headline: as the opening screen scrolls away, the question comes apart and «числа» stays */
  [data-motion="full"] .stage h1 .w {
    display: inline-block;
    animation: linear both;
    animation-timeline: scroll(root);
    animation-range: 0 85vh;
  }
  [data-motion="full"] .stage h1 .w1 { animation-name: drift-left; }
  [data-motion="full"] .stage h1 .w2 { animation-name: swell; transform-origin: 30% 80%; }
  [data-motion="full"] .stage h1 .w3 { animation-name: drift-right; }
  @keyframes drift-left { to { translate: -16vw 0; opacity: 0.12; } }
  @keyframes drift-right { to { translate: 16vw 0.1em; opacity: 0.12; } }
  @keyframes swell { to { scale: 1.14; } }

  [data-motion="full"] .lead {
    animation: rise 800ms var(--ease) 160ms both, recede linear both;
    animation-timeline: auto, scroll(root);
    animation-range: normal, 0 70vh;
  }
  @keyframes recede { to { translate: 0 -2.5rem; opacity: 0.25; } }

  [data-motion="full"] .stage-bg { animation: settle linear both; animation-timeline: scroll(root); animation-range: 0 100vh; }
  [data-motion="full"] .stage-bg::after { animation: brighten linear both; animation-timeline: scroll(root); animation-range: 0 100vh; }
  @keyframes settle { from { scale: 1.08; } to { scale: 1; translate: 0 -2%; } }
  @keyframes brighten { from { opacity: 0.35; } to { opacity: 1; } }

  [data-motion="full"] .cue { animation: fade linear both; animation-timeline: scroll(root); animation-range: 0 20vh; }

  /* section titles: words rise into place one after another while the title enters */
  [data-motion="full"] .section h2 { view-timeline-name: --title; }
  [data-motion="full"] .section h2 .wd {
    display: inline-block;
    animation: word-up linear both;
    animation-timeline: --title;
    animation-range: cover calc(var(--w) * 3%) cover calc(16% + var(--w) * 3%);
  }
  @keyframes word-up { from { opacity: 0; translate: 0 0.6em; rotate: 3deg; } }

  /* section notes: words darken in reading order, like ink settling, as the note scrolls up */
  [data-motion="full"] .section-note { view-timeline-name: --note; }
  [data-motion="full"] .section-note .wd {
    animation: ink linear both;
    animation-timeline: --note;
    animation-range: cover calc(10% + var(--w) * 2.5%) cover calc(18% + var(--w) * 2.5%);
  }
  @keyframes ink { from { opacity: 0.14; } }
}
