/* ============================================================ */
/*  WARM CLAY DESIGN TOKENS — v17                                 */
/*  Single source of truth for palette, typography, motion.       */
/*  Loaded BEFORE any other stylesheet.                           */
/*                                                                */
/*  v17 adds: mobile-first responsive primitives, WCAG 2.2 AA    */
/*  globals, touch-target baselines, dynamic viewport, safe-area,*/
/*  performance helpers (content-visibility, text-wrap).         */
/* ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* ── Brand · Warm Clay ───────────────────────────────────── */
  --brand-300: #f5a47c;
  --brand-400: #f08a5d;
  --brand-500: #e97451;
  --brand-600: #c95a37;
  --brand-700: #8f3d21;
  --brand: var(--brand-500);

  --brand-glow-soft: rgba(233, 116, 81, 0.15);
  --brand-glow: rgba(233, 116, 81, 0.3);
  --brand-glow-hard: rgba(233, 116, 81, 0.35);

  /* ── Surfaces (dark default) ─────────────────────────────── */
  --bg-primary: #1f1f1e;
  --bg-secondary: #262624;
  --bg-tertiary: #2b2b29;
  --bg-card: #2a2a28;
  --bg-panel: #1a1a19;
  --bg-elevated: #33332f;

  /* ── Borders ─────────────────────────────────────────────── */
  --border-primary: #262626;
  --border-subtle: #1f1f1f;
  --border-dark: #3a3a37;
  --border-brand: rgba(233, 116, 81, 0.35);

  /* ── Text (dark) ─────────────────────────────────────────── */
  --text-primary: #fafafa;
  --text-secondary: #a3a3a3;
  --text-tertiary: #737373;
  --text-quaternary: #525252;

  /* ── Status ──────────────────────────────────────────────── */
  --status-success: #22c55e;
  --status-warning: #f59e0b;
  --status-error: #e97451;
  --status-info: #3b82f6;

  /* ── Typography ──────────────────────────────────────────── */
  --font-display:
    'Space Grotesk', 'Plus Jakarta Sans', Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Plus Jakarta Sans', Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Menlo, Consolas, monospace;

  --tracking-tight: -0.02em;
  --tracking-tighter: -0.03em;
  --tracking-hero: -0.04em;

  /* ── Radius ──────────────────────────────────────────────── */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* ── Shadows ─────────────────────────────────────────────── */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-brand-glow: 0 0 32px rgba(233, 116, 81, 0.15);

  /* ── Motion ──────────────────────────────────────────────── */
  --motion-fast: 150ms;
  --motion-normal: 200ms;
  --motion-slow: 300ms;
  --ease-standard: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* ── v17 · Responsive & touch targets ───────────────────── */
  --touch-target-min: 44px;
  --tap-area-min: 44px;

  /* Safe-area insets (notches, gesture bars). Fallbacks to 0. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Dynamic viewport units (iOS Safari 15.4+, Android 108+).  */
  /* Fallback chain: svh/lvh/dvh → vh via @supports below.    */
  --vh-100: 100vh;
  --dvh-100: 100dvh;

  /* Fluid spacing & type (clamp for mobile→desktop).          */
  --space-xs: clamp(0.25rem, 0.5vw, 0.5rem);
  --space-sm: clamp(0.5rem, 1vw, 0.75rem);
  --space-md: clamp(0.75rem, 1.5vw, 1rem);
  --space-lg: clamp(1rem, 2.5vw, 1.5rem);
  --space-xl: clamp(1.5rem, 4vw, 2.5rem);
  --space-2xl: clamp(2rem, 6vw, 4rem);

  --fs-body: clamp(0.95rem, 0.9rem + 0.2vw, 1rem);
  --fs-h1: clamp(1.75rem, 1.2rem + 2.8vw, 3.25rem);
  --fs-h2: clamp(1.5rem, 1.1rem + 2vw, 2.5rem);
  --fs-h3: clamp(1.25rem, 1rem + 1.2vw, 1.75rem);

  /* Responsive breakpoint reference (for JS, not media).      */
  --bp-xs: 360px;
  --bp-sm: 480px;
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
  --bp-2xl: 1536px;
}

/* ── Light theme override ───────────────────────────────────── */
[data-theme='light'],
html[data-theme='light'] {
  --bg-primary: #f6f8fa;
  --bg-secondary: #edf0f4;
  --bg-tertiary: #ffffff;
  --bg-card: #fafbfc;
  --bg-panel: #ffffff;
  --bg-elevated: #e8ecf0;

  --border-primary: rgba(13, 13, 13, 0.1);
  --border-subtle: rgba(13, 13, 13, 0.06);
  --border-dark: rgba(13, 13, 13, 0.18);
  --border-brand: rgba(201, 90, 55, 0.45);

  --text-primary: #0d0d0d;
  --text-secondary: #404040;
  --text-tertiary: #666666;
  --text-quaternary: #999999;

  --shadow-card: 0 1px 3px rgba(13, 13, 13, 0.08);
  --shadow-elevated: 0 4px 12px rgba(13, 13, 13, 0.12);
  --shadow-brand-glow: 0 0 32px rgba(201, 90, 55, 0.18);
}

/* ── Selection ──────────────────────────────────────────────── */
::selection {
  background: rgba(233, 116, 81, 0.25);
  color: #fafafa;
}
[data-theme='light'] ::selection {
  background: rgba(233, 116, 81, 0.15);
  color: #0d0d0d;
}

/* ── Focus ring ─────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid rgba(233, 116, 81, 0.7);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Logo wordmark ──────────────────────────────────────────── */
.lydos-logo {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--tracking-tighter);
  background: linear-gradient(135deg, #ffffff 0%, #e97451 60%, #f5a47c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  display: inline-block;
}
[data-theme='light'] .lydos-logo {
  background: linear-gradient(135deg, #0d0d0d 0%, #e97451 60%, #c95a37 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Body baseline (only when html has no font-family yet) ──── */
html,
body {
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6,
.heading,
.display {
  font-family: var(--font-display);
  letter-spacing: var(--tracking-tight);
}

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

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================ */
/*  v17 · GLOBAL MOBILE / A11Y / PERFORMANCE FOUNDATION          */
/* ============================================================ */

/* ── Box sizing & overflow guard ─────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  tab-size: 4;
  scroll-padding-top: calc(4rem + var(--safe-top));
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  font-size: var(--fs-body);
  line-height: 1.5;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ── Modern heading wrap (browsers that support it) ──────── */
@supports (text-wrap: balance) {
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  .heading,
  .display {
    text-wrap: balance;
  }
}
@supports (text-wrap: pretty) {
  p,
  li,
  blockquote,
  figcaption {
    text-wrap: pretty;
  }
}

/* ── iOS zoom prevention: inputs must be ≥16px ───────────── */
input,
select,
textarea,
button {
  font: inherit;
  font-size: max(16px, 1rem);
  color: inherit;
}

input,
select,
textarea {
  max-width: 100%;
}

textarea {
  resize: vertical;
}

/* ── Minimum touch target (WCAG 2.2 SC 2.5.8) ────────────── */
button,
a.btn,
[role='button'],
input[type='button'],
input[type='submit'],
input[type='reset'],
.touchable {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  touch-action: manipulation;
}

/* Retain inline links without forcing oversized hit boxes. */
a {
  text-decoration-skip-ink: auto;
}

/* ── Replaced elements behave responsively ───────────────── */
img,
picture,
svg,
video,
canvas,
iframe {
  display: block;
  max-width: 100%;
  height: auto;
}
img,
picture,
video {
  object-fit: cover;
}

/* ── Visually-hidden helper (screen-reader only) ─────────── */
.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── Skip-to-content link (a11y entry point) ─────────────── */
.skip-to-content {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  z-index: 99999;
  padding: 12px 20px;
  background: var(--brand-500);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  transform: translateY(-200%);
  transition: transform var(--motion-normal) var(--ease-standard);
  text-decoration: none;
}
.skip-to-content:focus,
.skip-to-content:focus-visible {
  transform: translateY(0);
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ── Utility: safe-area-aware full-height containers ─────── */
.h-dvh {
  height: 100vh;
  height: 100dvh;
}
.min-h-dvh {
  min-height: 100vh;
  min-height: 100dvh;
}
.h-screen-safe {
  height: calc(100vh - var(--safe-top) - var(--safe-bottom));
  height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
}

/* ── Utility: safe-area padding helpers ──────────────────── */
.pt-safe {
  padding-top: var(--safe-top);
}
.pb-safe {
  padding-bottom: var(--safe-bottom);
}
.pl-safe {
  padding-left: var(--safe-left);
}
.pr-safe {
  padding-right: var(--safe-right);
}
.px-safe {
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.py-safe {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ── Utility: content-visibility (perf, long lists) ──────── */
.cv-auto {
  content-visibility: auto;
  contain-intrinsic-size: 1px 600px;
}

/* ── Utility: GPU compositing for animated layers ────────── */
.will-change-transform {
  will-change: transform;
}
.will-change-opacity {
  will-change: opacity;
}

/* ── Focus ring on non-button tappables ──────────────────── */
[tabindex]:focus-visible,
details summary:focus-visible {
  outline: 2px solid rgba(233, 116, 81, 0.7);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── High-contrast mode (Windows, forced-colors) ─────────── */
@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid CanvasText;
  }
  .skip-to-content {
    background: Canvas;
    color: CanvasText;
    border: 2px solid CanvasText;
  }
}

/* ── Print — legibility fallback ─────────────────────────── */
@media print {
  *,
  *::before,
  *::after {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  a[href]::after {
    content: ' (' attr(href) ')';
    font-size: 0.85em;
  }
  .skip-to-content,
  nav,
  header,
  footer,
  .no-print {
    display: none !important;
  }
}

/* ── Small-screen hardening (≤480px) ─────────────────────── */
@media (max-width: 480px) {
  :root {
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
  }
  body {
    font-size: clamp(0.95rem, 3.5vw, 1rem);
  }
  h1,
  .display {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    line-height: 1.15;
  }
}

/* ── Landscape phones: watch out for short viewports ─────── */
@media (max-height: 480px) and (orientation: landscape) {
  .h-dvh,
  .min-h-dvh {
    min-height: 100vh;
    min-height: 100svh;
  }
}

/* ============================================================ */
/*  v17 · VIEW TRANSITIONS API                                  */
/* ============================================================ */

/* Give the root view transition a clean hand-off (prevents flash). */
@supports (view-transition-name: none) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }
  ::view-transition-old(root) {
    z-index: 1;
  }
  ::view-transition-new(root) {
    z-index: 9999;
  }
}

/* Prevent flash-of-unthemed-content via .no-theme-transition class
   that theme-init.js adds on first paint. Removed after hydration. */
html.no-theme-transition,
html.no-theme-transition * {
  transition: none !important;
  animation: none !important;
}

/* ============================================================ */
/*  v17 · COMMON BUTTON / LINK HOVER MOTION HARDENING           */
/* ============================================================ */
@media (hover: hover) and (pointer: fine) {
  .btn,
  button,
  a.btn,
  [role='button'] {
    transition:
      transform var(--motion-normal) var(--ease-standard),
      background-color var(--motion-normal) var(--ease-standard),
      box-shadow var(--motion-normal) var(--ease-standard);
  }
}
