/* =========================================================================
   Brains
   Dark-first, mobile-first.
   Palette is locked: base #040810, cyan #22d3ee (actions/brand),
   blue #60a5fa (the brain), amber #fbbf24 (warn), emerald #34d399 (success).
   Nothing outside that set.
   ========================================================================= */

/* ------------------------------- TOKENS -------------------------------- */
:root {
  /* surface */
  --bg:        #040810;
  --bg-lift:   #070d1a;
  --card:      rgba(255, 255, 255, .05);
  --card-hi:   rgba(255, 255, 255, .075);
  --line:      rgba(255, 255, 255, .10);
  --line-soft: rgba(255, 255, 255, .06);
  --line-hi:   rgba(255, 255, 255, .18);

  /* brand + signal */
  --cyan:      #22d3ee;
  --cyan-dim:  rgba(34, 211, 238, .14);
  --cyan-line: rgba(34, 211, 238, .38);
  --blue:      #60a5fa;
  --blue-dim:  rgba(96, 165, 250, .14);
  --amber:     #fbbf24;
  --amber-dim: rgba(251, 191, 36, .12);
  --amber-line:rgba(251, 191, 36, .34);
  --emerald:   #34d399;
  --emerald-dim: rgba(52, 211, 153, .12);
  --danger:    #f87171;
  --danger-dim:rgba(248, 113, 113, .12);
  --danger-line: rgba(248, 113, 113, .38);

  /* text */
  --text:      #e8eefb;
  --text-2:    #b3c1d8;
  --muted:     #8698b4;
  --ink:       #03121a;   /* text on bright cyan */

  /* type */
  --f-head: "Orbitron", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            Helvetica, Arial, "Noto Sans", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo,
            Consolas, "Liberation Mono", monospace;

  /* metrics */
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --tap:  44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shell-pad: 16px;
  --blur: saturate(140%) blur(8px);
}

/* ------------------------------- RESET --------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;                 /* the app owns its own scrollers */
  overscroll-behavior: none;
}

/* Ambient depth — blue/cyan only, static, no repaint cost. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(96, 165, 250, .10), transparent 60%),
    radial-gradient(90% 60% at 100% 100%, rgba(34, 211, 238, .07), transparent 65%),
    radial-gradient(80% 60% at 0% 90%, rgba(96, 165, 250, .05), transparent 60%);
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

::selection { background: rgba(34, 211, 238, .28); }

/* focus: never invisible for keyboard users */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.14);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 99px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.24); background-clip: content-box; }

/* ----------------------------- UTILITIES ------------------------------- */
.mono { font-family: var(--f-mono); font-variant-ligatures: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r-lg);
}

.stack { display: flex; flex-direction: column; gap: 12px; }

/* Rendered (not display:none) so its gradients stay referenceable. */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ================================ BOOT ================================== */
.boot {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--bg);
  transition: opacity .35s ease;
}
body:not(.is-booting) .boot { opacity: 0; pointer-events: none; visibility: hidden; }

.boot-mark {
  font-family: var(--f-head);
  font-size: 15px;
  letter-spacing: .34em;
  color: var(--blue);
  text-indent: .34em;
}
.boot-bar {
  width: 140px; height: 2px;
  background: rgba(255,255,255,.08);
  border-radius: 2px;
  overflow: hidden;
}
.boot-bar span {
  display: block;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--blue), transparent);
  transform: translateX(-100%);
  animation: boot-sweep 1.15s cubic-bezier(.5,0,.5,1) infinite;
}
@keyframes boot-sweep {
  from { transform: translateX(-110%); }
  to   { transform: translateX(360%); }
}

/* ================================ SHELL ================================= */
.app-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.content-col {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
}

.screen {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.screen-scroll,
.screen-login {
  display: block;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* chrome is only for signed-in staff */
body:not(.is-authed) .topbar,
body:not(.is-authed) .tabbar,
body:not(.is-authed) .stats-strip { display: none; }
body:not(.is-admin) .nav-admin { display: none; }

/* ------------------------------- TOPBAR -------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) var(--shell-pad) 10px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(4, 8, 16, .72);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px;
  margin: -4px;
  border-radius: var(--r-sm);
}
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  color: var(--blue);
  border: 1px solid rgba(96,165,250,.32);
  border-radius: 9px;
  background: var(--blue-dim);
  flex: none;
  transition: color .18s ease, border-color .18s ease;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand:hover .brand-mark { color: #93c5fd; border-color: rgba(96,165,250,.55); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-family: var(--f-head);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  line-height: 1.2;
}
.brand-org {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .04em;
  line-height: 1.2;
}

.nav-rail { display: none; }

.topbar-account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.account-email {
  font-size: 12px;
  color: var(--muted);
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------- STATS --------------------------------- */
.stats-strip {
  display: flex;
  gap: 8px;
  padding: 10px var(--shell-pad);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line-soft);
  /* The last pill sits off-screen at 390px. Fading the right edge tells the
     eye it scrolls, instead of reading as a clipped, broken layout. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
          mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
}
@media (min-width: 900px) {
  /* Everything fits on desktop — no need to fade anything. */
  .stats-strip { -webkit-mask-image: none; mask-image: none; }
}
.stats-strip::-webkit-scrollbar { display: none; }

.stat {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: 99px;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.lbl-long { display: none; }
@media (min-width: 700px) {
  .lbl-long { display: inline; }
  .lbl-short { display: none; }
}
.stat-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  font-feature-settings: "tnum" 1;
}
.stat[data-stat="gaps"] .stat-value { color: var(--amber); }
.stat[data-stat="gaps"].is-zero .stat-value { color: var(--emerald); }

/* ------------------------------ OFFLINE -------------------------------- */
.offline-bar {
  padding: 9px var(--shell-pad);
  font-size: 12px;
  color: var(--amber);
  background: var(--amber-dim);
  border-bottom: 1px solid var(--amber-line);
}

/* ------------------------------ TAB BAR -------------------------------- */
.tabbar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-b));
  border-top: 1px solid var(--line-soft);
  background: rgba(4, 8, 16, .86);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.tab {
  position: relative;
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: var(--r);
  color: var(--muted);
  transition: color .16s ease, background-color .16s ease, transform .12s ease;
}
.tab-ico { width: 22px; height: 22px; }
.tab-ico svg { width: 100%; height: 100%; }
.tab-label { font-size: 12px; letter-spacing: .01em; }
.tab:hover { color: var(--text-2); background: rgba(255,255,255,.04); }
.tab:active { transform: scale(.96); }
.tab.is-on { color: var(--cyan); background: var(--cyan-dim); }
.tab-badge, .nav-badge {
  position: absolute;
  top: 4px; left: 50%;
  transform: translateX(6px);
  min-width: 18px;
  padding: 0 5px;
  font-family: var(--f-mono);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  color: var(--ink);
  background: var(--amber);
  border-radius: 99px;
}

/* ============================== CONTROLS ================================ */
.btn {
  --btn-bg: rgba(255,255,255,.05);
  --btn-bd: var(--line);
  --btn-fg: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .16s ease, border-color .16s ease,
              color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.btn:hover { border-color: var(--line-hi); background: var(--card-hi); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}
.btn[disabled]:hover { border-color: var(--btn-bd); background: var(--btn-bg); }

.btn-primary {
  --btn-bg: linear-gradient(180deg, #2fdcf4, #16b8d6);
  --btn-bd: rgba(34, 211, 238, .55);
  --btn-fg: var(--ink);
  font-weight: 600;
  box-shadow: 0 6px 22px -12px rgba(34, 211, 238, .75);
}
.btn-primary:hover {
  --btn-bg: linear-gradient(180deg, #55e6ff, #22d3ee);
  border-color: rgba(34, 211, 238, .85);
  box-shadow: 0 10px 26px -12px rgba(34, 211, 238, .9);
}
.btn-primary:active { box-shadow: 0 3px 14px -10px rgba(34, 211, 238, .8); }

.btn-ghost {
  --btn-bg: transparent;
  --btn-bd: var(--cyan-line);
  --btn-fg: var(--cyan);
}
.btn-ghost:hover { --btn-bg: var(--cyan-dim); border-color: var(--cyan); }

.btn-quiet {
  --btn-bg: transparent;
  --btn-bd: var(--line);
  --btn-fg: var(--text-2);
}
.btn-quiet:hover { --btn-fg: var(--text); }

.btn-danger {
  --btn-bg: var(--danger-dim);
  --btn-bd: var(--danger-line);
  --btn-fg: var(--danger);
}
.btn-danger:hover { --btn-bg: rgba(248,113,113,.2); border-color: var(--danger); }

.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }

.icon-btn {
  flex: none;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(255,255,255,.04);
  color: var(--text-2);
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease, background-color .16s ease, transform .12s ease;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--cyan); border-color: var(--cyan-line); background: var(--cyan-dim); }
.icon-btn:active { transform: scale(.94); }
.icon-btn[disabled] { opacity: .45; cursor: not-allowed; }

/* inputs */
.input, .composer-input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  color: var(--text);
  background: rgba(2, 6, 14, .6);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 16px;              /* 16px minimum: stops iOS zoom-on-focus */
  transition: border-color .16s ease, background-color .16s ease, box-shadow .16s ease;
}
.input::placeholder, .composer-input::placeholder { color: #61708a; }
.input:hover, .composer-input:hover { border-color: var(--line-hi); }
.input:focus, .composer-input:focus {
  border-color: var(--cyan-line);
  background: rgba(2, 6, 14, .9);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, .14);
}
/* keyboard focus gets a crisp ring instead of the soft glow */
.input:focus-visible, .composer-input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: none;
}
.input[aria-invalid="true"] { border-color: var(--danger-line); }

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
/* a literal token inside a label must keep its exact casing */
.field-label .mono {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--cyan);
}
.field-error {
  margin-top: 8px;
  font-size: 12px;
  color: var(--danger);
}

/* segmented control */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(255,255,255,.03);
}
.seg-btn {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color .16s ease, background-color .16s ease;
}
.seg-btn:hover { color: var(--text); background: rgba(255,255,255,.05); }
.seg-btn.is-on { color: var(--ink); background: var(--cyan); font-weight: 600; }

/* ============================ THE GLOWING BRAIN =========================
   A light source, not an illustration. Built from stacked radial gradients
   plus two *static* SVG blurs; the loops only ever touch opacity and
   transform on small elements, so nothing re-rasterises per frame.
   Blue-400 only — cyan stays reserved for actions.
   ======================================================================== */
.brain {
  width: clamp(180px, 52vw, 280px);
  aspect-ratio: 240 / 200;
  margin-inline: auto;
}
.brain svg { width: 100%; height: 100%; overflow: visible; }
.brain--hero { width: clamp(210px, 60vw, 330px); }
.brain--sm { width: 84px; margin: 0; }

/* transform reference boxes */
.b-halo, .b-ring, .b-core { transform-origin: 120px 102px; }
.b-node, .b-spark { transform-box: fill-box; transform-origin: center; }

/* --- the layers ------------------------------------------------------ */
/* ambient bloom leaving the skull */
.b-halo { opacity: .62; }

/* soft silhouette bloom — the light the mass itself throws */
.b-bloom { opacity: .38; }
.b-bloom use { fill: #4a8ef2; }

/* --- the folds are the light source --------------------------------------
   Three stacked copies of one generated fold group: a wide bloom, a soft
   mid-glow, and a crisp hot ridge on top. Brightness per fold is baked into
   the geometry's own opacity, so the rim dissolves instead of ending on a
   hard outline. Blurs are static; only opacity/transform ever animate. */
.b-bloom use { stroke: #3f86ef; stroke-width: 3.4; }
.b-bloom     { opacity: .62; }

.b-mid use   { stroke: #8fc0ff; stroke-width: 2.1; }
.b-mid       { opacity: .7; }

.b-ridge use { stroke: #eaf3ff; stroke-width: .95; }
.b-ridge     { opacity: .92; }

/* the light sitting inside the mass, up-left of centre for the 3/4 read */
.b-core { opacity: .55; mix-blend-mode: screen; }

/* faint surrounding network — suggestion, well below the brain */
.b-net { opacity: .17; }

/* synapse points and drifting motes — light, not stickers */
.b-nodes  { fill: #cfe3ff; }
.b-node   { opacity: .16; }
.b-sparks { fill: #cfe3ff; }
.b-spark  { opacity: 0; transform: translate(var(--ax), var(--ay)); }

/* one-shot ripple when an answer lands */
.b-ring { opacity: 0; stroke: #7fb4fb; stroke-width: 1.1; }

/* state-level brightness: the whole lit stack lifts and settles smoothly.
   app.js only flips data-state; the transition does the easing. */
.b-lum { opacity: .9; transition: opacity .55s ease; }
.brain[data-state="thinking"] .b-lum { opacity: 1; }
.brain[data-state="settling"] .b-lum { opacity: .97; }

/* --- keyframes (one set per state so a state change restarts cleanly) --- */
@keyframes halo-rest   { 0%, 100% { transform: scale(.94); opacity: .46; } 50% { transform: scale(1.06); opacity: .74; } }
@keyframes halo-think  { 0%, 100% { transform: scale(1);   opacity: .70; } 50% { transform: scale(1.15); opacity: 1;   } }
@keyframes halo-settle { 0%, 100% { transform: scale(.97); opacity: .56; } 50% { transform: scale(1.09); opacity: .88; } }

@keyframes core-rest   { 0%, 100% { transform: scale(.95); opacity: .70; } 50% { transform: scale(1.05); opacity: .96; } }
@keyframes core-think  { 0%, 100% { transform: scale(1.01); opacity: .88; } 50% { transform: scale(1.13); opacity: 1;  } }
@keyframes core-settle { 0%, 100% { transform: scale(.98); opacity: .78; } 50% { transform: scale(1.07); opacity: 1;   } }

@keyframes glow-rest   { 0%, 100% { opacity: .44; } 50% { opacity: .66; } }
@keyframes glow-think  { 0%, 100% { opacity: .72; } 50% { opacity: 1;   } }
@keyframes glow-settle { 0%, 100% { opacity: .56; } 50% { opacity: .82; } }

@keyframes fil-rest   { 0%, 100% { opacity: .52; } 50% { opacity: .74; } }
@keyframes fil-think  { 0%, 100% { opacity: .74; } 50% { opacity: 1;   } }
@keyframes fil-settle { 0%, 100% { opacity: .62; } 50% { opacity: .88; } }

@keyframes node-rest {
  0%, 100% { transform: scale(.88); opacity: .28; }
  50%      { transform: scale(1.08); opacity: .62; }
}
@keyframes node-think {
  0%, 100% { transform: scale(.94); opacity: .45; }
  50%      { transform: scale(1.2); opacity: .9; }
}
@keyframes node-settle {
  0%, 100% { transform: scale(.9);  opacity: .36; }
  50%      { transform: scale(1.12); opacity: .75; }
}

@keyframes spark-rest {
  0%   { transform: translate(var(--ax), var(--ay)) scale(.5); opacity: 0; }
  20%  { opacity: .5; }
  70%  { opacity: .5; }
  100% { transform: translate(var(--bx), var(--by)) scale(1); opacity: 0; }
}
@keyframes spark-think {
  0%   { transform: translate(var(--ax), var(--ay)) scale(.5); opacity: 0; }
  18%  { opacity: .95; }
  72%  { opacity: .95; }
  100% { transform: translate(var(--bx), var(--by)) scale(1.1); opacity: 0; }
}
@keyframes spark-settle {
  0%   { transform: translate(var(--ax), var(--ay)) scale(.5); opacity: 0; }
  18%  { opacity: .7; }
  72%  { opacity: .7; }
  100% { transform: translate(var(--bx), var(--by)) scale(1); opacity: 0; }
}

@keyframes ring-out {
  0%   { transform: scale(.6);  opacity: .5; }
  100% { transform: scale(1.75); opacity: 0; }
}

/* --- resting: a slow pulse you notice on second look ------------------ */
.brain[data-state="resting"] .b-halo  { animation: halo-rest 8.5s ease-in-out infinite; }
.brain[data-state="resting"] .b-core  { animation: core-rest 7s   ease-in-out infinite; }
.brain[data-state="resting"] .b-glow  { animation: glow-rest 7s   ease-in-out infinite; }
.brain[data-state="resting"] .b-fil   { animation: fil-rest  7s   ease-in-out infinite; }
.brain[data-state="resting"] .b-node {
  animation: node-rest 5.4s ease-in-out infinite;
  animation-delay: var(--nd, 0s);
}
.brain[data-state="resting"] .b-spark {
  animation: spark-rest 6.4s ease-in-out infinite;
  animation-delay: var(--sd, 0s);
}

/* --- thinking: the light lifts --------------------------------------- */
.brain[data-state="thinking"] .b-halo { animation: halo-think 2.1s ease-in-out infinite; }
.brain[data-state="thinking"] .b-core { animation: core-think 1.8s ease-in-out infinite; }
.brain[data-state="thinking"] .b-glow { animation: glow-think 1.8s ease-in-out infinite; }
.brain[data-state="thinking"] .b-fil  { animation: fil-think  1.8s ease-in-out infinite; }
.brain[data-state="thinking"] .b-node {
  animation: node-think 1.3s ease-in-out infinite;
  animation-delay: calc(var(--nd, 0s) * .4);
}
.brain[data-state="thinking"] .b-spark {
  animation: spark-think 2s ease-in-out infinite;
  animation-delay: calc(var(--sd, 0s) * .3);
}

/* --- settling: on the way back down ---------------------------------- */
.brain[data-state="settling"] .b-halo { animation: halo-settle 4.4s ease-in-out infinite; }
.brain[data-state="settling"] .b-core { animation: core-settle 3.6s ease-in-out infinite; }
.brain[data-state="settling"] .b-glow { animation: glow-settle 3.6s ease-in-out infinite; }
.brain[data-state="settling"] .b-fil  { animation: fil-settle  3.6s ease-in-out infinite; }
.brain[data-state="settling"] .b-node {
  animation: node-settle 2.8s ease-in-out infinite;
  animation-delay: calc(var(--nd, 0s) * .6);
}
.brain[data-state="settling"] .b-spark {
  animation: spark-settle 3.6s ease-in-out infinite;
  animation-delay: calc(var(--sd, 0s) * .5);
}
.brain[data-state="settling"] .b-ring { animation: ring-out 1.1s cubic-bezier(.2,.7,.3,1) 1 forwards; }

/* ================================ LOGIN ================================= */
.screen-login { padding: 0 var(--shell-pad) calc(28px + var(--safe-b)); }
.login-wrap {
  width: 100%;
  max-width: 420px;
  min-height: 100%;
  margin: 0 auto;
  padding: max(24px, calc(var(--safe-t) + 20px)) 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.login-title {
  margin-top: 4px;
  font-family: var(--f-head);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .3em;
  text-indent: .3em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #eaf4ff, #7cb6f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-sub {
  margin-top: 10px;
  max-width: 34ch;
  color: var(--muted);
  font-size: 13px;
}
.login-card {
  width: 100%;
  margin-top: 24px;
  padding: 20px;
  text-align: left;
}
.login-note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
#login-submit { margin-top: 14px; }

.login-sent { text-align: center; padding: 4px 0 2px; }
.sent-mark {
  width: 46px; height: 46px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  color: var(--emerald);
  border: 1px solid rgba(52, 211, 153, .4);
  background: var(--emerald-dim);
  border-radius: 50%;
}
.sent-mark svg { width: 24px; height: 24px; }
.sent-title { font-family: var(--f-head); font-size: 16px; letter-spacing: .06em; }
.sent-body { margin: 10px 0 18px; color: var(--text-2); font-size: 13px; }

.login-foot {
  margin-top: 22px;
  font-size: 12px;
  color: #4c5c74;
  letter-spacing: .08em;
}

/* ================================= CHAT ================================= */
.screen-chat { overflow: hidden; }

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.chat-inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px var(--shell-pad) 8px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 0 20px;
}
.empty-title {
  margin-top: 14px;
  font-family: var(--f-head);
  font-size: 17px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.empty-sub {
  margin-top: 10px;
  max-width: 42ch;
  color: var(--muted);
  font-size: 13px;
}
.chips {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 420px;
}
.chip {
  min-height: var(--tap);
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--card);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease, background-color .16s ease, transform .12s ease;
}
.chip:hover { color: var(--text); border-color: var(--cyan-line); background: var(--cyan-dim); }
.chip:active { transform: translateY(1px); }

/* messages */
.messages { display: flex; flex-direction: column; gap: 18px; padding-bottom: 8px; }

.msg { display: flex; flex-direction: column; animation: msg-in .28s ease both; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
  background: linear-gradient(180deg, rgba(34,211,238,.16), rgba(34,211,238,.08));
  border: 1px solid var(--cyan-line);
  color: #ddf7fd;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-assistant .answer {
  padding: 16px;
  border-radius: 6px var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.msg-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-family: var(--f-head);
  font-size: 12px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--blue);
}
.msg-label::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--blue);
  flex: none;
}

.prose { font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin: 3px 0; }
.prose li::marker { color: var(--blue); }
.prose strong { color: #fff; font-weight: 600; }
.prose em { color: var(--text-2); }
.prose h3, .prose h4 {
  margin: 14px 0 6px;
  font-family: var(--f-head);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-2);
}
.prose h3:first-child, .prose h4:first-child { margin-top: 0; }
.prose code {
  font-family: var(--f-mono);
  font-size: 13px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(96,165,250,.12);
  color: #bfdcff;
}

/* sources */
.sources {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sources-label {
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.src {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--text-2);
}
.src::before {
  content: "";
  flex: none;
  width: 5px; height: 5px;
  margin-top: 1px;
  border-radius: 1px;
  background: var(--blue);
  opacity: .8;
}
.src-title { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-path { color: #5f708a; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* gap marker on an answer */
.gap-note {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--amber-line);
  background: var(--amber-dim);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--amber);
}
.gap-note::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
  flex: none;
}

/* thinking row */
.thinking {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 6px var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  align-self: flex-start;
  transition: opacity .5s ease;
}
.thinking.is-done { opacity: 0; }
.thinking-text { font-size: 13px; color: var(--text-2); }
.thinking-sub { font-size: 12px; color: var(--muted); }

/* error row */
.msg-error .answer {
  border-color: var(--danger-line);
  background: var(--danger-dim);
}
.msg-error .msg-label { color: var(--danger); }
.msg-error .msg-label::before { background: var(--danger); }
.retry-row { margin-top: 12px; }

/* composer */
.composer {
  flex: none;
  border-top: 1px solid var(--line-soft);
  background: rgba(4, 8, 16, .8);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  padding: 10px var(--shell-pad) 10px;
}
.composer-inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer-input {
  flex: 1;
  min-width: 0;
  max-height: 148px;
  resize: none;
  overflow-y: auto;
  line-height: 1.45;
  border-radius: var(--r);
}
.send-btn {
  flex: none;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid rgba(34,211,238,.55);
  border-radius: var(--r);
  background: linear-gradient(180deg, #2fdcf4, #16b8d6);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 6px 20px -12px rgba(34,211,238,.8);
  transition: filter .16s ease, transform .12s ease, opacity .16s ease;
}
.send-btn svg { width: 22px; height: 22px; }
.send-btn:hover { filter: brightness(1.12); }
.send-btn:active { transform: scale(.94); }
.send-btn[disabled] { opacity: .4; cursor: not-allowed; filter: none; transform: none; }

/* ============================= PAGES (gaps/people) ====================== */
.page {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 18px var(--shell-pad) calc(28px + var(--safe-b));
}
.page-head {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}
.page-title {
  font-family: var(--f-head);
  font-size: 18px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.page-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  max-width: 60ch;
}
.page-head-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* gap card */
.gap {
  position: relative;
  padding: 16px;
  padding-left: 18px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: opacity .35s ease, transform .35s ease, border-color .16s ease;
}
.gap::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: rgba(96,165,250,.4);
}
.gap:hover { border-color: var(--line-hi); }
.gap.is-going { opacity: 0; transform: translateY(-6px); }

.gap-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.gap-count {
  flex: none;
  min-width: 44px;
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(255,255,255,.04);
}
.gap-count-n {
  display: block;
  font-family: var(--f-mono);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--text);
}
.gap-count-l {
  display: block;
  font-size: 12px;
  color: var(--muted);
}
.gap-q {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  color: var(--text);
  overflow-wrap: anywhere;
}
.gap-meta {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 12px;
  color: var(--muted);
}
.meta-chip .mono { color: var(--text-2); }
.meta-reason { border-color: rgba(96,165,250,.3); color: #9dc4f5; }
.meta-abs { display: none; }
@media (min-width: 560px) { .meta-abs { display: inline-flex; } }
.gap-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* a question asked 3+ times is money on the floor — make it shout, quietly */
.gap.is-hot { border-color: var(--amber-line); background: rgba(251,191,36,.05); }
.gap.is-hot::before { background: var(--amber); }
.gap.is-hot .gap-count { border-color: var(--amber-line); background: var(--amber-dim); }
.gap.is-hot .gap-count-n { color: var(--amber); }
.gap.is-hot .gap-count-l { color: rgba(251,191,36,.75); }
.gap-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--amber-line);
  background: var(--amber-dim);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  color: var(--amber);
}
.gap-flag::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
}
.gap.is-handled { opacity: .58; }
.gap.is-handled::before { background: rgba(52,211,153,.6); }

/* people */
.add-person { padding: 16px; margin-bottom: 18px; }
.add-row { display: flex; flex-direction: column; gap: 8px; }

.person {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r-lg);
  transition: opacity .3s ease, border-color .16s ease;
}
.person:hover { border-color: var(--line-hi); }
.person.is-going { opacity: 0; }
.person-main { flex: 1; min-width: 0; }
.person-email {
  font-family: var(--f-mono);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.person-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
}
.person-meta .mono { color: var(--text-2); }
.badge-admin {
  flex: none;
  padding: 3px 8px;
  border: 1px solid var(--cyan-line);
  background: var(--cyan-dim);
  border-radius: 99px;
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--cyan);
}
.badge-you {
  flex: none;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 12px;
  color: var(--muted);
}

/* empty / loading / error blocks */
.placeholder {
  padding: 28px 20px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  color: var(--muted);
  font-size: 13px;
}
.placeholder strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.placeholder .btn { margin-top: 14px; }

.skeleton {
  height: 92px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  background: rgba(255,255,255,.03);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent);
  transform: translateX(-100%);
  animation: skel 1.4s linear infinite;
}
@keyframes skel { to { transform: translateX(100%); } }

/* ================================ TOASTS ================================ */
.toasts {
  position: fixed;
  z-index: 70;
  left: 50%;
  transform: translateX(-50%);
  top: calc(10px + var(--safe-t));
  width: min(420px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--line);
  background: rgba(9, 15, 27, .94);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r);
  box-shadow: 0 18px 40px -22px rgba(0,0,0,.95);
  animation: toast-in .22s ease both;
  overflow: hidden;
  position: relative;
}
.toast.is-out { animation: toast-out .2s ease both; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

.toast-dot {
  flex: none;
  width: 7px; height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--blue);
}
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 600; color: var(--text); }
.toast-msg { margin-top: 2px; font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.toast-close {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: color .16s ease, background-color .16s ease;
}
.toast-close:hover { color: var(--text); background: rgba(255,255,255,.07); }

.toast--success .toast-dot { background: var(--emerald); }
.toast--warn .toast-dot    { background: var(--amber); }
.toast--error .toast-dot   { background: var(--danger); }
.toast--success { border-color: rgba(52,211,153,.34); }
.toast--warn    { border-color: var(--amber-line); }
.toast--error   { border-color: var(--danger-line); }

.toast-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: rgba(255,255,255,.08);
}
.toast-progress span {
  display: block;
  height: 100%;
  background: var(--cyan);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .18s ease;
}

/* ================================ MODAL ================================= */
dialog.modal {
  width: min(440px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: rgba(8, 13, 24, .98);
  color: var(--text);
  box-shadow: 0 40px 80px -30px rgba(0,0,0,1);
  animation: modal-in .2s ease both;
}
dialog.modal::backdrop {
  background: rgba(2, 5, 11, .74);
  backdrop-filter: blur(3px);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-inner { padding: 20px; }
.modal-title {
  font-family: var(--f-head);
  font-size: 15px;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.modal-body { margin-top: 10px; font-size: 13px; color: var(--text-2); }
.modal-body .mono { color: var(--text); overflow-wrap: anywhere; }
.modal-field { margin-top: 16px; }
.modal-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}
.modal--danger .modal-title { color: var(--danger); }

/* ============================== RESPONSIVE ============================== */
@media (min-width: 560px) {
  .chips { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: none; }
  .chip { flex: 0 1 auto; }
  .add-row { flex-direction: row; }
  .add-row .input { flex: 1; }
  .page-head { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .page-head-tools { flex: none; }
  .modal-actions { flex-direction: row; justify-content: flex-end; }
  .toasts { left: auto; right: 16px; transform: none; }
}

@media (min-width: 900px) {
  :root { --shell-pad: 28px; }

  body { font-size: 14px; }
  .input, .composer-input { font-size: 14px; }
  .chat-inner { padding-top: 24px; }

  .app-shell { flex-direction: row; }

  .topbar {
    flex: none;
    width: 264px;
    flex-direction: column;
    align-items: stretch;
    gap: 22px;
    padding: 24px 18px calc(18px + var(--safe-b));
    border-bottom: 0;
    border-right: 1px solid var(--line-soft);
  }
  .brand-name { font-size: 15px; }

  .nav-rail { display: flex; flex-direction: column; gap: 4px; }
  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: var(--r);
    color: var(--muted);
    border: 1px solid transparent;
    transition: color .16s ease, background-color .16s ease, border-color .16s ease, transform .12s ease;
  }
  .nav-ico { width: 20px; height: 20px; flex: none; }
  .nav-ico svg { width: 100%; height: 100%; }
  .nav-label { font-size: 14px; }
  .nav-item:hover { color: var(--text); background: rgba(255,255,255,.05); }
  .nav-item:active { transform: translateX(1px); }
  .nav-item.is-on {
    color: var(--cyan);
    background: var(--cyan-dim);
    border-color: var(--cyan-line);
  }
  .nav-badge {
    position: static;
    transform: none;
    margin-left: auto;
  }

  .topbar-account {
    margin-top: auto;
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--line-soft);
  }
  .account-email { max-width: none; }

  .tabbar { display: none; }

  .stats-strip { padding: 14px var(--shell-pad); }

  .composer { padding: 14px var(--shell-pad) 18px; }
  .msg-user .bubble { max-width: 78%; }
  .page { padding-top: 26px; }
  .page-title { font-size: 20px; }
}

@media (min-width: 1180px) {
  .chat-inner, .composer-inner { max-width: 820px; }
  .page { max-width: 900px; }
}

/* short viewports: don't let the login hero push the form off screen */
@media (max-height: 660px) {
  .brain--hero { width: clamp(150px, 34vw, 200px); }
  .login-wrap { padding-top: 16px; }
}

/* ========================== REDUCED MOTION ============================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  /* Still glowing, just still: hold every layer at its bright mid-point. */
  .b-sparks { display: none; }
  .b-lum  { opacity: 1; }
  .b-halo { opacity: .68; transform: scale(1.02); }
  .b-core { opacity: .92; transform: scale(1.01); }
  .b-glow { opacity: .62; }
  .b-fil  { opacity: .7; }
  .b-node { opacity: .7; }
  .b-ring { opacity: 0; }
  .boot-bar span { transform: none; width: 100%; }
}
