  :root {
    --bg: #f4f1eb;
    --surface: #ece8e1;
    --surface2: #e2ded6;
    --border: #d1ccc3;
    --text: #2c2a27;
    --text-secondary: #6e6b65;
    --primary: #4a5680;
    --primary-dark: #3a4468;
    --primary-light: #e8eaf2;
    --mark-bg: #fef3cd;
    --mark-text: #7d6608;
    --badge-act: #4a5680;
    --badge-sub: #7b5ea7;
    --badge-judgment: #b8792e;
    --badge-building: #c4854c;
    --radius: 10px;
  }
  [data-theme="dark"] {
    --bg: #1e1d1c;
    --surface: #282726;
    --surface2: #322f2e;
    --border: #3e3b39;
    --text: #e5e2dd;
    --text-secondary: #9a9690;
    --primary: #8b9bc7;
    --primary-dark: #2a3048;
    --primary-light: #282d3d;
    --mark-bg: #5d4e37;
    --mark-text: #f0d090;
    --badge-act: #8b9bc7;
    --badge-sub: #a889c9;
    --badge-judgment: #d4944a;
    --badge-building: #d9a06a;
  }

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

  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Source Sans 3', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
  }
  body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 600px;
    background: radial-gradient(ellipse at center 120px, rgba(74,86,128,0.22) 0%, rgba(74,86,128,0.07) 35%, transparent 60%);
    pointer-events: none;
    z-index: 0;
  }
  [data-theme="dark"] body::after {
    background: radial-gradient(ellipse at center 120px, rgba(139,155,199,0.18) 0%, rgba(139,155,199,0.06) 35%, transparent 60%);
  }

  /* ---- Header ---- */
  header {
    background: linear-gradient(135deg, #3a4468 0%, #2c3350 60%, #232840 100%);
    color: #fff;
    position: relative;
    z-index: 20;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  }
  header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='20' height='20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h1v1H0z' fill='%23ffffff' fill-opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
  }
  .header-top {
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
  }
  .header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
  }
  .header-logo {
    width: 28px;
    height: 28px;
    opacity: 0.9;
    flex-shrink: 0;
  }
  .header-title-group { display: flex; flex-direction: column; }
  .header-tagline {
    font-size: 0.75rem;
    opacity: 0.7;
    font-weight: 400;
    letter-spacing: 0.02em;
    margin-top: 1px;
  }
  .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
  }
  header h1 { font-family: 'Libre Baskerville', Georgia, serif; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; }

  #stats-bar {
    font-size: 0.8rem;
    opacity: 0.85;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
  }
  #stats-bar span { white-space: nowrap; }

  .header-nav {
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid rgba(255,255,255,0.15);
  }
  .disclaimer-inline {
    font-size: 0.75rem;
    opacity: 0.7;
  }
  .disclaimer-inline a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

  /* ---- Dark mode toggle ---- */
  #theme-toggle {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    padding: 6px 8px;
    flex-shrink: 0;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #theme-toggle:hover { background: rgba(255,255,255,0.15); }

  /* ---- Disclaimer (inline in header nav) ---- */

  /* ---- Search controls ---- */
  .controls {
    padding: 14px 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    background: transparent;
  }

  #search-input {
    padding: 14px 18px;
    font-size: 1.05rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  #search-input:focus { border-color: var(--primary); }


  /* Filter toggle — hidden on desktop */
  .filter-toggle { display: none; }
  .filter-drawer {
    display: contents;
  }
  .filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .filter-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
  }

  select, input[type=number], .filter-group input[type=text] {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
  }
  select:focus, input[type=number]:focus, .filter-group input[type=text]:focus { border-color: var(--primary); }
  input[type=number] { width: 76px; }

  /* ---- focus-visible for keyboard nav ---- */
  :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  /* ---- Main ---- */
  main {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 24px 20px;
  }

  /* ---- Tabs (inside header) ---- */
  .tabs {
    display: flex;
    gap: 0;
  }
  .tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
  }
  .tab-btn:hover { color: #fff; }
  .tab-btn.active {
    color: #fff;
    border-bottom-color: #fff;
  }

  /* ---- About blurb ---- */
  .hero-stat {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary);
    text-align: center;
    padding: 16px 0 8px;
    letter-spacing: -0.01em;
  }
  .hero-stat span { font-weight: 400; color: var(--text-secondary); font-size: 1rem; }

  /* ---- Hero welcome section ---- */
  .hero-welcome {
    text-align: center;
    padding: 28px 20px 24px;
  }
  .hero-welcome h2 {
    font-family: 'Libre Baskerville', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
    letter-spacing: -0.02em;
  }
  .hero-welcome p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto 20px;
    line-height: 1.6;
  }
  .hero-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 0;
  }
  .hero-divider {
    width: 48px;
    height: 2px;
    background: var(--border);
    margin: 24px auto 0;
    border-radius: 1px;
  }
  .hero-examples span { font-size: 0.82rem; color: var(--text-secondary); align-self: center; }
  .hero-example-pill {
    padding: 6px 14px;
    border-radius: 99px;
    border: 1px solid rgba(74,86,128,0.25);
    background: rgba(255,255,255,0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  }
  [data-theme="dark"] .hero-example-pill {
    border-color: rgba(139,155,199,0.3);
    background: rgba(255,255,255,0.07);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  }
  .hero-example-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  .hero-cards {
    display: flex;
    gap: 16px;
    margin-top: 24px;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
  @media (max-width: 600px) {
    .hero-cards { flex-direction: column; }
  }
  .lotd-card {
    padding: 20px 24px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    text-align: left;
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .lotd-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
    margin-bottom: 6px;
  }
  .lotd-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px;
    line-height: 1.4;
  }
  .lotd-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
  }
  .lotd-summary {
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.65;
    margin: 0 0 14px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
  }
  .lotd-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }
  .lotd-btn {
    padding: 7px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s;
  }
  .lotd-btn:hover { filter: brightness(1.1); }
  .lotd-btn-secondary {
    background: transparent;
    color: var(--primary);
  }
  .lotd-btn-secondary:hover {
    background: var(--primary-light);
    filter: none;
  }
  @media (max-width: 600px) {
    .hero-welcome h2 { font-size: 1.25rem; }
  }

  .about-blurb {
    margin-bottom: 16px;
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-secondary);
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    text-align: center;
  }
  .about-blurb a { color: var(--primary); }

  /* ---- How it works ---- */
  .how-it-works {
    display: none;
  }

  #results-meta {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
    padding-top: 20px;
    min-height: 1.4em;
  }

  /* ---- Result card ---- */
  .result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color 0.15s, box-shadow 0.2s, transform 0.15s;
  }
  .result-card[data-type="act"] { border-left: 3px solid var(--badge-act); }
  .result-card[data-type="subsidiary"] { border-left: 3px solid var(--badge-sub); }
  .result-card[data-type="judgment"] { border-left: 3px solid var(--badge-judgment); }
  .result-card[data-type="building_code"] { border-left: 3px solid var(--badge-building); }
  .result-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
  }
  .result-card[data-type]:hover { border-left-width: 3px; }
  .result-card[data-type="act"] .card-header { background: rgba(74,86,128,0.06); }
  .result-card[data-type="subsidiary"] .card-header { background: rgba(123,94,167,0.06); }
  .result-card[data-type="judgment"] .card-header { background: rgba(184,121,46,0.06); }
  .result-card[data-type="building_code"] .card-header { background: rgba(196,133,76,0.06); }
  [data-theme="dark"] .result-card[data-type="act"] .card-header { background: rgba(139,155,199,0.08); }
  [data-theme="dark"] .result-card[data-type="subsidiary"] .card-header { background: rgba(168,137,201,0.08); }
  [data-theme="dark"] .result-card[data-type="judgment"] .card-header { background: rgba(212,148,74,0.08); }
  [data-theme="dark"] .result-card[data-type="building_code"] .card-header { background: rgba(217,160,106,0.08); }

  .card-header {
    padding: 12px 16px 8px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }

  .doc-title {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text);
    flex: 1;
  }

  .badges {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
  }
  .badge {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 10px;
    border-radius: 99px;
    color: #fff;
  }
  .badge-act { background: var(--badge-act); }
  .badge-sub { background: var(--badge-sub); }
  .badge-judgment { background: var(--badge-judgment); }
  .badge-building { background: var(--badge-building); }
  .badge-year {
    background: #5c6272;
    color: #fff;
  }

  .section-line {
    padding: 0 16px 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
  }
  .section-line strong { color: var(--text); }

  .snippet-box {
    padding: 8px 16px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text);
  }
  .snippet-box mark {
    background: var(--mark-bg);
    color: var(--mark-text);
    border-radius: 2px;
    padding: 0 2px;
  }

  .card-footer {
    padding: 8px 16px 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
  }

  .btn-toggle, .btn-source {
    font-size: 0.82rem;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg);
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
  }
  .btn-toggle:hover, .btn-source:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
  }

  .full-text-box {
    padding: 12px 16px 14px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    border-top: 1px solid var(--border);
    display: none;
    background: var(--surface2);
  }
  .full-text-box.open {
    display: block;
  }
  .full-text-content {
    white-space: pre-wrap;
  }

  /* ---- Bottom collapse button ---- */
  .section-collapse {
    display: none;
    padding: 8px 16px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
  }
  .section-collapse.open { display: flex; align-items: center; gap: 8px; }
  .btn-collapse {
    font-size: 0.82rem;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg);
    color: var(--text-secondary);
    transition: background 0.1s, color 0.1s;
  }
  .btn-collapse:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
  }

  /* ---- States ---- */
  .state-box {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
  }
  .state-box .icon { font-size: 2.5rem; margin-bottom: 12px; }
  .state-box h2 { font-size: 1.1rem; margin-bottom: 8px; color: var(--text); }
  .state-box code {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    display: inline-block;
    margin-top: 8px;
  }

  /* ---- Load more ---- */
  #load-more-btn, #browse-load-more-btn {
    display: none;
    margin: 8px auto 24px;
    padding: 10px 28px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background 0.15s;
  }
  #load-more-btn:hover, #browse-load-more-btn:hover { background: var(--primary-light); }
  #load-more-btn:disabled, #browse-load-more-btn:disabled { opacity: 0.5; cursor: default; }

  /* ---- Spinner ---- */
  .spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ---- Browse view ---- */
  .browse-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    padding-top: 20px;
  }
  .browse-filters .filter-toggle { display: none; }
  .browse-filters .filter-drawer { display: contents; }

  /* A-Z nav */
  #browse-az-nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    margin-bottom: 12px;
    padding-bottom: 4px;
  }
  .az-btn {
    padding: 3px 7px;
    font-size: 0.82rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.12s, border-color 0.12s;
    line-height: 1.4;
  }
  .az-btn:hover { border-color: var(--primary); color: var(--primary); }
  .az-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
  #browse-meta {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
    min-height: 1.4em;
  }
  .browse-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 12px 16px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color 0.15s, background 0.15s, box-shadow 0.2s, transform 0.15s;
  }
  .browse-card[data-type="act"] { border-left: 3px solid var(--badge-act); }
  .browse-card[data-type="subsidiary"] { border-left: 3px solid var(--badge-sub); }
  .browse-card[data-type="judgment"] { border-left: 3px solid var(--badge-judgment); }
  .browse-card[data-type="building_code"] { border-left: 3px solid var(--badge-building); }
  .browse-card:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
  }
  .browse-card[data-type]:hover { border-left-width: 3px; }
  .browse-card-title {
    font-weight: 600;
    font-size: 0.97rem;
    color: var(--text);
    margin-bottom: 6px;
  }
  .browse-card-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.82rem;
    color: var(--text-secondary);
  }

  /* ---- Document modal ---- */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    overflow-y: auto;
  }
  .modal-box {
    background: var(--bg);
    border-radius: 12px;
    width: 100%;
    max-width: 860px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    position: relative;
  }
  .modal-header {
    padding: 16px 50px 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 12px;
    flex-shrink: 0;
    position: relative;
  }
  .modal-title {
    flex: 1 1 100%;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
  }
  .modal-header-meta {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    flex: 1 1 auto;
    min-width: 0;
  }
  .btn-modal-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 10px;
    flex-shrink: 0;
    position: absolute;
    top: 16px;
    right: 20px;
    transition: background 0.1s;
  }
  .btn-modal-close:hover { background: var(--surface2); }
  .modal-back-to-top {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(8px);
    z-index: 10;
  }
  .modal-back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
  .modal-back-to-top:hover {
    filter: brightness(1.1);
  }
  .modal-body {
    overflow-y: auto;
    padding: 16px 20px;
    flex: 1;
  }
  .modal-section {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }
  .modal-notice {
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    background: var(--surface);
    border-left: 3px solid var(--text-secondary);
    color: var(--text-secondary);
    font-size: 0.9rem;
  }
  .modal-section-header {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface);
    transition: background 0.15s;
  }
  .modal-section-header:hover { background: var(--primary-light); }
  .modal-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
  }
  .section-line-count {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 6px;
  }

  .modal-section-text {
    padding: 10px 14px;
    font-size: 0.88rem;
    line-height: 1.7;
    white-space: pre-wrap;
    color: var(--text);
    border-top: 1px solid var(--border);
    display: none;
    background: var(--surface2);
  }
  .modal-section-text.open { display: block; }

  /* ---- Reader mode (continuous document flow) ---- */
  .reader-toc {
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 0.82rem;
  }
  .reader-toc-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .reader-toc-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
    padding: 2px 6px;
  }
  .reader-toc-toggle:hover { color: var(--primary); }
  .reader-toc.collapsed { max-height: none; overflow: visible; }
  .reader-toc.collapsed .reader-toc-list { display: none; }
  .reader-toc-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 24px;
    line-height: 1.9;
  }
  @media (max-width: 600px) { .reader-toc-list { grid-template-columns: 1fr; } }
  .reader-toc-link {
    display: block;
    color: var(--primary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .reader-toc-link:hover { text-decoration: underline; }

  .reader-section {
    position: relative;
    padding: 0 0 8px;
  }
  .reader-section-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 10px 0 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .reader-section-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
  }
  .reader-section-label span {
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 6px;
  }
  .reader-section-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
  }
  .reader-section:hover .reader-section-actions { opacity: 1; }
  .reader-section-text {
    font-size: 0.88rem;
    line-height: 1.75;
    color: var(--text);
    white-space: pre-wrap;
    padding: 6px 0 16px;
  }

  /* ---- Footnotes section ---- */
  .reader-footnotes {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }
  .reader-footnotes .reader-section-header {
    position: static;
  }
  .footnote-list {
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-secondary);
    padding-left: 1.5em;
    margin: 4px 0 12px;
  }
  .footnote-list li {
    margin-bottom: 6px;
  }

  /* ---- Margin notes collapsible section ---- */
  .reader-margin-notes {
    margin: 0 0 16px;
    padding: 10px 14px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }
  .margin-notes-toggle {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 0;
    list-style: none;
  }
  .margin-notes-toggle::-webkit-details-marker { display: none; }
  .margin-notes-toggle::before {
    content: "▸ ";
    font-size: 0.7rem;
    margin-right: 2px;
  }
  details[open] > .margin-notes-toggle::before { content: "▾ "; }
  .margin-notes-toggle:hover {
    color: var(--primary);
  }
  .margin-note-list {
    font-size: 0.76rem;
    line-height: 1.6;
    color: var(--text-secondary);
    font-style: italic;
    list-style: none;
    padding: 8px 0 4px 14px;
    margin: 6px 0 0;
    border-left: 2px solid var(--border);
    columns: 2;
    column-gap: 24px;
  }
  @media (max-width: 600px) { .margin-note-list { columns: 1; } }
  .margin-note-list li {
    padding: 2px 0;
    break-inside: avoid;
  }
  .mn-page-divider {
    font-style: normal;
    font-weight: 600;
    font-size: 0.68rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 6px 0 2px;
    margin-top: 4px;
    opacity: 0.7;
  }
  .mn-page-divider:first-child { margin-top: 0; padding-top: 0; }

  /* ---- Modal meta sections (Referenced by, Amendments) ---- */
  .modal-meta-section {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 0.85rem;
  }
  .modal-meta-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    font-size: 0.88rem;
  }
  .modal-meta-body {
    color: var(--text-secondary);
    line-height: 1.6;
  }

  /* ---- Cross-references ---- */
  .refs-block {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
  }
  .refs-block-title {
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
  }
  .refs-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 0;
  }
  .ref-link {
    color: var(--primary);
    cursor: pointer;
    margin-right: 10px;
    margin-bottom: 2px;
  }
  .ref-link:hover { text-decoration: underline; }
  .act-link {
    color: var(--primary);
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    cursor: pointer;
  }
  .act-link:hover { text-decoration: underline solid; }
  .refs-unresolved-note {
    margin-top: 4px;
    color: var(--text-secondary);
    opacity: 0.6;
    font-size: 0.78rem;
  }

  /* ---- Copy button (modal sections) ---- */
  .btn-copy {
    font-size: 0.82rem;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg);
    color: var(--text-secondary);
    transition: background 0.1s, color 0.1s;
  }
  .btn-copy:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
  }

  /* ---- Browse card preview text ---- */
  .browse-card-preview {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 5px;
    line-height: 1.45;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  /* ---- TOC jump buttons ---- */
  .toc-entry { line-height: 1.9; }
  .toc-jump-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0;
    text-align: left;
    white-space: pre-wrap;
    font-family: inherit;
  }
  .toc-jump-btn:hover { text-decoration: underline; }

  /* ---- Section flash (TOC jump target) ---- */
  @keyframes section-flash {
    0%, 100% { background: transparent; }
    35% { background: var(--primary-light); }
  }
  .section-flash > .modal-section-header {
    animation: section-flash 1.1s ease-out;
  }

  /* ---- Modal in-document search row ---- */
  #modal-search-row {
    padding: 8px 20px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: none;
  }
  #modal-search-input {
    width: 100%;
    padding: 7px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    outline: none;
  }
  #modal-search-input:focus { border-color: var(--primary); }
  #modal-search-meta {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 5px;
    min-height: 1.2em;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .modal-search-mark {
    background: var(--mark-bg);
    color: var(--mark-text);
    border-radius: 2px;
    padding: 0 1px;
  }
  .modal-search-mark.active {
    background: var(--primary);
    color: #fff;
    outline: 2px solid var(--primary);
    outline-offset: 1px;
  }
  .btn-modal-nav {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 8px;
    line-height: 1;
    transition: background 0.1s;
  }
  .btn-modal-nav:hover { background: var(--primary-light); color: var(--primary); }

  /* ---- Footer ---- */
  .footer {
    text-align: center;
    padding: 24px 0 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
  }
  .footer-links {
    text-align: center;
    line-height: 2.2;
    margin-bottom: 0.5rem;
  }
  .footer-links a {
    padding: 0.4rem 0.6rem;
    display: inline-block;
  }
  .footer a { color: var(--text-secondary); text-decoration: none; }
  .footer a:hover { color: var(--primary); text-decoration: underline; }

  /* ---- Responsive ---- */
  @media (max-width: 600px) {
    .header-top { flex-direction: row; flex-wrap: wrap; gap: 8px; }
    .header-brand { flex: 1 1 auto; }
    .header-logo { width: 24px; height: 24px; }
    .header-nav { flex-direction: column; align-items: flex-start; gap: 4px; padding-bottom: 8px; }
    #stats-bar { display: none; }
    .disclaimer-inline { display: none; }
    .controls { padding: 12px 16px; }
    main { padding: 0 16px 16px; }
    .filter-toggle, .browse-filters .filter-toggle {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 6px 12px;
      font-size: 0.85rem;
      font-weight: 500;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      background: var(--surface);
      color: var(--text-secondary);
      cursor: pointer;
    }
    .filter-toggle.active {
      color: var(--primary);
      border-color: var(--primary);
    }
    .filter-drawer, .browse-filters .filter-drawer {
      display: none;
      flex-basis: 100%;
      flex-wrap: wrap;
      gap: 10px;
    }
    .filter-drawer.open, .browse-filters .filter-drawer.open {
      display: flex;
    }
    .reader-section-header {
      position: static;
    }
    #browse-az-nav {
      scrollbar-width: none;
    }
    #browse-az-nav::-webkit-scrollbar { display: none; }
    .modal-back-to-top {
      bottom: 10px;
      right: 10px;
      padding: 6px 10px;
      font-size: 0.75rem;
    }
  }

  /* ---- Scroll-to buttons ---- */
  .scroll-btn {
    position: fixed;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, background 0.1s;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  }
  .scroll-btn.visible { opacity: 1; pointer-events: auto; }
  .scroll-btn-top {
    bottom: 132px;
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }
  .scroll-btn-top:hover { background: var(--primary-light); color: var(--primary); }
  .scroll-btn-bottom {
    bottom: 84px;
    background: var(--surface);
    color: var(--text-secondary);
  }
  .scroll-btn-bottom:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

  /* ---- Hide blurbs when search results are showing ---- */
  #search-view.has-results .hero-welcome,
  #search-view.has-results .hero-stat,
  #search-view.has-results .about-blurb,
  #search-view.has-results .how-it-works { display: none; }

  /* ---- Search button ---- */
  .search-input-wrap {
    display: flex;
    flex: 1 1 280px;
    max-width: 560px;
    gap: 0;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    border-radius: var(--radius);
  }
  .search-input-wrap:focus-within {
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  }
  [data-theme="dark"] .search-input-wrap {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  [data-theme="dark"] .search-input-wrap:focus-within {
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  }
  .btn-clear-search {
    position: absolute;
    right: 52px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 6px;
    line-height: 1;
    display: none;
    opacity: 0.6;
    transition: opacity 0.15s;
  }
  .btn-clear-search:hover { opacity: 1; }
  .btn-clear-search.visible { display: block; }
  .search-input-wrap #search-input {
    flex: 1 1 auto;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
    padding-right: 32px;
  }
  .btn-search {
    padding: 14px 16px;
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: background 0.15s;
  }
  .btn-search:hover { background: var(--primary-light); color: var(--primary); }

  /* ---- AI Explain button ---- */
  .btn-explain {
    font-size: 0.82rem;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg);
    color: var(--text-secondary);
    transition: background 0.1s, color 0.1s;
  }
  .btn-explain:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
  }
  [data-theme="dark"] .btn-explain:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
  }
  .btn-explain:disabled { opacity: 0.5; cursor: default; }

  .ai-summary-box {
    padding: 12px 16px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    border-top: 1px solid var(--border);
    background: var(--primary-light);
    display: none;
  }
  [data-theme="dark"] .ai-summary-box { background: var(--primary-dark); }
  .ai-summary-box.open { display: block; }
  .ai-summary-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--primary);
    margin-bottom: 6px;
  }
  [data-theme="dark"] .ai-summary-label { color: var(--primary); }

  /* ---- AI Quota indicator ---- */
  #ai-quota {
    font-size: 0.8rem;
    opacity: 0.85;
    white-space: nowrap;
    display: none;
    color: #fff;
  }

  /* ---- Chat FAB ---- */
  #chat-fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
  }
  #chat-fab:hover { transform: scale(1.08); }
  #chat-fab.active { background: var(--text-secondary); }

  /* ---- Chat drawer ---- */
  .chat-drawer {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 950;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: right 0.25s ease;
  }
  .chat-drawer.open { right: 0; }
  @media (max-width: 480px) {
    .chat-drawer { width: 100vw; right: -100vw; }
  }

  .chat-header {
    padding: 14px 16px;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--surface2);
  }
  .chat-header-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
  }
  .chat-header-remaining {
    font-size: 0.78rem;
    color: var(--text-secondary);
  }
  .btn-chat-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 10px;
    transition: background 0.1s;
  }
  .btn-chat-close:hover { background: var(--surface2); }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
  }
  .chat-msg {
    margin-bottom: 12px;
    font-size: 0.88rem;
    line-height: 1.6;
  }
  .chat-msg-user {
    background: var(--primary);
    color: #fff;
    padding: 8px 14px;
    border-radius: 12px 12px 4px 12px;
    max-width: 85%;
    margin-left: auto;
    word-break: break-word;
  }
  .chat-msg-ai {
    background: var(--surface);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 12px 12px 12px 4px;
    max-width: 95%;
    word-break: break-word;
  }
  .chat-msg-ai p { margin: 0 0 8px 0; }
  .chat-msg-ai p:last-child { margin-bottom: 0; }
  .chat-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
  }
  .chat-source-link {
    color: var(--primary);
    cursor: pointer;
    display: block;
    margin-top: 2px;
  }
  .chat-source-link:hover { text-decoration: underline; }
  .chat-msg-error {
    background: #fef3cd;
    color: #7d6608;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
  }
  [data-theme="dark"] .chat-msg-error { background: #3a3000; color: #d4ac0d; }

  .chat-input-row {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: var(--surface);
  }
  #chat-input {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    outline: none;
    resize: none;
    min-height: 38px;
    max-height: 100px;
    font-family: inherit;
  }
  #chat-input:focus { border-color: var(--primary); }
  #chat-send {
    padding: 8px 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: background 0.15s;
  }
  #chat-send:hover { opacity: 0.85; }
  #chat-send:disabled { opacity: 0.5; cursor: default; }

  .chat-disclaimer {
    padding: 8px 16px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: center;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* Shift scroll buttons left when chat is open */
  .chat-drawer.open ~ .scroll-btn { right: 432px; }
  @media (max-width: 480px) {
    .chat-drawer.open ~ .scroll-btn { display: none; }
  }

  /* Accessibility: reduced motion */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* FAQ Section */
  .faq-section {
    padding: 32px 16px 8px;
  }
  .faq-container {
    max-width: 900px;
    margin: 0 auto;
  }
  .faq-heading {
    font-family: 'Libre Baskerville', Georgia, serif;
    font-size: 1.15rem;
    margin-bottom: 16px;
    color: var(--text);
  }
  .faq-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
  }
  .faq-item summary {
    padding: 14px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    list-style: none;
  }
  .faq-item summary::-webkit-details-marker { display: none; }
  .faq-item summary::before {
    content: '\25B8';
    display: inline-block;
    margin-right: 10px;
    transition: transform 0.2s;
    color: var(--primary);
  }
  .faq-item[open] summary::before {
    transform: rotate(90deg);
  }
  .faq-item p {
    padding: 0 20px 16px 34px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
  }
