/* ==========================================================================
   Kit2 V6 — Chameleon Studio, Multi-Tone Color Stories & Agent SDK Tokens (tokens.css)
   Reverse-engineered from the macOS ChatGPT & Codex Unified Desktop App,
   extrapolated into a multi-preset, concentric, vibrancy-layered token engine.

   Strict AST-Enforced Numeric Budgets:
     - 7 Text Sizes (rem)       - 3 Font Weights (400, 500, 600)
     - 3 Control Heights        - 4 Concentric Corner Radii
     - 3 Elevation Tiers        - 2 Icon Sizes (16px, 20px @ 1.5px stroke)
     - 5 Motion Curves          - 5 Curated Brand Presets (Dark & Light AA)
   ========================================================================== */

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

  /* --- Typography Families --- */
  --font-sans: "OpenAI Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --font-display: "OpenAI Sans", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Monaco, Consolas, monospace;

  /* --- Type Scale: Strictly 7 Steps (rem) --- */
  --text-xs: 0.8125rem;     /* 13px — optical floor: badges, mono pills, keycaps */
  --text-sm: 0.875rem;      /* 14px — secondary metadata, compact buttons, table headers */
  --text-base: 0.96875rem;  /* 15.5px — default human-readable body, rows, inputs, prose */
  --text-md: 1.15rem;       /* 18.4px — card titles, panel headers, lead paragraphs */
  --text-lg: 1.4375rem;     /* 23px — section subheads, modal titles, secondary KPIs */
  --text-xl: 1.9375rem;     /* 31px — primary page headings & hero KPI numerals */
  --text-2xl: 2.875rem;     /* 46px — flagship display hero headline */

  --leading-xs: 1.45;
  --leading-sm: 1.5;
  --leading-base: 1.62;
  --leading-md: 1.48;
  --leading-lg: 1.3;
  --leading-xl: 1.18;
  --leading-2xl: 1.08;

  /* --- Optical Letter-Spacing Grammar --- */
  --tracking-display: -0.03em;
  --tracking-heading: -0.018em;
  --tracking-ui: -0.005em;
  --tracking-caps: 0.06em;

  /* --- Font Weights: Strictly 3 Weights (Zero 700+ bolds) --- */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* --- Control Heights: Strictly 3 Steps --- */
  --control-sm: 32px;
  --control-md: 38px;
  --control-lg: 46px;

  /* --- Structural Layout Dimensions --- */
  --chrome-header-h: 56px;
  --site-nav-h: 76px;
  --shell-header-h: 76px;
  --page-gutter: var(--space-8);
  --icon-rail-w: 48px;
  --sidebar-w: 248px;
  --thread-max-w: 720px;
  --inspector-w: 400px;
  --page-max-w: 1280px;

  /* --- Spacing Scale (4px module) --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* --- Concentric Corner Radii: Strictly 4 Steps --- */
  --radius-sm: 7px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 9999px;

  /* --- Icons: Strictly 2 Sizes & 1 Stroke Weight --- */
  --icon-sm: 16px;
  --icon-lg: 20px;
  --icon-stroke: 1.5;

  /* --- 5-Curve Choreographed Motion Grammar --- */
  --motion-press: 90ms cubic-bezier(0.2, 0, 0, 1);
  --motion-fast: 130ms cubic-bezier(0.2, 0, 0, 1);
  --motion-popover: 175ms cubic-bezier(0.16, 1, 0.3, 1);
  --motion-glide: 210ms cubic-bezier(0.22, 1, 0.36, 1);
  --motion-panel: 260ms cubic-bezier(0.22, 1, 0.36, 1);

  /* --- Dark Mode Default Preset: Codex Pure Achromatic (Measured) --- */
  --surface-page: #181818;
  --surface-sidebar: #1d1d1d;
  --surface-rail: #252525;
  --surface-raised: #232323;
  --surface-control: #2f2f2f;
  --surface-floating: #2e2e2e;
  --surface-composer: #343434;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-pressed: rgba(255, 255, 255, 0.11);
  --surface-backdrop: rgba(0, 0, 0, 0.66);

  --surface-glass: rgba(29, 29, 29, 0.80);
  --surface-floating-glass: rgba(46, 46, 46, 0.86);
  --backdrop-vibrancy: blur(20px) saturate(145%);
  --rim-specular: inset 0 1px 0 rgba(255, 255, 255, 0.07);

  --ink-primary: #f5f5f5;
  --ink-secondary: #b5b5b5;
  --ink-muted: #9c9c9c;
  --ink-disabled: #6b6b6b;

  --border-subtle: rgba(255, 255, 255, 0.068);
  --border-elevated: rgba(255, 255, 255, 0.115);
  --border-control: #858585;
  --border-strong: #a3a3a3;

  --shadow-page: none;
  --shadow-raised: inset 0 1px 0 rgba(255, 255, 255, 0.055), 0 10px 30px -10px rgba(0, 0, 0, 0.42), 0 2px 8px rgba(0, 0, 0, 0.22);
  --shadow-floating: inset 0 1px 0 rgba(255, 255, 255, 0.085), 0 18px 44px rgba(0, 0, 0, 0.60), 0 4px 14px rgba(0, 0, 0, 0.42);

  --cta-bg: #ffffff;
  --cta-bg-hover: #e8e8e8;
  --cta-bg-pressed: #d4d4d4;
  --cta-ink: #0d0d0d;

  /* --- Shared 6-Hue Core Palette (Dark Mode — >= 4.66:1 across all surfaces) --- */
  --accent-cobalt: #66adff;
  --accent-cobalt-soft: rgba(102, 173, 255, 0.14);
  --accent-cobalt-solid: #2563eb;

  --accent-emerald: #47d98c;
  --accent-emerald-soft: rgba(71, 217, 140, 0.14);

  --accent-crimson: #ff858d;
  --accent-crimson-soft: rgba(255, 133, 141, 0.14);
  --accent-crimson-solid: #d92d3f;

  --accent-amber: #f7b948;
  --accent-amber-soft: rgba(247, 185, 72, 0.16);

  --accent-violet: #baa0ff;
  --accent-violet-soft: rgba(186, 160, 255, 0.15);

  --accent-cyan: #52d1f7;
  --accent-cyan-soft: rgba(82, 209, 247, 0.14);

  --accent-brand: var(--accent-cobalt);
  --accent-brand-soft: var(--accent-cobalt-soft);
  --accent-brand-solid: var(--accent-cobalt-solid);
  --focus-ring: var(--accent-brand);
}

[data-theme="light"] {
  color-scheme: light;

  --surface-page: #ffffff;
  --surface-sidebar: #f7f7f7;
  --surface-rail: #f0f0f0;
  --surface-raised: #f7f7f7;
  --surface-control: #ededed;
  --surface-floating: #ffffff;
  --surface-composer: #f2f2f2;
  --surface-hover: rgba(0, 0, 0, 0.05);
  --surface-pressed: rgba(0, 0, 0, 0.09);
  --surface-backdrop: rgba(0, 0, 0, 0.36);

  --surface-glass: rgba(247, 247, 247, 0.84);
  --surface-floating-glass: rgba(255, 255, 255, 0.90);
  --backdrop-vibrancy: blur(20px) saturate(145%);
  --rim-specular: inset 0 1px 0 rgba(255, 255, 255, 0.85);

  --ink-primary: #141414;
  --ink-secondary: #525252;
  --ink-muted: #666666;
  --ink-disabled: #999999;

  --border-subtle: rgba(0, 0, 0, 0.068);
  --border-elevated: rgba(0, 0, 0, 0.115);
  --border-control: #737373;
  --border-strong: #525252;

  --shadow-page: none;
  --shadow-raised: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 10px 28px -10px rgba(0, 0, 0, 0.07), 0 2px 6px rgba(0, 0, 0, 0.03);
  --shadow-floating: 0 16px 40px -6px rgba(0, 0, 0, 0.15), 0 4px 12px -2px rgba(0, 0, 0, 0.07), 0 0 0 1px rgba(0, 0, 0, 0.04);

  --cta-bg: #141414;
  --cta-bg-hover: #2b2b2b;
  --cta-bg-pressed: #000000;
  --cta-ink: #ffffff;

  --accent-cobalt: #1659c7;
  --accent-cobalt-soft: rgba(22, 89, 199, 0.10);
  --accent-cobalt-solid: #1d63dc;

  --accent-emerald: #0d6e3d;
  --accent-emerald-soft: rgba(13, 110, 61, 0.10);

  --accent-crimson: #bf2233;
  --accent-crimson-soft: rgba(191, 34, 51, 0.09);
  --accent-crimson-solid: #c81e32;

  --accent-amber: #944800;
  --accent-amber-soft: rgba(148, 72, 0, 0.10);

  --accent-violet: #6534e6;
  --accent-violet-soft: rgba(101, 52, 230, 0.10);

  --accent-cyan: #0b6682;
  --accent-cyan-soft: rgba(11, 102, 130, 0.10);

  --accent-brand: var(--accent-cobalt);
  --accent-brand-soft: var(--accent-cobalt-soft);
  --accent-brand-solid: var(--accent-cobalt-solid);
  --focus-ring: var(--accent-brand);
}

/* ==========================================================================
   V4 CURATED SURFACE PRESETS (WCAG 2.1 AA VERIFIED IN DARK & LIGHT)
   ========================================================================== */

/* Preset 2: Warm Editorial Paper */
[data-preset="editorial"][data-theme="dark"] {
  --surface-page: #191715;
  --surface-sidebar: #201d1a;
  --surface-rail: #26231f;
  --surface-raised: #24211d;
  --surface-control: #302c27;
  --surface-floating: #2e2a25;
  --surface-composer: #35302a;
  --surface-glass: rgba(32, 29, 26, 0.82);
  --surface-floating-glass: rgba(46, 42, 37, 0.88);
  --border-subtle: #332e29;
  --border-elevated: #423c35;
}
[data-preset="editorial"][data-theme="light"] {
  --surface-page: #fcfbf8;
  --surface-sidebar: #f4f1ea;
  --surface-rail: #ece8df;
  --surface-raised: #f5f2eb;
  --surface-control: #e8e4da;
  --surface-floating: #ffffff;
  --surface-composer: #efeae0;
  --surface-glass: rgba(244, 241, 234, 0.86);
  --border-subtle: #e2ddd2;
  --border-elevated: #d1cbc0;
}

/* Preset 3: Graphite Pro */
[data-preset="graphite"][data-theme="dark"] {
  --surface-page: #131416;
  --surface-sidebar: #181a1d;
  --surface-rail: #1f2226;
  --surface-raised: #1d2024;
  --surface-control: #292d32;
  --surface-floating: #262a2f;
  --surface-composer: #2f3339;
  --surface-glass: rgba(24, 26, 29, 0.82);
  --surface-floating-glass: rgba(38, 42, 47, 0.88);
  --border-subtle: #292d33;
  --border-elevated: #383d45;
}
[data-preset="graphite"][data-theme="light"] {
  --surface-page: #ffffff;
  --surface-sidebar: #f5f6f8;
  --surface-rail: #edeff2;
  --surface-raised: #f6f7f9;
  --surface-control: #e8eaee;
  --surface-floating: #ffffff;
  --surface-composer: #eff1f4;
  --border-subtle: #e2e5ea;
  --border-elevated: #cfd4dc;
}

/* Preset 4: Obsidian High-Contrast */
[data-preset="obsidian"][data-theme="dark"] {
  --surface-page: #0e0e0e;
  --surface-sidebar: #151515;
  --surface-rail: #1d1d1d;
  --surface-raised: #1a1a1a;
  --surface-control: #292929;
  --surface-floating: #262626;
  --surface-composer: #303030;
  --surface-glass: rgba(21, 21, 21, 0.84);
  --surface-floating-glass: rgba(38, 38, 38, 0.90);
  --border-subtle: #292929;
  --border-elevated: #3b3b3b;
}

/* Preset 5: Daylight Sandstone */
[data-preset="sandstone"][data-theme="dark"] {
  --surface-page: #1b1916;
  --surface-sidebar: #221f1b;
  --surface-rail: #292520;
  --surface-raised: #26221e;
  --surface-control: #332e28;
  --surface-floating: #312c26;
  --surface-composer: #38322c;
  --border-subtle: #36302a;
  --border-elevated: #463f37;
}
[data-preset="sandstone"][data-theme="light"] {
  --surface-page: #faf8f4;
  --surface-sidebar: #f1ede4;
  --surface-rail: #e8e2d6;
  --surface-raised: #f2eee6;
  --surface-control: #e5dfd2;
  --surface-floating: #fffdf9;
  --surface-composer: #ebe5d9;
  --border-subtle: #ddd6c7;
  --border-elevated: #ccc3b2;
}

/* --- V4 Corner Personality Modes (Strictly 4 Concentric Steps Each) --- */
[data-radii="sharp"] {
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 9999px;
}
[data-radii="soft"] {
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 9999px;
}

/* --- Live Studio Brand Accent Overrides --- */
[data-accent="emerald"] {
  --accent-brand: var(--accent-emerald);
  --accent-brand-soft: var(--accent-emerald-soft);
  --accent-brand-solid: #10b981;
  --focus-ring: var(--accent-emerald);
}
[data-accent="violet"] {
  --accent-brand: var(--accent-violet);
  --accent-brand-soft: var(--accent-violet-soft);
  --accent-brand-solid: #7c3aed;
  --focus-ring: var(--accent-violet);
}
[data-accent="amber"] {
  --accent-brand: var(--accent-amber);
  --accent-brand-soft: var(--accent-amber-soft);
  --accent-brand-solid: #d97706;
  --focus-ring: var(--accent-amber);
}
[data-accent="cyan"] {
  --accent-brand: var(--accent-cyan);
  --accent-brand-soft: var(--accent-cyan-soft);
  --accent-brand-solid: #0891b2;
  --focus-ring: var(--accent-cyan);
}

/* --- Spatial Density Modes (Preserving 3 Canonical Control Heights) --- */
[data-density="compact"] {
  --space-3: 10px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 20px;
  --space-8: 24px;
}
[data-density="comfortable"] {
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 24px;
  --space-6: 28px;
  --space-8: 38px;
}

/* --- OpenAI / MCP Apps Host CSS Variable Bridge --- */
:root,
[data-theme="dark"],
[data-theme="light"] {
  --color-background-primary: var(--surface-page);
  --color-background-secondary: var(--surface-raised);
  --color-background-tertiary: var(--surface-sidebar);
  --color-text-primary: var(--ink-primary);
  --color-text-secondary: var(--ink-secondary);
  --color-text-tertiary: var(--ink-muted);
  --color-border-primary: var(--border-subtle);
  --color-border-secondary: var(--border-control);
  --color-ring-primary: var(--focus-ring);
}

/* --- CSS View Transitions Smooth Root Crossfade --- */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 160ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  :root,
  [data-theme="dark"],
  [data-theme="light"] {
    --motion-press: 0ms linear;
    --motion-fast: 0ms linear;
    --motion-popover: 0ms linear;
    --motion-glide: 0ms linear;
    --motion-panel: 0ms linear;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0ms !important;
  }
}


/* ==========================================================================
   V6 MULTI-TONE COLOR STORIES & AMBIENT AURORA ATMOSPHERE
   Coordinates Primary Accent, Secondary Jewel Highlight, Top Hairline & Glow
   without shifting the 140 WCAG 2.1 AA verified surface/ink pairs.
   ========================================================================== */

:root,
[data-theme="dark"] {
  --story-glow-primary: rgba(59, 130, 246, 0.14);
  --story-glow-secondary: rgba(139, 92, 246, 0.10);
  --story-hairline: linear-gradient(90deg, rgba(102, 173, 255, 0.0) 0%, rgba(102, 173, 255, 0.55) 35%, rgba(82, 209, 247, 0.45) 68%, rgba(186, 160, 255, 0.0) 100%);
  --story-orb: linear-gradient(135deg, #3b82f6 0%, #38bdf8 52%, #8b5cf6 100%);
}

[data-theme="light"] {
  --story-glow-primary: rgba(37, 99, 235, 0.09);
  --story-glow-secondary: rgba(14, 165, 233, 0.07);
  --story-hairline: linear-gradient(90deg, rgba(22, 89, 199, 0.0) 0%, rgba(22, 89, 199, 0.42) 35%, rgba(11, 102, 130, 0.34) 68%, rgba(101, 52, 230, 0.0) 100%);
  --story-orb: linear-gradient(135deg, #1d63dc 0%, #0ea5e9 52%, #6534e6 100%);
}

/* Story 2: Botanical Emerald & Mint-Cyan */
[data-accent="emerald"][data-theme="dark"] {
  --story-glow-primary: rgba(16, 185, 129, 0.15);
  --story-glow-secondary: rgba(6, 182, 212, 0.10);
  --story-hairline: linear-gradient(90deg, rgba(71, 217, 140, 0) 0%, rgba(71, 217, 140, 0.58) 38%, rgba(82, 209, 247, 0.42) 70%, rgba(71, 217, 140, 0) 100%);
  --story-orb: linear-gradient(135deg, #10b981 0%, #34d399 50%, #06b6d4 100%);
}
[data-accent="emerald"][data-theme="light"] {
  --story-glow-primary: rgba(13, 110, 61, 0.09);
  --story-glow-secondary: rgba(11, 102, 130, 0.07);
  --story-hairline: linear-gradient(90deg, rgba(13, 110, 61, 0) 0%, rgba(13, 110, 61, 0.44) 38%, rgba(11, 102, 130, 0.32) 70%, rgba(13, 110, 61, 0) 100%);
  --story-orb: linear-gradient(135deg, #0d6e3d 0%, #10b981 52%, #0891b2 100%);
}

/* Story 3: Aura Rose-Violet & Orchid (Luxury Hospitality / Med Spa / Creative) */
[data-accent="violet"][data-theme="dark"] {
  --story-glow-primary: rgba(168, 85, 247, 0.16);
  --story-glow-secondary: rgba(244, 114, 182, 0.11);
  --story-hairline: linear-gradient(90deg, rgba(186, 160, 255, 0) 0%, rgba(186, 160, 255, 0.60) 36%, rgba(255, 133, 141, 0.46) 68%, rgba(186, 160, 255, 0) 100%);
  --story-orb: linear-gradient(135deg, #8b5cf6 0%, #c084fc 50%, #f472b6 100%);
}
[data-accent="violet"][data-theme="light"] {
  --story-glow-primary: rgba(101, 52, 230, 0.09);
  --story-glow-secondary: rgba(191, 34, 51, 0.07);
  --story-hairline: linear-gradient(90deg, rgba(101, 52, 230, 0) 0%, rgba(101, 52, 230, 0.45) 36%, rgba(191, 34, 51, 0.34) 68%, rgba(101, 52, 230, 0) 100%);
  --story-orb: linear-gradient(135deg, #6534e6 0%, #9333ea 50%, #e11d48 100%);
}

/* Story 4: Solar Editorial Amber & Terracotta */
[data-accent="amber"][data-theme="dark"] {
  --story-glow-primary: rgba(245, 158, 11, 0.15);
  --story-glow-secondary: rgba(244, 63, 94, 0.09);
  --story-hairline: linear-gradient(90deg, rgba(247, 185, 72, 0) 0%, rgba(247, 185, 72, 0.60) 38%, rgba(255, 133, 141, 0.40) 70%, rgba(247, 185, 72, 0) 100%);
  --story-orb: linear-gradient(135deg, #f59e0b 0%, #fbbf24 50%, #ef4444 100%);
}
[data-accent="amber"][data-theme="light"] {
  --story-glow-primary: rgba(148, 72, 0, 0.09);
  --story-glow-secondary: rgba(191, 34, 51, 0.06);
  --story-hairline: linear-gradient(90deg, rgba(148, 72, 0, 0) 0%, rgba(148, 72, 0, 0.45) 38%, rgba(191, 34, 51, 0.30) 70%, rgba(148, 72, 0, 0) 100%);
  --story-orb: linear-gradient(135deg, #b45309 0%, #f59e0b 52%, #dc2626 100%);
}

/* Story 5: Lagoon Electric Cyan & Indigo */
[data-accent="cyan"][data-theme="dark"] {
  --story-glow-primary: rgba(34, 211, 238, 0.15);
  --story-glow-secondary: rgba(99, 102, 241, 0.11);
  --story-hairline: linear-gradient(90deg, rgba(82, 209, 247, 0) 0%, rgba(82, 209, 247, 0.60) 36%, rgba(102, 173, 255, 0.45) 70%, rgba(82, 209, 247, 0) 100%);
  --story-orb: linear-gradient(135deg, #06b6d4 0%, #38bdf8 50%, #6366f1 100%);
}
[data-accent="cyan"][data-theme="light"] {
  --story-glow-primary: rgba(11, 102, 130, 0.09);
  --story-glow-secondary: rgba(22, 89, 199, 0.07);
  --story-hairline: linear-gradient(90deg, rgba(11, 102, 130, 0) 0%, rgba(11, 102, 130, 0.45) 36%, rgba(22, 89, 199, 0.35) 70%, rgba(11, 102, 130, 0) 100%);
  --story-orb: linear-gradient(135deg, #0b6682 0%, #0284c7 50%, #4f46e5 100%);
}

[data-accent="crimson"] {
  --accent-brand: var(--accent-crimson);
  --accent-brand-soft: var(--accent-crimson-soft);
  --accent-brand-solid: var(--accent-crimson-solid);
  --focus-ring: var(--accent-crimson);
}

@media (max-width: 760px) {
  :root,
  [data-theme="dark"],
  [data-theme="light"] {
    --page-gutter: var(--space-4);
    --shell-header-h: 64px;
  }
}

/* ==========================================================================
   V6.5 CURATED ZERO-NETWORK FONT PAIRINGS (data-fonts)
   Instant native macOS / system-ui typography shifts with 0 network calls
   ========================================================================== */
[data-fonts="precision"] {
  --font-display: "OpenAI Sans", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
}

[data-fonts="editorial"] {
  --font-display: ui-serif, "New York", "Iowan Old Style", "Palatino", Georgia, serif;
  --tracking-display: -0.018em;
  --tracking-heading: -0.01em;
}

[data-fonts="humanist"] {
  --font-display: ui-rounded, "SF Pro Rounded", "Avenir Next", -apple-system, system-ui, sans-serif;
  --font-sans: ui-rounded, "SF Pro Rounded", "Avenir Next", -apple-system, system-ui, sans-serif;
}

[data-fonts="technical"] {
  --font-display: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Monaco, Consolas, monospace;
  --tracking-display: -0.035em;
  --tracking-heading: -0.024em;
}
