/*
  MSV Code Assistant: shared foundation for every page.

  Direction: a calm reading desk for two non-technical owners. Cool, quiet
  neutrals with one teal accent; soft rounded objects (14px cards, 20px sheets,
  pill controls); motion that eases in slowly and never asks to be watched.
  Status colours carry meaning only (Active, Prototype, Superseded, Retired).
*/

:root {
  --font: "Onest", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Light: cool paper, never pure white or black */
  --bg: #f2f5f5;
  --bg-sunk: #e9eeee;
  --surface: #fbfcfc;
  --raised: #ffffff;
  --fg: #19252a;
  --fg-2: #33434a;
  --muted: #4d5c62;
  --faint: #5c6c72;
  --line: #e0e7e8;
  --line-strong: #cdd7d9;
  --accent: #0e7068;
  --accent-hover: #0b5f58;
  --accent-fg: #f3fbfa;
  --accent-soft: #e2f1ee;
  --accent-ring: rgb(14 112 104 / 0.32);
  --error: #a3304a;
  --error-soft: #fbe9ed;

  --st-active: #1b744b;     --st-active-bg: #e3f2e9;
  --st-proto: #3a59c4;      --st-proto-bg: #e7ecfb;
  --st-super: #96560a;      --st-super-bg: #fbefdc;
  --st-retired: #58676d;    --st-retired-bg: #e9eef0;

  --shadow-1: 0 1px 2px rgb(22 44 50 / 0.05), 0 1px 1px rgb(22 44 50 / 0.03);
  --shadow-2: 0 2px 4px rgb(22 44 50 / 0.04), 0 14px 32px -12px rgb(22 44 50 / 0.16);
  --shadow-3: 0 24px 64px -16px rgb(14 32 38 / 0.28), 0 4px 12px rgb(14 32 38 / 0.06);
  --scrim: rgb(16 28 32 / 0.32);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  /* Slow and gentle, inside researched limits: NN/g finds 500ms+ feels like a
     drag, entrances longer than exits. Curves from IBM Carbon's expressive set. */
  --ease-out: cubic-bezier(0, 0, 0.3, 1);          /* entrances */
  --ease-in-out: cubic-bezier(0.4, 0.14, 0.3, 1);  /* standard, reversible */
  --t-quick: 180ms;   /* hover, press */
  --t-base: 240ms;    /* closes, small changes */
  --t-calm: 360ms;    /* opens, theme change */
  --t-dim: 400ms;     /* backdrop */
  --t-slow: 480ms;    /* first-load entrance, once */

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1416;
    --bg-sunk: #0b1012;
    --surface: #141c1f;
    --raised: #192226;
    --fg: #e4ebec;
    --fg-2: #c3cfd2;
    --muted: #9aa9ae;
    --faint: #7f8f95;
    --line: #232f33;
    --line-strong: #2f3d42;
    --accent: #5ccbbf;
    --accent-hover: #7ad7cd;
    --accent-fg: #0b1a19;
    --accent-soft: #13302f;
    --accent-ring: rgb(92 203 191 / 0.36);
    --error: #f29bb0;
    --error-soft: #3a1b24;
    --st-active: #7fd3a3;     --st-active-bg: #15301f;
    --st-proto: #9cb3f5;      --st-proto-bg: #1a2648;
    --st-super: #efbb6a;      --st-super-bg: #33260f;
    --st-retired: #a8b6bb;    --st-retired-bg: #1f2a2e;
    --shadow-1: 0 0 0 transparent;
    --shadow-2: 0 1px 2px rgb(0 0 0 / 0.25), 0 12px 28px -14px rgb(0 0 0 / 0.5);
    --shadow-3: 0 28px 72px -16px rgb(0 0 0 / 0.7);
    --scrim: rgb(4 8 10 / 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1416;
  --bg-sunk: #0b1012;
  --surface: #141c1f;
  --raised: #192226;
  --fg: #e4ebec;
  --fg-2: #c3cfd2;
  --muted: #9aa9ae;
  --faint: #7f8f95;
  --line: #232f33;
  --line-strong: #2f3d42;
  --accent: #5ccbbf;
  --accent-hover: #7ad7cd;
  --accent-fg: #0b1a19;
  --accent-soft: #13302f;
  --accent-ring: rgb(92 203 191 / 0.36);
  --error: #f29bb0;
  --error-soft: #3a1b24;
  --st-active: #7fd3a3;     --st-active-bg: #15301f;
  --st-proto: #9cb3f5;      --st-proto-bg: #1a2648;
  --st-super: #efbb6a;      --st-super-bg: #33260f;
  --st-retired: #a8b6bb;    --st-retired-bg: #1f2a2e;
  --shadow-1: 0 0 0 transparent;
  --shadow-2: 0 1px 2px rgb(0 0 0 / 0.25), 0 12px 28px -14px rgb(0 0 0 / 0.5);
  --shadow-3: 0 28px 72px -16px rgb(0 0 0 / 0.7);
  --scrim: rgb(4 8 10 / 0.55);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--t-calm) var(--ease-in-out), color var(--t-calm) var(--ease-in-out);
}
::selection { background: var(--accent-soft); color: var(--fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { text-wrap: balance; letter-spacing: -0.015em; line-height: 1.25; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
code, kbd { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Theme-colour changes glide instead of flashing */
.topbar, .panel, .card, .sheet, .sidebar, .composer, .bubble, .answer, .pill, .chip, .seg, .seg a, .icon-btn, .btn, .recent-item, .conv {
  transition:
    background-color var(--t-calm) var(--ease-in-out),
    border-color var(--t-quick) var(--ease-in-out),
    color var(--t-quick) var(--ease-in-out),
    box-shadow var(--t-quick) var(--ease-out),
    transform var(--t-quick) var(--ease-out);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(16px, 3vw, 28px);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; color: var(--fg); text-decoration: none; min-width: 0; }
.brand-mark {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  border-radius: var(--r-sm); background: var(--accent); color: var(--accent-fg); font-size: 18px;
}
.brand-name { font-weight: 600; font-size: 0.98rem; letter-spacing: -0.01em; white-space: nowrap; }
.brand-name span { color: var(--muted); font-weight: 500; }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--bg-sunk); border: 1px solid var(--line); border-radius: var(--r-pill); }
.seg a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--r-pill);
  font-size: 0.88rem; font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap;
}
.seg a:hover { color: var(--fg); }
.seg a[aria-current] { background: var(--raised); color: var(--fg); box-shadow: var(--shadow-1); }
.seg i { font-size: 16px; }

.icon-btn {
  width: 36px; height: 36px; flex: none; display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface);
  color: var(--fg-2); font-size: 18px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--fg); background: var(--raised); }
.icon-btn:active { transform: scale(0.96); }

/* 44px touch targets without making the visible controls bigger */
.icon-btn, .seg a, .chip, .conv .del, .tool-btn { position: relative; }
.icon-btn::after, .seg a::after, .chip::after, .conv .del::after, .tool-btn::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: max(100%, 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 500 0.92rem/1 var(--font); padding: 11px 18px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); background: var(--raised); color: var(--fg); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; font-weight: 500; line-height: 1; padding: 5px 10px 5px 8px;
  border-radius: var(--r-pill); background: var(--st-bg); color: var(--st); white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-Active { --st: var(--st-active); --st-bg: var(--st-active-bg); }
.st-Prototype { --st: var(--st-proto); --st-bg: var(--st-proto-bg); }
.st-Superseded { --st: var(--st-super); --st-bg: var(--st-super-bg); }
.st-Retired { --st: var(--st-retired); --st-bg: var(--st-retired-bg); }

/* ---------- Long-form text (READMEs, answers) ---------- */
.prose { font-size: 1rem; line-height: 1.7; color: var(--fg-2); max-width: 68ch; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--fg); margin: 1.6em 0 0.5em; }
.prose h1 { font-size: 1.3rem; }
.prose h2 { font-size: 1.15rem; }
.prose h3, .prose h4 { font-size: 1rem; }
.prose p, .prose ul, .prose ol { margin: 0 0 0.9em; }
.prose li + li { margin-top: 0.3em; }
.prose strong { color: var(--fg); font-weight: 600; }
.prose code { font-size: 0.86em; background: var(--bg-sunk); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
.prose pre { background: var(--bg-sunk); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; overflow-x: auto; font-size: 0.86rem; line-height: 1.55; }
.prose pre code { background: none; border: 0; padding: 0; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 0.9rem; margin: 0 0 1em; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 8px 14px 8px 0; border-bottom: 1px solid var(--line); }
.prose th { color: var(--fg); font-weight: 600; }
.prose img { max-width: 100%; border-radius: var(--r-sm); }
.prose blockquote { margin: 0 0 1em; padding: 4px 0 4px 16px; border-left: 1px solid var(--line-strong); color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }

/* ---------- Entrance: one calm moment, content visible by default ---------- */
@media (prefers-reduced-motion: no-preference) {
  .rise { animation: rise var(--t-slow) var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 8) * 40ms); }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } }
  .fade { animation: fade var(--t-calm) var(--ease-out) both; }
  @keyframes fade { from { opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) {
  /* No movement; keep a short fade so changes are still noticed */
  *, *::before, *::after { transition-duration: 120ms !important; transition-property: opacity, background-color, color, border-color !important; animation: none !important; }
}

.seg .short { display: none; }
@media (max-width: 820px) {
  .topbar:has(#menu) .brand-name { display: none; }
}
@media (max-width: 640px) {
  .brand-name span { display: none; }
  .seg a { padding: 6px 11px; }
  .seg .full { display: none; }
  .seg .short { display: inline; }
}
@media (max-width: 420px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .brand-name { display: none; }
  .topbar:has(#menu) .brand { display: none; }
  .topbar:has(#menu) nav.seg { margin-right: auto; }
  .seg a { padding: 6px 10px; gap: 5px; }
  .icon-btn { width: 34px; height: 34px; }
}
