/* LUMI CASE STUDY, "Rulebook": the styles, all inside #rulebook (the shared page's contract).
   One picture: the page of rules (the clinic's library.md, word for word) beside Lumi's chat
   window, with Lumi above the window. One pattern shows at a time; its rule is lit on the page,
   in big type, and the recorded chat follows it: the chat line that follows the rule is marked
   the same way as the rule.
   THE LAYOUT (his pick, 25 Nov 2026, chat LUMI RULES, layout 4 "Side list"): the few words sit on
   top and the picture runs across under them. The five pattern words are the sheet's own side
   list, so they read as part of the page of rules they switch; before, they stood loose under
   the lead and read as a second subheading. The line back from Testing sits under the picture.
   The ground is Lumi's green, painted on the section's own id, so the page's one padding sits
   inside the colour (page.css, data-band on the section tag). His pick, 19 Nov 2026 (chat CASE
   STUDY SCROLL), replaces the grey he had locked: --cs-green (page.css). While the whole page
   fades the page carries it (page.css, trip.js).
   The stage itself has no ground: the one Lumi is drawn in this stage, over the section's ground
   and under everything else here, so the page of rules and the window stand in front of it.
   ONE UNIT, as the hero built it: every size is a count of --u, which follows the section's
   width and the screen's height, so the section scales as one picture.
   Nothing here crops, masks or clips a picture, Lumi or a glow. */
#rulebook {
  background: var(--cs-green);

  .r5 {
    --hh: clamp(40rem, 100svh, 54rem); --fh: 60; --u: min(1cqw, calc(var(--hh) / var(--fh)));
    --pad: calc(5 * var(--u));
    --edge: calc((100% - 100 * var(--u)) / 2);
    --ink: var(--neutral-950); --sub: var(--neutral-600);
    --paper: var(--neutral-0);              /* a white page of rules on the grey ground */
    --title: 6.72;                          /* the size of the section above's title; under the hero's (7.19) */
    --body: 2;                              /* the lead */
    --doc: 1.2; --logo: 1.6;                /* the page of rules: its lines, a mark's height */
    --rule-s: 2.8;                          /* the lit rule, in big type */
    --ls: 30;                               /* Lumi's seat: the side of its square; its body is about two thirds of that. Big enough never to get lost (his review, 19 Nov 2026) */
    --chatw: min(calc(31 * var(--u)), 25.5rem); /* the window's column: never wider than the window at its largest scale (17rem at 1.5, rulebook.js) */
    /* The air above and below is the page's (--section-padding on every .row, page.css): this
       section sets no margin or padding of its own above or below its picture. */
    position: relative; z-index: 1; box-sizing: border-box;
    display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "title" "lead" "pic" "turn";
    padding: 0 calc(var(--edge) + var(--pad));
    color: var(--ink);
    scroll-margin-top: var(--section-padding);
  }

  /* ---- the words: few, on top. In front of Lumi's layer, so Lumi never passes over them. ---- */
  .r-type { display: contents; }
  .r-title, .r-lead, .r-turn { position: relative; z-index: 1; }
  .r-title, .r-lead, .r-turn, .r-page, .r-win-m, .r-cap {
    transition: opacity var(--duration-flourish) var(--ease-default), transform var(--duration-expressive) var(--ease-emphasized);
  }
  .r5:not([data-on~="type"]) :is(.r-title, .r-lead, .r-turn),
  .r5:not([data-on~="pic"]) :is(.r-page, .r-win-m, .r-cap) { opacity: 0; transform: translateY(var(--space-500)); }
  .r-title {
    grid-area: title; margin: 0;
    font-family: var(--font-display); font-weight: var(--display-weight);
    font-size: calc(var(--title) * var(--u)); line-height: var(--line-display); letter-spacing: var(--display-tight);
    text-wrap: balance;
  }
  .r-lead {
    grid-area: lead; margin: calc(var(--body) * var(--u) * 0.8) 0 0;
    font-size: calc(var(--body) * var(--u)); font-weight: var(--weight-medium); line-height: var(--line-snug);
    color: var(--sub); text-wrap: pretty;
  }
  .r-lead span { display: block; } /* two sentences, a line each */

  /* ---- the line back from Testing (his YES, 17 Nov 2026): one sentence, under the picture. Its two
     figures came off on his pick, 25 Nov 2026 ---- */
  .r-turn {
    grid-area: turn; margin: calc(3 * var(--u)) 0 0;
    font-size: calc(1.7 * var(--u)); font-weight: var(--weight-semibold); line-height: var(--line-snug); text-wrap: balance;
  }

  /* ---- the five pattern words: the side list of the page of rules. The word that is on takes the
     lit rule's colours (chat.css, with the lit rule's own), and a line fills under it while it plays ---- */
  .r-tabs {
    grid-area: 2 / 1; display: flex; flex-direction: column; align-items: stretch; gap: calc(0.3 * var(--u));
    /* out to the sheet's left and bottom edges and up to the file's name, through the sheet's own padding */
    margin: calc(-1.3 * var(--u)) 0 calc(-2.2 * var(--u)) calc(-2.2 * var(--u)); padding: calc(1.6 * var(--u)) calc(1.2 * var(--u));
    border-right: 1px solid var(--neutral-200); /* lint-ok: a hairline beside the list, as under the file's name */
    border-bottom-left-radius: var(--radius-xl);
    background: var(--neutral-50); /* lint-ok: the sheet's grounds come straight from the neutral ramp, which page.css turns over in dark */
  }
  .r-tab {
    position: relative; display: inline-flex; align-items: center; justify-content: flex-start; min-height: max(1.5rem, calc(3 * var(--u)));
    margin: 0; padding: 0 var(--u); border: 0; border-radius: var(--radius-md); background: none; cursor: pointer;
    font: inherit; font-size: calc(1.3 * var(--u)); font-weight: var(--weight-medium); line-height: var(--line-title);
    color: var(--sub); white-space: nowrap; -webkit-tap-highlight-color: transparent;
  }
  .r-tab[aria-selected="true"] { color: var(--ink); font-weight: var(--weight-semibold); } /* its ground comes with the lit rule's colours (chat.css) */
  .r-tab:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
  .r-tab::after {
    content: ""; position: absolute; left: var(--u); right: var(--u); bottom: calc(0.4 * var(--u)); height: 2px;
    background: var(--ink); transform: scaleX(0); transform-origin: left;
  }
  .r-tab[aria-selected="true"]::after { animation: r-fill var(--step-t, 8s) linear both; }
  .r5[data-held] .r-tab[aria-selected="true"]::after { animation: none; transform: scaleX(1); }

  /* ---- the picture: the page of rules, one rule in big type, and Lumi above its window ---- */
  .r-pic {
    grid-area: pic; min-width: 0; position: relative; margin-top: calc(5 * var(--u));
    display: grid; grid-template-columns: minmax(0, 1fr) var(--chatw); column-gap: calc(2 * var(--u));
    grid-template-areas: "page win" "pcap cap"; align-items: start;
  }

  /* The page of rules: a sheet of paper. The file's name runs across its top, the five pattern words
     down its side. Its five patterns share one place, one showing at a time: when the rule applies,
     the rule, who it follows. */
  .r-page {
    grid-area: page; position: relative; z-index: 1; box-sizing: border-box; min-width: 0;
    display: grid; grid-template-columns: calc(15 * var(--u)) minmax(0, 1fr); grid-template-rows: auto 1fr; row-gap: calc(1.3 * var(--u));
    min-height: calc(21.5rem * var(--k, 1)); padding: calc(2.2 * var(--u)); /* room for the longest pattern beside the list; grows with the window's scale */
    border-radius: var(--radius-xl); background: var(--paper); color: var(--neutral-950);
    font-size: calc(var(--doc) * var(--u)); line-height: var(--line-snug);
  }
  .r-file {
    position: static; grid-area: 1 / 1 / 2 / -1; display: flex; align-items: center; gap: calc(0.6 * var(--u));
    margin: calc(-2.2 * var(--u)) calc(-2.2 * var(--u)) 0; padding: calc(1.3 * var(--u)) calc(2.2 * var(--u));
    border-bottom: 1px solid var(--neutral-200); /* lint-ok: a hairline under the file's name */
    font-family: var(--font-mono); font-size: calc(1.1 * var(--u)); line-height: 1; color: var(--neutral-600);
  }
  /* the file icon: Lucide file-text from the icon folder as a mask, so it takes the file name's colour */
  .r-fi {
    flex: none; width: calc(1.4 * var(--u)); height: calc(1.4 * var(--u)); background: currentColor;
    -webkit-mask: url("../../../assets/icons/file-text.svg") center / contain no-repeat;
    mask: url("../../../assets/icons/file-text.svg") center / contain no-repeat;
  }
  @media (forced-colors: active) { .r-fi { forced-color-adjust: none; background: CanvasText; } }
  .r-pat {
    grid-area: 2 / 2; min-width: 0; display: flex; flex-direction: column;
    padding: calc(0.6 * var(--u)) 0 0 calc(2.6 * var(--u));
    opacity: 0; visibility: hidden;
    transition: opacity var(--duration-slow) var(--ease-default), visibility 0s linear var(--duration-slow);
  }
  .r-pat[data-cur] { opacity: 1; visibility: visible; transition-delay: 0s; }
  /* The page's order (his pick, 19 Nov 2026, Rulebook card option 3): the file's name as the sheet's
     header, the pattern's name as its title, then When as a small label over its line. */
  .r-h {
    margin: 0 0 calc(1.4 * var(--u));
    font-family: var(--font-display); font-weight: var(--display-weight); font-size: calc(2.9 * var(--u));
    line-height: var(--line-display); letter-spacing: var(--display-tight); color: var(--neutral-950);
  }
  .r-when { display: grid; gap: calc(0.5 * var(--u)); margin: 0; }
  .r-wl {
    font-family: var(--font-mono); font-size: max(var(--text-label), calc(0.95 * var(--u))); font-weight: var(--weight-medium); /* never under the site's smallest label */
    line-height: 1; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--neutral-600);
  }
  .r-wt { font-size: calc(1.45 * var(--u)); font-weight: var(--weight-medium); line-height: var(--line-snug); color: var(--neutral-950); text-wrap: pretty; }
  .r-rules { margin: calc(1.4 * var(--u)) 0 0; padding: 0 0 calc(1.8 * var(--u)); list-style: none; color: var(--neutral-950); } /* the air under it: a long rule never touches the Follows card */
  .r-rules li { margin: 0; padding: 0; text-wrap: balance; }
  .r-rules li + li { margin-top: calc(0.55 * var(--u)); }
  /* only the rule the chat follows shows; the rest stay on the page for a reader of the source */
  .r-rules li:not(:has(.r-lit)), .r-more { display: none; }
  /* The rule the chat is following right now: picked out in big type with a marker. */
  .r-lit {
    font-weight: var(--weight-semibold);
    font-size: calc(var(--rule-s) * var(--u)); line-height: 1.34; letter-spacing: var(--display-tight); /* lint-ok: room between the marked lines, so the strips never touch */
    -webkit-box-decoration-break: clone; box-decoration-break: clone;
    background-color: var(--neutral-950); color: var(--neutral-0);
    padding: 0.06em 0.28em; margin-inline: 0; border-radius: var(--radius-sm); box-shadow: none;
    opacity: 0; transition: opacity var(--duration-slow) var(--ease-default);
  }
  .r5[data-on~="lit"] .r-pat[data-cur] .r-lit { opacity: 1; }
  /* every rule names its source: a label, then each publisher once, its own mark in its own colour, then what its guide asks */
  /* the Follows rows sit in a grey card on the white page, each mark right beside its words (his review, 19 Nov 2026) */
  .r-src {
    display: flex; flex-direction: column; gap: calc(0.6 * var(--u)); margin: auto 0 0; list-style: none;
    padding: calc(1.2 * var(--u)) calc(1.4 * var(--u)); border-radius: var(--radius-lg); background: var(--neutral-100);
  }
  .r-src::before { content: "Follows"; font-size: calc(1.1 * var(--u)); font-weight: var(--weight-semibold); line-height: var(--line-title); color: var(--neutral-950); }
  .r-src li { display: flex; align-items: flex-start; gap: calc(0.6 * var(--u)); min-width: 0; font-size: calc(var(--doc) * var(--u)); line-height: var(--line-title); color: var(--neutral-600); }
  .r-src li span { text-wrap: balance; } /* never one word alone on a last line */
  .r-src li.r-same { margin-top: calc(-0.45 * var(--u)); }
  .r-same img { visibility: hidden; }
  .r-same b { display: none; }
  .r-src b { font-weight: var(--weight-semibold); color: var(--neutral-950); }
  /* a mark's middle sits on the middle of the capital letters of its first line (measured: the
     capitals' middle sits a touch above the line's, under a pixel at every size), also when the words run to two lines */
  .r-src img { --mh: var(--logo); flex: none; width: auto; height: calc(var(--mh) * var(--u)); margin-top: calc(((var(--doc) * var(--line-title) - var(--mh)) / 2 - 0.025 * var(--doc)) * var(--u)); object-fit: contain; object-position: left center; }
  .r-src img.r-wide { --mh: calc(0.84 * var(--logo)); } /* a wide wordmark is drawn shorter, so it weighs the same as a square mark */

  /* Lumi and its window: Lumi above the pair, then the window it speaks in beside the sheet, then
     the captions. The window is the site's real one, in its light theme on its own solid surface,
     the sheet's height, held at the height of its longest chat so nothing beside it moves as the
     lines come in; they stack up from its bottom edge. */
  .r-win { display: contents; }
  .r-win-m { grid-area: win; position: relative; z-index: 1; width: 17rem; zoom: var(--k, 1); text-align: left; }
  .r-win .ccs-win {
    position: relative; inset: auto; box-sizing: border-box; min-height: 17rem; height: var(--wh, auto);
    background: var(--color-surface); -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .r-win .ccs-log { flex: 1 1 auto; justify-content: flex-end; -webkit-mask-image: none; mask-image: none; }
  .r-win .ccs-msg--bot { align-items: flex-start; }
  .r-win .ccs-chips { flex-wrap: wrap; overflow: visible; }
  .r-win .ccs-name { gap: 0; }   /* lumi and IMAGING close, as one lockup (his review, 19 Nov 2026) */
  .r-pcap, .r-cap {
    display: block; position: relative; z-index: 1; margin: calc(0.9 * var(--u)) 0 0;
    font-size: calc(1.2 * var(--u)); line-height: var(--line-title); color: var(--sub); text-align: left;
  }
  .r-pcap { grid-area: pcap; transition: opacity var(--duration-flourish) var(--ease-default); }
  .r-cap { grid-area: cap; }
  .r5:not([data-on~="pic"]) .r-pcap { opacity: 0; }
  /* the line that follows the rule: marked as the rule is, a strip to each line, so it never
     reads as one of the patient's bubbles */
  .r-obey { max-width: 94%; }
  .r-obey span { text-wrap: balance; }
  .r-obey mark {
    font-weight: var(--weight-semibold); line-height: 1.72; /* lint-ok: room between the marked lines, so the strips never touch */
    background-color: var(--neutral-950); color: var(--neutral-0);
    -webkit-box-decoration-break: clone; box-decoration-break: clone;
    padding: 0.1em 0.42em; border-radius: var(--radius-sm);
  }
  /* Lumi's seat: a place and a size, above its own window, on the ground beside the words.
     rulebook.js puts the one Lumi's canvas in it. All of Lumi sits on the section's ground, clear
     of the window and the page of rules. The square is bigger than Lumi's body, so its empty
     lower edge is taken back, and Lumi's body stands on the window's top. */
  .r-lumi-w {
    position: absolute; z-index: 0; pointer-events: none;
    right: calc((var(--chatw) - var(--ls) * var(--u)) / 2); bottom: calc(100% - 0.11 * var(--ls) * var(--u));
    width: calc(var(--ls) * var(--u)); aspect-ratio: 1;
  }
  .r-fly { width: 100%; height: 100%; }
  .r-fly canvas { display: block; width: 100%; height: 100%; }

  .r5[data-snap] *, .r5[data-snap] { transition: none !important; }

  @media (prefers-reduced-motion: reduce) {
    .r5 *, .r5 { transition: none !important; }
    .r-tab[aria-selected="true"]::after { animation: none; transform: scaleX(1); }
  }

  /* =====================================================================
     PHONE: its own stack. Words, then Lumi, the page of rules with the five pattern words as a
     row of pills under the file's name, the chat right under it, and the line from Testing last.
     ===================================================================== */
  @container row (max-width: 1000px) {
    .r5 {
      --hh: clamp(48rem, 122svh, 76rem); --fh: 230;
      --pad: calc(6 * var(--u)); --title: 12; --body: 4.27; --doc: 3.47; --logo: 4.6;
      --rule-s: 5.6; --ls: 88;
    }
    .r-lead span { display: inline; }
    .r-turn { margin-top: calc(7 * var(--u)); font-size: calc(3.47 * var(--u)); }
    .r-tabs { flex-direction: row; flex-wrap: wrap; align-items: center; gap: calc(1.6 * var(--u)); margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
    .r-tab {
      min-height: 2.75rem; padding: 0 calc(3.2 * var(--u)); border-radius: var(--chip-radius); font-size: max(var(--text-label), calc(3.2 * var(--u))); /* never under the site's smallest label */
      background: var(--neutral-100); /* lint-ok: the sheet's grounds come straight from the neutral ramp, which page.css turns over in dark */
    }
    .r-tab::after { display: none; } /* the pill itself says which is on */
    .r-pic { grid-template-columns: minmax(0, 1fr); grid-template-areas: "lumi" "page" "pcap" "win" "cap"; row-gap: 0; }
    /* Lumi in the stack, between the words and the page of rules; its square's empty edges taken back */
    .r-lumi-w { position: relative; grid-area: lumi; justify-self: center; right: auto; bottom: auto; margin: calc(-0.15 * var(--ls) * var(--u)) 0 calc(-0.11 * var(--ls) * var(--u)); }
    .r-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; min-height: 0; padding: calc(5.5 * var(--u)); row-gap: calc(4 * var(--u)); }
    .r-file { grid-area: 1 / 1; margin: calc(-5.5 * var(--u)) calc(-5.5 * var(--u)) 0; padding: calc(3.2 * var(--u)) calc(5.5 * var(--u)); gap: calc(1.6 * var(--u)); font-size: calc(2.9 * var(--u)); }
    .r-pat { grid-area: 3 / 1; padding: 0; }
    .r-fi { width: calc(3.6 * var(--u)); height: calc(3.6 * var(--u)); }
    .r-h { font-size: calc(7.6 * var(--u)); margin-bottom: calc(3.6 * var(--u)); }
    .r-when { gap: calc(1.4 * var(--u)); }
    .r-wl { font-size: max(var(--text-label), calc(2.6 * var(--u))); } /* never under the site's smallest label */
    .r-wt { font-size: calc(3.9 * var(--u)); }
    .r-rules { margin-top: calc(3.6 * var(--u)); padding-bottom: calc(4.5 * var(--u)); }
    .r-rules li + li { margin-top: calc(1.6 * var(--u)); }
    .r-src { gap: calc(1.8 * var(--u)); padding: calc(3.6 * var(--u)) calc(4 * var(--u)); }
    .r-src::before { font-size: calc(2.9 * var(--u)); }
    .r-src li { gap: calc(1.8 * var(--u)); }
    .r-src li.r-same { margin-top: calc(-1.1 * var(--u)); }
    .r-pcap, .r-cap { margin-top: calc(2.4 * var(--u)); font-size: calc(3.2 * var(--u)); }
    .r-win-m { margin-top: calc(6 * var(--u)); }
    .r-win .ccs-win { height: auto; }
  }
}
@keyframes r-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
