/* ==========================================================================
   The mark: "medisim" with one lit i.

   The wordmark is the app's own typeface with one engineered change: the
   second i is a dotless ı, and its dot is a round amber lamp, "the pilot".
   It is the only identity lamp in the system; amber everywhere else still
   means pending (system.css channel doc). Its colour is --pilot (amber when
   unset); CardiSim sets it red (src/cardisim/static/cardisim.css).

   Every .brand carries the same markup (tests/web/brand.test.ts fences it):
     <… class="brand"><span class="sr-only">medisim</span>
       <span class="brandMark" aria-hidden="true">medis<span class="brandI">ı</span>m</span></…>

   Voices, one mark:
     faceplate  lowercase, Archivo at 125% width, a flat lamp
     original   UPPERCASE wide; its leading pip (.brand::before, drawn in the
                theme's own sheet) is the lamp, so the I stays plain
     runsheet   condensed 62% black; the lamp is a flat filled bubble

   This sheet is unthemed (theme-render.ts UNTHEMED_SHEETS): it only uses
   tokens every theme defines, and branches on data-theme for the voice.
   Motion (brand.js): the landing ignition, the quote sweep, and the 90 ms
   off-blink in the working headers. Nothing here loops.
   ========================================================================== */

.brand { -webkit-user-select: none; user-select: none; }
.brandMark {
  display: inline-block; white-space: nowrap;
  font-family: var(--font-ui); font-stretch: var(--mk-wdth, 125%);
  /* The mark's box ends at the baseline's descent, so the lamp's offsets
     below are measured from a fixed point at every line-height. */
}
:root[data-theme="runsheet"] .brandMark { --mk-wdth: 62%; }

/* The pilot. .brandI must stay inline (not inline-block): an inline box's
   bottom edge sits a constant .208em under the baseline in Archivo, which
   is what --base-off measures from. */
.brandI { position: relative; display: inline; }
.brandI::after {
  content: ""; position: absolute; pointer-events: none;
  width: var(--led-d, .184em); height: var(--led-d, .184em);
  left: calc(50% - var(--led-d, .184em) / 2);
  bottom: calc(var(--led-y, .672em) - var(--led-d, .184em) / 2 + var(--base-off, .208em));
  border-radius: 50%; background: var(--pilot, var(--led-amber));
}
/* Small marks (working headers) need a proportionally bigger lamp. */
.brand--sm .brandI::after { --led-d: .22em; }
:root[data-theme="runsheet"] .brandI::after { --led-d: .17em; --led-y: .668em; }
:root[data-theme="runsheet"] .brand--sm .brandI::after { --led-d: .2em; }
/* Original: the leading pip is the lamp. */
:root[data-theme="original"] .brandI::after { display: none; }
/* High contrast: keep the dot, in the system's text colour. */
@media (forced-colors: active) {
  .brandI::after { forced-color-adjust: none; background: CanvasText; }
}

/* ── Working headers: a 90 ms off-blink per committed order or answer ──── */
.brand.is-blink .brandI::after,
:root[data-theme="original"] .brand.is-blink::before { visibility: hidden; }

/* ── /me: the mark is the way home, so it presses like a key ─────────── */
a.brand { color: inherit; text-decoration: none; }
a.brand .brandMark {
  transform-origin: 0 100%;
  transition: transform var(--m-release) var(--e-spring);
}
a.brand:active .brandMark {
  transform: scaleX(.93) translateY(1px);
  transition: transform var(--m-press) linear;
}
a.brand:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 2px; }

/* ==========================================================================
   Landing ignition (brand.js adds .is-igniting to the masthead for ~1.8 s,
   once per tab session; a click on the wordmark replays it).
     0–420 ms     the mast rule feeds out left to right
     120–760 ms   letters rise out of the rule, at the far end of the width axis
     760–1320 ms  the word unfolds across the width axis to its theme width
     1380 ms      lamp test: blue for 120 ms, then amber snaps on
     ~1450 ms     the first quote sweeps in
   The live copy (.brandLive) is a clone laid over the real mark, which is
   hidden but keeps its box, so nothing around the mark moves.
   ========================================================================== */
.startMast { position: relative; }
.startMast .brand { position: relative; }
.startMast.is-igniting { border-bottom-color: transparent; }
.startMast.is-igniting::after {
  content: ""; position: absolute; left: 0; right: 0;
  bottom: calc(-1 * var(--mast-rule, 2px)); height: var(--mast-rule, 2px);
  background: var(--ink); transform-origin: 0 50%;
  animation: brandRule 420ms linear both;
}
@keyframes brandRule { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.startMast.is-igniting .brand > .brandMark:not(.brandLive) { visibility: hidden; }
.brandLive {
  position: absolute; z-index: 1; pointer-events: none;
  /* Letters come up out of the mark's own floor. */
  clip-path: inset(-1em -2em 0 -2em);
  --w0: 62%; --w1: 125%;
  font-stretch: var(--w0);
  animation: brandUnfold 560ms var(--e-seat) 760ms both;
}
:root[data-theme="runsheet"] .brandLive { --w0: 100%; --w1: 62%; }
@keyframes brandUnfold { from { font-stretch: var(--w0); } to { font-stretch: var(--w1); } }
.brandLive .bl {
  display: inline-block;
  animation: brandRise 640ms var(--e-spring) calc(120ms + var(--i, 0) * 55ms) both;
}
@keyframes brandRise { from { transform: translateY(1.05em); } to { transform: none; } }

/* The lamp test, on the live copy's lamp (or the original theme's pip). */
.brandLive .brandI::after,
:root[data-theme="original"] .startMast.is-igniting .brand::before {
  animation: brandLamp 1720ms linear both;
}
@keyframes brandLamp {
  0%, 80.2% { background: transparent; box-shadow: inset 0 0 0 max(1px, .012em) var(--rule-2); transform: none; }
  80.3%, 87.1% { background: var(--led-blue); box-shadow: none; transform: none; }
  87.2% { background: var(--pilot, var(--led-amber)); transform: scale(1.22); animation-timing-function: var(--e-spring); }
  100% { background: var(--pilot, var(--led-amber)); transform: none; }
}

/* ==========================================================================
   The quote slot (replaces the masthead's old tagline; keeps .tag so the
   theme sheets' grid placement still applies).

   A new quote replaces the old one the way a monitor redraws: a 2 px ink
   bar crosses left to right in 24 steps; behind it the new quote, ahead of
   it (after a 1.1em gap) what is left of the old one. Every frame shows
   whole glyphs. The slot is a fixed number of lines; a quote that does not
   fit is skipped, never cut.
   ========================================================================== */
.quoteSlot {
  --q-lines: 2;
  display: grid; grid-template-columns: minmax(0, 1fr); align-items: end;
  min-width: 0; max-width: 62ch; margin: 0;
}
.quoteStack { position: relative; display: grid; min-width: 0; cursor: pointer; }
.quoteLayer {
  grid-area: 1 / 1; margin: 0; min-width: 0;
  height: calc(var(--q-lines) * 1lh + var(--q-cite-h, 1.4em));
  display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
}
.quoteBody { display: block; }
.quoteText { text-wrap: pretty; }
.quoteCite {
  display: block; margin-top: 3px; font-style: normal;
  font: 600 var(--fs-legend)/var(--lh-legend, 1.4) var(--font-ui); letter-spacing: .01em; color: var(--ink-3, var(--ink-2));
}
.quoteCite::before { content: "— "; }
.quoteCite:has(.quoteName:empty)::before { content: none; }
.quoteCite .quoteWho { font-weight: 400; }
.quoteLayer.is-out { pointer-events: none; }
/* The sweep (brand.js) moves each layer as a window and its words back the
   other way by the same amount, so the words hold still while the window's
   edge crosses them. Only transforms change, which the compositor animates
   without restyling or repainting the page each step. The stack clips so a
   window sliding past the edge never widens the page. */
.quoteStack { overflow: clip; overflow-clip-margin: 2px; }
.quoteStack:not(.is-sweeping) .quoteLayer.is-out { visibility: hidden; }
.quoteBar {
  position: absolute; top: 0; bottom: 0; left: 0; width: 2px; margin-left: -1px;
  background: var(--ink); pointer-events: none; visibility: hidden;
}
.quoteStack.is-sweeping .quoteBar { visibility: visible; }
/* During the ignition the slot is empty until its first sweep. */
.startMast.is-igniting .quoteSlot:not(.is-live) .quoteLayer { visibility: hidden; }

/* Voices. */
:root[data-theme="runsheet"] .quoteSlot { --q-lines: 3; max-width: 46ch; }

/* Phone: the slot takes the masthead's second row; the name runs in after
   the words and the descriptor drops. */
@media (max-width: 720px) {
  .quoteSlot, :root[data-theme="runsheet"] .quoteSlot { --q-lines: 2; --q-cite-h: 0px; max-width: none; }
  .quoteCite { display: inline; margin: 0 0 0 .35em; }
  .quoteCite .quoteWho { display: none; }
}
/* A phone on its side has no room for it. */
@media (orientation: landscape) and (max-height: 500px) {
  .startMast .quoteSlot { display: none; }
}

/* /me loads no theme page sheet, so the original voice (uppercase, leading
   pip) is drawn here for its mark. */
:root[data-theme="original"] .meMast .brand {
  display: inline-flex; align-items: center; gap: .2em; text-transform: uppercase; letter-spacing: .01em;
}
:root[data-theme="original"] .meMast .brand::before {
  content: ""; flex: none; width: .2em; height: .2em; border-radius: 50%;
  background: var(--pilot, var(--led-amber)); box-shadow: var(--lens);
}
