/* NEX foundation: design tokens and base elements.
   Loaded early by every page (including /dateien/, /wissen/, /projekte/) so the
   first paint already uses the NEX surface. Shell and components live in
   nex-design.css, which preferences.js appends last. */

:root,
:root[data-nex-theme="dark"] {
  color-scheme: dark;

  /* Spatial background layers, deepest first. */
  --nex-bg-0: #03060a;
  --nex-bg-1: #060a10;
  --nex-bg-2: #0a1018;
  --nex-bg-3: #0f1722;
  --nex-bg-4: #15202d;

  /* Surfaces float above the field with controlled transparency. */
  --nex-surface: rgba(13, 20, 30, .74);
  --nex-surface-strong: rgba(17, 26, 38, .9);
  --nex-surface-hover: rgba(23, 35, 50, .92);
  --nex-surface-sunken: rgba(3, 7, 12, .55);

  --nex-border: rgba(150, 188, 226, .09);
  --nex-border-strong: rgba(150, 188, 226, .17);
  --nex-border-focus: rgba(98, 214, 232, .6);

  --nex-text: #e6edf5;
  --nex-text-2: #a2b2c4;
  --nex-text-3: #8293a7;

  /* One signal accent; secondary hues only carry meaning. */
  --nex-accent: #62d6e8;
  --nex-accent-strong: #93e7f3;
  --nex-accent-ink: #031418;
  --nex-accent-soft: rgba(98, 214, 232, .12);
  --nex-memory: #a99bff;
  --nex-memory-soft: rgba(169, 155, 255, .13);
  --nex-time: #e8bc76;
  --nex-time-soft: rgba(232, 188, 118, .13);
  --nex-success: #61d6a4;
  --nex-success-soft: rgba(97, 214, 164, .12);
  --nex-warning: #e8bc76;
  --nex-warning-soft: rgba(232, 188, 118, .13);
  --nex-error: #ef8d8f;
  --nex-error-soft: rgba(239, 141, 143, .12);

  --nex-glow: 0 0 0 1px rgba(98, 214, 232, .22), 0 0 28px -4px rgba(98, 214, 232, .28);
  --nex-shadow-1: 0 1px 2px rgba(0, 0, 0, .45);
  --nex-shadow-2: 0 14px 34px -16px rgba(0, 0, 0, .7);
  --nex-shadow-3: 0 36px 90px -30px rgba(0, 0, 0, .85);
  --nex-field: radial-gradient(1200px 700px at 72% -12%, rgba(98, 214, 232, .075), transparent 62%),
               radial-gradient(900px 600px at -8% 108%, rgba(169, 155, 255, .05), transparent 60%);
}

:root[data-nex-theme="light"] {
  color-scheme: light;
  --nex-bg-0: #e9eef4;
  --nex-bg-1: #f2f5f9;
  --nex-bg-2: #ffffff;
  --nex-bg-3: #f6f8fb;
  --nex-bg-4: #ffffff;
  --nex-surface: rgba(255, 255, 255, .82);
  --nex-surface-strong: rgba(255, 255, 255, .96);
  --nex-surface-hover: #ffffff;
  --nex-surface-sunken: rgba(220, 229, 239, .5);
  --nex-border: rgba(30, 60, 95, .1);
  --nex-border-strong: rgba(30, 60, 95, .18);
  --nex-border-focus: rgba(8, 128, 150, .55);
  --nex-text: #0f1b2a;
  --nex-text-2: #45576c;
  --nex-text-3: #596a7d;
  --nex-accent: #06768a;
  --nex-accent-strong: #055f6f;
  --nex-accent-ink: #ffffff;
  --nex-accent-soft: rgba(11, 142, 163, .1);
  --nex-memory: #6a56d8;
  --nex-memory-soft: rgba(106, 86, 216, .1);
  --nex-time: #8a5a0a;
  --nex-time-soft: rgba(168, 111, 18, .1);
  --nex-success: #16744c;
  --nex-success-soft: rgba(29, 138, 92, .1);
  --nex-warning: #8a5a0a;
  --nex-warning-soft: rgba(168, 111, 18, .1);
  --nex-error: #b6383b;
  --nex-error-soft: rgba(182, 56, 59, .09);
  --nex-glow: 0 0 0 1px rgba(11, 142, 163, .25), 0 6px 20px -8px rgba(11, 142, 163, .35);
  --nex-shadow-1: 0 1px 2px rgba(15, 27, 42, .08);
  --nex-shadow-2: 0 12px 30px -18px rgba(15, 27, 42, .25);
  --nex-shadow-3: 0 30px 70px -30px rgba(15, 27, 42, .3);
  --nex-field: radial-gradient(1100px 600px at 75% -15%, rgba(11, 142, 163, .07), transparent 60%);
}

:root {
  /* Shape, depth and motion. */
  --nex-radius-xs: 6px;
  --nex-radius-sm: 10px;
  --nex-radius-md: 14px;
  --nex-radius-lg: 20px;
  --nex-radius-xl: 28px;
  --nex-radius-pill: 999px;
  --nex-blur: 18px;
  --nex-ease: cubic-bezier(.2, .8, .2, 1);
  --nex-ease-out: cubic-bezier(.16, 1, .3, 1);
  --nex-dur-1: 120ms;
  --nex-dur-2: 220ms;
  --nex-dur-3: 420ms;
  --nex-dur-slow: 1200ms;

  /* 4px spacing scale. */
  --nex-s1: 4px; --nex-s2: 8px; --nex-s3: 12px; --nex-s4: 16px;
  --nex-s5: 24px; --nex-s6: 32px; --nex-s7: 48px; --nex-s8: 64px;

  --nex-font: "Inter var", Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --nex-font-display: "Inter var", Inter, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --nex-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --nex-fs-xs: 11px; --nex-fs-sm: 13px; --nex-fs-md: 15px; --nex-fs-lg: 18px;
  --nex-control-height: 44px;
  --nex-control-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  --nex-fs-xl: 23px; --nex-fs-2xl: 30px; --nex-fs-3xl: 42px;

  /* Shell geometry. */
  --nex-rail: 248px;
  --nex-topbar: 0px;
  --nex-tabbar: 0px;
  --nex-content: 1180px;
  --nex-gutter: clamp(16px, 3.2vw, 40px);

  /* Live system state colour; nex-visual.js sets data-nex-state on <html>. */
  --nex-state: var(--nex-accent);

  /* Historical names still referenced by module pages. */
  --nex-ink: var(--nex-text);
  --nex-muted: var(--nex-text-2);
  --nex-line: var(--nex-border);
  --nex-panel: var(--nex-surface);
  --nex-soft: var(--nex-surface-sunken);
  --nex-surface-soft: var(--nex-surface-sunken);
  --nex-focus: var(--nex-border-focus);
  --nex-radius: var(--nex-radius-md);
  --nex-radius-control: var(--nex-radius-sm);
  --nex-bg: var(--nex-bg-1);
  --surface: var(--nex-surface);
  --line: var(--nex-border);
  --blue: var(--nex-accent);
}

:root[data-nex-compact="true"] {
  /* Compact view: same structure, tighter rhythm. */
  --nex-s3: 10px; --nex-s4: 12px; --nex-s5: 18px; --nex-s6: 24px; --nex-s7: 36px; --nex-s8: 48px;
  --nex-fs-md: 14px; --nex-fs-lg: 17px; --nex-fs-xl: 21px; --nex-fs-2xl: 27px; --nex-fs-3xl: 36px;
}

:root[data-nex-state="LISTENING"] { --nex-state: var(--nex-accent-strong); }
:root[data-nex-state="THINKING"],
:root[data-nex-state="SEARCHING"] { --nex-state: var(--nex-accent-strong); }
:root[data-nex-state="ANALYZING"],
:root[data-nex-state="WRITING"],
:root[data-nex-state="ACTING"] { --nex-state: var(--nex-memory); }
:root[data-nex-state="SYNCING"],
:root[data-nex-state="PROCESSING"],
:root[data-nex-state="WAITING"] { --nex-state: var(--nex-accent); }
:root[data-nex-state="SUCCESS"] { --nex-state: var(--nex-success); }
:root[data-nex-state="WARNING"] { --nex-state: var(--nex-warning); }
:root[data-nex-state="ERROR"] { --nex-state: var(--nex-error); }

/* Base elements. Low specificity on purpose: components refine them. */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--nex-bg-1); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--nex-field), var(--nex-bg-1);
  background-attachment: fixed;
  color: var(--nex-text);
  font: 400 var(--nex-fs-md)/1.55 var(--nex-font);
  font-feature-settings: "cv11", "ss01", "tnum" 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--nex-font-display); color: var(--nex-text); letter-spacing: -.015em; line-height: 1.18; }
a { color: var(--nex-accent); text-underline-offset: 3px; }
::selection { background: rgba(98, 214, 232, .28); color: var(--nex-text); }
:focus-visible { outline: 2px solid var(--nex-border-focus); outline-offset: 2px; }
img, svg, canvas, video { max-width: 100%; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
:root[data-nex-motion="false"] *, :root[data-nex-motion="false"] *::before, :root[data-nex-motion="false"] *::after {
  animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important;
}

/* One digital world (OS3 Phase 5): same-origin page changes morph the presence, the memory space and
   the city into each other. Declared here because appearance.css is render-blocking on every page.
   Browsers without cross-document view transitions simply navigate; reduced motion turns it off. */
@view-transition { navigation: auto; }
[data-nex-entity], #brain-visual .network-stage, .city-scene { view-transition-name: nex-world; }
::view-transition-group(nex-world) { animation-duration: .6s; animation-timing-function: cubic-bezier(.2, .75, .1, 1); }
::view-transition-old(nex-world) { animation: .35s ease both nex-world-out; }
::view-transition-new(nex-world) { animation: .6s cubic-bezier(.2, .75, .1, 1) both nex-world-in; }
::view-transition-old(root) { animation: .25s ease both nex-page-out; }
::view-transition-new(root) { animation: .35s ease both nex-page-in; }
@keyframes nex-world-out { to { opacity: 0; filter: blur(6px) brightness(1.6); } }
@keyframes nex-world-in { from { opacity: 0; filter: blur(8px) brightness(1.8); } }
@keyframes nex-page-out { to { opacity: 0; } }
@keyframes nex-page-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }
:root[data-nex-motion="false"]::view-transition-group(*), :root[data-nex-motion="false"]::view-transition-old(*), :root[data-nex-motion="false"]::view-transition-new(*) { animation: none !important; }
