/*
  TechStoneUI — Neomorphic (soft UI) baseline
  Framework-free. Token-driven light + dark.
  Drop this file into any page and use the classes/tokens.
*/

/* -------------------------------------------------------------------------- */
/* Tokens                                                                     */
/* -------------------------------------------------------------------------- */

:root,
.theme-light {
  color-scheme: light;

  /* Surfaces — plain neutral white / gray plate; elevated matches bg (classic neo) */
  --color-bg: #e5e5e5;           /* page plate — sits below panels */
  --color-bg-elevated: #f2f2f2;
  --color-bg-muted: #e6e6e6;
  --color-bg-subtle: #dadada;
  --color-border: #bcbcbc;
  --color-separator: #a4a4a4;     /* dividers: hr, headings, card/table rules */
  --grid-line: color-mix(in srgb, var(--color-accent) 10%, #cfcfcf); /* diamond grid, tinted by accent */
  --nav-tint: 30%;                /* how much accent tints the top bar */
  --glow-color: var(--color-accent); /* cursor glow (see fx.js) */
  --glow-size: 380px;  /* glow radius */
  --glow-opacity: 0.55;
  --card-ring: color-mix(in srgb, var(--color-accent) 60%, transparent);
  --card-glow: transparent;       /* light mode: ring only, no glow */
  --grid-size: 32px;
  --color-border-strong: #9a9a9a;

  /* Text — neutral grays (R=G=B) for readable contrast */
  --color-text: #2a2a2a;
  --color-text-secondary: #4a4a4a;
  --color-text-muted: #6b6b6b;
  --color-text-inverse: #f0f0f0;
  --color-nav-link: var(--color-text-secondary); /* nav links on tinted bar */

  /* Brand / accent */
  --color-accent: #5b7cfa;
  --color-accent-hover: #4466e8;
  --color-accent-muted: #d4dcf8;
  --color-accent-text: #3d56c7;
  /* Filled controls (white label) — tuned for >=4.5:1 */
  --color-accent-fill: #4562e6;
  --color-accent-fill-hover: #3a54d4;
  --color-danger-fill: #c0352d;
  --color-danger-fill-hover: #a02b24;

  /* Semantic */
  --color-success: #1f8a55;
  --color-success-bg: #d4ebe0;
  --color-success-border: #9ecfb8;
  --color-warning: #9a6b00;
  --color-warning-bg: #f0e4c4;
  --color-warning-border: #d4bc7a;
  --color-danger: #c0352d;
  --color-danger-hover: #a02b24;
  --color-danger-bg: #f0d6d4;
  --color-danger-border: #d4a09c;
  --color-info: #5b7cfa;
  --color-info-bg: #d4dcf8;
  --color-info-border: #a8b8f0;

  /* Neomorphic shadow pairs (pure white highlight + neutral gray shade) */
  --shadow-light: #ffffff;
  --shadow-dark: #c4c4c4;

  --shadow-raised-sm:
    6px 6px 12px var(--shadow-dark),
    -6px -6px 12px var(--shadow-light);
  --shadow-raised:
    10px 10px 20px var(--shadow-dark),
    -10px -10px 20px var(--shadow-light);
  --shadow-raised-lg:
    16px 16px 32px var(--shadow-dark),
    -16px -16px 32px var(--shadow-light);

  --shadow-inset-sm:
    inset 4px 4px 8px var(--shadow-dark),
    inset -4px -4px 8px var(--shadow-light);
  --shadow-inset:
    inset 8px 8px 16px var(--shadow-dark),
    inset -8px -8px 16px var(--shadow-light);
  --shadow-inset-lg:
    inset 12px 12px 24px var(--shadow-dark),
    inset -12px -12px 24px var(--shadow-light);

  /* Flat aliases kept for demo / legacy utility use */
  --shadow-sm: var(--shadow-raised-sm);
  --shadow-md: var(--shadow-raised);
  --shadow-lg: var(--shadow-raised-lg);

  /* Concave top face for raised (non-button) surfaces.
     Overlay gradient layered over background-color: top-left dips darker,
     bottom-right catches light — the reverse of a convex/glossy face.
     Neutral black/white overlays keep light-mode grays at R=G=B. */
  --concave-start: rgb(0 0 0 / 0.035);      /* on #f2f2f2 ≈ #e9e9e9 */
  --concave-end: rgb(255 255 255 / 0.55);   /* on #f2f2f2 ≈ #f9f9f9 */
  --surface-concave: linear-gradient(145deg, var(--concave-start) 0%, var(--concave-end) 100%);
  --shadow-concave-inner:
    inset 2px 2px 5px rgb(0 0 0 / 0.05),
    inset -2px -2px 5px rgb(255 255 255 / 0.7);

  /* Matte dome (top bar): gentle convex face, no specular shine */
  --dome-hi: rgb(255 255 255 / 0.38);
  --dome-lo: rgb(0 0 0 / 0.045);
  --surface-dome:
    radial-gradient(120% 220% at 50% 0%, var(--dome-hi) 0%, rgb(255 255 255 / 0) 70%),
    linear-gradient(180deg, rgb(255 255 255 / 0.08) 0%, var(--dome-lo) 100%);
  --shadow-dome-inner:
    inset 0 1px 3px rgb(255 255 255 / 0.5),
    inset 0 -3px 6px rgb(0 0 0 / 0.05);

  /* Button gloss (Web 2.0 shine) — surface = neutral pills, fill = colored */
  --gloss-surface-hi: rgb(255 255 255 / 0.9);
  --gloss-surface-hi-end: rgb(255 255 255 / 0.12);
  --gloss-surface-edge: rgb(255 255 255 / 0.95);
  --gloss-surface-shade: rgb(0 0 0 / 0.10);
  --gloss-surface-glow: rgb(255 255 255 / 0.55);
  --gloss-surface-text-shadow: 0 1px 0 rgb(255 255 255 / 0.7);
  --gloss-fill-hi: rgb(255 255 255 / 0.6);
  --gloss-fill-hi-end: rgb(255 255 255 / 0.06);
  --gloss-fill-edge: rgb(255 255 255 / 0.5);
  --gloss-fill-shade: rgb(0 0 0 / 0.22);
  --gloss-fill-glow: rgb(255 255 255 / 0.28);
  --gloss-fill-text-shadow: 0 -1px 0 rgb(0 0 0 / 0.28);

  /* Focus — soft but clearly visible */
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--color-accent) 45%, transparent);
  --focus-ring-danger: 0 0 0 3px color-mix(in srgb, var(--color-danger) 40%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
    color-scheme: dark;

    --color-bg: #181b21;           /* page plate — sits below panels */
    --color-bg-elevated: #2a2e35;
    --color-bg-muted: #23272e;
    --color-bg-subtle: #1e2228;
    --color-border: #4a5260;
    --color-border-strong: #5f6a7c;
    --color-separator: #5a6577;
    --grid-line: color-mix(in srgb, var(--color-accent) 12%, #2b3038);
    --nav-tint: 26%;
    --glow-opacity: 0.6;
    --card-ring: color-mix(in srgb, var(--color-accent) 70%, transparent);
    --card-glow: color-mix(in srgb, var(--color-accent) 45%, transparent);

    --color-text: #e8ecf2;
    --color-text-secondary: #b0b8c8;
    --color-text-muted: #7a8498;
    --color-text-inverse: #1a1e24;
    --color-nav-link: #c8d0e0; /* lighter for WCAG on tinted nav */

    --color-accent: #7b96ff;
    --color-accent-hover: #9aafff;
    --color-accent-muted: #343c5a;
    --color-accent-text: #a8baff;
    --color-accent-fill: #4a66e8;
    --color-accent-fill-hover: #5b78f5;
    --color-danger-fill: #c83e37;
    --color-danger-fill-hover: #b8433d;

    --color-success: #4ecf8a;
    --color-success-bg: #1e3328;
    --color-success-border: #2a4a38;
    --color-warning: #e0b040;
    --color-warning-bg: #332a14;
    --color-warning-border: #4a3e20;
    --color-danger: #f07068;
    --color-danger-hover: #f88880;
    --color-danger-bg: #3a2220;
    --color-danger-border: #5a3430;
    --color-info: #7b96ff;
    --color-info-bg: #343c5a;
    --color-info-border: #4a5478;

    --shadow-light: #2a2f38;
    --shadow-dark: #0f1115;

    --shadow-raised-sm:
      6px 6px 12px var(--shadow-dark),
      -6px -6px 12px var(--shadow-light);
    --shadow-raised:
      10px 10px 20px var(--shadow-dark),
      -10px -10px 20px var(--shadow-light);
    --shadow-raised-lg:
      16px 16px 32px var(--shadow-dark),
      -16px -16px 32px var(--shadow-light);

    --shadow-inset-sm:
      inset 4px 4px 8px var(--shadow-dark),
      inset -4px -4px 8px var(--shadow-light);
    --shadow-inset:
      inset 8px 8px 16px var(--shadow-dark),
      inset -8px -8px 16px var(--shadow-light);
    --shadow-inset-lg:
      inset 12px 12px 24px var(--shadow-dark),
      inset -12px -12px 24px var(--shadow-light);

    --shadow-sm: var(--shadow-raised-sm);
    --shadow-md: var(--shadow-raised);
    --shadow-lg: var(--shadow-raised-lg);

    /* Concave top face — tuned for the slate plate (#2a2e35) */
    --concave-start: rgb(0 0 0 / 0.13);       /* ≈ #25282e */
    --concave-end: rgb(255 255 255 / 0.02);   /* dimmed top-right face */
    --surface-concave: linear-gradient(145deg, var(--concave-start) 0%, var(--concave-end) 100%);
    --shadow-concave-inner:
      inset 2px 2px 5px rgb(0 0 0 / 0.22),
      inset -2px -2px 5px rgb(255 255 255 / 0.02);

    /* Matte dome (top bar): gentle convex face, no specular shine */
    --dome-hi: rgb(255 255 255 / 0.035);
    --dome-lo: rgb(0 0 0 / 0.16);
    --surface-dome:
      radial-gradient(120% 220% at 50% 0%, var(--dome-hi) 0%, rgb(255 255 255 / 0) 70%),
      linear-gradient(180deg, rgb(255 255 255 / 0.008) 0%, var(--dome-lo) 100%);
    --shadow-dome-inner:
      inset 0 1px 3px rgb(255 255 255 / 0.028),
      inset 0 -3px 6px rgb(0 0 0 / 0.2);

    /* Button gloss (Web 2.0 shine) */
    --gloss-surface-hi: rgb(255 255 255 / 0.12);
    --gloss-surface-hi-end: rgb(255 255 255 / 0.01);
    --gloss-surface-edge: rgb(255 255 255 / 0.09);
    --gloss-surface-shade: rgb(0 0 0 / 0.28);
    --gloss-surface-glow: rgb(255 255 255 / 0.04);
    --gloss-surface-text-shadow: 0 -1px 0 rgb(0 0 0 / 0.45);
    --gloss-fill-hi: rgb(255 255 255 / 0.32);
    --gloss-fill-hi-end: rgb(255 255 255 / 0.03);
    --gloss-fill-edge: rgb(255 255 255 / 0.24);
    --gloss-fill-shade: rgb(0 0 0 / 0.28);
    --gloss-fill-glow: rgb(255 255 255 / 0.12);
    --gloss-fill-text-shadow: 0 -1px 0 rgb(0 0 0 / 0.35);
  }
}

.theme-dark {
  color-scheme: dark;

  --color-bg: #181b21;           /* page plate — sits below panels */
  --color-bg-elevated: #2a2e35;
  --color-bg-muted: #23272e;
  --color-bg-subtle: #1e2228;
  --color-border: #4a5260;
  --color-border-strong: #5f6a7c;
  --color-separator: #5a6577;
  --grid-line: color-mix(in srgb, var(--color-accent) 12%, #2b3038);
    --nav-tint: 26%;
    --glow-opacity: 0.6;
    --card-ring: color-mix(in srgb, var(--color-accent) 70%, transparent);
    --card-glow: color-mix(in srgb, var(--color-accent) 45%, transparent);

  --color-text: #e8ecf2;
  --color-text-secondary: #b0b8c8;
  --color-text-muted: #7a8498;
  --color-text-inverse: #1a1e24;
  --color-nav-link: #c8d0e0; /* lighter for WCAG on tinted nav */

  --color-accent: #7b96ff;
  --color-accent-hover: #9aafff;
  --color-accent-muted: #343c5a;
  --color-accent-text: #a8baff;
  --color-accent-fill: #4a66e8;
  --color-accent-fill-hover: #5b78f5;
  --color-danger-fill: #c83e37;
  --color-danger-fill-hover: #b8433d;

  --color-success: #4ecf8a;
  --color-success-bg: #1e3328;
  --color-success-border: #2a4a38;
  --color-warning: #e0b040;
  --color-warning-bg: #332a14;
  --color-warning-border: #4a3e20;
  --color-danger: #f07068;
  --color-danger-hover: #f88880;
  --color-danger-bg: #3a2220;
  --color-danger-border: #5a3430;
  --color-info: #7b96ff;
  --color-info-bg: #343c5a;
  --color-info-border: #4a5478;

  --shadow-light: #2a2f38;
  --shadow-dark: #0f1115;

  --shadow-raised-sm:
    6px 6px 12px var(--shadow-dark),
    -6px -6px 12px var(--shadow-light);
  --shadow-raised:
    10px 10px 20px var(--shadow-dark),
    -10px -10px 20px var(--shadow-light);
  --shadow-raised-lg:
    16px 16px 32px var(--shadow-dark),
    -16px -16px 32px var(--shadow-light);

  --shadow-inset-sm:
    inset 4px 4px 8px var(--shadow-dark),
    inset -4px -4px 8px var(--shadow-light);
  --shadow-inset:
    inset 8px 8px 16px var(--shadow-dark),
    inset -8px -8px 16px var(--shadow-light);
  --shadow-inset-lg:
    inset 12px 12px 24px var(--shadow-dark),
    inset -12px -12px 24px var(--shadow-light);

  --shadow-sm: var(--shadow-raised-sm);
  --shadow-md: var(--shadow-raised);
  --shadow-lg: var(--shadow-raised-lg);

  /* Concave top face — tuned for the slate plate (#2a2e35) */
  --concave-start: rgb(0 0 0 / 0.13);       /* ≈ #25282e */
  --concave-end: rgb(255 255 255 / 0.02);   /* dimmed top-right face */
  --surface-concave: linear-gradient(145deg, var(--concave-start) 0%, var(--concave-end) 100%);
  --shadow-concave-inner:
    inset 2px 2px 5px rgb(0 0 0 / 0.22),
    inset -2px -2px 5px rgb(255 255 255 / 0.02);

  /* Matte dome (top bar): gentle convex face, no specular shine */
  --dome-hi: rgb(255 255 255 / 0.035);
  --dome-lo: rgb(0 0 0 / 0.16);
  --surface-dome:
    radial-gradient(120% 220% at 50% 0%, var(--dome-hi) 0%, rgb(255 255 255 / 0) 70%),
    linear-gradient(180deg, rgb(255 255 255 / 0.008) 0%, var(--dome-lo) 100%);
  --shadow-dome-inner:
    inset 0 1px 3px rgb(255 255 255 / 0.028),
    inset 0 -3px 6px rgb(0 0 0 / 0.2);

  /* Button gloss (Web 2.0 shine) */
  --gloss-surface-hi: rgb(255 255 255 / 0.12);
  --gloss-surface-hi-end: rgb(255 255 255 / 0.01);
  --gloss-surface-edge: rgb(255 255 255 / 0.09);
  --gloss-surface-shade: rgb(0 0 0 / 0.28);
  --gloss-surface-glow: rgb(255 255 255 / 0.04);
  --gloss-surface-text-shadow: 0 -1px 0 rgb(0 0 0 / 0.45);
  --gloss-fill-hi: rgb(255 255 255 / 0.32);
  --gloss-fill-hi-end: rgb(255 255 255 / 0.03);
  --gloss-fill-edge: rgb(255 255 255 / 0.24);
  --gloss-fill-shade: rgb(0 0 0 / 0.28);
  --gloss-fill-glow: rgb(255 255 255 / 0.12);
  --gloss-fill-text-shadow: 0 -1px 0 rgb(0 0 0 / 0.35);
}

:root {
  /* Typography */
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace, Menlo,
    Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing scale (4px base) */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radii — soft neo favors larger rounds */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  /* Motion */
  --ease: 180ms ease;
  --ease-slow: 280ms ease;

  /* Layout */
  --container-max: 72rem;
  --nav-height: 3.75rem;

  /* Code — BLOCKS (pre): black + neon blue, identical in light and dark */
  --code-bg: #000000;
  --code-text: #00d4ff;
  --code-glow: 0 0 6px rgb(0 212 255 / 0.35);
  --code-inset:
    inset 2px 2px 6px rgb(0 0 0 / 0.85),
    inset -1px -1px 4px rgb(0 212 255 / 0.08);

  /* Code — INLINE: sunken neomorphic well on the surface, theme-aware */
  --code-inline-bg: var(--color-bg-elevated);
  --code-inline-text: var(--color-text);
  --code-inline-inset:
    inset 3px 3px 5px var(--shadow-dark),
    inset 1px 1px 2px var(--shadow-dark),
    inset -3px -3px 5px var(--shadow-light);
}

/* -------------------------------------------------------------------------- */
/* Base                                                                       */
/* -------------------------------------------------------------------------- */

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

html {
  min-height: 100%;
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  position: relative;      /* containing block for the page-height fx layers */
  display: flow-root;      /* body height includes children's margins */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background fx layers (page-height, scroll with the page, behind all content).
   Order, bottom to top: --color-bg (canvas), glow, grid lines.
   .fx-glow-wrap (created by fx.js) holds a small fixed-size glow element that is
   moved with transform only, so pointer movement never repaints a large layer.
   body::after = diamond grid (two crossing 45deg line sets), painted once. */
body::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background-image:
    repeating-linear-gradient(45deg, transparent 0, transparent calc(var(--grid-size) - 1px), var(--grid-line) calc(var(--grid-size) - 1px), var(--grid-line) var(--grid-size)),
    repeating-linear-gradient(-45deg, transparent 0, transparent calc(var(--grid-size) - 1px), var(--grid-line) calc(var(--grid-size) - 1px), var(--grid-line) var(--grid-size));
}
.fx-glow-wrap {
  position: absolute;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}
.fx-glow {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--glow-size) * 2);
  height: calc(var(--glow-size) * 2);
  background: radial-gradient(circle closest-side, var(--glow-color) 0%, transparent 100%);
  opacity: 0;
  transform: translate3d(-9999px, 0, 0);
  will-change: transform, opacity;
  pointer-events: none;
  contain: strict;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* -------------------------------------------------------------------------- */
/* Typography                                                                 */
/* -------------------------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 var(--space-3);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--color-text);
  letter-spacing: -0.02em;
}

h1 {
  font-size: var(--text-4xl);
  letter-spacing: -0.03em;
}
h2 {
  font-size: var(--text-3xl);
}
h3 {
  font-size: var(--text-2xl);
}
h4 {
  font-size: var(--text-xl);
}
h5 {
  font-size: var(--text-lg);
}
h6 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

p {
  margin: 0 0 var(--space-4);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

p:last-child {
  margin-bottom: 0;
}

.text-muted {
  color: var(--color-text-muted);
}
.text-secondary {
  color: var(--color-text-secondary);
}
.text-accent {
  color: var(--color-accent-text);
}
.lead {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}
.small,
small {
  font-size: var(--text-sm);
}

strong,
b {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

/* -------------------------------------------------------------------------- */
/* Links                                                                      */
/* -------------------------------------------------------------------------- */

a {
  color: var(--color-accent-text);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  transition: color var(--ease);
}

a:hover {
  color: var(--color-accent-hover);
}

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

a.link-subtle {
  color: var(--color-text-secondary);
  text-decoration: none;
}

a.link-subtle:hover {
  color: var(--color-text);
  text-decoration: underline;
}

/* -------------------------------------------------------------------------- */
/* Layout                                                                     */
/* -------------------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 768px) {
  .container {
    padding-inline: var(--space-6);
  }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack-sm {
  gap: var(--space-2);
}
.stack-lg {
  gap: var(--space-8);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.section {
  padding-block: var(--space-10);
}

.section-title {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: none;
  box-shadow: 0 1px 0 var(--color-separator);
  font-size: var(--text-xl);
}

/* -------------------------------------------------------------------------- */
/* Nav — raised soft bar                                                      */
/* -------------------------------------------------------------------------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--nav-height);
  margin: var(--space-3) var(--space-4) 0;
  padding-inline: var(--space-4);
  background: color-mix(in srgb, var(--color-accent) var(--nav-tint), var(--color-bg-elevated));
  border: none;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-raised-sm), var(--shadow-dome-inner);
}

@media (min-width: 768px) {
  .nav {
    margin-inline: var(--space-6);
    padding-inline: var(--space-5);
  }
}

.nav-brand {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-brand:hover {
  color: var(--color-text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-nav-link);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}

.nav-links a:hover {
  color: var(--color-text);
  background: var(--color-bg-elevated);
  box-shadow: var(--shadow-inset-sm);
  text-decoration: none;
}

.nav-links a[aria-current="page"] {
  color: var(--color-text);
  background: var(--color-bg-elevated);
  box-shadow: var(--shadow-inset-sm);
}

.nav-links a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* -------------------------------------------------------------------------- */
/* Buttons — raised + glossy "Web 2.0" shine, inset when :active               */
/*                                                                            */
/* Layers (bottom → top):                                                     */
/*   1. background-color   — the variant's color token (unchanged)            */
/*   2. background-image   — body curvature: soft bottom shade + low glow     */
/*   3. ::before           — the glossy lozenge highlight on the top half     */
/*   4. inset box-shadows  — crisp top rim light + soft bottom rim shade      */
/*   5. outer box-shadows  — the neomorphic raise                             */
/* Per-variant knobs: --btn-hi, --btn-hi-end, --btn-edge, --btn-shade,        */
/* --btn-glow, --btn-raise, --btn-raise-hover.                                */
/* -------------------------------------------------------------------------- */

.btn {
  /* Gloss knobs — neutral surface by default */
  --btn-hi: var(--gloss-surface-hi);
  --btn-hi-end: var(--gloss-surface-hi-end);
  --btn-edge: var(--gloss-surface-edge);
  --btn-shade: var(--gloss-surface-shade);
  --btn-glow: var(--gloss-surface-glow);
  --btn-text-shadow: var(--gloss-surface-text-shadow);
  --btn-raise: var(--shadow-raised-sm);
  --btn-raise-hover: var(--shadow-raised);
  --btn-rim:
    inset 0 1px 0 var(--btn-edge),
    inset 0 -2px 4px var(--btn-shade);
  --btn-body:
    radial-gradient(ellipse 70% 45% at 50% 100%, var(--btn-glow), transparent 70%),
    linear-gradient(180deg, transparent 0%, transparent 48%, var(--btn-shade) 100%);

  position: relative;
  isolation: isolate; /* keeps the gloss layer above the fill, below the label */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  min-height: 2.5rem;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  text-decoration: none;
  text-shadow: var(--btn-text-shadow);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  background-color: var(--color-bg-elevated);
  background-image: var(--btn-body);
  color: var(--color-text);
  box-shadow: var(--btn-raise), var(--btn-rim);
  transition: background-color var(--ease), color var(--ease), box-shadow var(--ease),
    transform var(--ease);
  white-space: nowrap;
  user-select: none;
}

/* Glossy lozenge — inset from the edges, top half only, fades downward */
.btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 2px;
  left: 7%;
  right: 7%;
  height: 48%;
  border-radius: 1.25rem 1.25rem 0.6rem 0.6rem / 1rem 1rem 0.4rem 0.4rem;
  background: linear-gradient(180deg, var(--btn-hi) 0%, var(--btn-hi-end) 100%);
  opacity: 0.9;
  pointer-events: none;
  transition: opacity var(--ease), transform var(--ease);
}

.btn:hover {
  color: var(--color-text);
  text-decoration: none;
  box-shadow: var(--btn-raise-hover), var(--btn-rim);
}

.btn:hover::before {
  opacity: 1;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--btn-raise), var(--btn-rim), var(--focus-ring);
}

/* Pressed — sinks into the plate; shine dims and the body shading flips */
.btn:active {
  box-shadow: var(--shadow-inset-sm);
  background-image: linear-gradient(180deg, var(--btn-shade) 0%, transparent 60%);
  transform: translateY(1px);
}

.btn:active::before {
  opacity: 0.25;
  transform: translateY(1px);
}

.btn:focus-visible:active {
  box-shadow: var(--shadow-inset-sm), var(--focus-ring);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Filled variants share the colored-gloss knobs */
.btn-primary,
.btn-danger {
  --btn-hi: var(--gloss-fill-hi);
  --btn-hi-end: var(--gloss-fill-hi-end);
  --btn-edge: var(--gloss-fill-edge);
  --btn-shade: var(--gloss-fill-shade);
  --btn-glow: var(--gloss-fill-glow);
  --btn-text-shadow: var(--gloss-fill-text-shadow);
  --btn-raise:
    4px 4px 8px var(--shadow-dark),
    -2px -2px 6px var(--shadow-light);
  --btn-raise-hover:
    5px 5px 10px var(--shadow-dark),
    -2px -2px 6px var(--shadow-light);
  color: #fff;
}

.btn-primary {
  background-color: var(--color-accent-fill);
}

.btn-primary:hover {
  background-color: var(--color-accent-fill-hover);
  color: #fff;
}

/* Filled pressed — darker colored well instead of the plate's light/dark pair,
   so the fill doesn't wash out with a pale inner glow */
.btn-primary:active,
.btn-danger:active {
  color: #fff;
  box-shadow:
    inset 3px 3px 8px rgb(0 0 0 / 0.35),
    inset -2px -2px 6px rgb(255 255 255 / 0.12);
}

.btn-primary:focus-visible:active {
  box-shadow:
    inset 3px 3px 8px rgb(0 0 0 / 0.35),
    inset -2px -2px 6px rgb(255 255 255 / 0.12),
    var(--focus-ring);
}

.btn-secondary {
  color: var(--color-text);
  background-color: var(--color-bg-elevated);
}

.btn-secondary:hover {
  color: var(--color-text);
  text-decoration: none;
}

/* Ghost — no surface at rest; on hover it becomes a glassy inset well */
.btn-ghost {
  color: var(--color-text-secondary);
  background-color: transparent;
  background-image: none;
  box-shadow: none;
  text-shadow: none;
}

.btn-ghost::before {
  opacity: 0;
}

.btn-ghost:hover {
  color: var(--color-text);
  background-color: transparent;
  box-shadow: var(--shadow-inset-sm);
  text-decoration: none;
}

.btn-ghost:hover::before {
  opacity: 0.35;
}

.btn-ghost:active {
  background-image: none;
  box-shadow: var(--shadow-inset);
}

.btn-ghost:active::before {
  opacity: 0.1;
}

.btn-ghost:focus-visible {
  box-shadow: var(--focus-ring);
}

.btn-ghost:focus-visible:active {
  box-shadow: var(--shadow-inset), var(--focus-ring);
}

.btn-danger {
  background-color: var(--color-danger-fill);
}

.btn-danger:hover {
  background-color: var(--color-danger-fill-hover);
  color: #fff;
}

.btn-danger:focus-visible {
  box-shadow: var(--btn-raise), var(--btn-rim), var(--focus-ring-danger);
}

.btn-danger:focus-visible:active {
  box-shadow:
    inset 3px 3px 8px rgb(0 0 0 / 0.35),
    inset -2px -2px 6px rgb(255 255 255 / 0.12),
    var(--focus-ring-danger);
}

.btn-sm {
  min-height: 2rem;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn-sm::before {
  top: 1px;
  border-radius: 1rem 1rem 0.45rem 0.45rem / 0.75rem 0.75rem 0.3rem 0.3rem;
}

.btn-lg {
  min-height: 3rem;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.btn-lg::before {
  top: 3px;
  border-radius: 1.5rem 1.5rem 0.75rem 0.75rem / 1.2rem 1.2rem 0.5rem 0.5rem;
}


/* -------------------------------------------------------------------------- */
/* Forms — inset wells                                                        */
/* -------------------------------------------------------------------------- */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-group:last-child {
  margin-bottom: 0;
}

label,
.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="date"],
textarea,
select,
.input {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-4);
  min-height: 2.5rem;
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg-elevated);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-inset);
  transition: box-shadow var(--ease), color var(--ease);
  appearance: none;
}

textarea {
  min-height: 6rem;
  resize: vertical;
  padding-top: var(--space-3);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b778c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-color: var(--color-bg-elevated);
  padding-right: var(--space-8);
}

input:not([type="checkbox"]):not([type="radio"]):hover,
textarea:hover,
select:hover,
.input:hover {
  box-shadow: var(--shadow-inset-lg);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.input:focus-visible {
  outline: none;
  box-shadow: var(--shadow-inset), var(--focus-ring);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--color-bg-muted);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
}

.input-error {
  box-shadow: var(--shadow-inset), 0 0 0 2px color-mix(in srgb, var(--color-danger) 50%, transparent) !important;
}

.input-error:focus-visible {
  box-shadow: var(--shadow-inset), var(--focus-ring-danger) !important;
}

/* Checkbox & radio */
.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.choice input[type="checkbox"],
.choice input[type="radio"] {
  width: 1.125rem;
  height: 1.125rem;
  min-height: 0;
  margin: 0.125rem 0 0;
  flex-shrink: 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.choice input[type="checkbox"]:focus-visible,
.choice input[type="radio"]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.choice-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* -------------------------------------------------------------------------- */
/* Cards — soft extruded surfaces                                             */
/* -------------------------------------------------------------------------- */

.card {
  background: var(--color-bg-elevated);
  border: none;
  border-radius: var(--radius-xl);
  /* Hover outline: the first two shadow layers always exist (same list structure
     in every state); only their colours change on hover, so box-shadow
     interpolates and the ring/glow fade in. */
  --card-ring-now: transparent;
  --card-glow-now: transparent;
  box-shadow: 0 0 0 1px var(--card-ring-now), 0 0 14px 1px var(--card-glow-now),
    var(--shadow-raised), var(--shadow-concave-inner);
  overflow: hidden;
  /* intentionally NOT disabled under prefers-reduced-motion: a 250ms colour
     fade is not motion, and many desktops report reduce-motion by default */
  transition: box-shadow 250ms ease;
}

.card:hover,
.card:focus-within,
.card.is-hover {
  --card-ring-now: var(--card-ring);
  --card-glow-now: var(--card-glow);
}

.card-body {
  padding: var(--space-5);
}

.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: none;
  box-shadow: 0 1px 0 var(--color-separator);
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: none;
  box-shadow: 0 -1px 0 var(--color-separator);
  background: transparent;
}

.card-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.card-desc {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* -------------------------------------------------------------------------- */
/* Badges — soft pills                                                        */
/* -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2rem 0.65rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  border-radius: var(--radius-full);
  border: none;
  white-space: nowrap;
  box-shadow: var(--shadow-raised-sm), var(--shadow-concave-inner);
}

.badge-neutral {
  color: var(--color-text-secondary);
  background: var(--color-bg-elevated);
}

.badge-accent {
  color: var(--color-accent-text);
  background: var(--color-accent-muted);
  box-shadow: var(--shadow-raised-sm), var(--shadow-concave-inner);
}

.badge-success {
  color: var(--color-success);
  background: var(--color-success-bg);
}

.badge-warning {
  color: var(--color-warning);
  background: var(--color-warning-bg);
}

.badge-danger {
  color: var(--color-danger);
  background: var(--color-danger-bg);
}

/* -------------------------------------------------------------------------- */
/* Alerts — soft inset panels                                                 */
/* -------------------------------------------------------------------------- */

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: none;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  box-shadow: var(--shadow-inset-sm);
}

.alert-title {
  display: block;
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
  color: inherit;
}

.alert-info {
  color: var(--color-accent-text);
  background: var(--color-info-bg);
}

.alert-success {
  color: var(--color-success);
  background: var(--color-success-bg);
}

.alert-warning {
  color: var(--color-warning);
  background: var(--color-warning-bg);
}

.alert-danger {
  color: var(--color-danger);
  background: var(--color-danger-bg);
}

/* -------------------------------------------------------------------------- */
/* Tables — raised wrap, soft rows                                            */
/* -------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: none;
  border-radius: var(--radius-xl);
  background: var(--color-bg-elevated);
  box-shadow: var(--shadow-raised), var(--shadow-concave-inner);
}

table,
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th,
td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-separator);
  vertical-align: top;
}

th {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  background: transparent;
  white-space: nowrap;
}

td {
  color: var(--color-text-secondary);
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--shadow-dark) 8%, transparent);
}

/* -------------------------------------------------------------------------- */
/* Lists                                                                      */
/* -------------------------------------------------------------------------- */

ul,
ol {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-6);
  color: var(--color-text-secondary);
}

li {
  margin-bottom: var(--space-1);
  line-height: var(--leading-relaxed);
}

li::marker {
  color: var(--color-text-muted);
}

.list-plain {
  list-style: none;
  padding-left: 0;
}

.list-plain li {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-separator);
}

.list-plain li:last-child {
  border-bottom: none;
}

/* -------------------------------------------------------------------------- */
/* Code — inline: sunken well; blocks (pre): black + neon blue                */
/* -------------------------------------------------------------------------- */

code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

code {
  padding: 0.15em 0.5em;
  color: var(--code-inline-text);
  font-weight: var(--weight-medium, 500);
  background: var(--code-inline-bg);
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--code-inline-inset);
}

pre {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid #1a1a1a;
  border-radius: var(--radius-lg);
  box-shadow: var(--code-inset);
  text-shadow: var(--code-glow);
}

pre code {
  padding: 0;
  font-weight: inherit;
  color: inherit;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  font-size: inherit;
  text-shadow: inherit;
}

pre::selection,
pre *::selection {
  background: #00d4ff;
  color: #000000;
  text-shadow: none;
}

kbd {
  display: inline-block;
  padding: 0.15em 0.45em;
  font-size: var(--text-xs);
  color: var(--color-text);
  background: var(--color-bg-elevated);
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-raised-sm), var(--shadow-concave-inner);
}

/* -------------------------------------------------------------------------- */
/* HR                                                                         */
/* -------------------------------------------------------------------------- */

hr {
  margin: var(--space-8) 0;
  border: none;
  height: 2px;
  background: var(--color-separator);
  border-radius: 1px;
}

/* -------------------------------------------------------------------------- */
/* Token swatches (showcase)                                                  */
/* -------------------------------------------------------------------------- */

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: var(--space-3);
}

.swatch {
  border: none;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-bg-elevated);
  box-shadow: var(--shadow-raised-sm), var(--shadow-concave-inner);
}

.swatch-color {
  height: 3.5rem;
}

.swatch-meta {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.swatch-meta strong {
  display: block;
  font-size: var(--text-xs);
  margin-bottom: 0.125rem;
}

.token-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.space-demo {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.space-bar {
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  opacity: 0.9;
  box-shadow: var(--shadow-raised-sm), var(--shadow-concave-inner);
}

.radius-demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.radius-box {
  width: 4rem;
  height: 4rem;
  background: var(--color-bg-elevated);
  border: none;
  box-shadow: var(--shadow-raised), var(--shadow-concave-inner);
}

.shadow-demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}

.shadow-box {
  width: 6.5rem;
  height: 4.5rem;
  background: var(--color-bg-elevated);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* -------------------------------------------------------------------------- */
/* Concave raised surfaces                                                    */
/* Raised (extruded) non-button surfaces get a slightly dished top face:      */
/* lifted by the outer --shadow-raised* pair, with --surface-concave layered  */
/* over their background-color. Placed after the components so it survives   */
/* variant rules that use the `background` shorthand (badges, etc.).          */
/* Buttons (glossy convex) and inset wells are intentionally excluded.        */
/* Opt in elsewhere with the .surface-concave utility.                        */
/* -------------------------------------------------------------------------- */

.card,
.badge,
.table-wrap,
kbd,
.swatch,
.space-bar,
.radius-box,
.shadow-box[style*="shadow-raised"],
.surface-concave {
  background-image: var(--surface-concave);
}


/* Top bar: matte convex dome (overrides concave); placed after concave list */
.nav {
  background-image: var(--surface-dome);
}

/* -------------------------------------------------------------------------- */
/* Utilities                                                                  */
/* -------------------------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mt-0 {
  margin-top: 0;
}
.mb-0 {
  margin-bottom: 0;
}
.mb-2 {
  margin-bottom: var(--space-2);
}
.mb-4 {
  margin-bottom: var(--space-4);
}
.mb-6 {
  margin-bottom: var(--space-6);
}
.mt-4 {
  margin-top: var(--space-4);
}
.mt-6 {
  margin-top: var(--space-6);
}

.text-center {
  text-align: center;
}
