/* Grid Twin Lab design system.
   One palette for every page. Page stylesheets reference only these tokens, never literal colors.
   Theme: follows the operating system; data-theme="light|dark" on <html> pins a choice (see shell.mjs). */

:root {
  color-scheme: light;
  /* Neutrals: cool graphite, no tint, so energy colors carry the meaning. */
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f3;
  --line: #e3e6eb;
  --line-strong: #c8ced7;
  --ink: #0e1726;
  --ink-2: #2f3a4b;
  --muted: #5d6878;
  --faint: #8a94a3;
  --on-solid: #ffffff;
  --on-ink: #ffffff;
  --shadow: #0e1726;
  --elev-1: 0 1px 2px rgb(14 23 38 / 6%), 0 0 0 1px rgb(14 23 38 / 4%);
  --elev-2: 0 6px 24px -8px rgb(14 23 38 / 18%), 0 0 0 1px rgb(14 23 38 / 5%);
  --stage: radial-gradient(120% 90% at 50% 0%, #ffffff 0%, #f5f7fa 60%, #eef1f5 100%);
  --stage-grid: rgb(14 23 38 / 5%);
  --glow: 0;

  /* Hue families: fg = text, mid = strokes and marks, solid = filled controls, line = tinted border, soft = tinted fill. */
  --red-fg: #b42318;    --red-mid: #e5484d;    --red-solid: #c62a2f;    --red-line: #f7c6c4;    --red-soft: #fef2f1;
  --orange-fg: #b14a07; --orange-mid: #f0820f; --orange-solid: #c45a0a; --orange-line: #f9d4a8; --orange-soft: #fff6ec;
  --amber-fg: #8a6300;  --amber-mid: #e0a100;  --amber-solid: #a87700;  --amber-line: #f1dd9a;  --amber-soft: #fffaea;
  --green-fg: #067a46;  --green-mid: #1ba566;  --green-solid: #0b8a52;  --green-line: #b4e6cb;  --green-soft: #edfaf3;
  --teal-fg: #0b7470;   --teal-mid: #12a39b;   --teal-solid: #0c827c;   --teal-line: #ade3dd;   --teal-soft: #ebf9f7;
  --blue-fg: #1d4ed8;   --blue-mid: #3b7bf6;   --blue-solid: #2558e0;   --blue-line: #c4d5fd;   --blue-soft: #eff4ff;
  --violet-fg: #6237c8; --violet-mid: #8b63ee; --violet-solid: #6c43d6; --violet-line: #dacffc; --violet-soft: #f5f2ff;

  /* Energy semantics, identical on every page. */
  --solar: var(--amber-fg);
  --grid: var(--blue-fg);
  --storage: var(--teal-fg);
  --load: var(--violet-fg);
  --hvac: var(--blue-mid);

  /* Experiment roles. */
  --world: var(--teal-fg);
  --world-soft: var(--teal-soft);
  --sandbox: var(--blue-fg);
  --agent: var(--orange-fg);
  --agent-soft: var(--orange-soft);
  --true: var(--teal-fg);
  --est: var(--blue-fg);
  --meas: var(--orange-fg);
  --observed: var(--orange-fg);
  --model: var(--blue-fg);
  --frozen: var(--faint);
  --evolving: var(--teal-fg);

  /* Status. */
  --ok: var(--green-fg);
  --pos: var(--green-fg);
  --warn: var(--orange-fg);
  --danger: var(--red-fg);
  --danger-bg: var(--red-soft);
  --neg: var(--red-fg);

  /* Legacy aliases kept so every page resolves the same palette. */
  --page: var(--bg);
  --paper: var(--bg);
  --card: var(--surface);
  --accent: var(--blue-solid);
  --accent-soft: var(--blue-soft);
  --focus: var(--blue-mid);
  --chart-grid: var(--line);

  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: "Inter", "HarmonyOS Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei",
    "Noto Sans SC", "Source Han Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", ui-monospace, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* Dark: a dispatch-room console. Marks glow slightly so flows read at a glance. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d13;
  --surface: #10161e;
  --surface-2: #141b24;
  --surface-3: #1a222d;
  --line: #222b37;
  --line-strong: #344052;
  --ink: #e7ecf3;
  --ink-2: #c3ccd8;
  --muted: #8d98a8;
  --faint: #5f6b7b;
  --on-solid: #ffffff;
  --on-ink: #0b1017;
  --shadow: #000000;
  --elev-1: 0 0 0 1px rgb(255 255 255 / 4%), 0 1px 2px rgb(0 0 0 / 40%);
  --elev-2: 0 0 0 1px rgb(255 255 255 / 5%), 0 12px 32px -12px rgb(0 0 0 / 70%);
  --stage: radial-gradient(120% 90% at 50% 0%, #121b26 0%, #0c1219 60%, #090d13 100%);
  --stage-grid: rgb(140 170 210 / 6%);
  --glow: 1;

  --red-fg: #ff8a80;    --red-mid: #f2555a;    --red-solid: #c9363b;    --red-line: #5a2427;    --red-soft: #221214;
  --orange-fg: #ffad66; --orange-mid: #f28c38; --orange-solid: #c0651c; --orange-line: #573717; --orange-soft: #23190f;
  --amber-fg: #f0c454;  --amber-mid: #e0ac2c;  --amber-solid: #a8801a;  --amber-line: #4f4116;  --amber-soft: #1f1a0c;
  --green-fg: #5fd68e;  --green-mid: #2fb86c;  --green-solid: #1d8a4f;  --green-line: #1d4a31;  --green-soft: #0f1f17;
  --teal-fg: #56d6cb;   --teal-mid: #26b8ac;   --teal-solid: #158a82;   --teal-line: #194743;   --teal-soft: #0d1f1e;
  --blue-fg: #86b6ff;   --blue-mid: #4f8dff;   --blue-solid: #2f6be6;   --blue-line: #1f3a66;   --blue-soft: #0f1a2c;
  --violet-fg: #c3a6ff; --violet-mid: #9a74f5; --violet-solid: #6f4bd6; --violet-line: #3b2d66; --violet-soft: #18132a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #090d13;
    --surface: #10161e;
    --surface-2: #141b24;
    --surface-3: #1a222d;
    --line: #222b37;
    --line-strong: #344052;
    --ink: #e7ecf3;
    --ink-2: #c3ccd8;
    --muted: #8d98a8;
    --faint: #5f6b7b;
    --on-solid: #ffffff;
    --on-ink: #0b1017;
    --shadow: #000000;
    --elev-1: 0 0 0 1px rgb(255 255 255 / 4%), 0 1px 2px rgb(0 0 0 / 40%);
    --elev-2: 0 0 0 1px rgb(255 255 255 / 5%), 0 12px 32px -12px rgb(0 0 0 / 70%);
    --stage: radial-gradient(120% 90% at 50% 0%, #121b26 0%, #0c1219 60%, #090d13 100%);
    --stage-grid: rgb(140 170 210 / 6%);
    --glow: 1;

    --red-fg: #ff8a80;    --red-mid: #f2555a;    --red-solid: #c9363b;    --red-line: #5a2427;    --red-soft: #221214;
    --orange-fg: #ffad66; --orange-mid: #f28c38; --orange-solid: #c0651c; --orange-line: #573717; --orange-soft: #23190f;
    --amber-fg: #f0c454;  --amber-mid: #e0ac2c;  --amber-solid: #a8801a;  --amber-line: #4f4116;  --amber-soft: #1f1a0c;
    --green-fg: #5fd68e;  --green-mid: #2fb86c;  --green-solid: #1d8a4f;  --green-line: #1d4a31;  --green-soft: #0f1f17;
    --teal-fg: #56d6cb;   --teal-mid: #26b8ac;   --teal-solid: #158a82;   --teal-line: #194743;   --teal-soft: #0d1f1e;
    --blue-fg: #86b6ff;   --blue-mid: #4f8dff;   --blue-solid: #2f6be6;   --blue-line: #1f3a66;   --blue-soft: #0f1a2c;
    --violet-fg: #c3a6ff; --violet-mid: #9a74f5; --violet-solid: #6f4bd6; --violet-line: #3b2d66; --violet-soft: #18132a;
  }
}

/* ------------------------------------------------------------------ base */
html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-feature-settings: "cv11", "ss01", "tnum";
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
}

::selection { background: var(--blue-line); color: var(--ink); }

code, kbd, samp, pre { font-family: var(--font-mono); }

/* Theme switch fades colors instead of snapping. */
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: background-color .25s var(--ease), border-color .25s var(--ease), color .25s var(--ease), fill .25s var(--ease), stroke .25s var(--ease) !important;
}

/* ------------------------------------------------------------------ app bar (shared on every page) */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  padding: 0 max(16px, calc((100vw - 1680px) / 2 + 24px));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.app-bar .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}

.app-bar .brand:hover { text-decoration: none; }

.app-bar .brand svg { width: 26px; height: 26px; flex: none; }

.app-bar .brand small {
  color: var(--faint);
  font-weight: 500;
  font-size: 12px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-3);
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.app-nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s, background-color .15s;
}

.app-nav a:hover { color: var(--ink); text-decoration: none; }

.app-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--elev-1);
}

.app-nav a .tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--faint);
  background: var(--surface-2);
}

.app-nav a[data-main] .tag { color: var(--teal-fg); background: var(--teal-soft); }

.app-bar .bar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.app-bar .bar-tools > * { flex: none; }

.sim-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.sim-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber-mid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber-mid) 22%, transparent);
}

.theme-switch {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 26px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}

.theme-switch button:hover { color: var(--ink); background: var(--surface-3); }

.theme-switch button[aria-pressed="true"] { color: var(--ink); background: var(--surface-3); }

.theme-switch svg { width: 15px; height: 15px; }

@media (max-width: 900px) {
  .app-bar { gap: 10px; }
  .app-bar .brand small, .sim-badge { display: none; }
  .app-nav { margin-left: 0; }
}

@media (max-width: 560px) {
  .app-bar { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; row-gap: 8px; }
  .app-nav { order: 3; width: 100%; }
}

/* ------------------------------------------------------------------ page header (replaces marketing heroes) */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.page-head .crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: .02em;
}

.page-head .crumb b { color: var(--muted); font-weight: 600; }

.page-head h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 680;
  letter-spacing: -.02em;
  color: var(--ink);
}

.page-head .lede {
  margin: 6px 0 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

/* Shared readable defaults for focus and motion. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: none !important; }
}
