/* Gently Led. One stylesheet, two systems built on one set of tokens:
   the room (before the break) and the record (after it). See ../../DESIGN.md.
   Rule: no literal length, colour, font size or duration below the token blocks. */

/* ------------------------------------------------------------------ tokens */

:root {
  /* space: one unit, one scale */
  --u: 0.25rem;
  --s1: calc(var(--u) * 1);
  --s2: calc(var(--u) * 2);
  --s3: calc(var(--u) * 3);
  --s4: calc(var(--u) * 4);
  --s5: calc(var(--u) * 6);
  --s6: calc(var(--u) * 8);
  --s7: calc(var(--u) * 12);
  --s8: calc(var(--u) * 16);
  --s9: calc(var(--u) * 24);
  --gutter: var(--s5);
  --hit: var(--s7);
  --hair: calc(var(--u) / 4);
  --focus: calc(var(--u) / 2);

  /* type */
  --font-room: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", P052, Georgia, serif;
  --font-hard: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --font: var(--font-room);
  --t1: 0.8125rem;
  --t2: 1rem;
  --t3: 1.1875rem;
  --t4: clamp(1.4375rem, 1.2rem + 1vw, 1.75rem);
  --t5: clamp(1.75rem, 1.3rem + 2vw, 2.625rem);
  --lh-line: 1.2;
  --lh-text: 1.55;
  --track: 0;
  --track-label: 0.08em;
  --measure: 30rem;
  --measure-wide: 40rem;

  /* shape */
  --r-pill: calc(var(--hit) / 2);
  --r-card: var(--s5);

  /* motion */
  --d-press: 160ms;
  --d-move: 700ms;
  --d-fade: 1400ms;
  --d-room: 9000ms;
  --ease: cubic-bezier(0.37, 0, 0.18, 1);
  --breath: 8000ms;
  --breath-slow: 11000ms;
  --ripple: 2600ms;      /* life of one ripple ring */
  --drift-life: 7000ms;  /* life of one drifting word */
  --cross: 6000ms;       /* how long the boat is in the room */
  --breath-min: 1400ms;  /* the shortest hold that counts as a breath */
  --cut: 2600ms;         /* how long the cut line stands alone */
  --read: 420ms;         /* the pace at which the record is read out */
  --dwell: 1400ms;       /* one beat of reading time; reduced motion does not shorten it */

  /* scene: the orb's place and size; the canvas reads the same values */
  --orb-y: 34vh;
  --orb-d: min(44vmin, calc(var(--u) * 56));
  --orb-rest: 0.8;      /* scale at the bottom of a breath */
  --orb-bloom: 1.28;    /* scale while held */
  --orb-away: 0.14;     /* opacity when the room steps back for a page of text */
  --drift-ink: 0.62;    /* opacity of words that drift past */
  --drift-speed: 0.9;   /* drift, in units per second */
  --ring-ink: 0.34;     /* opacity of ripple and progress rings */

  --ghost: 0.55;        /* opacity of a phrase waiting to be typed */
  --cut-hold: 50vh;     /* the height the cut line holds, alone, after the break */

  /* colour: the three lights' accents, then sand in its first state. */
  --accent-sand: #c58f6c;
  --accent-sage: #7e9a80;
  --accent-slate: #8291aa;
  /* colour: sand, first state. Lights and room states override these. */
  --ground: #f4eee3;
  --ink: #2b2722;
  --ink-2: #6a6258;
  --rule: #cfc6b8;
  --accent: var(--accent-sand);
  --wash: #ebe3d5;
  --lift-ink: rgb(43 39 34 / 0.1);
  --lift: 0 var(--s4) var(--s8) var(--lift-ink);
}

@supports (height: 1svh) {
  :root { --orb-y: 34svh; }
}

/* Short screens (a phone on its side): a smaller orb sits higher and the line
   drops one step, so the words never reach the foot link. */
@media (max-height: 30rem) {
  :root { --orb-y: 26vh; --orb-d: 30vmin; }
  .line { font-size: var(--t4); min-height: calc(var(--t4) * var(--lh-line)); }
}

/* Three lights. Each has three room states: the room changes colour twice. */
:root[data-light="sand"]                 { --ground: #f4eee3; --ink: #2b2722; --ink-2: #6a6258; --rule: #cfc6b8; --accent: var(--accent-sand); --wash: #ebe3d5; }
:root[data-light="sand"][data-room="1"]  { --ground: #f4e5de; --rule: #d3c2ba; --wash: #ecdad2; }
:root[data-light="sand"][data-room="2"]  { --ground: #e7ebdd; --rule: #c6cbb9; --wash: #dce1d0; }
:root[data-light="sage"]                 { --ground: #eaeee4; --ink: #242a25; --ink-2: #5b655d; --rule: #c5cdbf; --accent: var(--accent-sage); --wash: #dfe5d7; }
:root[data-light="sage"][data-room="1"]  { --ground: #e2ecec; --rule: #bccbcb; --wash: #d5e2e2; }
:root[data-light="sage"][data-room="2"]  { --ground: #f0e9dd; --rule: #d2c8b8; --wash: #e6ddcf; }
:root[data-light="slate"]                { --ground: #e9ebee; --ink: #23272d; --ink-2: #5c636e; --rule: #c3c8cf; --accent: var(--accent-slate); --wash: #dde0e5; }
:root[data-light="slate"][data-room="1"] { --ground: #ece7ef; --rule: #cac2cf; --wash: #e1dae5; }
:root[data-light="slate"][data-room="2"] { --ground: #e3ece9; --rule: #bdcbc6; --wash: #d6e2de; }

/* After the break: black, white, monospace, square, and no motion at all.
   The second selector outranks every light and room state. */
:root.broken,
:root.broken[data-light][data-room] {
  --font: var(--font-hard);
  --t1: 0.8125rem;
  --t2: 0.9375rem;
  --t3: 0.9375rem;
  --t4: 1.1875rem;
  --t5: clamp(1.4375rem, 1.1rem + 1.6vw, 2rem);
  --lh-line: 1.3;
  --lh-text: 1.6;
  --track: 0;
  --r-pill: 0;
  --r-card: 0;
  --d-press: 0ms;
  --d-move: 0ms;
  --d-fade: 0ms;
  --d-room: 0ms;
  --ground: #000000;
  --ink: #ffffff;
  --ink-2: #a6a6a6;
  --rule: #4a4a4a;
  --accent: #ffffff;
  --wash: #1c1c1c;
  --lift: none;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --d-press: 0ms;
    --d-move: 0ms;
    --d-fade: 400ms;   /* opacity only: nothing moves */
    --d-room: 9000ms;  /* a slow colour change is not motion */
  }
}

/* Choosing a light answers at once; the room's own changes take their time. */
:root[data-shift="light"] { --d-room: var(--d-fade); }

/* -------------------------------------------------------------------- base */

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

html {
  height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 100%;
  line-height: var(--lh-text);
  letter-spacing: var(--track);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--d-room) linear;
}

body {
  margin: 0;
  min-height: 100%;
  background: transparent;
}

/* The room does not scroll. The record and the plain pages do. */
:root:not(.broken):not(.reading) body { position: fixed; inset: 0; overflow: hidden; }

p, h1, h2, h3, ul, ol, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1, h2, h3 { font-size: inherit; font-weight: inherit; }
a { color: inherit; text-underline-offset: var(--s1); text-decoration-thickness: var(--hair); }
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: var(--focus) solid var(--ink); outline-offset: var(--focus); }

.sr {
  position: absolute; width: var(--hair); height: var(--hair); overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- the room */

.room {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  pointer-events: none;
}

.stage {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 var(--gutter) var(--s8);
}

/* The orb is a real button, exactly where the canvas draws the circle. */
.orb {
  position: absolute;
  top: calc(var(--orb-y) - var(--orb-d) / 2);
  left: calc(50% - var(--orb-d) / 2);
  width: var(--orb-d); height: var(--orb-d);
  border-radius: 50%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.orb:focus-visible { outline-offset: var(--s2); }
.orb[disabled] { cursor: default; }

.say {
  width: 100%; max-width: var(--measure-wide);
  margin-top: calc(var(--orb-y) + var(--orb-d) / 2 + var(--s5));
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
}
.stage[data-mode="page"] .say { margin-top: auto; margin-bottom: auto; }
.stage[data-mode="page"] .orb { pointer-events: none; }

.line {
  font-size: var(--t5);
  line-height: var(--lh-line);
  text-wrap: balance;
  min-height: calc(var(--t5) * var(--lh-line));
}
.aside {
  margin-top: var(--s3);
  max-width: var(--measure);
  font-size: var(--t2);
  color: var(--ink-2);
  text-wrap: balance;
}
.aside:empty { display: none; }

.controls {
  margin-top: var(--s6);
  width: 100%; max-width: var(--measure);
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: var(--s3);
}
.controls:empty { display: none; }
.controls--stack { flex-direction: column; flex-wrap: nowrap; gap: var(--s3); }

.out { margin-top: var(--s2); min-height: var(--hit); display: flex; align-items: center; }
.out:has(.btn) { margin-top: var(--s5); }

/* Everything in the room arrives and leaves by opacity alone. */
.fade { opacity: 0; transition: opacity var(--d-fade) var(--ease); }
.fade.is-in { opacity: 1; }
.fade.is-quick { transition-duration: var(--d-move); }

/* ----------------------------------------------------------- room controls */

.btn {
  min-height: var(--hit);
  min-width: calc(var(--hit) * 2);
  padding: var(--s2) var(--s5);
  border: var(--hair) solid var(--ink-2);
  border-radius: var(--r-pill);
  font-size: var(--t2);
  line-height: var(--lh-line);
  text-align: center;
  transition: background-color var(--d-press) var(--ease), color var(--d-press) var(--ease), border-color var(--d-press) var(--ease);
}
.btn:hover { background: var(--wash); }
.btn:active, .btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--ground); }
.btn--round { min-width: var(--hit); width: var(--hit); padding: 0; border-radius: 50%; }
.btn--wide { width: 100%; border-radius: var(--r-card); padding: var(--s3) var(--s5); }

.quiet-btn {
  min-height: var(--hit);
  padding: 0 var(--s3);
  font-size: var(--t1);
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-thickness: var(--hair);
  text-underline-offset: var(--s1);
  transition: color var(--d-press) var(--ease);
}
.quiet-btn:hover { color: var(--ink); }

.swatch { display: inline-flex; align-items: center; gap: var(--s2); min-width: 0; padding-left: var(--s4); padding-right: var(--s4); }
.swatch__dot {
  width: var(--s4); height: var(--s4); border-radius: 50%;
  background: var(--dot); border: var(--hair) solid var(--ink-2);
}
.swatch[data-light="sand"]  { --dot: var(--accent-sand); }
.swatch[data-light="sage"]  { --dot: var(--accent-sage); }
.swatch[data-light="slate"] { --dot: var(--accent-slate); }

.field {
  width: 100%;
  min-height: var(--hit);
  padding: var(--s2) 0;
  background: transparent;
  border: 0;
  border-bottom: var(--hair) solid var(--ink-2);
  border-radius: 0;
  font-size: var(--t4);
  line-height: var(--lh-line);
  text-align: center;
  caret-color: var(--accent);
}
.field::placeholder { color: var(--ink-2); opacity: var(--ghost); }
.field:focus-visible { outline: none; border-bottom-color: var(--ink); box-shadow: 0 var(--hair) 0 var(--ink); }

.dial { width: 100%; display: flex; flex-direction: column; align-items: center; gap: var(--s4); }
.dial__value { font-size: var(--t4); line-height: var(--lh-line); font-variant-numeric: tabular-nums; }
.dial__range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: var(--hit); margin: 0;
  background: transparent; cursor: pointer;
}
.dial__range::-webkit-slider-runnable-track { height: var(--hair); background: var(--ink-2); }
.dial__range::-moz-range-track { height: var(--hair); background: var(--ink-2); }
.dial__range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: var(--s5); height: var(--s5); margin-top: calc(var(--s5) / -2);
  border-radius: 50%; background: var(--ink); border: 0;
}
.dial__range::-moz-range-thumb { width: var(--s5); height: var(--s5); border-radius: 50%; background: var(--ink); border: 0; }
.dial__range:focus-visible { outline: none; }
.dial__range:focus-visible::-webkit-slider-thumb { outline: var(--focus) solid var(--ink); outline-offset: var(--focus); }
.dial__range:focus-visible::-moz-range-thumb { outline: var(--focus) solid var(--ink); outline-offset: var(--focus); }

.scale { display: flex; flex-direction: column; align-items: center; gap: var(--s3); width: 100%; }
.scale__row { display: flex; justify-content: center; gap: var(--s3); }
.scale__ends { display: flex; justify-content: space-between; width: calc(var(--hit) * 5 + var(--s3) * 4); font-size: var(--t1); color: var(--ink-2); }

.count { font-size: var(--t4); line-height: var(--lh-line); font-variant-numeric: tabular-nums; color: var(--ink-2); min-height: calc(var(--t4) * var(--lh-line)); }

/* ---------------------------------------------------------------- the gate */

.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s8) var(--gutter);
}
.gate__card {
  width: 100%; max-width: var(--measure);
  padding: var(--s6);
  background: var(--ground);
  border: var(--hair) solid var(--rule);
  border-radius: var(--r-card);
  box-shadow: var(--lift);
  transition: background-color var(--d-room) linear;
}
.gate__text { font-size: var(--t3); line-height: var(--lh-text); }
.gate__text + .gate__text { margin-top: var(--s3); }
.gate__lead { font-size: var(--t4); line-height: var(--lh-line); margin-bottom: var(--s4); }
/* Two equal buttons: same size, same weight, same row or same stack. */
.gate__choice { margin-top: var(--s6); display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.gate__choice .btn { width: 100%; min-width: 0; padding-left: var(--s3); padding-right: var(--s3); }
.gate__choice--one { grid-template-columns: 1fr; }
.gate__note { margin-top: var(--s4); text-align: center; font-size: var(--t1); color: var(--ink-2); }
.gate__note a { display: inline-flex; align-items: center; min-height: var(--hit); }

@media (max-width: 26rem) {
  .gate__card { padding: var(--s5); }
  .gate__choice { grid-template-columns: 1fr; }
}

/* ------------------------------------------------- foot link, sound switch */

.foot {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding: 0 var(--gutter) var(--s2);
  pointer-events: none;
}
.foot a, .corner {
  pointer-events: auto;
  display: inline-flex; align-items: center;
  min-height: var(--hit);
  padding: 0 var(--s3);
  font-size: var(--t1);
  color: var(--ink-2);
  transition: color var(--d-press) var(--ease);
}
.foot a:hover, .corner:hover { color: var(--ink); }
.corner { position: fixed; top: var(--s2); right: var(--s3); text-decoration: underline; text-decoration-thickness: var(--hair); text-underline-offset: var(--s1); }
:root.broken .foot { position: static; padding: var(--s7) var(--gutter) var(--s5); justify-content: flex-start; max-width: calc(var(--measure-wide) + var(--gutter) * 2); margin: 0 auto; }
:root.broken .foot a { padding: 0; }
:root.gating .foot { visibility: hidden; }
:root.broken .corner, :root.broken .room, :root.broken .stage, :root.broken .gate { display: none; }

/* -------------------------------------------------- sheets: note, studies */

.sheet {
  width: 100%; max-width: calc(var(--measure-wide) + var(--gutter) * 2);
  margin: 0 auto;
  padding: var(--s8) var(--gutter) var(--s7);
  font-size: var(--t2);
}
.sheet > * + * { margin-top: var(--s4); }
.sheet__path { font-size: var(--t1); color: var(--ink-2); }
.sheet__title { font-size: var(--t5); line-height: var(--lh-line); text-wrap: balance; margin-top: var(--s3); margin-bottom: var(--s6); }
.sheet__foot { margin-top: var(--s7); font-size: var(--t1); color: var(--ink-2); }
.sheet__foot a, .sheet__path a { display: inline-flex; align-items: center; min-height: var(--hit); }
.block { margin-top: var(--s7); }
.block > * + * { margin-top: var(--s3); }
.label { font-size: var(--t1); letter-spacing: var(--track-label); text-transform: uppercase; color: var(--ink-2); }
.quiet { color: var(--ink-2); font-size: var(--t1); }
.rows > li { padding: var(--s3) 0; border-top: var(--hair) solid var(--rule); }
.rows > li:last-child { border-bottom: var(--hair) solid var(--rule); }
.rows--links > li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--s1) var(--s4); padding: 0; }
.rows--links a { display: inline-flex; align-items: center; min-height: var(--hit); }
.doi { color: var(--ink-2); overflow-wrap: anywhere; }
strong { font-weight: 700; }

/* The note opens over the room when the foot link is followed (#note). */
.note {
  display: none;
  position: fixed; inset: 0; z-index: 2;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--ground);
  transition: background-color var(--d-room) linear;
}
.note:target, .note.is-open { display: block; }
.note__back { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 0 var(--s3); background: var(--ground); border-bottom: var(--hair) solid var(--rule); transition: background-color var(--d-room) linear; }
.note__back a { display: inline-flex; align-items: center; min-height: var(--hit); padding: 0 var(--s3); font-size: var(--t1); color: var(--ink-2); }
.note .sheet { padding-top: var(--s5); }
.note__actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s4); }
.note__result { min-height: calc(var(--t2) * var(--lh-text)); }
.dump {
  max-height: calc(var(--s9) * 3); overflow: auto;
  padding: var(--s4);
  border: var(--hair) solid var(--rule);
  font-family: var(--font-hard); font-size: var(--t1); line-height: var(--lh-text);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

/* -------------------------------------------------------------- the record */

.record {
  width: 100%; max-width: calc(var(--measure-wide) + var(--gutter) * 2);
  margin: 0 auto;
  padding: var(--s8) var(--gutter) 0;
  font-size: var(--t2);
  line-height: var(--lh-text);
}
.record__cut { font-size: var(--t5); line-height: var(--lh-line); min-height: var(--cut-hold); }
.record__section { margin-top: var(--s8); }
.record__section > * + * { margin-top: var(--s4); }
.record__big { font-size: var(--t5); line-height: var(--lh-line); }
.record__section > h3.label { margin-top: var(--s7); }

.entry { display: grid; grid-template-columns: calc(var(--u) * 14) 1fr; column-gap: var(--s4); padding: var(--s3) 0; border-top: var(--hair) solid var(--rule); }
.entry__time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.entry__body > * + * { margin-top: var(--s2); }
.entry a { color: var(--ink-2); font-size: var(--t1); }

.tag {
  display: inline-block;
  padding: 0 var(--s2);
  margin-right: var(--s2);
  border: var(--hair) solid var(--ink);
  font-family: var(--font-hard); font-size: var(--t1); line-height: var(--lh-text);
  letter-spacing: var(--track-label);
}
.tag--staged { background: var(--ink); color: var(--ground); }

.rooms { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.rooms__one { padding: var(--s3); min-height: var(--s9); display: flex; align-items: flex-end; font-size: var(--t1); border: var(--hair) solid var(--rule); background: var(--was); color: var(--was-ink); }

.bar { display: grid; grid-template-columns: 1fr; row-gap: var(--s1); padding: var(--s3) 0; border-top: var(--hair) solid var(--rule); }
.bar__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); }
.bar__n { color: var(--ink-2); font-size: var(--t1); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar__track { height: var(--s3); background: var(--wash); }
.bar__fill { height: 100%; width: calc(var(--share) * 100%); background: var(--ink); }
.bar--you .bar__head > :first-child::after { content: "  <- you stopped here"; color: var(--ink-2); }

.doors { display: grid; gap: var(--s3); }
.door {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s1);
  width: 100%; min-height: var(--hit);
  padding: var(--s4);
  border: var(--hair) solid var(--ink);
  text-align: left; text-decoration: none;
}
.door:hover:not([aria-disabled="true"]) { background: var(--ink); color: var(--ground); }
.door:hover:not([aria-disabled="true"]) .door__sub { color: var(--ground); }
.door[aria-disabled="true"] { border-color: var(--rule); color: var(--ink-2); cursor: default; }
.door__sub { font-size: var(--t1); color: var(--ink-2); }
.plain-controls { display: flex; flex-wrap: wrap; gap: var(--s3); }
.plain-controls .door { width: auto; flex: 1 1 calc(var(--hit) * 4); }
.status { min-height: calc(var(--t2) * var(--lh-text)); color: var(--ink-2); }

/* Plain pages (studies) use the record's system from the first frame. */
:root.plain body { position: static; overflow: visible; }
.wall > * + * { margin-top: 0; }
