  :root {
    --ink: #1A241D;
    --paper: #E9E7DC;
    --surface: #F5F3E8;
    --surface-hover: #EAE7D8;
    --muted: #5B6157;
    --line: rgba(26, 36, 29, 0.15);
    --line-strong: rgba(26, 36, 29, 0.28);
    --accent: #A23B2E;
    --accent-ink: #FBF6EC;
    --shadow: rgba(26, 36, 29, 0.16);

    --font-display: Georgia, "Times New Roman", serif;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Consolas, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --ink: #E4E6DC;
      --paper: #10160F;
      --surface: #171F16;
      --surface-hover: #1E271C;
      --muted: #8B9184;
      --line: rgba(228, 230, 220, 0.14);
      --line-strong: rgba(228, 230, 220, 0.24);
      --accent: #E2735C;
      --accent-ink: #1A0D09;
      --shadow: rgba(0, 0, 0, 0.4);
    }
  }

  :root[data-theme="dark"] {
    --ink: #E4E6DC;
    --paper: #10160F;
    --surface: #171F16;
    --surface-hover: #1E271C;
    --muted: #8B9184;
    --line: rgba(228, 230, 220, 0.14);
    --line-strong: rgba(228, 230, 220, 0.24);
    --accent: #E2735C;
    --accent-ink: #1A0D09;
    --shadow: rgba(0, 0, 0, 0.4);
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    background-image: repeating-linear-gradient(
      var(--paper),
      var(--paper) 34px,
      var(--line) 35px
    );
    color: var(--ink);
    font-family: var(--font-ui);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 1.5rem 4rem;
  }

  @media (max-height: 620px) {
    body { padding-top: 4rem; }
  }

  /* initial display:none is inline on the element itself (not here),
     so it applies even if this stylesheet fails to load -- see .stage
     in index.html / leg.haml. app.js flips it to flex directly once
     loading has actually succeeded. */
  .stage {
    width: 100%;
    max-width: 620px;
    flex-direction: column;
    align-items: center;
  }

  .eyebrow {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.3rem;
    color: var(--muted);
    margin: 0 0 0.6rem;
    letter-spacing: 0.01em;
  }

  /* anchored to the window, not the page's own content flow -- so it
     stays put at the bottom of the viewport regardless of how tall
     .stage ends up (results list open/closed, settings panel, ...) */
  .credit {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 1.2rem;
    margin: 0;
    text-align: center;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1rem;
    color: var(--muted);
    letter-spacing: 0.01em;
  }

  h1 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1rem;
    margin: 0 0 2rem;
    text-align: center;
    text-wrap: balance;
    letter-spacing: -0.01em;
  }

  .console {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    box-shadow: 0 18px 40px -20px var(--shadow);
    overflow: hidden;
    position: relative;
  }

  .search-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
  }

  .search-row svg {
    flex: none;
    width: 20px;
    height: 20px;
    color: var(--muted);
  }

  #q {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 500;
  }

  #q::placeholder {
    color: var(--muted);
    font-weight: 400;
  }

  .kbd-hint {
    flex: none;
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--muted);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    padding: 0.15rem 0.4rem;
  }

  .icon-btn {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    color: var(--muted);
    cursor: pointer;
  }

  .icon-btn svg { width: 17px; height: 17px; }

  .icon-btn:hover, .icon-btn[aria-expanded="true"] {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--surface-hover);
  }

  .settings-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem 1.1rem;
    border-top: 1px solid var(--line);
    background: var(--surface-hover);
    font-size: 1rem;
  }

  .settings-panel[hidden] { display: none; }

  .settings-panel label {
    color: var(--muted);
  }

  .settings-panel select {
    font-family: var(--font-ui);
    font-size: 1rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    padding: 0.3rem 0.5rem;
  }

  #results {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--line);
    max-height: 60vh;
    overflow-y: auto;
    display: none;
  }

  #results.open { display: block; }

  #results li {
    border-bottom: 1px solid var(--line);
  }

  #results li:last-child { border-bottom: none; }

  #results li.active { background: var(--surface-hover); }

  #results li a.row {
    display: flex;
    align-items: baseline;
    gap: 0.7rem;
    padding: 0.7rem 1.1rem;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
  }

  #results li a.row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  .r-title {
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .r-title mark {
    background: none;
    color: var(--accent);
    font-weight: 600;
  }

  .r-jur {
    flex: none;
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--jur-color, var(--muted));
    border: 1px solid color-mix(in srgb, var(--jur-color, var(--muted)) 55%, transparent);
    border-radius: 3px;
    padding: 0.12rem 0.4rem;
  }

  .r-jur.r-jur-pin {
    color: var(--accent-ink);
    background: var(--jur-color, var(--muted));
    border-color: transparent;
  }

  .empty, .idle {
    padding: 1.4rem 1.1rem 1.6rem;
    color: var(--muted);
    font-size: 1rem;
    border-top: 1px solid var(--line);
    display: none;
  }

  .empty.show, .idle.show { display: block; }

  .idle b { color: var(--ink); font-variant-numeric: tabular-nums; }

  footer {
    margin-top: 1.4rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--muted);
  }

  footer kbd {
    font-family: var(--font-mono);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    padding: 0 0.32rem;
    margin-right: 0.3rem;
  }

  @media (prefers-reduced-motion: no-preference) {
    .stage { animation: rise 0.5s ease-out; }
    @keyframes rise {
      from { opacity: 0; transform: translateY(6px); }
      to { opacity: 1; transform: translateY(0); }
    }
  }

  /* views/table.haml -- the "which Act did you mean?" disambiguation
     page shown when a citation matches more than one Act. Everything
     below is specific to that page's markup; colors/fonts still come
     from the custom properties above so it matches the /leg search
     page's look. */
  .wrap { width: 100%; max-width: 780px; }

  code, .q { font-family: var(--font-mono); background: var(--surface-hover); padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.9em; }

  .explain { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 3px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; line-height: 1.55; }
  .explain p { margin: 0.5rem 0; }

  .parts { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.5rem; }
  .parts li { background: var(--surface-hover); border: 1px solid var(--line); border-radius: 3px; padding: 0.5rem 0.7rem; }
  .parts b { display: block; font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.15rem; }
  .parts .missing { color: var(--muted); font-style: italic; }

  .parts input { width: 100%; border: none; background: transparent; color: var(--ink); font-family: var(--font-ui); font-size: 0.95rem; padding: 0; outline: none; }
  .parts input::placeholder { color: var(--muted); font-style: italic; }
  .parts li:focus-within { border-color: var(--accent); }

  #match-status { min-height: 1.3em; }

  table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 3px; overflow: hidden; }
  th, td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
  th { background: var(--surface-hover); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
  tr:last-child td { border-bottom: none; }
  tr:hover { background: var(--surface-hover); }

  .hit { color: var(--accent); font-weight: 700; }

  .jur { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 3px; border: 1px solid var(--line-strong); font-family: var(--font-mono); color: var(--muted); font-size: 0.76rem; font-weight: 500; letter-spacing: 0.03em; text-transform: uppercase; }

  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }

  .hint { color: var(--muted); margin-top: 1rem; }
