
  :root {
    --bg0: #0c0e14;
    --card: rgba(24, 28, 40, 0.82);
    --border: rgba(98, 115, 180, 0.18);
    --text: #e8eaf2;
    --muted: #8b92a8;
    --accent: #6c8cff;
    --accent2: #40d9c4;
    --danger: #ff8b7a;
    --sec-bg: rgba(0, 0, 0, 0.12);
    --imd-search-bg: rgba(0, 0, 0, 0.25);
    --imd-search-border: var(--border);
    --imd-search-radius: 8px;
    --imd-search-pad: 0.5rem 0.75rem;
    /* #1917: plain vh first. Safari < 15.4 has no dvh/lvh, and a custom
       property keeps an unsupported unit (it is only checked where used), so
       var(--imd-frame) went invalid and the list-scroll lock collapsed to 0.
       The new units are set only under @supports, below. */
    --imd-frame: 100vh;
    /* One reading gutter for every book and exam surface. It is applied on
       .wrap, which is never inside a reader zoom root, so it cannot be
       multiplied by CSS zoom the way per-publisher #doc padding was (#805).
       --imd-read-inset is the matching inset inside the reader card; it grows
       with the screen so a wide window is not one edge-to-edge column. */
    --imd-read-gutter: 1.5rem;
    --imd-read-inset: 2rem;
  }
  @supports (height: 100dvh) {
    :root {
      --imd-frame: 100dvh;
    }
  }
  * { box-sizing: border-box; }
  a.did-you-mean { color: #8ab4f8; font-weight: 600; }
  html[data-theme="light"] a.did-you-mean { color: #0b57d0; }
  html {
    min-height: 100%;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    background: radial-gradient(1200px 800px at 12% -10%, rgba(108, 140, 255, 0.14), transparent),
      radial-gradient(900px 600px at 88% 20%, rgba(64, 217, 196, 0.1), transparent), var(--bg0);
  }
  body {
    margin: 0;
    min-height: 100%;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: radial-gradient(1200px 800px at 12% -10%, rgba(108, 140, 255, 0.14), transparent),
      radial-gradient(900px 600px at 88% 20%, rgba(64, 217, 196, 0.1), transparent), var(--bg0);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
  }
  /* iPhone PWA: 100svh is the small viewport (754 vs screen 956 on #372 /
     #367). The leftover is --bg0 — the black hole. --imd-frame is the
     painted window (100lvh standalone, 100dvh in the browser). */
  @supports (height: 100lvh) {
    html.imd-standalone {
      --imd-frame: 100lvh;
    }
  }
  html.imd-standalone,
  html.imd-standalone body {
    min-height: var(--imd-frame);
  }
  /* #763: EPUBStyle hides the bar. Account “Show page scroller” (on by default). */
  html.imd-show-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(90, 102, 140, 0.55) transparent;
  }
  html.imd-show-scroll ::-webkit-scrollbar {
    width: 11px;
    height: 11px;
  }
  html.imd-show-scroll ::-webkit-scrollbar-thumb {
    background: rgba(90, 102, 140, 0.45);
    border-radius: 8px;
  }
  html.imd-show-scroll ::-webkit-scrollbar-track {
    background: transparent;
  }
  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }
  /* Dead AMBOSS learning-card / template anchors must not look like links (#315). */
  #reader-content a.autolink,
  #reader-content a[data-learningcard-id],
  #reader-content a[ng-href],
  #reader-content a:not([href]),
  #reader-content a[href=""],
  #reader-content a[href="#"]:not([data-utd-abstract]):not([data-utd-pathway]):not([data-utd-grade]):not([data-utd-action]) {
    color: inherit !important;
    text-decoration: none !important;
    cursor: inherit;
    pointer-events: none;
  }
  .top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 0;
  }
  html.imd-standalone .top {
    padding-top: max(0.65rem, env(safe-area-inset-top, 0px));
  }
  .top nav { margin-left: auto; }
  .top h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(120deg, #fff 0%, #b8c9ff 45%, #8af5e5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  .top .who { color: var(--muted); font-size: 0.88rem; max-width: 55vw; }
  .top nav { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
  .top a.navlink,
  .top a.navlink:link,
  .top a.navlink:visited,
  .top a.navlink:hover,
  .top a.navlink:focus,
  .top a.navlink:active {
    text-decoration: none;
  }
  .top a.navlink {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    line-height: 1;
    white-space: nowrap;
    padding: 0 0.6rem;
    min-height: 2.15rem;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid transparent;
    -webkit-tap-highlight-color: transparent;
  }
  .top a.navlink:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.12);
  }
  .top a.navlink.navlink--active {
    color: var(--text);
    border-color: rgba(108, 140, 255, 0.35);
    background: rgba(108, 140, 255, 0.08);
  }
  /* Phone-first app tabs. labrange_nav.html's <style> comes after the
     markup, and .top a.navlink { display } outranks a lone .lr-tab-extra
     { display: none }, so Highlights/Flashcards painted on iPhone until
     JS added lr-top--compact — or stayed if that flip never ran.
     Keep this in the head so the phone set is correct before first paint.
     Desktop enhance needs a real device-width, not Safari's ~980 CSS-px
     placeholder / Request Desktop Website. */
  .top a.navlink.lr-tab-extra { display: none; }
  .top.lr-top > .lr-more { display: inline-flex; }
  @media (min-width: 1024px) and (min-device-width: 900px) {
    html:not(.imd-phone) .top.lr-top:not(.lr-top--compact) a.navlink.lr-tab-extra {
      display: flex;
    }
    html:not(.imd-phone) .top.lr-top:not(.lr-top--compact) > .lr-more {
      display: none;
    }
  }
  html.imd-phone .top a.navlink.lr-tab-extra { display: none !important; }
  html.imd-phone .top.lr-top > .lr-more { display: inline-flex !important; }
  /* imd-chip-center: flex + system UI so a selected pill is optically
     centered. Later page rules that set font:inherit must not undo it. */
  .srch-tabs a,
  .srch-hist button,
  .srch-virt button,
  .dl-tabs button,
  .tool-tabs a,
  .tool-tabs button,
  .mm-tabs a,
  .mm-tabs button,
  .utd-segs button,
  .dp-tabs button,
  .vd-tabs a,
  .vd-mods a,
  .lexi-types a,
  .lexi-types span,
  .lexi-az a,
  .utdd-az a,
  .sw-tabs button,
  .iv-tabs button,
  .iv-az a,
  .ol-tabs button,
  .bugs-filters button,
  .qbank-bankbar-links a,
  .reader-toc-pill,
  .lr-chip,
  .lr-exp-chip,
  .lr-badge,
  .acct-kind,
  .bug-badge,
  .blocks-pill,
  .kap-badge,
  .cme-badge,
  .choice-your-badge,
  .pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif !important;
    line-height: 1;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }
  .srch-tabs a,
  .srch-tabs a:link,
  .srch-tabs a:visited,
  .srch-tabs a:hover,
  .srch-tabs a:focus,
  .srch-tabs a:active,
  .tool-tabs a,
  .tool-tabs a:link,
  .tool-tabs a:visited,
  .tool-tabs a:hover,
  .tool-tabs a:focus,
  .tool-tabs a:active,
  .mm-tabs a,
  .mm-tabs a:link,
  .mm-tabs a:visited,
  .mm-tabs a:hover,
  .mm-tabs a:focus,
  .mm-tabs a:active,
  .vd-tabs a,
  .vd-tabs a:link,
  .vd-tabs a:visited,
  .vd-tabs a:hover,
  .vd-tabs a:focus,
  .vd-tabs a:active,
  .vd-mods a,
  .vd-mods a:link,
  .vd-mods a:visited,
  .vd-mods a:hover,
  .vd-mods a:focus,
  .vd-mods a:active,
  .lexi-types a,
  .lexi-types a:link,
  .lexi-types a:visited,
  .lexi-types a:hover,
  .lexi-types a:focus,
  .lexi-types a:active,
  .lexi-az a,
  .lexi-az a:link,
  .lexi-az a:visited,
  .lexi-az a:hover,
  .lexi-az a:focus,
  .lexi-az a:active,
  .iv-az a,
  .iv-az a:link,
  .iv-az a:visited,
  .iv-az a:hover,
  .iv-az a:focus,
  .iv-az a:active,
  .utdd-az a,
  .utdd-az a:link,
  .utdd-az a:visited,
  .utdd-az a:hover,
  .utdd-az a:focus,
  .utdd-az a:active,
  .reader-toc-pill,
  .reader-toc-pill:link,
  .reader-toc-pill:visited,
  .reader-toc-pill:hover,
  .reader-toc-pill:focus,
  .reader-toc-pill:active,
  .lr-chip,
  .lr-chip:link,
  .lr-chip:visited,
  .lr-chip:hover,
  .lr-chip:focus,
  .lr-chip:active {
    text-decoration: none;
  }
  .btn, button {
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    border: 1px solid transparent;
    background: #2c3348;
    background: var(--imd-btn-bg, #2c3348);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
  }
  button.primary {
    background: #4f6fff;
    border-color: transparent;
    color: #fff;
  }
  button.danger {
    background: #e23b32;
    border-color: transparent;
    color: #fff;
  }
  button.primary:hover:not(:disabled) { background: #6280ff; }
  button.danger:hover:not(:disabled) { background: #ef4a40; }
  .btn:hover:not(:disabled),
  button:not(.primary):not(.danger):not(.item-row):not(.theme-toggle):not(.imd-bars-fab):not(.imd-section-fab):not(.find-btn):not(.star-btn):not(.zoom-btn):not(.pdf-btn):not(.gallery-btn):not(.find-nav):not(.sys-tree-toggle):not(.pick-row):not(.qmap-cell):not(.qmap-x):not(.acct-action):not(.acct-logout):not(.utd-folder):not(.toc-item):not(.imd-hl-menu-swatch):not(.imd-hl-menu-act):not(.test-cell-rename-btn):not(.test-cell-copy-btn):not(.test-cell-del-btn):not(.imd-icon-btn):not(.vd-icon):not(.srch-chip):not(.utdd-toggle):not(.tr-card-pill):not(.tr-start):not(.tr-qid-pill):hover:not(:disabled) {
    background: #363e56;
  }
  /* Choice rows and other list buttons set disabled after an answer; leave their paint alone. */
  button:disabled:not(.item-row):not(.choice-row):not(.test-cell-rename-btn):not(.test-cell-copy-btn):not(.test-cell-del-btn):not(.imd-icon-btn):not(.primary):not(.danger):not(.theme-toggle):not(.imd-bars-fab):not(.imd-section-fab):not(.find-btn):not(.star-btn):not(.zoom-btn):not(.pdf-btn):not(.gallery-btn):not(.find-nav):not(.sys-tree-toggle):not(.pick-row):not(.qmap-cell):not(.qmap-x):not(.utd-folder):not(.toc-item):not(.imd-hl-menu-swatch):not(.imd-hl-menu-act):not(.vd-icon):not(.srch-chip):not(.utdd-toggle):not(.tr-card-pill):not(.tr-start):not(.tr-qid-pill) {
    background: #3a4054;
    color: rgba(232, 234, 242, 0.42);
    border-color: transparent;
    box-shadow: none;
    cursor: not-allowed;
  }
  /* #2665: .imd-icon-btn = a button that paints itself (icon, close X, link, FAB, chip, pill, its own
     filled colour). The global hover/disabled rules here and the light-theme ones below skip it
     (and .primary/.danger), so the component's own colour and states win in both themes. Its rest
     state, if the component paints none, is the themed --imd-btn-bg grey. Keep this a plain class
     (old iOS Safari: no :is()/:where()). */
  .imd-icon-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }
  /* The disabled rules above skip .primary/.danger and self-painted buttons; they still get the
     not-allowed cursor (components' own :disabled cursor, e.g. locked NGN items, wins). */
  button:disabled {
    cursor: not-allowed;
  }
  button.primary:disabled:not(.item-row):not(.choice-row) {
    background: #3a4568;
    color: rgba(232, 234, 242, 0.4);
    border-color: transparent;
    box-shadow: none;
    cursor: not-allowed;
  }
  button.danger:disabled:not(.item-row):not(.choice-row) {
    background: #6b3532;
    color: rgba(255, 255, 255, 0.45);
    border-color: transparent;
    box-shadow: none;
    cursor: not-allowed;
  }
  .wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1rem var(--imd-read-gutter) 3rem;
  }
  /* Default exam chrome used the 1500px catalog column. On an ultrawide
     that left empty side gutters (#334). USMLE already sets none. */
  body.exam-run .wrap {
    max-width: none;
  }
  /* Default: the main card grows with the leftover column so a short page
     cannot leave a hole under the panel (bugs #191 / #196 / #197). */
  .wrap > .qbank-bankbar {
    flex: 0 0 auto;
  }
  .wrap > .panel:last-of-type,
  .wrap > .panel--fill {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  /* Exam / practice docks sit on the viewport floor. A short question must
     still grow the card down to that bar — otherwise --bg0 shows as empty
     space (#370 / #371). min-content keeps a long stem from being clipped. */
  body.has-tr-dock {
    /* Dock is 0.5rem + 2.55rem buttons + max(0.5rem, safe, keyboard).
       Adding safe on top of 3.55rem reserved an extra 0.5rem of --bg0
       above Prev/Next on iPhone (#401). */
    --tr-dock-h: calc(3.05rem + max(0.5rem, env(safe-area-inset-bottom, 0px), var(--imd-vv-bottom, 0px)));
  }
  body.has-tr-dock .wrap {
    padding-bottom: var(--tr-dock-h);
  }
  body.has-tr-dock .wrap > .panel,
  body.has-tr-dock .wrap > .panel:last-of-type {
    flex: 1 0 auto;
    min-height: min-content;
    margin-bottom: 0;
  }
  /* min-height on body does not stretch flex children. A short stem then
     leaves --bg0 between the card and Prev/Next (#370 / #371 / #373).
     Practice has the same dock (#368 was only “good” because that Q was long). */
  body.exam-run.has-tr-dock .wrap > .panel {
    min-height: calc(var(--exam-vh, var(--imd-frame)) - var(--tr-dock-h) - max(1.25rem, env(safe-area-inset-top, 0px)));
  }
  body.has-tr-dock:not(.exam-run) .wrap > .panel {
    min-height: calc(var(--imd-frame) - var(--tr-dock-h) - env(safe-area-inset-top, 0px) - 7rem);
  }
  /* Catalog / account / progress: one card, no list lock, so flex-grow
     never runs. Size the last card to the painted window. */
  html.imd-standalone:not(:has(.list-scroll)) body:not(.has-tr-dock) .wrap > .panel:last-of-type,
  html.imd-standalone:not(:has(.list-scroll)) body:not(.has-tr-dock) .wrap > .panel--fill {
    min-height: calc(var(--imd-frame) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 7.25rem);
  }
  /* v12libui: 7.25rem (116px) is less than the chrome around a library card: top bar 45px +
     .wrap padding 1rem + 3rem + card margin 1rem = 125px, so short pages in the iPad app were
     9px taller than the window. Subtract a little more (phones with the bug-button strip
     below are ~130px). In current WebKit / Chromium html.imd-standalone body is a flex column
     with min-height var(--imd-frame) and flex-grow fills the card to the window floor
     (v12libui lab); where it does not, this floor leaves at most ~11px of page background
     under the card instead of a scrollable page. Exam pages keep the rule above. */
  html.imd-standalone:not(:has(.list-scroll)) body:not(.has-tr-dock):not(.exam-run) .wrap > .panel:last-of-type,
  html.imd-standalone:not(:has(.list-scroll)) body:not(.has-tr-dock):not(.exam-run) .wrap > .panel--fill {
    min-height: calc(var(--imd-frame) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 8.5rem);
  }
  .tr-dock button:disabled,
  .tr-dock button.is-nav-off {
    opacity: 0.4 !important;
    cursor: not-allowed;
    pointer-events: none;
    color: var(--muted) !important;
  }
  .wrap > [id^="pane_"]:not([hidden]) {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .wrap > [id^="pane_"][hidden] {
    display: none !important;
  }
  .wrap > #pane_tests > .panel {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 0;
  }
  .wrap > #pane_create {
    overflow-y: auto;
  }
  /* Create Test: the form card must fill the leftover column. Otherwise the
     page background (--bg0) shows as a black hole under a short form (#365).
     Reset stays content-sized at the bottom of the pane. */
  .wrap > #pane_create > .panel:not(#qbank-danger) {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
  }
  .wrap > #pane_create > #qbank-danger {
    flex: 0 0 auto;
    margin-bottom: 0;
  }
  /* List pages lock the shell so the list scrolls inside the card, not
     under a 520px cap. Reader pages have no .list-scroll, so window
     scroll (Find / highlights) stays unchanged. */
  html:has(.list-scroll),
  html:has(.list-scroll) body {
    height: var(--imd-frame);
    min-height: var(--imd-frame);
    max-height: var(--imd-frame);
  }
  html:has(.list-scroll) body {
    overflow: hidden;
  }
  /* Plain and :has() selectors stay in separate rules: Safari < 15.4 drops a
     whole selector list that contains :has(). */
  body.exam-run {
    min-height: var(--exam-vh, var(--imd-frame));
  }
  html:has(body.exam-run) {
    min-height: var(--exam-vh, var(--imd-frame));
  }
  /* #2613: --exam-vh is the window height the exam cap is measured in (set by
     reader_tools_script.html with this class, exam pages only). The class also
     covers Safari < 15.4, which drops the :has() rule above. Not on the results
     view, where body.exam-run is gone but the inline token can remain. */
  :root.imd-exam-vh:not([data-exam-results]) {
    min-height: var(--exam-vh);
  }
  html:has(.list-scroll) .wrap {
    flex: 1 1 0;
    overflow: hidden;
    /* Default wrap pad is 3rem for reader docks. On a locked list page
       that 3rem is just a black strip under the card (#365). */
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }
  .panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem 1.35rem;
    box-shadow: none;
    min-width: 0;
    margin-bottom: 1rem;
  }
  .panel h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: #c8cfec;
  }
  .msg { font-size: 0.9rem; color: var(--danger); min-height: 1.25rem; }
  input, textarea, select {
    width: 100%;
    max-width: 100%;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    font: inherit;
  }
  /* v12bugs1121b (#2761): checkboxes and radios keep their native size. The rule above
     stretched them across their row (a flex label put the text in a ~40px column at the far
     right). :where() keeps this at that rule's weight, so any page rule that sizes a box
     (.acct-setting, .sb-figs, .usmle-check ...) still wins. */
  input:where([type="checkbox"], [type="radio"]) {
    width: auto;
    padding: 0;
  }
  /* Shared page search field — Home / Favorites look. Theme via --imd-search-*. */
  input.imd-search {
    display: block;
    width: 100%;
    max-width: 28rem;
    box-sizing: border-box;
    font: inherit;
    color: var(--text);
    background: var(--imd-search-bg);
    border: 1px solid var(--imd-search-border);
    border-radius: var(--imd-search-radius);
    padding: var(--imd-search-pad);
    margin: 0 0 0.45rem;
  }
  .srch-bar input.imd-search,
  .book-search input.imd-search,
  .lr-toolbar input.imd-search,
  .catalog-search input.imd-search,
  .cme-search input.imd-search,
  .kap-search input.imd-search,
  .other-tools input.imd-search,
  .page-tools input.imd-search {
    flex: 1 1 180px;
    width: auto;
    min-width: 0;
    max-width: none;
    margin: 0;
  }
  /* First-screen tool row: search takes leftover width, Edit stays on the right (#583). */
  .page-tools {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.45rem;
  }
  .page-tools > .btn,
  .page-tools-acts {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 0 0 auto;
    margin-left: auto;
  }
  .stack { display: flex; flex-direction: column; gap: 0.75rem; }
  .rowflex { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
  .list-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .item-row {
    display: block;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.45rem;
    background: rgba(0, 0, 0, 0.2);
    color: inherit;
    text-align: left;
    font: inherit;
    cursor: pointer;
    width: 100%;
  }
  .item-row:hover { border-color: rgba(108, 140, 255, 0.35); }
  /* iPhone keeps :hover after a tap. Option text is strike-only; a leftover
     blue frame looks like the answer was selected (#360). */
  @media (hover: none), (pointer: coarse) {
    .choice-row:hover,
    body.exam-run .item-row:hover {
      border-color: var(--border);
    }
  }
  .muted { color: var(--muted); font-size: 0.88rem; }
  /* #829 / #841: outside the exam the vignette keeps its own size. Inside the
     exam it must carry NO font-size at all.
     Report #841 measured it on the device: with a CSS `zoom` of 1.9 on
     #reader-content, the stem was the only reading box with an explicit
     declaration and the only one painted wrong -- computed 8.42px, exactly
     16px / 1.9, while the choices and #reader-content itself were 16px. Any
     value that references something computed elsewhere (`inherit`, `var()`,
     `1em`) is substituted without the subtree's zoom multiplier. Plain
     inheritance is the only mechanism that survives, so the reading boxes now
     declare nothing and inherit from the zoom root. */
  body:not(.exam-run) .stem { font-size: 0.95rem; }
  /* #853: the exam zooms by layout, not by a visual transform. `transform:
     scale()` hands WebKit a rasterised layer to stretch, which is what made
     dual pane, tables and struck-out choices go soft over and over (#281,
     #283, #405, #847, #853). Reading size is one px token, so the zoom can
     multiply it and every glyph is laid out and drawn at its real size.
     The text-size control sets the base; the reader zoom sets the multiplier.
     --imd-exam-zoom is left undeclared here on purpose: the reader writes it on
     the document element, and a declaration on body would shadow the inherited
     value. */
  body.exam-run { --imd-exam-text-base: 16px; }
  body.exam-run,
  body.exam-run #reader-content {
    --imd-exam-text: calc(var(--imd-exam-text-base, 16px) * var(--imd-exam-zoom, 1));
  }
  .stem img { max-width: 100%; height: auto; }
  .pill {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    background: rgba(108, 140, 255, 0.2);
    color: #dbe2ff;
    margin-right: 0.35rem;
  }
  .item-row--seen { opacity: 0.78; }
  .item-row--answered { opacity: 0.52; }
  .theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    padding: 0.15rem !important;
    flex-shrink: 0;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--text);
    line-height: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }
  .theme-toggle svg {
    display: block;
    width: 1.25rem;
    height: 1.25rem;
  }
  html[data-theme="light"] {
    color-scheme: light;
  }
  html[data-theme="light"] {
    --bg0: #e8edf5;
    --card: #f2f5fb;
    --sec-bg: #ffffff;
    --border: rgba(55, 65, 100, 0.12);
    --text: #1a1f2e;
    --muted: #5a6172;
    --accent: #3d52d9;
    --accent2: #0d9488;
    --danger: #b91c1c;
    --imd-search-bg: var(--card);
    --imd-search-border: rgba(55, 65, 100, 0.14);
  }
  html[data-theme="light"] body {
    background: radial-gradient(1000px 700px at 14% -8%, rgba(61, 82, 217, 0.05), transparent),
      radial-gradient(800px 560px at 88% 12%, rgba(13, 148, 136, 0.035), transparent),
      var(--bg0);
  }
  /* Reader pages only: page / panel / gutters match the text paper. */
  html[data-theme="light"]:has(#reader-content),
  html[data-theme="light"]:has(#doc) {
    --bg0: #ffffff;
    --card: #ffffff;
  }
  html[data-theme="light"]:has(#reader-content),
  html[data-theme="light"]:has(#reader-content) body,
  html[data-theme="light"]:has(#doc),
  html[data-theme="light"]:has(#doc) body {
    background: #ffffff;
  }
  html[data-theme="light"]:has(#reader-content) #reader-content,
  html[data-theme="light"]:has(#doc) #doc,
  html[data-theme="light"]:has(#doc) .wrap > .panel:not(.login-panel) {
    background: #ffffff;
  }
  html[data-theme="light"].imd-reader-surface {
    --bg0: var(--imd-surface);
    --card: var(--imd-surface);
  }
  html[data-theme="light"].imd-reader-surface,
  html[data-theme="light"].imd-reader-surface body {
    background: var(--imd-surface) !important;
  }
  html[data-theme="light"].imd-reader-surface .panel:not(.login-panel),
  html[data-theme="light"].imd-reader-surface #reader-content,
  html[data-theme="light"].imd-reader-surface #doc {
    background: var(--imd-surface);
  }
  html[data-theme="light"].imd-reader-surface #doc {
    --reader-bg: var(--imd-surface);
  }
  /* Night mode: exam/reader body stays on the dark page. Light paper rules above
     must not paint a white sheet here. */
  /* :has() kept in its own rules (Safari < 15.4 drops a mixed list). */
  html[data-theme="dark"] body.exam-run {
    color: var(--text);
  }
  html[data-theme="dark"]:has(#reader-content) body {
    color: var(--text);
  }
  html[data-theme="dark"] body.exam-run #reader-content,
  html[data-theme="dark"] body.exam-run #stem,
  html[data-theme="dark"] body.exam-run #choices,
  html[data-theme="dark"] body.exam-run #expl,
  html[data-theme="dark"] body.exam-run #fbExpl {
    background: transparent !important;
    color: var(--text) !important;
  }
  html[data-theme="dark"]:has(#reader-content) #reader-content {
    background: transparent !important;
    color: var(--text) !important;
  }
  /* #1659: bank HTML pastes color:rgb(0,0,0) onto the choice text.
     A yellow (or other) highlight inside the choice must keep dark ink.
     Inheriting the night-mode color paints white on #ffe566. */
  html[data-theme="dark"] body.exam-run #choices .stem,
  html[data-theme="dark"] body.exam-run #choices .stem *:not([class*="hl-"]):not([class*="highlight"]):not(.qbank-exhibit-link):not(#exhibit) {
    color: inherit !important;
    caret-color: auto !important;
  }
  html[data-theme="dark"] body.exam-run #choices .stem [class*="hl-"],
  html[data-theme="dark"] body.exam-run #choices .stem [class*="hl-"] *,
  html[data-theme="dark"] body.exam-run #choices .stem [class*="highlight"],
  html[data-theme="dark"] body.exam-run #choices .stem [class*="highlight"] * {
    color: #111 !important;
  }
  /* #1649: explanation lines ship background:white and black ink.
     Highlight marks keep their own background. */
  html[data-theme="dark"] body.exam-run #expl,
  html[data-theme="dark"] body.exam-run #fbExpl,
  html[data-theme="dark"] body.exam-run #expl *:not([class*="hl-"]):not([class*="highlight"]):not(.qbank-exhibit-link):not(#exhibit),
  html[data-theme="dark"] body.exam-run #fbExpl *:not([class*="hl-"]):not([class*="highlight"]):not(.qbank-exhibit-link):not(#exhibit) {
    color: inherit !important;
    background-color: transparent !important;
  }
  /* #1785: a figure link stays blue and underlined. The night-mode
     inherit above would paint it the same color as the paragraph.
     A highlight on the link keeps its own ink. */
  html[data-theme="dark"] body.exam-run #expl a.qbank-exhibit-link:not([class*="hl-"]),
  html[data-theme="dark"] body.exam-run #fbExpl a.qbank-exhibit-link:not([class*="hl-"]),
  html[data-theme="dark"] body.exam-run #choices .stem a.qbank-exhibit-link:not([class*="hl-"]),
  html[data-theme="dark"] body.exam-run #expl a#exhibit:not([class*="hl-"]),
  html[data-theme="dark"] body.exam-run #fbExpl a#exhibit:not([class*="hl-"]),
  html[data-theme="dark"] body.exam-run #choices .stem a#exhibit:not([class*="hl-"]) {
    color: #5ec8e8 !important;
    background-color: transparent !important;
    text-decoration: underline !important;
  }
  /* Account "Document theme: Light" paints white paper. On a dark exam that
     leaves light ink on a white card (#235). Follow the app theme instead. */
  html[data-theme="dark"] body.exam-run .imd-pdf-print-root,
  html[data-theme="dark"][data-doc-theme="light"] body.exam-run #reader-content,
  html[data-theme="dark"] body.exam-run [data-doc-theme="light"].imd-pdf-print-root {
    background: transparent !important;
    color: var(--text) !important;
  }
  html[data-theme="light"] .top h1 {
    background: linear-gradient(120deg, #121620 0%, #3d52d9 42%, #0d9488 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  html[data-theme="light"] .top a.navlink:hover {
    border-color: rgba(0, 0, 0, 0.1);
  }
  html[data-theme="light"] .top a.navlink.navlink--active {
    border-color: rgba(61, 82, 217, 0.35);
    background: rgba(61, 82, 217, 0.08);
  }
  html[data-theme="light"] .panel h2 {
    color: #2c3350;
  }
  html[data-theme="light"] .pill {
    background: rgba(61, 82, 217, 0.15);
    color: #2c3c9a;
  }
  html[data-theme="light"] .item-row {
    background: rgba(255, 255, 255, 0.65);
    border-color: rgba(0, 0, 0, 0.08);
  }
  html[data-theme="light"] .item-row:hover {
    border-color: rgba(61, 82, 217, 0.35);
  }
  @media (hover: none), (pointer: coarse) {
    html[data-theme="light"] .choice-row:hover,
    html[data-theme="light"] body.exam-run .item-row:hover {
      border-color: rgba(0, 0, 0, 0.08);
    }
  }
  html[data-theme="light"] .item-row--seen { opacity: 0.88; }
  html[data-theme="light"] .item-row--answered { opacity: 0.62; }
  html[data-theme="light"] input,
  html[data-theme="light"] textarea,
  html[data-theme="light"] select {
    background: rgba(255, 255, 255, 0.92);
    border-color: var(--border);
    color: var(--text);
  }
  html[data-theme="light"] input.imd-search {
    background: var(--imd-search-bg);
    border-color: var(--imd-search-border);
    color: var(--text);
  }
  html[data-theme="light"] {
    --imd-btn-bg: #e4e8f2;
  }
  html[data-theme="light"] .btn,
  html[data-theme="light"] button:not(.acct-action):not(.acct-logout):not(.find-btn):not(.star-btn):not(.zoom-btn):not(.pdf-btn):not(.gallery-btn):not(.theme-toggle):not(.imd-bars-fab):not(.imd-section-fab):not(.find-nav):not(.utd-folder):not(.toc-item):not(.pick-row):not(.item-row):not(.imd-hl-menu-swatch):not(.imd-hl-menu-act):not(.vd-icon):not(.srch-chip):not(.qmap-cell):not(.qmap-x):not(.utdd-toggle):not(.tr-card-pill):not(.tr-start):not(.tr-qid-pill):not(.test-cell-rename-btn):not(.test-cell-copy-btn):not(.test-cell-del-btn):not(.imd-icon-btn):not(.primary):not(.danger):not(.sys-tree-toggle) {
    background: #e4e8f2;
    border-color: transparent;
    color: var(--text);
  }
  html[data-theme="light"] button.primary {
    background: #3d52d9;
    border-color: transparent;
    color: #fff;
  }
  html[data-theme="light"] button.danger {
    background: #dc2626;
    border-color: transparent;
    color: #fff;
  }
  html[data-theme="light"] button.primary:hover:not(:disabled) { background: #3346c4; }
  html[data-theme="light"] button.danger:hover:not(:disabled) { background: #b91c1c; }
  html[data-theme="light"] .btn:hover:not(:disabled),
  html[data-theme="light"] button:not(.primary):not(.danger):not(.item-row):not(.theme-toggle):not(.imd-bars-fab):not(.imd-section-fab):not(.find-btn):not(.star-btn):not(.zoom-btn):not(.pdf-btn):not(.gallery-btn):not(.find-nav):not(.sys-tree-toggle):not(.pick-row):not(.qmap-cell):not(.qmap-x):not(.acct-action):not(.acct-logout):not(.utd-folder):not(.toc-item):not(.imd-hl-menu-swatch):not(.imd-hl-menu-act):not(.vd-icon):not(.srch-chip):not(.utdd-toggle):not(.tr-card-pill):not(.tr-start):not(.tr-qid-pill):not(.test-cell-rename-btn):not(.test-cell-copy-btn):not(.test-cell-del-btn):not(.imd-icon-btn):hover:not(:disabled) {
    background: #d5dbe8;
  }
  html[data-theme="light"] button:disabled:not(.item-row):not(.choice-row):not(.find-btn):not(.star-btn):not(.zoom-btn):not(.pdf-btn):not(.gallery-btn):not(.tr-card-pill):not(.tr-start):not(.tr-qid-pill):not(.test-cell-rename-btn):not(.test-cell-copy-btn):not(.test-cell-del-btn):not(.imd-icon-btn):not(.primary):not(.danger):not(.theme-toggle):not(.imd-bars-fab):not(.imd-section-fab):not(.find-nav):not(.sys-tree-toggle):not(.pick-row):not(.qmap-cell):not(.qmap-x):not(.utd-folder):not(.toc-item):not(.imd-hl-menu-swatch):not(.imd-hl-menu-act):not(.vd-icon):not(.srch-chip):not(.utdd-toggle),
  html[data-theme="light"] button.primary:disabled:not(.item-row):not(.choice-row) {
    background: #d5dae6;
    color: rgba(26, 31, 46, 0.38);
  }
  html[data-theme="light"] button.danger:disabled:not(.item-row):not(.choice-row) {
    background: #e8b4b4;
    color: rgba(255, 255, 255, 0.7);
  }
  html[data-theme="light"] .theme-toggle {
    background: transparent !important;
    border: none !important;
    color: var(--text);
  }
  html[data-theme="light"] .sys-tree-wrap {
    background: rgba(0, 0, 0, 0.03);
    border-color: var(--border);
  }
  html[data-theme="light"] .sys-tree-row:hover {
    background: rgba(0, 0, 0, 0.045);
  }
  html[data-theme="light"] .sys-tree-toggle {
    border-color: rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.95);
    color: var(--accent);
  }
  /* Light-mode list rows are white at every width, not only phones. */
  html[data-theme="light"] .lr-row,
  html[data-theme="light"] .lr-item,
  html[data-theme="light"] .srch-hit,
  html[data-theme="light"] .srch-sec-body,
  html[data-theme="light"] .sec-body,
  html[data-theme="light"] .item-row,
  html[data-theme="light"] .pick-row,
  html[data-theme="light"] .sys-tree-row,
  html[data-theme="light"] .search-hit,
  html[data-theme="light"] .search-hit-row,
  html[data-theme="light"] .toc a,
  html[data-theme="light"] .toc .toc-item,
  html[data-theme="light"] .toc-item,
  html[data-theme="light"] .utd-folder,
  html[data-theme="light"] button.utd-folder,
  html[data-theme="light"] .acct-stack,
  html[data-theme="light"] .acct-row,
  html[data-theme="light"] .acct-row-plain,
  html[data-theme="light"] .acct-link,
  html[data-theme="light"] .acct-setting,
  html[data-theme="light"] .acct-db,
  html[data-theme="light"] .acct-action:not([class*="acct-fill-"]),
  html[data-theme="light"] .cme-row,
  html[data-theme="light"] .kap-row,
  html[data-theme="light"] .bug-item,
  html[data-theme="light"] .ol-card,
  html[data-theme="light"] .vd-card,
  html[data-theme="light"] .vd-icon,
  html[data-theme="light"] .srch-chip,
  html[data-theme="light"] .srch-hist button,
  html[data-theme="light"] details.paste-ids,
  html[data-theme="light"] .bug-events,
  html[data-theme="light"] .as-thumbs a,
  html[data-theme="light"] .prog-tile,
  html[data-theme="light"] .bk-card {
    background-color: #fff;
  }
  /* Reading margin by screen: 11px phone, 56px tablet, 72px laptop, 96px wide. */
  @media (min-width: 1024px) {
    :root {
      --imd-read-inset: 3rem;
    }
  }
  @media (min-width: 1440px) {
    :root {
      --imd-read-inset: 4.5rem;
    }
  }
  @media (max-width: 640px) {
    :root {
      --imd-read-gutter: 0.7rem;
      /* Phone cards have no chrome, so the page gutter is the whole margin. */
      --imd-read-inset: 0rem;
    }
    .wrap {
      padding: 0.45rem var(--imd-read-gutter) 1.25rem;
    }
    /* v12libui (UI audit): the Report Bugs button (bug_report.css: 44px, fixed at
       max(0.85rem, safe area) from the floor) covered ~30px of the last row of a list
       (book contents, Favorites, Search) even at max scroll. Leave room under the content
       while the button is on (bug_report.js sets html.imd-bug-fab-on). Not on pages with
       a dock (the button sits above it) or an inner-scrolling list (QBank lists keep their
       own padding; Create Test has its own strip). Safari < 15.4 drops the rule (no :has). */
    html.imd-bug-fab-on:not(:has(.list-scroll)) body:not(.has-tr-dock):not(.exam-run) .wrap {
      padding-bottom: calc(44px + max(0.85rem, env(safe-area-inset-bottom, 0px)) + 0.75rem);
    }
    /* With the always-visible highlight strip at the bottom the button sits above the strip
       (bug_report.css), and the reader's "Topic N of M" line after #doc must clear both. */
    html.imd-bug-fab-on[data-hl-bar-pos="bottom"]:not([data-reader-bars="floating"]):not(:has(.list-scroll)) body:not(.has-tr-dock):not(.exam-run) .wrap {
      padding-bottom: calc(var(--imd-hl-bot, 3.4rem) + env(safe-area-inset-bottom, 0px) + 0.45rem + 44px + 0.75rem);
    }
    .panel:not(.login-panel) {
      background: transparent;
      border: none;
      box-shadow: none;
      border-radius: 0;
      padding: 0;
      margin-bottom: 0.5rem;
    }
    html[data-theme="light"].imd-reader-surface .panel:not(.login-panel) {
      background: transparent;
    }
  }
  /* Landscape iPhone: the gutter never runs under the sensor housing. The
     plain values above stay the fallback for browsers without max(). */
  :root {
    --imd-safe-x: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
    --imd-read-gutter: max(1.5rem, var(--imd-safe-x));
    /* One stacking scale for floating chrome. Sheets and menus that the
       user opens sit above the always-there buttons, modals above all. */
    --imd-z-bar: 50;
    --imd-z-hl-strip: 10850;
    --imd-z-options: 10900;
    --imd-z-bug-fab: 11000;
    --imd-z-sheet: 11100;
    --imd-z-modal: 12000;
  }
  @media (max-width: 640px) {
    :root {
      --imd-read-gutter: max(0.7rem, var(--imd-safe-x));
    }
  }
  /* "Couldn't save" notice (Account, Home). Fixed, so a failed toggle far
     down a long list is still seen. */
  .imd-save-err {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    z-index: var(--imd-z-modal, 12000);
    width: max-content;
    max-width: calc(100vw - 2rem);
    box-sizing: border-box;
    margin: 0;
    padding: 0.65rem 0.9rem;
    border: 1px solid #b42318;
    border-left-width: 5px;
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 0.9rem;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
  }
  .imd-save-err[hidden] { display: none; }
