    /* ── Design tokens (UI-1) ──────────────────────────────────────── */
    :root {
      --ground: #F6F7F5;
      --surface: #FFFFFF;
      --border: #E4E8E6;
      --border-strong: #D5DCD9;
      --divider: #EEF1EF;
      --ink: #16232E;
      --ink-2: #3E4A54;
      --muted: #56636E;
      --accent: #0F766E;
      --accent-hover: #0B5A54;
      --accent-tint: #E3F1EE;
      --accent-border: #CFE3DF;
      --amber: #B45309;
      --amber-tint: #FEF6EB;
      --amber-text: #92400E;
      --danger: #B42318;
      --not-started: #8A96A0;

      --radius-badge: 8px;
      --radius-button: 10px;
      --radius-card: 14px;
      --radius-bubble: 16px;
      --radius-chip: 999px;
      --radius-sheet: 20px;

      --font-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
    }

    @font-face {
      font-family: 'Plus Jakarta Sans';
      font-style: normal;
      font-weight: 400 700;
      font-display: swap;
      src: url('/static/fonts/PlusJakartaSans-Variable.woff2') format('woff2');
    }

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

    html, body {
      height: 100%;
      overflow: hidden;
      font-family: var(--font-sans);
      color: var(--ink);
      background: var(--ground);
    }

    /* ── App shell ─────────────────────────────────────────────────── */
    #app { display: flex; flex-direction: column; height: 100vh; }

    /* ── Header ────────────────────────────────────────────────────── */
    #header {
      height: 64px;
      flex-shrink: 0;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
    }
    .header-brand { display: flex; flex-direction: column; gap: 2px; }
    .header-brand .logo    { color: var(--accent); font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
    .header-brand .tagline { color: var(--muted); font-size: 12px; font-weight: 400; }
    .header-module         { color: var(--ink); font-size: 17px; font-weight: 700; }
    .header-actions { display: flex; align-items: center; gap: 10px; }

    /* ── Desktop Study/Progress nav (UI-2 item 8, Desktop.html) ───────── */
    #desktop-nav { display: none; gap: 4px; margin: 0 auto 0 32px; }
    .desktop-nav-item {
      display: flex; align-items: center; min-height: 44px; padding: 0 16px;
      border-radius: var(--radius-button); font-size: 15px; font-weight: 600;
      color: var(--ink-2); text-decoration: none;
    }
    .desktop-nav-item.active { background: var(--accent-tint); color: var(--ink); font-weight: 700; }
    .desktop-nav-item:hover:not(.active) { background: var(--ground); }

    .header-icon-btn {
      display: inline-flex; align-items: center; gap: 6px;
      min-height: 44px; padding: 0 14px;
      border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      background: var(--surface); color: var(--ink-2);
      font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
      transition: background 0.15s, border-color 0.15s;
    }
    .header-icon-btn:hover { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent); }
    .header-icon-btn svg { flex-shrink: 0; }

    .header-test-btn {
      display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
      border: 1px solid var(--amber); border-radius: var(--radius-button);
      background: var(--amber-tint); color: var(--amber-text);
      font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
    }

    /* ── Avatar + account menu ─────────────────────────────────────── */
    .avatar-btn {
      width: 44px; height: 44px; border-radius: 22px; border: none;
      background: var(--accent-tint); color: var(--accent);
      font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .avatar-btn[aria-expanded="true"] { background: var(--accent); color: var(--surface); }

    #account-menu-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(22, 35, 46, 0.35); z-index: 1300;
    }
    #account-menu-overlay.visible { display: block; }
    #account-menu {
      position: absolute; top: 76px; right: 24px; width: 280px;
      display: flex; flex-direction: column;
      background: var(--surface); border: 1px solid var(--border);
      border-radius: 16px; box-shadow: 0 12px 32px rgba(22, 35, 46, 0.18);
      overflow: hidden;
    }
    #account-menu-header {
      padding: 16px; border-bottom: 1px solid var(--divider);
    }
    #account-menu-header #user-email { font-size: 13px; color: var(--muted); display: none; }
    .account-menu-item {
      display: flex; align-items: center; gap: 12px;
      min-height: 52px; padding: 0 16px;
      font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
      text-decoration: none; border: none; background: none; width: 100%; text-align: left;
      cursor: pointer;
    }
    .account-menu-item:hover { background: var(--ground); }
    .account-menu-item-btn { border-top: 1px solid var(--divider); }

    /* ── Main layout ───────────────────────────────────────────────── */
    #main { display: flex; flex: 1; overflow: hidden; }

    /* ── Chat panel (grows to fill whatever the context panel doesn't
         use -- lets collapsing the chapter-list panel hand its width
         back here). order:1 puts it visually after the context panel,
         which sits on the left via order:-1 below. ─────────────────── */
    #chat-panel {
      flex: 1;
      min-width: 0;
      order: 1;
      display: flex;
      flex-direction: column;
      background: var(--ground);
      border-left: 1px solid var(--border);
    }

    #messages {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      padding: 24px 28px;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    /* ── Empty-state suggestions (shown until the first question of the
         session) -- margin: auto on a column flex item centers it in
         whatever space #messages isn't using for the resume card/typing
         indicator, rather than pinning it to the top. ─────────────────── */
    #ask-empty-state {
      display: none;
      margin: auto;
      flex-direction: column;
      align-items: center;
      text-align: center;
      gap: 6px;
      max-width: 420px;
      padding: 0 12px;
    }
    #ask-empty-state.visible { display: flex; }
    .ask-empty-title { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink); }
    .ask-empty-subtitle { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
    #ask-empty-suggestions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
    .ask-empty-suggestion-btn {
      min-height: 44px; padding: 0 16px; border: 1px solid var(--accent-border); border-radius: var(--radius-button);
      background: var(--surface); color: var(--accent); font-family: inherit;
      font-size: 14px; font-weight: 600; cursor: pointer; text-align: left;
    }
    .ask-empty-suggestion-btn:hover { background: var(--accent-tint); }

    /* ── Chat topic context (UI-2 items 5/8) -- desktop shows the full bar
         (View topic/My note/Test me); mobile shows a compact dismissible
         chip instead. Same markup, same JS-populated text; the media
         queries below (see "Responsive") pick which half is visible. ──── */
    #chat-topic-context {
      flex-shrink: 0; align-items: center; gap: 12px;
      padding: 12px 20px; border-bottom: 1px solid var(--divider);
    }
    .chat-topic-context-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    .chat-topic-context-eyebrow { font-size: 12px; font-weight: 600; color: var(--muted); }
    .chat-topic-context-title { font-size: 15px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .chat-topic-context-actions { display: flex; gap: 8px; flex-shrink: 0; }
    .chat-topic-action-btn {
      display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px;
      border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      background: var(--surface); color: var(--ink); font-family: inherit;
      font-size: 13px; font-weight: 600; cursor: pointer;
    }
    .chat-topic-action-btn.chat-topic-action-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
    /* Previous/Next topic (item 5) -- same compact circular icon-button
       treatment as #chat-topic-clear-btn, bookending the actions cluster. */
    .chat-topic-nav-btn {
      flex-shrink: 0; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
      border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
      cursor: pointer; border-radius: 999px;
    }
    .chat-topic-nav-btn:hover { background: var(--ground); }
    .chat-topic-nav-btn:disabled { opacity: 0.35; cursor: default; }
    .chat-topic-nav-btn:disabled:hover { background: var(--surface); }
    #chat-topic-clear-btn {
      display: none; flex-shrink: 0; width: 36px; height: 36px; align-items: center; justify-content: center;
      border: none; background: none; color: var(--muted); cursor: pointer; border-radius: 999px;
    }
    #chat-topic-clear-btn:hover { background: var(--ground); }

    /* ── "Continue where you left off" resume card (G3) ───────────────── */
    #resume-card {
      align-items: center; gap: 12px; padding: 14px 16px;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
      text-decoration: none; color: var(--ink); margin-bottom: 4px;
    }
    .resume-card-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    .resume-card-eyebrow { font-size: 12px; font-weight: 600; color: var(--muted); }
    .resume-card-title { font-size: 15px; font-weight: 600; color: var(--ink); }
    .resume-card-meta { font-size: 13px; color: var(--muted); }
    #resume-card svg { flex-shrink: 0; color: var(--accent); }

    /* ── Source chips under an answer (replaces the old plain-text hint) ── */
    .source-chips-label {
      margin-top: 10px; font-size: 12px; font-weight: 600; color: var(--muted);
    }
    /* One chip per line, always -- flex-direction: column guarantees this
       regardless of how short a title is (flex-wrap alone only wraps once a
       row actually overflows, which let two short chips sit side by side).
       max-width: 100% (of the bubble) instead of a flat px cap lets a long
       H2 title use the full available width before ellipsis ever kicks in;
       width: fit-content keeps a short chip from stretching to fill it
       unnecessarily. */
    .source-chips-row { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 4px; }
    .source-chip {
      flex: none; min-height: 36px; max-width: 100%; width: fit-content; padding: 0 12px; border: none; border-radius: var(--radius-chip);
      background: var(--accent-tint); color: var(--ink); font-family: inherit;
      font-size: 13px; font-weight: 600; cursor: pointer;
      overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
    }
    .source-chip:hover { background: var(--accent-border); }

    /* ── Message bubbles ───────────────────────────────────────────── */
    .message-row { display: flex; flex-direction: column; max-width: 82%; }
    .message-row.user      { align-self: flex-end;   align-items: flex-end; }
    .message-row.assistant { align-self: flex-start; align-items: flex-start; }

    .bubble {
      max-width: 100%;
      padding: 12px 16px;
      border-radius: var(--radius-bubble);
      font-size: 15px;
      line-height: 1.6;
      word-break: break-word;
      overflow-wrap: anywhere;
    }
    /* Markdown tables/code blocks don't wrap or shrink on their own --
       without their own scroll box, a wide table or an unbroken code line
       would force .bubble (and .message-row) wider than the viewport. Each
       gets its own horizontal scrollbar instead, so only the table/code
       itself scrolls, not the whole message list. */
    .bubble table {
      display: block;
      max-width: 100%;
      overflow-x: auto;
      border-collapse: collapse;
      font-size: 13px;
    }
    .bubble table th, .bubble table td {
      padding: 6px 10px;
      border: 1px solid var(--border);
      text-align: left;
      white-space: nowrap;
    }
    .bubble pre {
      max-width: 100%;
      overflow-x: auto;
      background: var(--ground);
      padding: 10px 12px;
      border-radius: 8px;
      font-size: 13px;
    }
    .bubble pre code { background: none; padding: 0; border-radius: 0; }
    .message-row.user .bubble {
      background: var(--accent);
      color: #fff;
      border-bottom-right-radius: 4px;
    }
    .message-row.assistant .bubble {
      background: var(--surface);
      color: var(--ink);
      border: 1px solid var(--border);
      border-bottom-left-radius: 4px;
    }

    /* UI-4b: "Answering: <rewritten question>" (docs/mockups/FollowUp.html) */
    .answering-line {
      display: block;
      font-size: 12px;
      color: #56636E;
      margin-bottom: 8px;
    }

    /* Markdown inside assistant bubbles */
    .bubble p              { margin: 0 0 10px; }
    .bubble p:last-child   { margin-bottom: 0; }
    .bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
    .bubble li             { margin-bottom: 3px; }
    .bubble strong         { font-weight: 600; }
    .bubble h1,.bubble h2,.bubble h3 { margin: 10px 0 5px; font-weight: 700; }
    .bubble code { background: var(--ground); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

    /* Images returned with an /ask answer, rendered inside the chat flow
       right below the bubble -- width:100% here is what the image-card's
       own width:100% actually resolves against (a flex item under
       align-items:flex-start otherwise shrinks-to-fit with no basis). */
    .msg-images { width: 100%; margin-top: 10px; }

    .source-hint {
      font-size: 12px;
      color: var(--muted);
      font-style: italic;
      margin-top: 5px;
      padding-left: 2px;
    }

    /* ── Rating widget (Module D3) ─────────────────────────────────── */
    .rating-widget {
      margin-top: 8px;
      padding: 10px 12px;
      background: var(--ground);
      border: 1px solid var(--border);
      border-radius: 10px;
      font-size: 12px;
      color: var(--ink-2);
      max-width: 320px;
    }
    .rating-label { margin-bottom: 6px; font-weight: 600; }
    .rating-stars { display: flex; gap: 4px; margin-bottom: 8px; }
    .rating-stars .star {
      font-size: 20px;
      line-height: 1;
      cursor: pointer;
      color: var(--border-strong);
      user-select: none;
    }
    .rating-stars .star.filled { color: var(--amber); }
    .rating-comment {
      width: 100%;
      box-sizing: border-box;
      resize: vertical;
      min-height: 44px;
      padding: 6px 8px;
      border: 1px solid var(--border-strong);
      border-radius: 6px;
      font-size: 12px;
      font-family: inherit;
      margin-bottom: 8px;
    }
    .rating-submit-btn {
      background: var(--accent);
      color: #fff;
      border: none;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 600;
      font-family: inherit;
      padding: 5px 12px;
      cursor: pointer;
    }
    .rating-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }
    .rating-confirmed { color: var(--accent); font-weight: 600; }

    /* ── Typing indicator ──────────────────────────────────────────── */
    #typing-indicator { display: none; align-self: flex-start; }
    .typing-bubble {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-bubble);
      border-bottom-left-radius: 4px;
      padding: 13px 18px;
      display: flex;
      align-items: center;
      gap: 5px;
    }
    .typing-dot {
      width: 7px; height: 7px;
      background: var(--accent);
      border-radius: 50%;
      animation: tdot 1.2s infinite ease-in-out;
    }
    .typing-dot:nth-child(2) { animation-delay: 0.2s; }
    .typing-dot:nth-child(3) { animation-delay: 0.4s; }
    @keyframes tdot {
      0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
      30%           { transform: translateY(-6px); opacity: 1;   }
    }

    /* ── Input area ────────────────────────────────────────────────── */
    #input-area {
      padding: 14px 28px;
      background: var(--surface);
      border-top: 1px solid var(--border);
      display: flex;
      gap: 10px;
      align-items: center;
    }
    #question-input {
      flex: 1;
      min-width: 0;
      min-height: 48px;
      padding: 0 16px;
      border: 1px solid var(--border-strong);
      border-radius: 12px;
      font-size: 15px;
      font-family: inherit;
      color: var(--ink);
      background: var(--surface);
      outline: none;
      transition: border-color 0.15s;
    }
    #question-input:focus        { border-color: var(--accent); }
    #question-input::placeholder { color: var(--muted); }
    #send-btn {
      width: 48px; height: 48px;
      background: var(--accent);
      border: none;
      border-radius: 12px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background 0.15s, opacity 0.15s;
    }
    #send-btn:hover:not(:disabled) { background: var(--accent-hover); }
    #send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
    #send-btn svg { fill: #fff; }

    /* ── Context panel (chapter-list/MAP panel only now -- "Sources &
         References" was removed entirely, and the D3 knowledge-map view
         was removed in UI-1). order:-1 puts it on the left, ahead of
         #chat-panel's order:1, regardless of DOM/source order. */
    #context-panel {
      width: 35%;
      min-width: 0;
      order: -1;
      background: var(--surface);
      border-right: 1px solid var(--border);
      overflow-y: auto;
      transition: width 0.2s ease;
    }
    #context-panel.panel-collapsed {
      width: 44px;
      overflow: hidden;
    }
    #context-panel-collapsed-strip {
      display: none;
      width: 100%;
      height: 100%;
      flex-direction: column;
      align-items: center;
      overflow-y: auto;
      padding: 8px 0;
    }
    #context-panel.panel-collapsed #context-panel-collapsed-strip { display: flex; }
    #context-panel.panel-collapsed #context-panel-content { display: none; }
    #collapsed-rail-expand-btn {
      cursor: pointer;
      color: var(--muted);
      font-size: 16px;
      user-select: none;
      flex-shrink: 0;
      width: 28px;
      text-align: center;
      padding-bottom: 8px;
      margin-bottom: 6px;
      border-bottom: 1px solid var(--border);
    }
    #collapsed-rail-expand-btn:hover { color: var(--ink); }
    #collapsed-rail-list {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
      width: 100%;
    }
    .rail-icon {
      width: 28px;
      height: 28px;
      border-radius: var(--radius-badge);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 700;
      cursor: pointer;
      flex-shrink: 0;
      transition: background 0.15s;
    }
    .rail-icon.rail-chapter { background: var(--accent-tint); color: var(--accent); }
    .rail-icon.rail-chapter:hover { background: var(--accent-border); }
    .rail-icon.rail-checkpoint {
      background: var(--amber-tint); color: var(--amber); border: 1px solid var(--amber);
    }
    .rail-icon.rail-checkpoint:hover { background: #F5E6CC; }

    /* Rail flyout -- position:fixed so it escapes #context-panel's own
       overflow/width without reflowing the chat column; see the JS
       positioning logic (positionRailFlyout()) for placement math. */
    #rail-flyout {
      display: none;
      position: fixed;
      z-index: 1200;
      width: 240px;
      max-height: 360px;
      overflow-y: auto;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-card);
      box-shadow: 0 8px 24px rgba(22,35,46,0.18);
      padding: 10px 0;
    }
    #rail-flyout.visible { display: block; }
    .rail-flyout-title {
      font-size: 12px;
      font-weight: 700;
      color: var(--ink);
      padding: 0 14px 8px;
      margin-bottom: 4px;
      border-bottom: 1px solid var(--divider);
    }
    /* #rail-flyout prefix beats .km-chapter-test-btn's own width/margin
       regardless of stylesheet order (id+class > class specificity). */
    #rail-flyout .rail-flyout-checkpoint-btn {
      display: block;
      width: calc(100% - 28px);
      margin: 8px 14px 0;
      text-align: center;
    }

    /* Image cards */
    .image-card {
      background: var(--ground);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 13px;
      margin-bottom: 8px;
      font-size: 13px;
      display: flex;
      gap: 10px;
      align-items: flex-start;
    }
    .image-card img {
      max-height: 200px;
      object-fit: contain;
      background: var(--ground);
    }
    .img-icon {
      width: 34px; height: 34px;
      background: var(--accent-tint);
      border-radius: var(--radius-badge);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }
    .img-icon svg { fill: var(--accent); }
    .img-caption  { color: var(--ink); line-height: 1.45; margin-bottom: 5px; }
    .img-meta     { color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 4px; }
    .rel-dot {
      display: inline-block;
      width: 7px; height: 7px;
      border-radius: 50%;
    }
    .rel-dot.high   { background: var(--accent); }
    .rel-dot.medium { background: var(--amber); }
    .rel-dot.low    { background: var(--danger); }

    /* ── Mini-map panel (Contents) ──────────────────────────────────── */
    #minimap-panel {
      border: 1px solid var(--border);
      border-radius: var(--radius-card);
      overflow: hidden;
      margin: 16px;
      background: var(--surface);
    }
    #minimap-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 14px 16px;
      background: var(--surface);
      color: var(--ink);
      font-size: 15px;
      font-weight: 700;
    }
    #minimap-expand-icon { font-size: 14px; color: var(--muted); }
    /* Both header icons were bare glyphs with no padding -- their actual
       clickable box was just the character's own render width, so a
       click a couple px to either side missed the icon and fell through
       to #minimap-header's parent click handler (openMapOverlay) instead
       of the icon's own. Give them a real, centered hit target. */
    #minimap-collapse-panel-icon, #minimap-expand-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      border-radius: var(--radius-badge);
      color: var(--muted);
    }
    #minimap-collapse-panel-icon:hover, #minimap-expand-icon:hover {
      background: var(--ground);
    }
    #minimap-progress {
      padding: 0 16px 14px;
      border-bottom: 1px solid var(--divider);
    }

    /* ── Part C: Chapters / My notes segmented control + My notes view ──── */
    .learn-view-toggle {
      display: flex; gap: 4px; margin: 0 16px 12px; padding: 3px;
      background: var(--ground); border-radius: var(--radius-button);
    }
    .learn-view-toggle-btn {
      flex: 1; min-height: 36px; border: none; border-radius: calc(var(--radius-button) - 3px);
      background: none; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
    }
    .learn-view-toggle-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(22,35,46,0.1); }

    #my-notes-container { display: none; flex-direction: column; flex: 1; min-height: 0; }
    #my-notes-toolbar { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 12px; border-bottom: 1px solid var(--divider); flex-shrink: 0; }
    #my-notes-search {
      min-height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      font-family: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
    }
    #my-notes-filters { display: flex; gap: 6px; flex-wrap: wrap; }
    .my-notes-filter-btn {
      min-height: 30px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-chip);
      background: var(--surface); color: var(--ink-2); font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
    }
    .my-notes-filter-btn.active { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent); }
    .my-notes-filter-count { opacity: 0.75; }
    #my-notes-review-all-btn {
      align-self: flex-start; min-height: 32px; padding: 0 12px; border: none; border-radius: var(--radius-button);
      background: none; color: var(--accent); font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
    }
    #my-notes-list { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
    .my-notes-empty { padding: 32px 8px; text-align: center; color: var(--muted); font-size: 13px; }
    .my-notes-group { margin-bottom: 18px; }
    .my-notes-group-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
    .my-notes-group-title { font-size: 13px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
    .my-notes-group-num {
      display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
      padding: 0 5px; border-radius: 5px; background: var(--ink); color: #fff; font-size: 11px;
    }
    .my-notes-review-btn {
      min-height: 28px; padding: 0 10px; border: 1px solid var(--accent-border); border-radius: var(--radius-button);
      background: var(--surface); color: var(--accent); font-family: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
    }
    .my-notes-rows { display: flex; flex-direction: column; gap: 8px; }
    .my-notes-row {
      display: flex; flex-direction: column;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden;
    }
    /* Part A: the card itself is a <button aria-expanded> -- Open topic/
       Edit/Flag live in the sibling panel below, never nested inside it. */
    .my-notes-row-card {
      display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left;
      padding: 10px 12px; background: none; border: none; cursor: pointer; font-family: inherit; color: inherit;
    }
    .my-notes-row-top { display: flex; align-items: center; gap: 6px; }
    .my-notes-row-chevron { flex-shrink: 0; color: var(--muted); transition: transform 0.15s ease; }
    .my-notes-row-expanded .my-notes-row-chevron { transform: rotate(90deg); }
    .my-notes-row-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .my-notes-row-flag { display: flex; flex-shrink: 0; }
    .my-notes-row-stale-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); flex-shrink: 0; }
    .my-notes-row-orphan-label {
      flex-shrink: 0; font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase;
      padding: 1px 5px; background: var(--divider); border-radius: 4px;
    }
    .my-notes-row-preview {
      display: block; font-size: 13px; color: var(--ink-2); line-height: 1.4;
      overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    }
    .my-notes-row-date { display: block; font-size: 11px; color: var(--muted); }
    .my-notes-row-panel {
      display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; border-top: 1px solid var(--divider); padding-top: 10px;
    }
    .my-notes-row-full { font-size: 13px; color: var(--ink-2); line-height: 1.55; }
    .my-notes-row-full p { margin: 0 0 8px; }
    .my-notes-row-full blockquote { margin: 0 0 8px; padding-left: 10px; border-left: 2px solid var(--border-strong); color: var(--muted); }
    .my-notes-row-actions { display: flex; align-items: center; gap: 8px; }
    .my-notes-action-btn {
      min-height: 30px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      background: var(--surface); color: var(--ink-2); font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
    }
    .my-notes-row-flag-btn {
      min-height: 28px; min-width: 28px; display: flex; align-items: center; justify-content: center;
      border: 1px solid var(--border-strong); border-radius: 999px; background: none; cursor: pointer;
    }

    /* Saved entries (Part B) -- shared by the note editor, Topic card, Add-
       note sheet's existing-note preview, and My notes expanded cards. */
    .saved-entries-list { display: flex; flex-direction: column; gap: 8px; }
    .saved-entry-card {
      background: var(--accent-tint); border: 1px solid var(--accent-border); border-radius: var(--radius-card);
      padding: 8px 10px;
    }
    .saved-entry-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
    .saved-entry-label { font-size: 11px; font-weight: 700; color: var(--accent); }
    .saved-entry-question { font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
    .saved-entry-body { font-size: 13px; color: var(--ink-2); line-height: 1.5; }
    .saved-entry-body p { margin: 0 0 6px; }
    .saved-entry-body p:last-child { margin-bottom: 0; }
    .saved-entry-remove-btn {
      flex-shrink: 0; min-height: 22px; min-width: 22px; display: flex; align-items: center; justify-content: center;
      border: none; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0;
    }

    .progress-summary-row {
      display: flex; align-items: baseline; justify-content: space-between;
      margin-bottom: 10px;
    }
    .progress-summary-label { font-size: 15px; font-weight: 700; color: var(--ink); }
    .progress-summary-visited { font-size: 13px; color: var(--muted); }
    .progress-summary-bar { height: 8px; border-radius: 4px; background: var(--divider); overflow: hidden; }
    .progress-summary-bar-fill { height: 8px; background: var(--accent); border-radius: 4px; transition: width 0.4s ease; }
    #minimap-container {
      width: 100%;
      background: var(--surface);
      position: relative;
      /* No independent scroll here -- this panel takes its natural content
         height and shares #context-panel's own scroll region. */
    }
    #minimap-loading {
      padding: 24px;
      text-align: center;
      color: var(--muted);
      font-size: 13px;
    }

    /* ── Expanded map overlay ───────────────────────────────────────── */
    #map-overlay {
      display: none;
      position: fixed;
      top: 0; left: 0;
      width: 100vw; height: 100vh;
      background: rgba(22,35,46,0.5);
      z-index: 1000;
      align-items: center;
      justify-content: center;
    }
    #map-overlay.visible { display: flex; }
    #map-expanded {
      width: 82vw;
      height: 82vh;
      background: var(--surface);
      border-radius: var(--radius-card);
      overflow: hidden;
      position: relative;
      box-shadow: 0 20px 60px rgba(22,35,46,0.3);
      display: flex;
      flex-direction: column;
    }
    #map-expanded-header {
      min-height: 56px;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px;
      flex-shrink: 0;
    }
    #map-expanded-title { color: var(--ink); font-size: 15px; font-weight: 700; }
    #map-close-btn {
      color: var(--muted);
      background: none;
      border: none;
      font-size: 20px;
      cursor: pointer;
      font-family: inherit;
      line-height: 1;
      padding: 4px 8px;
    }
    #map-close-btn:hover { color: var(--ink); }
    #map-expanded-body {
      flex: 1;
      overflow-y: auto;
    }

    /* ── Accordion knowledge map (Contents) ─────────────────────────── */
    .km-container { padding: 4px 0; }
    .km-chapter { border-bottom: 1px solid var(--divider); }
    .km-chapter-header {
      display: flex; align-items: center; gap: 12px;
      padding: 0 16px; cursor: pointer; user-select: none;
      background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 600;
      min-height: 60px; box-sizing: border-box;
    }
    .km-chapter-header:hover { background: var(--ground); }
    .km-chapter-header.km-chapter-active { background: var(--accent-tint); }
    /* flex-wrap: at a narrow #context-panel (tablet tier, expanded), the
       checkpoint title + fixed-ish test button no longer both fit on one
       line -- wrapping the button to its own line keeps the title readable
       instead of squeezing it to nothing (min-height becomes a floor, not
       a fixed height, so the row can grow when it wraps). */
    .km-checkpoint-header {
      background: var(--amber-tint); padding-left: 16px;
      flex-wrap: wrap; row-gap: 6px;
    }
    .km-checkpoint-header .km-ch-name { flex-basis: 140px; }
    .km-checkpoint-header .km-chapter-test-btn { flex-grow: 1; }
    .km-checkpoint-header:hover { background: #FBEAD2; }
    .km-ch-num {
      width: 30px; height: 30px; flex-shrink: 0;
      background: var(--divider); border-radius: var(--radius-badge);
      display: flex; align-items: center; justify-content: center;
      font-size: 13px; font-weight: 700; color: var(--ink);
    }
    .km-chapter-header.km-chapter-active .km-ch-num { background: var(--accent); color: #fff; }
    .km-checkpoint-header .km-ch-num { background: var(--amber); color: #fff; }
    .km-ch-name {
      flex: 1; min-width: 0; line-height: 1.3;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
      overflow: hidden; text-overflow: ellipsis;
    }
    .km-checkpoint-header .km-ch-name { color: var(--muted); font-size: 14px; font-weight: 600; }
    .km-ch-toggle { opacity: 0.6; font-size: 10px; color: var(--muted); transition: transform 0.2s; }
    .km-chapter.km-collapsed .km-ch-toggle { transform: rotate(-90deg); }
    .km-h2-list { overflow: hidden; transition: max-height 0.25s ease; max-height: 2000px; }
    .km-chapter.km-collapsed .km-h2-list { max-height: 0; }
    .km-h2-item {
      display: flex; align-items: center; gap: 12px;
      min-height: 48px; padding: 0 16px; font-size: 15px; color: var(--ink);
      border-bottom: 1px solid var(--divider); transition: background 0.1s;
    }
    .km-h2-item:hover { background: var(--ground); }
    .km-h2-item.km-h2-source {
      background: var(--amber-tint); border-left: 3px solid var(--amber); padding-left: 13px;
    }
    .km-h2-item.km-h2-source .km-h2-text { font-weight: 600; color: var(--amber-text); }
    .km-status-icon { flex-shrink: 0; }
    .km-h2-text { flex: 1; line-height: 1.35; }
    .km-source-badge {
      display: none;
      font-size: 10px; font-weight: 700; background: var(--amber-tint);
      color: var(--amber); padding: 1px 6px; border-radius: 6px; flex-shrink: 0;
    }

    /* ── Orphaned notes ("restructured topics") group ──────────────────── */
    .km-orphan-group { border-top: 1px dashed var(--border); }
    .km-orphan-group-title {
      font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
      padding: 10px 16px 4px;
    }
    .km-orphan-item .km-h2-text { font-style: italic; color: var(--muted); }

    /* ── Assessment mode toggle (Easy/MCQ vs Hard/essay) ──────────────── */
    #assessment-mode-toggle {
      display: flex; gap: 0; margin: 14px 20px 0;
      border-radius: var(--radius-button); overflow: hidden; border: 1px solid var(--border); flex-shrink: 0;
    }
    .assess-mode-btn {
      flex: 1; min-height: 44px; padding: 6px 10px; border: none; background: var(--surface); color: var(--muted);
      font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
      transition: background 0.15s, color 0.15s;
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    }
    .assess-mode-btn.active { background: var(--accent); color: #fff; }
    .assess-mode-btn:not(.active):hover { background: var(--ground); }
    .assess-mode-btn-secondary { font-size: 10px; font-weight: 500; opacity: 0.75; }

    /* ── MCQ question/results ─────────────────────────────────────────── */
    .mcq-option-row {
      display: flex; align-items: flex-start; gap: 12px; min-height: 60px; padding: 10px 14px;
      border: 1.5px solid var(--border-strong); border-radius: var(--radius-button); margin-bottom: 8px;
      cursor: pointer; font-size: 15px; color: var(--ink); line-height: 1.4;
      transition: border-color 0.15s, background 0.15s;
    }
    .mcq-option-row:hover { border-color: var(--accent); background: var(--accent-tint); }
    .mcq-option-row input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; width: 20px; height: 20px; cursor: pointer; accent-color: var(--accent); }
    .mcq-reveal-row {
      display: flex; gap: 10px; align-items: flex-start; padding: 8px 0;
      border-bottom: 1px solid var(--divider); font-size: 13px; line-height: 1.5;
    }
    .mcq-reveal-icon { flex-shrink: 0; font-weight: 700; margin-top: 1px; width: 16px; text-align: center; }
    .mcq-reveal-note {
      font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
      padding: 1px 5px; border-radius: 3px; margin-left: 6px; white-space: nowrap;
    }
    #mcq-pass-badge {
      display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.5px; padding: 3px 10px; border-radius: var(--radius-badge); margin-bottom: 8px;
    }
    .km-h2-item.km-h2-source .km-source-badge { display: inline-block; }

    /* ── Chapter test (Module E3) ─────────────────────────────────────── */
    /* width: max-content (capped by max-width, not a fixed 138px) so this
       button can shrink -- at a 35%-of-viewport #context-panel, the tablet
       tier's narrow end (~210px at 600px viewport) doesn't leave room for a
       fixed-width button plus the chapter-number badge plus any chapter
       name text; a fixed, non-shrinking width there forced this row wider
       than its panel. */
    .km-chapter-test-btn {
      background: var(--surface); border: 1.5px solid var(--accent);
      color: var(--accent); border-radius: var(--radius-button); font-size: 12px; font-weight: 700;
      padding: 3px 9px; cursor: pointer; font-family: inherit; margin-left: 8px;
      flex-shrink: 1; min-width: 0; box-sizing: border-box; width: max-content; max-width: 138px; text-align: center;
      min-height: 32px;
    }
    .km-chapter-test-btn:hover { background: var(--accent-tint); }

    /* "Read chapter" (item 4) -- phone-only (hidden at >=600px, see that
       media query below); lives inside .km-h2-list like the test button
       below it, so it shows/hides with the same collapse CSS. */
    .km-chapter-read-link {
      display: block; padding: 10px 16px 0; font-size: 13px; font-weight: 700;
      color: var(--accent); text-decoration: none;
    }

    /* UI-2 item 4: one button at the bottom of each chapter's (collapsible)
       topic list, replacing the old always-visible per-row header button --
       lives inside .km-h2-list so it shows/hides with the same max-height
       collapse CSS, no extra JS to keep it in sync. */
    .km-chapter-test-bottom { padding: 12px 16px 16px; }
    .km-chapter-test-btn-bottom {
      display: flex; align-items: center; justify-content: center; width: 100%;
      min-height: 48px; border: 1.5px solid var(--accent); border-radius: var(--radius-button);
      background: var(--surface); color: var(--accent); font-family: inherit;
      font-size: 15px; font-weight: 700; cursor: pointer;
    }
    .km-chapter-test-btn-bottom:hover { background: var(--accent-tint); }

    #chapter-test-overlay {
      display: none; position: fixed; top: 0; left: 0;
      width: 100vw; height: 100vh; background: rgba(22,35,46,0.5); z-index: 2000;
      align-items: center; justify-content: center;
    }
    #chapter-test-overlay.visible { display: flex; }
    #chapter-test-modal {
      width: 640px; max-width: 92vw; max-height: 88vh; background: var(--surface);
      border-radius: var(--radius-card); overflow: hidden; box-shadow: 0 20px 60px rgba(22,35,46,0.3);
      display: flex; flex-direction: column;
    }
    #chapter-test-banner {
      background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 20px; color: var(--ink); flex-shrink: 0;
    }
    #chapter-test-banner .ct-title { font-weight: 700; font-size: 16px; }
    #chapter-test-banner .ct-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
    #chapter-test-body { overflow-y: auto; flex: 1; padding: 20px; }
    .ct-question-card {
      border: 1px solid var(--border); border-radius: var(--radius-card); padding: 16px; margin-bottom: 16px;
    }
    .ct-question-num { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
    .ct-question-stem { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 12px; line-height: 1.5; }
    #chapter-test-footer {
      padding: 14px 20px; border-top: 1px solid var(--divider); display: flex;
      justify-content: flex-end; gap: 10px; flex-shrink: 0;
    }
    .ct-result-card { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px; margin-bottom: 12px; }
    .ct-result-card .ct-result-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
    .ct-result-score { font-size: 12px; font-weight: 700; }

    /* ── Essay/quiz modal (moved from inline styles so UI-5's mobile
       full-screen media query below can apply -- same display:none/flex
       JS toggle as before, now set via class default instead of inline). ── */
    .assessment-overlay {
      display: none; position: fixed; top: 0; left: 0;
      width: 100vw; height: 100vh; background: rgba(22,35,46,0.5); z-index: 2000;
      align-items: center; justify-content: center;
    }
    .assessment-modal {
      width: 580px; max-width: 92vw; max-height: 88vh; background: #fff;
      border-radius: 12px; overflow: hidden; box-shadow: 0 20px 60px rgba(22,35,46,0.3);
      display: flex; flex-direction: column;
    }

    /* UI-5 item 7 (T1-T4): essay/quiz/chapter/checkpoint tests become
       full-screen on mobile instead of a centered modal; desktop keeps the
       modal, restyled above. Same <600px breakpoint isMobileLayout() uses everywhere else. */
    @media (max-width: 599px) {
      .assessment-overlay, #chapter-test-overlay { background: var(--surface); }
      .assessment-modal, #chapter-test-modal {
        width: 100vw; width: 100dvw; height: 100vh; height: 100dvh;
        max-width: none; max-height: none; border-radius: 0; box-shadow: none;
      }
    }

    /* ── Essay result headline + critical errors (UI-5 item 7, EssayResult.html) ── */
    .result-headline {
      display: flex; align-items: center; gap: 16px; padding: 18px 16px; margin-bottom: 20px;
      background: var(--surface); border: 1px solid var(--accent-border); border-radius: var(--radius-card);
    }
    .result-headline.not-passed { border-color: var(--border); }
    .result-status-icon {
      flex-shrink: 0; width: 56px; height: 56px; border-radius: 28px;
      display: flex; align-items: center; justify-content: center; color: #fff; background: var(--accent);
    }
    .result-headline.not-passed .result-status-icon { background: var(--danger); }
    .result-headline-text { display: flex; flex-direction: column; gap: 2px; }
    .result-status-label { font-size: 20px; font-weight: 700; color: var(--ink); }
    .result-score-detail { font-size: 13px; color: var(--ink-2); }
    .result-critical-summary { font-size: 12px; font-weight: 600; color: var(--accent); }
    .result-critical-summary.has-error { color: var(--danger); }
    .critical-errors-box {
      margin-bottom: 20px; padding: 14px; background: #FEF2F2; border: 1px solid #F3C9C4;
      border-radius: 8px;
    }
    .critical-errors-label {
      font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
      color: var(--danger); margin-bottom: 6px;
    }
    .critical-errors-text { margin: 0; font-size: 13px; line-height: 1.5; color: var(--ink); }
    .easy-mode-tag {
      font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px;
      text-transform: uppercase; letter-spacing: 0.04em;
    }

    /* ── Page images overlay (UI-5 item 3, mobile "Open page full-screen") ── */
    #page-images-overlay {
      display: none; flex-direction: column; position: fixed; inset: 0;
      z-index: 1500; background: var(--ground);
    }
    #page-images-overlay.visible { display: flex; }
    #page-images-header {
      flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 6px 8px;
      background: var(--surface); border-bottom: 1px solid var(--border);
    }
    #page-images-header span { font-size: 15px; font-weight: 700; color: var(--ink); }
    #page-images-close-btn {
      width: 44px; height: 44px; border: none; background: none; color: var(--ink);
      display: flex; align-items: center; justify-content: center; cursor: pointer;
    }
    #page-images-body { flex: 1; overflow-y: auto; background: #2B3440; }
    #page-images-body img { display: block; width: 100%; height: auto; margin-bottom: 2px; }

    /* ── Content viewer overlay ─────────────────────────────────────── */
    #content-overlay {
      display: none; position: fixed; top: 0; left: 0;
      width: 100vw; height: 100vh;
      background: rgba(22,35,46,0.5); z-index: 1500;
      align-items: center; justify-content: center;
    }
    #content-overlay.visible { display: flex; }
    #content-modal {
      width: 700px; max-width: 94vw; height: 88vh; max-height: 90vh;
      background: var(--surface); border-radius: var(--radius-card);
      box-shadow: 0 20px 60px rgba(22,35,46,0.35);
      display: flex; flex-direction: column;
    }
    .pdf-page-wrapper {
      position: relative;
      box-shadow: 0 2px 8px rgba(22,35,46,0.15);
      background: var(--surface); border-radius: 4px; overflow: hidden;
    }
    .pdf-page-wrapper.target-page { outline: 3px solid var(--accent); }

    /* ── Note editor overlay ───────────────────────────────────────── */
    /* z-index 2500: above assessment-overlay/chapter-test-overlay (2000)
       so the editor stays reachable during assessment (open-book decision),
       below progress-overlay (3000), which is an unrelated context. */
    #note-editor-overlay {
      display: none; position: fixed; top: 0; left: 0;
      width: 100vw; height: 100vh;
      background: rgba(22,35,46,0.5); z-index: 2500;
      align-items: center; justify-content: center;
    }
    #note-editor-overlay.visible { display: flex; }
    #note-editor-modal {
      width: 560px; max-width: 94vw; height: 70vh; max-height: 640px;
      background: var(--surface); border-radius: var(--radius-card);
      box-shadow: 0 20px 60px rgba(22,35,46,0.35);
      display: flex; flex-direction: column;
    }
    /* UI-5 item 6: full-screen on mobile (NoteEditor.html) -- same
       <600px breakpoint isMobileLayout() uses everywhere else. */
    @media (max-width: 599px) {
      #note-editor-overlay { background: var(--surface); padding: 0; }
      #note-editor-modal {
        width: 100vw; width: 100dvw; height: 100vh; height: 100dvh;
        max-width: none; max-height: none; border-radius: 0; box-shadow: none;
      }
    }
    /* flex:1 (not a fixed max-height) -- shares the remaining space with the
       textarea rather than always capping at a small fixed box, so a note
       that's only ever had a saved answer (no student text) doesn't leave
       its one meaningful piece of content squeezed under a huge empty
       textarea. refreshNoteEditorSavedEntries() shrinks the textarea's own
       flex-basis via JS whenever this is non-empty -- see notes.js. */
    #note-editor-saved-entries:not(:empty) {
      flex: 1; min-height: 0; margin-top: 10px; overflow-y: auto;
    }
    .note-editor-banner {
      flex-shrink: 0; display: flex; gap: 10px; margin: 12px 20px 0; padding: 12px 14px;
      background: var(--amber-tint); border: 1px solid #F5D9B0; border-radius: var(--radius-card);
    }
    .note-banner-icon { flex-shrink: 0; color: var(--amber); }
    .note-banner-text { display: flex; flex-direction: column; gap: 4px; }
    .note-banner-title { font-size: 14px; font-weight: 700; color: var(--amber-text); }
    .note-banner-subtitle { font-size: 13px; line-height: 1.45; color: var(--amber-text); }
    .note-banner-review-btn {
      background: none; border: none; color: var(--amber-text); text-decoration: underline;
      cursor: pointer; font: inherit; padding: 0; font-weight: 700;
    }

    /* ── Note indicators (Contents panel row, rail flyout, H2 modal button) ── */
    /* Fixed-width column regardless of state, so rows stay aligned whether
       or not an icon is shown -- width/height never change across the
       has-note / no-note / stale variants, only the SVG content inside. */
    .km-note-icon {
      flex-shrink: 0; cursor: pointer; line-height: 1;
      width: 20px; height: 20px; display: flex; align-items: center;
      justify-content: center; position: relative; margin-left: 4px;
    }
    /* No note, not hovering: fully invisible (opacity:0) -- the outline
       bubble + "+" badge only appears on desktop row hover (no :hover on
       touch, so this never shows on mobile -- notes are started from the
       H2 modal there instead). */
    .km-note-icon.km-note-icon-empty { opacity: 0; transition: opacity .15s; }
    .km-h2-item:hover .km-note-icon.km-note-icon-empty { opacity: 1; }
    .km-note-plus-badge {
      position: absolute; top: 48%; left: 50%; transform: translate(-50%, -60%);
      font-size: 8px; font-weight: 800; color: var(--muted); line-height: 1; pointer-events: none;
    }
    .km-note-icon.km-note-stale::after {
      content: ''; position: absolute; top: 0; right: 0; width: 6px; height: 6px;
      border-radius: 50%; background: var(--amber); border: 1px solid var(--surface);
    }
    /* Starred marker -- bottom-left, so it never collides with the stale
       dot (top-right); both can show on the same icon at once. */
    .km-note-flag-badge {
      position: absolute; bottom: -2px; left: -2px; line-height: 0; pointer-events: none;
    }
    /* "Needs review" star toggle button (note editor, Topic note card,
       My-notes row) -- same filled/outline treatment as the icon above,
       just a real button rather than a passive marker. */
    .note-flag-btn.flagged { border-color: var(--amber) !important; }
    @media (max-width: 480px) {
      /* Touch target >= 44x44, independent of the icon's own visual size --
         the brief's requirement is about tappability, not making the glyph
         itself bigger. */
      .km-note-icon { width: 44px; height: 44px; }
    }

    #note-hover-popover {
      display: none; position: fixed; z-index: 2600;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
      box-shadow: 0 8px 24px rgba(22,35,46,0.2); padding: 10px 12px;
      width: 220px; max-width: 80vw;
    }
    #note-hover-popover.visible { display: block; }
    .note-preview-markdown p, .note-preview-markdown blockquote { margin: 0 0 4px; }
    .note-preview-markdown blockquote { border-left: 2px solid var(--border); padding-left: 6px; color: var(--muted); }

    #note-mobile-sheet-overlay {
      display: none; position: fixed; top: 0; left: 0;
      width: 100vw; height: 100vh; background: rgba(22,35,46,0.4); z-index: 2600;
      align-items: flex-end; justify-content: center;
    }
    #note-mobile-sheet-overlay.visible { display: flex; }
    #note-mobile-sheet {
      width: 100%; max-width: 560px; background: var(--surface);
      border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; padding: 16px 20px 20px;
      box-shadow: 0 -8px 24px rgba(22,35,46,0.25);
    }
    #note-mobile-sheet-preview {
      font-size: 14px; color: var(--ink);
      max-height: 140px; overflow: hidden; margin-bottom: 8px;
    }
    #note-mobile-sheet-preview p, #note-mobile-sheet-preview blockquote { margin: 0 0 6px; }
    #note-mobile-sheet-date { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
    #note-mobile-sheet-edit-btn {
      width: 100%; min-height: 48px; padding: 10px; border: none; border-radius: var(--radius-button);
      background: var(--accent); color: #fff; font-size: 15px; font-weight: 700;
      font-family: inherit; cursor: pointer;
    }

    /* ── Save to note (answer bubbles + glossary entries) ─────────────── */
    .save-to-note-btn {
      margin-top: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--accent); border-radius: var(--radius-button);
      background: none; color: var(--accent); font-size: 13px; font-weight: 600;
      font-family: inherit; cursor: pointer;
    }
    .save-to-note-btn:hover { background: var(--accent-tint); }
    .save-to-note-btn:disabled { opacity: 0.55; cursor: not-allowed; }
    .save-to-note-btn.saved { background: var(--accent-tint); }
    #save-to-note-toast {
      display: none; position: fixed; top: 76px; right: 24px;
      background: var(--ink); color: #fff; border: 1px solid var(--accent);
      border-radius: var(--radius-button); padding: 12px 18px; font-size: 13px; font-weight: 600;
      z-index: 5000; box-shadow: 0 8px 24px rgba(22,35,46,0.3);
    }
    #save-to-note-toast a { color: #5EEAD4; margin-left: 8px; text-decoration: underline; cursor: pointer; }

    /* ── Add note sheet (UI-3, N1/N2, AddNote.html) -- bottom sheet below
         900px, centred modal at desktop widths (see the >=900px override
         below). ─────────────────────────────────────────────────────── */
    #add-note-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(22,35,46,0.4); z-index: 2600;
      align-items: flex-end; justify-content: center;
    }
    #add-note-overlay.visible { display: flex; }
    #add-note-sheet {
      width: 100%; max-width: 560px; max-height: 88vh;
      background: var(--surface);
      border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
      display: flex; flex-direction: column; overflow: hidden;
      box-shadow: 0 -8px 24px rgba(22,35,46,0.25);
    }
    .add-note-grabber {
      align-self: center; width: 40px; height: 4px; border-radius: 2px;
      background: var(--border-strong); margin: 10px 0 0; flex-shrink: 0;
    }
    .add-note-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 10px 16px; flex-shrink: 0;
    }
    .add-note-header h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--ink); }
    #add-note-cancel-btn {
      min-height: 44px; padding: 0 8px; border: none; background: none;
      font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink); cursor: pointer;
    }
    #add-note-scroll-body { flex: 1; overflow-y: auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
    .add-note-field { display: flex; flex-direction: column; gap: 6px; }
    .add-note-field > label, .add-note-field > span:first-child { font-size: 13px; font-weight: 600; color: var(--muted); }
    #add-note-topic-select {
      min-height: 48px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      background: var(--surface); font-family: inherit; font-size: 15px; color: var(--ink);
    }
    .add-note-existing-preview {
      padding: 10px 12px; border-radius: 10px; background: var(--ground);
      font-size: 14px; line-height: 1.5; color: var(--ink-2);
      max-height: 100px; overflow: hidden;
    }
    .add-note-existing-preview p, .add-note-existing-preview blockquote { margin: 0 0 6px; }
    #add-note-existing-saved-entries:not(:empty) { margin-top: 8px; max-height: 120px; overflow-y: auto; }
    #add-note-thoughts {
      padding: 12px; border: 1.5px solid var(--accent); border-radius: var(--radius-button);
      font-family: inherit; font-size: 15px; line-height: 1.5; color: var(--ink); resize: none;
    }
    #add-note-answer-box {
      display: flex; flex-direction: column; gap: 10px; padding: 12px;
      border: 1px solid var(--accent-border); border-radius: var(--radius-button); background: #F4FAF8;
    }
    .add-note-checkbox-row {
      display: flex; align-items: center; gap: 10px; min-height: 32px;
      font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer;
    }
    .add-note-checkbox-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
    .add-note-checkbox-row:has(input:disabled) { color: var(--muted); cursor: default; }
    .add-note-answer-preview {
      padding-left: 12px; border-left: 3px solid var(--accent-border);
      display: flex; flex-direction: column; gap: 4px;
    }
    .add-note-answer-q { font-size: 12px; font-weight: 600; color: var(--muted); }
    .add-note-answer-text { font-size: 13px; line-height: 1.5; color: var(--ink-2); }
    #add-note-char-counter { font-size: 12px; color: var(--muted); text-align: right; padding-bottom: 4px; }
    #add-note-save-btn {
      flex-shrink: 0; position: sticky; bottom: 0; margin: 12px 16px 16px;
      min-height: 52px; border: none; border-radius: var(--radius-button);
      background: var(--accent); color: #fff; font-family: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
    }
    #add-note-save-btn:disabled { opacity: 0.4; cursor: not-allowed; }
    @media (min-width: 600px) {
      #add-note-overlay { align-items: center; }
      #add-note-sheet { border-radius: var(--radius-card); max-height: 85vh; }
      .add-note-grabber { display: none; }
    }

    /* confirmDialog/showAppAlert CSS lives in /static/shared_dialogs.css
       (linked in <head>) -- this override just repositions the toast below
       this page's fixed header, which the admin shell doesn't have. */
    #app-alert-toast { top: 76px; }

    /* ── Mobile bottom tab bar (UI-2 item 1) ──────────────────────────── */
    #mobile-tab-bar {
      display: none; flex-shrink: 0; grid-template-columns: repeat(3, minmax(0, 1fr));
      background: var(--surface); border-top: 1px solid var(--border);
      padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }
    .tab-item {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      gap: 2px; min-height: 52px; text-decoration: none;
      color: var(--muted); font-size: 12px; font-weight: 600;
    }
    .tab-item.active { color: var(--accent); font-weight: 700; }

    /* ── Topic screen (UI-2 item 5, mobile only, Topic.html) ──────────── */
    #view-topic { display: none; flex-direction: column; background: var(--ground); overflow: hidden; }
    #topic-header {
      flex-shrink: 0; display: flex; align-items: center; padding: 6px 8px;
      background: var(--surface); border-bottom: 1px solid var(--border);
    }
    #topic-back-link {
      display: flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 8px;
      font-size: 15px; font-weight: 600; color: var(--ink); text-decoration: none;
    }
    #topic-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 16px; }
    .topic-heading { display: flex; flex-direction: column; gap: 6px; }
    .topic-eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); }
    #topic-title { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
    .topic-status-pill {
      align-self: flex-start; padding: 4px 10px; border-radius: var(--radius-chip);
      background: var(--divider); font-size: 13px; font-weight: 600; color: var(--ink-2);
    }
    .topic-status-pill-assessed { background: var(--accent-tint); color: var(--accent); }
    .topic-status-pill-visited, .topic-status-pill-quizzed { background: var(--accent-tint); color: var(--accent); }

    .topic-actions-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .topic-action-btn {
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
      min-height: 76px; background: var(--surface); border: 1px solid var(--accent-border);
      border-radius: var(--radius-card); font-size: 13px; font-weight: 700; color: var(--ink);
      text-decoration: none; cursor: pointer; font-family: inherit;
    }
    .topic-action-btn.topic-action-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

    /* ── Content inline (item 2) -- replaces the old "Source material /
       Open page full-screen" card. aspect-ratio is set per-image in JS
       (renderTopicPageImages()/applyPageImageAspectRatio() in contents.js)
       -- most pages are cropped to their printed content box (Part D,
       ~44% larger effective size at a fixed width) and have a narrower
       aspect ratio than a page served full-size, so a single fixed value
       here can't cover both; this is just the fallback for the instant
       before that JS runs. ── */
    .topic-page-images { display: flex; flex-direction: column; gap: 10px; }
    .topic-page-image {
      width: 100%; aspect-ratio: 780 / 1592; display: block; object-fit: cover;
      border-radius: var(--radius-card); background: var(--divider); cursor: zoom-in;
    }
    .topic-read-chapter-link {
      display: flex; align-items: center; justify-content: center; gap: 6px;
      min-height: 40px; font-size: 14px; font-weight: 700; color: var(--accent); text-decoration: none;
    }

    .topic-card {
      display: flex; flex-direction: column; gap: 12px; padding: 16px;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
    }
    .topic-card h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
    .topic-test-row {
      display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 14px;
      border: 1px solid var(--border-strong); border-radius: var(--radius-button);
      background: var(--surface); color: var(--ink); cursor: pointer; font-family: inherit; text-align: left;
    }
    .topic-test-row-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
    .topic-test-row-title { font-size: 15px; font-weight: 600; }
    .topic-test-row-meta { font-size: 13px; color: var(--muted); }
    .topic-note-header { display: flex; align-items: center; justify-content: space-between; }
    #topic-note-edit-btn {
      min-height: 44px; padding: 0 4px; border: none; background: none;
      font-family: inherit; font-size: 14px; font-weight: 700; color: var(--accent); cursor: pointer;
    }
    #topic-note-flag-btn {
      min-height: 36px; min-width: 36px; display: flex; align-items: center; justify-content: center;
      border: 1px solid var(--border-strong); border-radius: 999px; background: none; cursor: pointer;
    }
    #topic-note-preview { margin: 0; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
    #topic-note-saved-entries:not(:empty) { margin-top: 10px; }

    /* ── Previous/Next topic cards (item 3) ─────────────────────────────── */
    .topic-nav-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .topic-nav-card {
      display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; min-width: 0;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
      text-decoration: none;
    }
    .topic-nav-card-label { font-size: 12px; font-weight: 600; color: var(--muted); }
    .topic-nav-card-title {
      font-size: 14px; font-weight: 700; color: var(--ink);
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    /* First/last topic in the book: the missing side renders as this empty,
       borderless cell instead of being omitted, so the row's two-column
       width/gap never shifts and the present card never slides into the
       other column. */
    .topic-nav-card.topic-nav-card-empty { background: none; border: none; }

    /* ── Read-chapter view (item 4, mobile only, Topic.html-style chrome) ── */
    #view-read { display: none; flex-direction: column; background: var(--ground); overflow: hidden; position: relative; }
    #read-header {
      flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 6px 12px;
      background: var(--surface); border-bottom: 1px solid var(--border);
    }
    #read-back-link {
      display: flex; align-items: center; justify-content: center; width: 44px; height: 44px;
      color: var(--ink); text-decoration: none; flex-shrink: 0;
    }
    #read-chapter-title { font-size: 16px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #read-body { flex: 1; overflow-y: auto; padding: 0 12px 24px; display: flex; flex-direction: column; gap: 6px; }
    /* aspect-ratio set per-image in JS, same reasoning as .topic-page-image
       above -- this is just the pre-JS fallback. */
    .read-page-image { width: 100%; aspect-ratio: 780 / 1592; display: block; object-fit: cover; background: var(--divider); }
    .read-floating-label {
      display: none; position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
      max-width: calc(100% - 32px); align-items: center; gap: 6px; padding: 10px 16px;
      background: var(--ink); color: #fff; border-radius: var(--radius-button);
      font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap;
      overflow: hidden; text-overflow: ellipsis; box-shadow: 0 4px 16px rgba(22,35,46,0.3);
    }

    /* ── Progress tab (UI-2 item 7, restyled UI-5 item 1 / Progress.html) ── */
    #view-progress { display: none; flex-direction: column; background: var(--ground); overflow: hidden; }
    #progress-view-header {
      flex-shrink: 0; padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    }
    #progress-view-header h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--ink); }
    #progress-scroll-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
    #progress-headline-card {
      display: flex; flex-direction: column; gap: 10px; padding: 16px;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
    }
    #progress-summary-label { font-size: 15px; font-weight: 600; color: var(--ink); }
    #progress-summary-bar { height: 8px; border-radius: 4px; background: var(--divider); overflow: hidden; }
    #progress-summary-bar-fill { height: 8px; border-radius: 4px; background: var(--accent); transition: width 0.8s ease; }
    .progress-section-label {
      font-size: 13px; font-weight: 700; margin: 0 4px 8px; color: var(--ink);
    }
    #progress-badges-section { display: flex; flex-direction: column; }
    #progress-recent-results-section { display: flex; flex-direction: column; }
    #progress-recent-results {
      display: flex; flex-direction: column; background: var(--surface);
      border: 1px solid var(--border); border-radius: var(--radius-button); overflow: hidden;
    }
    .progress-result-row {
      display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px;
      border-bottom: 1px solid var(--divider); font-size: 14px;
    }
    .progress-result-row:last-child { border-bottom: none; }
    .progress-result-tag {
      padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap;
    }
    .progress-result-tag.essay { background: var(--accent-tint); color: var(--accent); }
    .progress-result-tag.quiz { background: var(--divider); color: var(--ink-2); }
    .progress-result-topic { flex: 1; }
    .progress-result-status { font-size: 13px; font-weight: 700; }
    .progress-result-status.passed { color: var(--accent); }
    .progress-result-status.not-passed { color: var(--muted); }
    #progress-legend {
      margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--divider);
      display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted);
    }
    #progress-legend > div { display: flex; align-items: center; gap: 6px; }
    .progress-legend-swatch { width: 12px; height: 12px; border-radius: 3px; }

    /* ── Settings (UI-5 item 2, Settings.html) ─────────────────────────── */
    #view-settings { display: none; flex-direction: column; background: var(--ground); overflow: hidden; }
    #settings-view-header {
      flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 6px 8px;
      background: var(--surface); border-bottom: 1px solid var(--border);
    }
    #settings-view-header h1 { margin: 0; font-size: 18px; font-weight: 700; color: var(--ink); }
    #settings-back-btn {
      width: 44px; height: 44px; border: none; background: none; color: var(--ink);
      display: flex; align-items: center; justify-content: center; cursor: pointer;
    }
    #settings-scroll-body { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 22px; }
    .settings-section { display: flex; flex-direction: column; gap: 8px; }
    .settings-section h2 {
      margin: 0 4px; font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
      text-transform: uppercase; color: var(--muted);
    }
    .settings-card {
      display: flex; flex-direction: column; background: var(--surface);
      border: 1px solid var(--border); border-radius: var(--radius-button); overflow: hidden;
    }
    .settings-row {
      display: flex; justify-content: space-between; align-items: center; min-height: 52px;
      padding: 0 14px; font-size: 15px; color: var(--ink); text-decoration: none;
    }
    .settings-row + .settings-row { border-top: 1px solid var(--divider); }
    .settings-row-value { color: var(--muted); }
    .settings-row-link { font-weight: 600; }
    .settings-danger-card {
      flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px 14px;
      border-color: #F3C9C4;
    }
    .settings-danger-title { font-size: 15px; font-weight: 700; color: var(--ink); }
    .settings-danger-copy { font-size: 13px; line-height: 1.5; color: var(--muted); margin-top: 4px; }
    .settings-danger-btn {
      align-self: flex-start; min-height: 44px; padding: 0 16px; border: 1.5px solid var(--danger);
      border-radius: var(--radius-button); background: var(--surface); color: var(--danger);
      font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
    }

    /* ── Responsive: three tiers ────────────────────────────────────────
       phone (<600px): #chat-panel/#context-panel/#view-topic/#view-progress
       are mutually-exclusive full screens, picked by body[data-route] (set
       in contents.js's router) and reached via #mobile-tab-bar.
       tablet (600-1023px) and desktop (>=1024px): identical CSS -- both
       show #chat-panel + #context-panel together (the "Study" view,
       two-pane layout), no tab bar; the only difference between them is
       which default panel-collapsed state contents.js's applyRailTierDefault()
       applies (tablet defaults collapsed and remembers the student's choice
       per device via localStorage; desktop always defaults expanded) --
       that's JS-driven, not a separate CSS breakpoint. #view-topic never
       shows at tablet/desktop (the chat-topic-context bar covers the same
       ground); #view-progress replaces the whole Study area in every tier.
       100dvh (falls back to 100vh where unsupported) keeps the input bar
       clear of mobile browser chrome. */
    html, body { height: 100vh; height: 100dvh; }
    #app { height: 100vh; height: 100dvh; }

    @media (max-width: 599px) {
      #desktop-nav { display: none; }
      #mobile-tab-bar { display: grid; }
      #main { flex: 1; min-height: 0; }
      #chat-panel, #context-panel { display: none; width: 100%; min-height: 0; border: none; }
      body[data-route="ask"] #chat-panel { display: flex; }
      body[data-route="learn"] #context-panel { display: flex; }
      body[data-route="topic"] #main,
      body[data-route="read"] #main,
      body[data-route="progress"] #main,
      body[data-route="settings"] #main { display: none; }
      body[data-route="topic"] #view-topic { display: flex; }
      body[data-route="read"] #view-read { display: flex; }
      body[data-route="progress"] #view-progress { display: flex; }
      body[data-route="settings"] #view-settings { display: flex; }

      #minimap-header, #collapsed-rail-expand-btn { display: none; }
      #context-panel.panel-collapsed { width: 100%; }
      #context-panel-collapsed-strip { display: none !important; }

      .chat-topic-context-actions { display: none; }
      .chat-topic-nav-btn { display: none; }
      #chat-topic-clear-btn { display: flex; }
    }

    @media (min-width: 600px) {
      #view-topic { display: none !important; }
      #view-read { display: none !important; }
      .km-chapter-read-link { display: none !important; }
      body[data-route="progress"] #main,
      body[data-route="settings"] #main { display: none; }
      body[data-route="progress"] #view-progress { display: flex; }
      body[data-route="settings"] #view-settings { display: flex; }
      #desktop-nav { display: flex; }
    }

    /* ── Glossary ────────────────────────────────────────────────────────────── */
    .glossary-term { text-decoration: underline dotted var(--accent); cursor: pointer; }
    .glossary-card {
      background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
      border-radius: var(--radius-card);
      box-shadow: 0 2px 8px rgba(22,35,46,0.12); padding: 16px; margin: 8px 0; font-size: 14px;
      overflow: hidden; max-height: 0; transition: max-height 0.3s ease;
    }
    .glossary-card.open { max-height: 500px; }
    .glossary-card-header { display: flex; align-items: flex-start; margin-bottom: 6px; }
    .glossary-card-term { font-weight: 700; color: var(--accent); flex: 1; }
    .glossary-card-close {
      border: none; background: none; cursor: pointer; font-size: 18px;
      line-height: 1; color: var(--muted); padding: 0 0 0 8px; flex-shrink: 0;
    }
    .glossary-card-definition { color: var(--ink); line-height: 1.55; }
    .glossary-card-context { font-style: italic; color: var(--ink-2); margin-top: 8px; line-height: 1.5; }
    .glossary-card-related { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
    .glossary-chip {
      display: inline-flex; align-items: center; border: 1px solid var(--accent-border);
      background: var(--accent-tint); color: var(--accent); border-radius: var(--radius-chip); padding: 0 10px; font-size: 13px; font-weight: 600; cursor: pointer;
      min-height: 36px; line-height: 1.2; transition: background 0.15s;
    }
    .glossary-chip:hover { background: var(--accent-border); }
    .glossary-covered-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; margin-right: 2px; }
    .glossary-card-actions { display: flex; gap: 8px; margin-top: 14px; }
    .glossary-card-actions .save-to-note-btn { flex: 1; }
    .glossary-ask-btn {
      flex: 1; display: flex; align-items: center; justify-content: center; min-height: 52px;
      border: none; border-radius: var(--radius-button); background: var(--accent); color: #fff;
      font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
    }
    @media (max-width:768px) {
      .glossary-card { width: 100%; box-sizing: border-box; }
      .glossary-card-related { flex-wrap: wrap; }
    }

    /* UI-5 item 5: mobile bottom sheet (isMobileLayout(), <900px) -- the
       same .glossary-card content, positioned as a fixed sheet instead of
       inserted inline in the answer flow. */
    .glossary-sheet-backdrop {
      position: fixed; inset: 0; background: rgba(22,35,46,0.45); z-index: 2600;
    }
    .glossary-card.glossary-sheet {
      position: fixed; left: 0; right: 0; bottom: 0; z-index: 2601;
      max-height: 80vh; overflow-y: auto; margin: 0; width: auto;
      border-left: none; border-bottom: none;
      border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
      padding: 10px 16px 24px;
      box-shadow: 0 -8px 32px rgba(22,35,46,0.25);
    }
