  /* ================================================================
     ghgraph glassmorphism mockup
     - Frosted translucent panels (backdrop-filter) over soft gradient
       orbs; light and dark themes; same DOM, tokens swap only.
     - Structure mirrors the production contract: ranked results
       render first, the synthesized answer and citations stream after.
     ================================================================ */

  :root {
    color-scheme: light dark;

    /* typography */
    --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;

    /* layout */
    --content-max: 1120px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;

    /* accent stays in the blue family for continuity with the current UI */
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --accent-ink: #ffffff;

    /* motion */
    --speed: 220ms;
  }

  /* ---- light theme (default) ---- */
  :root,
  html[data-theme="light"] {
    --bg-base: #eef2f9;
    --text: #101828;
    --text-soft: #475467;
    --text-faint: #98a2b3;

    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-bg-strong: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.65);
    --glass-border-soft: rgba(16, 24, 40, 0.08);
    --glass-shadow: 0 8px 32px rgba(16, 24, 40, 0.10);
    --glass-inner: inset 0 1px 0 rgba(255, 255, 255, 0.8);

    --orb-1: #93c5fd;  /* sky */
    --orb-2: #c4b5fd;  /* violet */
    --orb-3: #99f6e4;  /* teal */

    --chip-bg: rgba(255, 255, 255, 0.6);
    --chip-hover: rgba(255, 255, 255, 0.9);

    --score-track: rgba(16, 24, 40, 0.08);
    --ok: #067647;
    --err: #b42318;
    --skeleton: rgba(16, 24, 40, 0.06);
  }

  /* ---- dark theme ---- */
  html[data-theme="dark"] {
    --bg-base: #0b0e17;
    --text: #e6eaf2;
    --text-soft: #a5aec2;
    --text-faint: #5d6780;

    --glass-bg: rgba(23, 28, 44, 0.55);
    --glass-bg-strong: rgba(23, 28, 44, 0.75);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-border-soft: rgba(255, 255, 255, 0.07);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --glass-inner: inset 0 1px 0 rgba(255, 255, 255, 0.08);

    --accent: #60a5fa;
    --accent-strong: #3b82f6;
    --accent-ink: #0b0e17;

    --orb-1: #1d4ed8;  /* deep blue */
    --orb-2: #6d28d9;  /* violet */
    --orb-3: #0f766e;  /* teal */

    --chip-bg: rgba(255, 255, 255, 0.06);
    --chip-hover: rgba(255, 255, 255, 0.12);

    --score-track: rgba(255, 255, 255, 0.10);
    --ok: #34d399;
    --err: #f87171;
    --skeleton: rgba(255, 255, 255, 0.07);
  }

  * { box-sizing: border-box; }

  html, body { height: 100%; }

  body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg-base);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background var(--speed) ease, color var(--speed) ease;
    overflow-x: hidden;
  }

  /* ---- background orbs (the colour the glass refracts) ---- */
  .orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
  .orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.55;
    animation: drift 26s ease-in-out infinite alternate;
  }
  .orb-1 { width: 44vw; height: 44vw; background: var(--orb-1); top: -12vw; left: -8vw; }
  .orb-2 { width: 38vw; height: 38vw; background: var(--orb-2); top: 24vh; right: -10vw; animation-delay: -8s; }
  .orb-3 { width: 30vw; height: 30vw; background: var(--orb-3); bottom: -12vw; left: 28vw; animation-delay: -16s; }
  @keyframes drift {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to   { transform: translate3d(4vw, 3vh, 0) scale(1.12); }
  }
  @media (prefers-reduced-motion: reduce) {
    .orb { animation: none; }
    *, *::before, *::after { transition: none !important; animation: none !important; }
  }

  /* ---- glass primitives ---- */
  .glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-inner);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
  }

  /* ---- top bar ---- */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--glass-bg-strong);
    border-bottom: 1px solid var(--glass-border-soft);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
  }
  .topbar-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    /* Reset button defaults — this is a <button> so the topbar can act as a
       "back to home" control, but it must look identical to the plain label
       it replaced. */
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    border-radius: 6px;
  }
  .brand:hover { opacity: 0.8; }
  .brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
  .brand-mark {
    width: 30px; height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--orb-2));
    display: grid;
    place-items: center;
    color: #fff;
    flex: none;
  }
  .topbar-spacer { flex: 1; }

  .icon-button {
    display: inline-grid;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border-soft);
    background: var(--chip-bg);
    color: var(--text-soft);
    cursor: pointer;
    transition: background var(--speed), color var(--speed), transform var(--speed);
  }
  .icon-button:hover { background: var(--chip-hover); color: var(--text); }
  .icon-button:active { transform: scale(0.95); }
  .icon-button svg { width: 18px; height: 18px; }
  .icon-button:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* ---- layout ---- */
  main {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 24px 20px 64px;
  }

  /* ---- landing (hero search) ---- */
  .landing {
    min-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
  }
  .landing h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin: 0 0 8px;
    letter-spacing: -0.03em;
  }
  .landing .tagline {
    margin: 0 auto 28px;
    color: var(--text-soft);
    font-size: 1.05rem;
    max-width: 46ch;
    text-align: center;
  }

  .search-shell { width: min(680px, 100%); }
  .search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 8px 18px;
    border-radius: 999px;
    transition: box-shadow var(--speed), border-color var(--speed);
  }
  .search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent),
                var(--glass-shadow), var(--glass-inner);
  }
  .search-box .lead-icon { color: var(--text-faint); flex: none; }
  .search-box input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    font-size: 1.05rem;
    color: var(--text);
    padding: 8px 0;
  }
  .search-box input::placeholder { color: var(--text-faint); }
  .search-box input:focus { outline: none; }

  .btn-primary {
    border: none;
    border-radius: 999px;
    padding: 10px 22px;
    font-size: 0.95rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--accent-ink);
    cursor: pointer;
    flex: none;
    transition: filter var(--speed), transform var(--speed);
  }
  .btn-primary:hover { filter: brightness(1.08); }
  .btn-primary:active { transform: scale(0.97); }

  .examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
  .chip {
    border: 1px solid var(--glass-border-soft);
    background: var(--chip-bg);
    color: var(--text-soft);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--speed), color var(--speed), transform var(--speed);
  }
  .chip:hover { background: var(--chip-hover); color: var(--text); transform: translateY(-1px); }

  /* ---- results layout ---- */
  .results-layout { display: none; }
  .results-layout[data-active="true"] { display: block; }
  .results-bar { margin-bottom: 18px; }
  .results-bar .search-box { border-radius: var(--radius-md); padding-right: 10px; }

  .status-line {
    min-height: 22px;
    margin: 0 0 14px 2px;
    font-size: 0.85rem;
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .spinner {
    width: 13px; height: 13px;
    border-radius: 50%;
    border: 2px solid var(--score-track);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
    flex: none;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .banner {
    display: none;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--err);
    background: color-mix(in srgb, var(--err) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  }
  .banner[data-visible="true"] { display: block; }

  /* ---- result cards ---- */
  .results-list { display: flex; flex-direction: column; gap: 12px; }
  .result-card {
    border-radius: var(--radius-md);
    padding: 16px 18px;
    transition: transform var(--speed), box-shadow var(--speed), border-color var(--speed);
  }
  .result-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--glass-border));
  }
  .result-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .result-title {
    font-family: var(--mono);
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
  }
  .result-title:hover { text-decoration: underline; }
  .stars { font-size: 0.8rem; color: var(--text-faint); display: inline-flex; align-items: center; gap: 4px; }
  .stars svg { width: 13px; height: 13px; fill: #f59e0b; }
  .score-badge {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--text-soft);
    background: var(--chip-bg);
    border: 1px solid var(--glass-border-soft);
    border-radius: 999px;
    padding: 2px 10px;
    flex: none;
  }
  .result-desc {
    margin: 8px 0 12px;
    color: var(--text-soft);
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .score-breakdown { display: flex; gap: 14px; flex-wrap: wrap; }
  .score-leg { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--text-faint); }
  .score-leg .track {
    width: 64px; height: 4px;
    border-radius: 2px;
    background: var(--score-track);
    overflow: hidden;
  }
  .score-leg .fill { height: 100%; border-radius: 2px; background: var(--accent); }
  .score-leg.pagerank .fill { background: var(--orb-2); }
  .score-leg.popularity .fill { background: var(--orb-3); }

  .empty-state {
    border-radius: var(--radius-md);
    padding: 40px 24px;
    text-align: center;
    color: var(--text-soft);
  }
  .empty-state strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 1.05rem; }

  /* ---- skeletons ---- */
  .skeleton-card { border-radius: var(--radius-md); padding: 16px 18px; }
  .sk { border-radius: 6px; background: var(--skeleton); animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
  .sk-title { width: 38%; height: 14px; margin-bottom: 10px; }
  .sk-line { width: 92%; height: 10px; margin-bottom: 6px; }
  .sk-line.short { width: 61%; }

  /* ---- ask: floating chat bubble + panel ----
     Deliberately separate from search (REQ-010/ADR-0003 already keep
     retrieval independent of synthesis at the API level) — this is that
     same separation carried into the UI, so a search never pays the
     CPU-bound LLM cost unless the user explicitly opens this and asks. */
  .chat-bubble {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 52px; height: 52px;
    border-radius: 50%;
    border: none;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--orb-2));
    color: #fff;
    box-shadow: var(--glass-shadow);
    cursor: pointer;
    z-index: 30;
    transition: transform var(--speed);
  }
  .chat-bubble:hover { transform: scale(1.06); }
  .chat-bubble:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  .chat-panel {
    position: fixed;
    right: 24px;
    bottom: 88px;
    width: min(400px, calc(100vw - 48px));
    max-height: min(70vh, 640px);
    padding: 18px;
    border-radius: var(--radius-md);
    z-index: 30;
    display: none;
    flex-direction: column;
    overflow-y: auto;
  }
  .chat-panel[data-open="true"] { display: flex; }
  .chat-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  .chat-form { display: flex; gap: 8px; margin-bottom: 8px; }
  .chat-form input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid var(--glass-border-soft);
    background: var(--chip-bg);
    color: var(--text);
    font-size: 0.88rem;
  }
  .chat-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .chat-panel .status-line { margin: 0 0 8px; }

  .chat-panel-head h2 {
    margin: 0;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .answer-body { font-size: 0.92rem; white-space: pre-wrap; }
  .answer-body .caret {
    display: inline-block;
    width: 7px; height: 15px;
    background: var(--accent);
    border-radius: 1px;
    vertical-align: text-bottom;
    animation: pulse 0.9s ease-in-out infinite;
    margin-left: 1px;
  }
  /* Hidden by default so index.html needs no inline style="" (CSP style-src
     'self' blocks that, per ops/traefik/ghgraph.yml's ghgraph-headers) — the
     JS toggle in app.js still overrides this at runtime via .style.display,
     which the same CSP directive does not restrict. */
  #icon-moon { display: none; }
  #citations { display: none; }
  .citations { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--glass-border-soft); }
  .citations h3 { margin: 0 0 8px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
  .citations ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
  .citations a {
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .citations a:hover { text-decoration: underline; }
  .citations .n {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--chip-bg);
    border: 1px solid var(--glass-border-soft);
    color: var(--text-soft);
    font-size: 0.66rem;
    display: inline-grid;
    place-items: center;
    font-family: var(--font);
    flex: none;
  }
  .answer-idle { color: var(--text-faint); font-size: 0.85rem; }
