/* ============================================================================
   NEXUS LAB — design system
   ----------------------------------------------------------------------------
   Shared tokens and primitives for every tool, game and experiment in /lab.
   Deliberately dependency-free: one stylesheet, no CDN, no framework.

   Colour rule inherited from the dashboard: the accent is a single hue and it
   means "interactive or live". Green is reserved for positive state. Nothing
   glows. Depth comes from surface steps and hairlines, never from neon.
   ========================================================================= */

/* ============================== Themes ===============================
   Eleven presets, sharing names and hexes with the dashboard so the two
   surfaces read as one product.

   Each preset sets only a palette. Everything else — the third surface step,
   the ink ramp, the hairline scale, the translucent accent wash — is derived
   below from that palette, so a new theme is eight values rather than thirty.
   The derivation works for light presets too: mixing toward --ink lightens in
   dark themes and darkens in light ones, which is the correct direction both
   ways.

   Colour rule inherited from the dashboard: the accent is a single hue meaning
   "interactive or live", green is reserved for positive state, and nothing
   glows — depth comes from surface steps and hairlines, never neon.
   ==================================================================== */

:root {
  /* -- default preset: nexus (same palette as the dashboard default) -- */
  --void:      #050510;
  --surface-1: #0a0d1c;
  --surface-2: #101426;
  --ink:       #aab4d4;
  --accent:    #64e8ff;
  --accent-2:  #7c5cff;
  --accent-dim:#2f8fb5;
  --line-base: #1c2240;
  --on-accent: #04121a;

  /* -- derived from the palette above --------------------------------------
     These are declared once and resolve against whichever preset wins the
     cascade on <html>, so they do not need repeating per theme. */
  --surface-3: color-mix(in srgb, var(--surface-2) 88%, var(--ink));
  --ink-2:     color-mix(in srgb, var(--ink) 68%, var(--void));
  --ink-3:     color-mix(in srgb, var(--ink) 46%, var(--void));
  --line-soft: color-mix(in srgb, var(--line-base) 55%, transparent);
  --line:      color-mix(in srgb, var(--line-base) 82%, transparent);
  --line-hard: var(--line-base);
  --accent-bg: color-mix(in srgb, var(--accent) 10%, transparent);

  --good:      #3ddc97;
  --warn:      #ffc857;
  --bad:       #ff6b8a;

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --pad: 22px;
  --max: 1440px;
}

/* -- the other ten presets: palette only ---------------------------------- */

html[data-lab-theme="matrix"] {
  --void:#050505; --surface-1:#0d0d0d; --surface-2:#141414; --ink:#bbbbbb;
  --accent:#00ff41; --accent-2:#ffb000; --accent-dim:#008822; --line-base:#1a331a;
  --rain:#00ff41;
}
html[data-lab-theme="cyberpunk"] {
  --void:#0a000a; --surface-1:#150015; --surface-2:#1a001a; --ink:#dddddd;
  --accent:#ff00ff; --accent-2:#00ffff; --accent-dim:#aa00aa; --line-base:#331a33;
}
html[data-lab-theme="ocean"] {
  --void:#000a14; --surface-1:#001a2e; --surface-2:#002040; --ink:#c0d8f0;
  --accent:#00bfff; --accent-2:#ffd700; --accent-dim:#0088cc; --line-base:#1a3350;
}
html[data-lab-theme="sunset"] {
  --void:#0f0500; --surface-1:#1a0a00; --surface-2:#200f05; --ink:#e8d5c8;
  --accent:#ff6b35; --accent-2:#ffd700; --accent-dim:#cc4400; --line-base:#3a1a0a;
}
html[data-lab-theme="forest"] {
  --void:#0a140a; --surface-1:#0f1a0f; --surface-2:#152215; --ink:#c8e0c8;
  --accent:#4caf50; --accent-2:#8bc34a; --accent-dim:#2e7d32; --line-base:#1a3a1a;
}
html[data-lab-theme="midnight"] {
  --void:#0a0a14; --surface-1:#0f0f1a; --surface-2:#151522; --ink:#c8c8e0;
  --accent:#7c4dff; --accent-2:#b388ff; --accent-dim:#5e35b1; --line-base:#2a2a3a;
  --on-accent:#ffffff;
}
html[data-lab-theme="dracula"] {
  --void:#282a36; --surface-1:#44475a; --surface-2:#6272a4; --ink:#f8f8f2;
  --accent:#ff79c6; --accent-2:#bd93f9; --accent-dim:#ff5555; --line-base:#6272a4;
}
html[data-lab-theme="solarized"] {
  --void:#002b36; --surface-1:#073642; --surface-2:#586e75; --ink:#839496;
  --accent:#2aa198; --accent-2:#b58900; --accent-dim:#268bd2; --line-base:#586e75;
  --on-accent:#ffffff;
}
html[data-lab-theme="monokai"] {
  --void:#272822; --surface-1:#3e3d32; --surface-2:#49483e; --ink:#f8f8f2;
  --accent:#a6e22e; --accent-2:#f92672; --accent-dim:#e6db74; --line-base:#75715e;
}

/* -- rain colour -----------------------------------------------------------
   Only the two themes that want a specific rain hue set --rain; every other
   preset leaves it undefined and the rain falls back to that theme's own accent,
   so it always belongs to the theme rather than always being green. Nexus and
   Matrix keep the classic green. Read by LAB.chrome.matrix(). */
html[data-lab-theme="nexus"] { --rain: #00ff9c; }

/* -- the one light preset: minimal ----------------------------------------
   Status colours need darkening here, not the default bright ramp. */
html[data-lab-theme="minimal"] {
  --void:#f5f5f5; --surface-1:#ffffff; --surface-2:#fafafa; --ink:#333333;
  --accent:#0066cc; --accent-2:#cc6600; --accent-dim:#004499; --line-base:#e0e0e0;
  --on-accent:#ffffff;
  --good:#128a5e; --warn:#9a6b00; --bad:#c62a4c;
}

/* Keep the old two-way value working for anyone whose saved choice was "light". */
html[data-lab-theme="light"] {
  --void:#f5f5f5; --surface-1:#ffffff; --surface-2:#fafafa; --ink:#333333;
  --accent:#0066cc; --accent-2:#cc6600; --accent-dim:#004499; --line-base:#e0e0e0;
  --on-accent:#ffffff;
  --good:#128a5e; --warn:#9a6b00; --bad:#c62a4c;
}

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

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

body {
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* The one ambient detail: a very faint grid, so large empty areas read as a
   floor rather than a void. Fixed so it never scrolls with content. */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, #000 10%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, #000 10%, transparent 78%);
}

/* ============================ Typography ================================ */

h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: clamp(28px, 5vw, 46px); }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
p  { margin: 0 0 14px; color: var(--ink-2); }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre, .mono { font-family: var(--mono); font-size: .9em; }

.eyebrow {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ============================ Layout =================================== */

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--pad); position: relative; z-index: 1; }

.topbar {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--void) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: var(--max); margin: 0 auto; padding: 11px var(--pad);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand {
  font: 600 13px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink); display: flex; align-items: center; gap: 9px; white-space: nowrap;
}
.brand-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.brand a { color: inherit; }
.brand a:hover { text-decoration: none; color: var(--accent); }

.topbar-search { flex: 1 1 240px; min-width: 180px; }
.topbar-search input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); color: var(--ink); padding: 8px 12px;
  font: 13px var(--sans);
}
.topbar-search input:focus { outline: none; border-color: var(--accent-dim); }

main { padding: 34px 0 90px; }

.hero { padding: 30px 0 26px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.hero p { max-width: 66ch; }
.hero-stats { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 20px; }
.stat { }
.stat b { display: block; font: 600 24px/1 var(--mono); color: var(--ink); letter-spacing: -.02em; }
.stat span { font: 500 10px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }

/* ============================ Buttons ================================= */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 14px; font: 500 13px var(--sans); cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-hard); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 84%, #fff); border-color: var(--accent); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; font-size: 12px; }

/* Theme picker. A native <select> dressed as a .btn: keyboard and screen-reader
   correct, uses the platform picker on mobile, and there is no popover to
   position or maintain. Sits last in the topbar so it never crowds the search. */
.theme-pick {
  /* The global form rule sets select{width:100%}, which stretched this across
     the whole topbar and wrapped it onto its own row. It also needs its own
     chevron: .btn's `background` shorthand resets background-image, which
     cancels the gradient the global select rule provides. */
  width: auto; flex: 0 0 auto;
  appearance: none; -webkit-appearance: none;
  font: 500 12px var(--sans);
  padding: 5px 28px 5px 12px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.theme-pick:hover { color: var(--accent); }
.theme-pick option { background: var(--surface-1); color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============================ Forms ================================== */

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; margin-bottom: 6px;
  font: 500 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
input[type=text], input[type=number], input[type=search], input[type=date],
input[type=datetime-local], input[type=time], select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); color: var(--ink); padding: 10px 12px;
  font: 14px var(--sans);
}
textarea { resize: vertical; min-height: 110px; font-family: var(--mono); font-size: 13px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-dim); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 15px; height: 15px; }
select { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
  linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px;
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px,1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr)); gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

/* ============================ Surfaces =============================== */

.card {
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px;
}
.card--flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.card-head h3 { font-size: 13px; font-family: var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-2); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.out {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; font-family: var(--mono); font-size: 13px;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto; margin: 0;
  min-height: 46px;
}
.out--big { font-size: 22px; letter-spacing: -.01em; padding: 18px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); font-family: var(--mono); font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; padding-top: 3px; }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 10.5px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--ink-3); background: var(--surface-2);
}
.pill--on { border-color: var(--accent-dim); color: var(--accent); background: var(--accent-bg); }
.pill--good { border-color: color-mix(in srgb, var(--good) 45%, transparent); color: var(--good); }
.pill--bad  { border-color: color-mix(in srgb, var(--bad) 45%, transparent);  color: var(--bad); }
.pill--warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); }

.note {
  font-size: 13px; color: var(--ink-3); border-left: 2px solid var(--line-hard);
  padding: 2px 0 2px 13px; margin: 16px 0;
}
.note--warn { border-left-color: var(--warn); color: var(--ink-2); }

.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 7px; }

/* ============================ Tool grid ============================== */

.filters { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 22px; }
.chip {
  font: 500 12px var(--sans); padding: 5px 12px; border-radius: 99px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.chip:hover { border-color: var(--line-hard); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }
.chip .n { opacity: .55; margin-left: 4px; font-family: var(--mono); font-size: 10.5px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px,1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 7px; justify-content: space-between;
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 15px; min-height: 122px; color: inherit;
  transition: border-color .16s, transform .16s, background .16s;
}
.tile:hover { border-color: var(--accent-dim); transform: translateY(-2px); text-decoration: none; background: var(--surface-2); }
.tile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tile svg { width: 19px; height: 19px; stroke: var(--accent-dim); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tile:hover svg { stroke: var(--accent); }
.tile h3 { font-size: 13.5px; letter-spacing: -.005em; }
.tile p { font-size: 12.5px; margin: 0; color: var(--ink-3); line-height: 1.5; }
.tile .n { font: 500 11px var(--mono); color: var(--ink-3); }
.tile-new { font: 600 9px/1 var(--mono); letter-spacing: .12em; color: var(--accent-2); }

/* ============================ Empty state ============================ */

.empty {
  border: 1px dashed var(--line-hard); border-radius: var(--r-lg);
  padding: 52px 24px; text-align: center; color: var(--ink-3);
}
.empty h3 { color: var(--ink-2); margin-bottom: 8px; }

/* ============================ Keyboard ============================== */

kbd {
  font-family: var(--mono); font-size: 11px; background: var(--surface-3);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px; color: var(--ink-2);
}

/* ============================ Footer =============================== */

.foot { border-top: 1px solid var(--line); margin-top: 60px; padding: 24px 0 40px; }
.foot-in { display: flex; gap: 18px; flex-wrap: wrap; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--ink-3); }
.foot a { color: var(--ink-2); }

/* ============================ Utilities ============================ */

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { margin-left: auto; }
.mt0 { margin-top: 0 } .mt8 { margin-top: 8px } .mt16 { margin-top: 16px } .mt24 { margin-top: 24px }
.mb0 { margin-bottom: 0 } .mb8 { margin-bottom: 8px } .mb16 { margin-bottom: 16px } .mb24 { margin-bottom: 24px }
.center { text-align: center }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 620px) {
  :root { --pad: 15px; }
  main { padding: 22px 0 60px; }
  .hero-stats { gap: 18px; }
}

/* Respect reduced motion everywhere, globally, once. */
@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

@media print {
  .topbar, .foot, .filters { display: none; }
  body { background: #fff; color: #000; }
}
