/* ==========================================================================
   CardiSim's instrument voice: Nerd Fonts.

   Archivo stays the reading voice (the mark, heads, body, answers). Under it
   runs an instrument voice, a patched mono with its own icons and powerline
   caps, chosen per theme for what the theme is:

     faceplate  Martian Mono     silkscreened legends on a hardware panel
     original   JetBrains Mono   the original look's own mono, now with icons
     runsheet   Monaspice Xe     typed entries on the printed form (the form's
                                 labels stay Archivo; only what is filled in
                                 is typed)

   Three things speak in it:
     1. Legends and readouts: every engraved label and printed value on
        CardiSim's own pages (calibrations, counts, kickers, field labels),
        by re-pointing --font-legend inside .csPage and the bug sheet. The
        study modes behind #monitorOverlay are MediSim's and keep their
        voice; nothing here selects into the overlay.
     2. Glyphs: <i class="nf nf-…" aria-hidden="true"></i>, named as on the
        Nerd Fonts cheat sheet (nf-md-* is Material Design). A glyph comes
        from the same font as the legend beside it, so it sits on the same
        baseline at the same weight. nf-go and nf-back are the two roles
        every key shares.
     3. The tab and the status line: a chip with a powerline cap (.csTab),
        and a head plus body of readouts with thin chevrons between them
        (.csLine). The recorder heads, the strip captions, the section
        indexes and the tour's stop numbers all print in this one shape.

   The fonts are CardiSim's alone (/cardisim/fonts/, cut by
   scripts/cardisim-fonts.py), so MediSim's screens never change. A page
   downloads only its theme's family, and its glyph file only once a glyph
   shows. Every icon in the glyph files is named by a string escape in this
   sheet: add a glyph class below, run the script, and the icon is in.
   ========================================================================== */

/* ── 1. Faces. Letters per weight; the glyphs in a file of their own. ─── */
@font-face {
  font-family: "CS Martian NF"; src: url("/cardisim/fonts/martian-mono-nf-500.woff2") format("woff2");
  font-weight: 100 649; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS Martian NF"; src: url("/cardisim/fonts/martian-mono-nf-700.woff2") format("woff2");
  font-weight: 650 1000; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS Martian NF"; src: url("/cardisim/fonts/martian-mono-nf-glyphs.woff2") format("woff2");
  font-weight: 100 1000; font-display: block;
  unicode-range: U+E000-F8FF, U+F0000-FFFFD;
}
@font-face {
  font-family: "CS JetBrains NF"; src: url("/cardisim/fonts/jetbrains-mono-nf-500.woff2") format("woff2");
  font-weight: 100 649; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS JetBrains NF"; src: url("/cardisim/fonts/jetbrains-mono-nf-700.woff2") format("woff2");
  font-weight: 650 1000; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS JetBrains NF"; src: url("/cardisim/fonts/jetbrains-mono-nf-glyphs.woff2") format("woff2");
  font-weight: 100 1000; font-display: block;
  unicode-range: U+E000-F8FF, U+F0000-FFFFD;
}
@font-face {
  font-family: "CS Monaspice Xe NF"; src: url("/cardisim/fonts/monaspice-xe-nf-500.woff2") format("woff2");
  font-weight: 100 649; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS Monaspice Xe NF"; src: url("/cardisim/fonts/monaspice-xe-nf-700.woff2") format("woff2");
  font-weight: 650 1000; font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010-2027, U+2030-203A, U+2190-2195, U+2212, U+221A, U+2220, U+2264-2265, U+25B8, U+25C2, U+2713, U+2715;
}
@font-face {
  font-family: "CS Monaspice Xe NF"; src: url("/cardisim/fonts/monaspice-xe-nf-glyphs.woff2") format("woff2");
  font-weight: 100 1000; font-display: block;
  unicode-range: U+E000-F8FF, U+F0000-FFFFD;
}

/* ── 2. Tokens, per theme ──────────────────────────────────────────────
   --nf-cell is the family's ascent + descent in em and --nf-cap its
   powerline cap's advance (scripts/cardisim-fonts.py prints both into
   fonts/fonts.json): a cap set at bar-height / cell fills the bar exactly,
   and is that times cap wide. */
:root[data-product="CardiSim"] {
  --font-nerd: "CS Martian NF", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --nf-cell: 1.2; --nf-cap: .699;
  --fs-nerd: 10px; --tr-nerd: .04em;
  /* The tab and the line: head, body, the thin chevrons between readouts. */
  --tab-bg: var(--graphite); --tab-ink: var(--screen-ink);
  --line-body: var(--chassis-2); --line-ink: var(--ink-2); --line-sep: var(--rule-2);
}
:root[data-product="CardiSim"][data-theme="original"] {
  --font-nerd: "CS JetBrains NF", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --nf-cell: 1.32; --nf-cap: .599;
  --fs-nerd: 11px; --tr-nerd: .02em;
}
:root[data-product="CardiSim"][data-theme="runsheet"] {
  --font-nerd: "CS Monaspice Xe NF", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --nf-cell: 1.245; --nf-cap: .6195;
  --fs-nerd: 11px; --tr-nerd: 0em;
  /* The form's black section bars; what is typed sits on the sheet. */
  --tab-bg: var(--ink); --tab-ink: var(--cap);
  --line-body: transparent; --line-ink: var(--ink); --line-sep: var(--ink-3);
}

/* Legends: the panel's own voice on faceplate and original. The run
   sheet's labels are printed, so they stay Archivo (runsheet.css). */
:root[data-product="CardiSim"]:not([data-theme="runsheet"]) :is(.csPage, .csBugSheet) {
  --font-legend: var(--font-nerd); --fs-legend: var(--fs-nerd); --tr-legend: var(--tr-nerd);
}

/* ── 3. Glyphs ─────────────────────────────────────────────────────────── */
.nf {
  display: inline-block; flex: none;
  font-family: var(--font-nerd); font-style: normal; font-weight: 500; font-variant: normal;
  font-size: 1.15em; line-height: 1; letter-spacing: 0; text-transform: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
/* A key's glyph: a touch larger than its legend, centred on the caps. */
.key .nf { font-size: 1.2em; }
.key--sm .nf { font-size: 1.15em; }

/* Roles. */
.nf-go::before                { content: "\f0054"; }  /* md-arrow_right */
.nf-back::before              { content: "\f004d"; }  /* md-arrow_left */
/* Doors and the account. */
.nf-md-login::before          { content: "\f0342"; }
.nf-md-logout::before         { content: "\f0343"; }
.nf-md-account_plus_outline::before { content: "\f0801"; }
.nf-md-account_circle_outline::before { content: "\f0b55"; }
.nf-md-shield_account_outline::before { content: "\f0a12"; }
.nf-md-account_multiple::before { content: "\f000e"; }
.nf-md-home_outline::before   { content: "\f06a1"; }
.nf-md-key_variant::before    { content: "\f030b"; }
.nf-md-email_fast_outline::before { content: "\f1870"; }
.nf-md-email_outline::before  { content: "\f01f0"; }
.nf-md-restart::before        { content: "\f0709"; }
.nf-md-trash_can_outline::before { content: "\f0a7a"; }
.nf-md-devices::before        { content: "\f0fb0"; }
.nf-md-credit_card_outline::before { content: "\f019b"; }
.nf-md-chart_line::before     { content: "\f012a"; }
.nf-md-check::before          { content: "\f012c"; }
.nf-md-check_circle_outline::before { content: "\f05e1"; }
.nf-md-close::before          { content: "\f0156"; }
.nf-md-bug_outline::before    { content: "\f0a30"; }
.nf-md-file_document_outline::before { content: "\f09ee"; }
.nf-md-shield_lock_outline::before { content: "\f0ccc"; }
.nf-md-cash_refund::before    { content: "\f0a9c"; }
.nf-md-coffee_outline::before { content: "\f06ca"; }
/* The work. */
.nf-md-pulse::before          { content: "\f0430"; }
.nf-md-heart_pulse::before    { content: "\f05f6"; }
.nf-md-heart_outline::before  { content: "\f02d5"; }
.nf-md-book_open_variant::before { content: "\f14f7"; }
.nf-md-lightning_bolt::before { content: "\f140b"; }
.nf-md-needle::before         { content: "\f0391"; }
.nf-md-sine_wave::before      { content: "\f095b"; }
.nf-md-tag_outline::before    { content: "\f04fc"; }
.nf-md-fire::before           { content: "\f0238"; }
.nf-md-shuffle_variant::before { content: "\f049f"; }
.nf-md-tune_variant::before   { content: "\f1542"; }
.nf-md-stairs::before         { content: "\f04cd"; }
.nf-md-monitor_cellphone::before { content: "\f0989"; }
.nf-md-printer_outline::before { content: "\f1786"; }

/* ── 4. The tab and the status line ────────────────────────────────────
   Powerline caps, sized from the bar: --cap-fs sets the cap glyph so its
   cell is exactly the bar's height, --cap-w is how wide it then runs. An
   element paints its own fill short of its cap (a gradient sized to the
   rest), so the cap's point sits on whatever is behind it. */
.csTab, .csLine {
  --bar-h: 18px;
  --cap-fs: calc(var(--bar-h) / var(--nf-cell));
  --cap-w: calc(var(--cap-fs) * var(--nf-cap));
}
.csTab::after, .csLineHead::after, .csLine::after, .csLineBody > * + *::before {
  flex: none; font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); letter-spacing: 0; text-transform: none;
}

/* A tab: a chip with a cap on its right. */
.csTab {
  display: inline-flex; align-items: center; height: var(--bar-h); padding-left: 6px;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(var(--tab-bg), var(--tab-bg)) no-repeat left / calc(100% - var(--cap-w)) 100%;
  color: var(--tab-ink);
}
.csTab::after { content: "\e0b0"; margin-left: 5px; color: var(--tab-bg); }

/* A status line: a tab for its head, a body of readouts, a cap to close. */
.csLine {
  display: inline-flex; align-items: center; height: var(--bar-h); min-width: 0; max-width: 100%;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(var(--line-body), var(--line-body)) no-repeat left / calc(100% - var(--cap-w)) 100%;
  font: 500 var(--fs-nerd)/var(--bar-h) var(--font-nerd); letter-spacing: var(--tr-nerd);
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--line-ink);
}
.csLine::after { content: "\e0b0"; color: var(--line-body); }
.csLineHead {
  display: inline-flex; align-items: center; gap: 5px; height: 100%; padding-left: 6px;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(var(--tab-bg), var(--tab-bg)) no-repeat left / calc(100% - var(--cap-w)) 100%;
  color: var(--tab-ink); text-transform: uppercase;
}
.csLineHead::after { content: "\e0b0"; margin-left: 1px; color: var(--tab-bg); }
.csLineHead .nf { font-size: 1.2em; }
.csLineBody { display: inline-flex; align-items: center; min-width: 0; padding: 0 2px 0 6px; overflow: hidden; }
.csLineBody > * { display: inline-flex; align-items: center; }
.csLineBody > * + *::before { content: "\e0b1"; margin: 0 6px; color: var(--line-sep); }

/* ── 5. Where they print ───────────────────────────────────────────────── */

/* The recorder heads (landing, tour): the calibration is a status line. */
.csCal.csLine {
  flex: 0 1 auto; margin-right: auto; overflow: visible; text-overflow: clip;
  color: var(--line-ink); text-transform: none; letter-spacing: var(--tr-nerd);
}
.csRecHead { gap: 8px; }
/* A strip's own number and seed close the head from the right, the line
   mirrored: a cap pointing in, then the readout. */
.tourStamp:not(:empty) {
  --bar-h: 18px; --cap-fs: calc(var(--bar-h) / var(--nf-cell)); --cap-w: calc(var(--cap-fs) * var(--nf-cap));
  display: inline-block; height: var(--bar-h); padding: 0 8px 0 0;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: linear-gradient(var(--line-body), var(--line-body)) no-repeat right / calc(100% - var(--cap-w)) 100%;
  font: 500 var(--fs-nerd)/var(--bar-h) var(--font-nerd); letter-spacing: var(--tr-nerd); text-transform: none;
  color: var(--line-ink);
}
.tourStamp:not(:empty)::before {
  content: "\e0b2"; display: inline-block; vertical-align: top; margin-right: 6px;
  font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); color: var(--line-body);
}

/* The strip's caption: the lead is a tab, the name runs on under its cap. */
:is(.csPaperCap, .csHome .studyStripCap) {
  --bar-h: 18px; --cap-fs: calc(var(--bar-h) / var(--nf-cell)); --cap-w: calc(var(--cap-fs) * var(--nf-cap));
  --cap-name: color-mix(in oklab, var(--strip-paper) 86%, transparent);
  gap: 0;
}
:is(.csPaperCap, .csHome .studyStripCap):has(.is-named) { --cap-name: var(--amber); }
:is(.csPaperLead, .csHome .studyStripLead) {
  position: relative; z-index: 1; display: inline-flex; align-items: center; height: var(--bar-h);
  padding: 0 0 0 6px; border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(var(--strip-trace), var(--strip-trace)) no-repeat left / calc(100% - var(--cap-w)) 100%;
  font: 600 var(--fs-nerd)/var(--bar-h) var(--font-nerd); letter-spacing: var(--tr-nerd);
}
:is(.csPaperLead, .csHome .studyStripLead)::after {
  content: "\e0b0"; margin-left: 4px; font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); color: var(--strip-trace);
}
:is(.csPaperName, .csHome .studyStripName) {
  height: var(--bar-h); margin-left: calc(-1 * var(--cap-w)); padding: 0 4px 0 calc(var(--cap-w) + 6px);
  border-radius: 0; box-shadow: none; background: var(--cap-name);
  font: 500 var(--fs-nerd)/var(--bar-h) var(--font-nerd); letter-spacing: var(--tr-nerd);
}
:is(.csPaperName, .csHome .studyStripName):empty { display: none; }
:is(.csPaperName, .csHome .studyStripName).is-named {
  background: var(--cap-name); box-shadow: none; color: var(--ink);
  font: 600 var(--fs-small)/var(--bar-h) var(--font-ui); letter-spacing: 0;
}
:is(.csPaperCap, .csHome .studyStripCap)::after {
  content: "\e0b0"; flex: none; font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); color: var(--cap-name);
}
:is(.csPaperCap, .csHome .studyStripCap):not(:has(:is(.csPaperName, .studyStripName):not(:empty)))::after { content: none; }

/* Section indexes: the number is a tab pointing into its title (the
   home and admin heads, the account rows, the policies' sections). */
:root[data-product="CardiSim"] :is(.csSecHead, .csAcctSide, .csDocSecHead) .csIdx:not(:empty) {
  --bar-h: 18px; --cap-fs: calc(var(--bar-h) / var(--nf-cell)); --cap-w: calc(var(--cap-fs) * var(--nf-cap));
  display: inline-flex; align-items: center; justify-self: start; height: var(--bar-h); padding-left: 6px;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  background: linear-gradient(var(--tab-bg), var(--tab-bg)) no-repeat left / calc(100% - var(--cap-w)) 100%;
  color: var(--tab-ink); line-height: var(--bar-h);
}
:root[data-product="CardiSim"] :is(.csSecHead, .csAcctSide, .csDocSecHead) .csIdx:not(:empty)::after {
  content: "\e0b0"; margin-left: 5px; font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); color: var(--tab-bg);
}
:root[data-product="CardiSim"] .csSecHead .csIdx { align-self: center; }
.csAcctSide { grid-template-columns: max-content minmax(0, 1fr); column-gap: 12px; }
.csDocSecHead { grid-template-columns: 48px minmax(0, 1fr); }
.csProse { padding-left: 48px; }
@media (max-width: 560px) {
  .csDocSecHead { grid-template-columns: 46px minmax(0, 1fr); }
  .csProse { padding-left: 0; }
}
.csSecHead { gap: 10px; }

/* The tour's stop numbers: a tab in the stop's own channel colour. */
.tourNo {
  --bar-h: 20px; --cap-fs: calc(var(--bar-h) / var(--nf-cell)); --cap-w: calc(var(--cap-fs) * var(--nf-cap));
  display: inline-flex; align-items: center; height: var(--bar-h); padding: 0 0 0 7px;
  border-radius: var(--r-sm) 0 0 var(--r-sm); box-shadow: none;
  background: linear-gradient(var(--tab), var(--tab)) no-repeat left / calc(100% - var(--cap-w)) 100%;
}
.tourNo::after {
  content: "\e0b0"; margin-left: 5px; font: 400 var(--cap-fs)/var(--bar-h) var(--font-nerd); color: var(--tab);
}
.tourKicker { gap: 8px; }

/* Keys: a glyph and its legend. */
.csFootReport.key .nf, .csReportKey.key .nf { font-size: 16px; }
/* The doors in a page's bar carry their glyph by where they go, so every
   page (and the server's admin key) gets the same one with no markup. */
.cardisim :is(.csBarKeys, .csMastKeys) .key:is([href="/account"], [href^="/admin"], [href="/home"], [href^="/signin"], [href^="/signup"])::before {
  flex: none; font: 500 1.2em/1 var(--font-nerd); letter-spacing: 0;
}
.cardisim :is(.csBarKeys, .csMastKeys) .key[href="/account"]::before { content: "\f0b55"; }
.cardisim :is(.csBarKeys, .csMastKeys) .key[href^="/admin"]::before { content: "\f0a12"; }
.cardisim :is(.csBarKeys, .csMastKeys) .key[href="/home"]::before { content: "\f06a1"; }
.cardisim :is(.csBarKeys, .csMastKeys) .key[href^="/signin"]::before { content: "\f0342"; }
.cardisim :is(.csBarKeys, .csMastKeys) .key[href^="/signup"]::before { content: "\f0801"; }
.csBarKeys .key, .csMastKeys .key { gap: 7px; }
/* A phone's bar is tight: the doors keep their words and drop the glyph. */
@media (max-width: 560px) {
  .cardisim .csBarKeys .key:is([href="/account"], [href^="/admin"], [href="/home"], [href^="/signin"], [href^="/signup"])::before { content: none !important; }
}
/* The admin pages' switch. */
.csAdminModeGlyph::before { display: block; font: 500 17px/1 var(--font-nerd); }
.csAdminMode[href="/admin"] .csAdminModeGlyph::before { content: "\f000e"; }
.csAdminMode[href="/admin/bugs"] .csAdminModeGlyph::before { content: "\f0a30"; }
.csAdminMode[href="/admin/settings"] .csAdminModeGlyph::before { content: "\f1542"; }
@media (max-width: 720px) { .csAdminModeGlyph::before { font-size: 21px; } }
/* The policies' switch, and each policy's kicker (a status line). */
.csLegalSwitch .nf { font-size: 1.2em; }
@media (max-width: 560px) { .csLegalSwitch .nf { display: none; } }
.csDocKicker .csLine { --line-body: transparent; }

/* The course map: each track's number carries its glyph, in its colour. */
.csTrackNo { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.csTrackNo .nf { font-size: 24px; color: var(--tab-glyph, var(--ink)); }
.csTrack[data-tab="blue"]  { --tab-glyph: var(--blue-ink); }
.csTrack[data-tab="green"] { --tab-glyph: var(--green-ink); }
.csTrack[data-tab="red"]   { --tab-glyph: var(--red-ink); }
.csTrack[data-tab="amber"] { --tab-glyph: var(--amber-ink); }
@media (max-width: 720px) {
  .csTrackNo { gap: 8px; }
  .csTrackNo .nf { font-size: 18px; }
}

/* The shared tiles on the home print their go glyph as text (MediSim's
   ▸ and →); on CardiSim's home they take the theme's own. */
.csHome :is(.keyGlyph, .hlEntryGoGlyph) { font-size: 0; }
.csHome :is(.keyGlyph, .hlEntryGoGlyph)::before { content: "\f0054"; font: 500 17px/1 var(--font-nerd); }

/* The plan's latte. */
.csPriceNote .nf { margin-right: 6px; font-size: 1.2em; vertical-align: -.12em; color: var(--ink-2); }

/* The home's readouts: a glyph before each label. */
.csReadouts dt { display: inline-flex; align-items: center; gap: 5px; }
.csReadouts dt .nf { font-size: 1.35em; color: var(--ink-2); }

/* The password's Show key: an eye, open or shut, beside the word. */
.csPwShow { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.csPwShow::before {
  content: "\f06d0"; font: 500 15px/1 var(--font-nerd); letter-spacing: 0;
}
.csPwShow[aria-pressed="true"]::before { content: "\f06d1"; }

/* The run sheet: what the learner types goes onto the form typed. */
:root[data-product="CardiSim"][data-theme="runsheet"] :is(.csPage, .csBugSheet) .input {
  font-family: var(--font-nerd); letter-spacing: 0;
}

/* ── 6. Forced colours: tabs and lines keep a shape in system ink ─────── */
@media (forced-colors: active) {
  .csTab, .csLine, .csLineHead, :is(.csSecHead, .csAcctSide, .csDocSecHead) .csIdx:not(:empty), .tourNo, .tourStamp:not(:empty),
  :is(.csPaperLead, .csHome .studyStripLead), :is(.csPaperName, .csHome .studyStripName) {
    background: none !important; border: 1px solid CanvasText; padding-right: 4px;
  }
  .csTab::after, .csLine::after, .csLineHead::after, .csIdx::after, .tourNo::after,
  .tourStamp:not(:empty)::before, :is(.csPaperLead, .csHome .studyStripLead)::after,
  :is(.csPaperCap, .csHome .studyStripCap)::after { content: none !important; }
}
