/* ═══════════════════════════════════════════════════════════════
   Design System — Core Tokens & Foundation
   Version: 1.0.0
   ═══════════════════════════════════════════════════════════════ */

/* ──────────────────────────────────────────────────────────────
   1. TOKENS
   Source of truth. All values derive from these scales.
   ────────────────────────────────────────────────────────────── */

:root {

  /* ── Color: Base Palette ────────────────────────────────── */
  /* Neutral — warm gray, not blue-gray */
  --gray-50:  #fafaf9;
  --gray-100: #f5f5f4;
  --gray-200: #e7e5e4;
  --gray-300: #d6d3d1;
  --gray-400: #a8a29e;
  --gray-500: #78716c;
  --gray-600: #57534e;
  --gray-700: #44403c;
  --gray-800: #292524;
  --gray-900: #1c1917;
  --gray-950: #0c0a09;

  /* Brand — a single, restrained blue */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  /* Success */
  --green-50:  #f0fdf4;
  --green-500: #22c55e;
  --green-600: #16a34a;

  /* Warning */
  --amber-50:  #fffbeb;
  --amber-500: #f59e0b;
  --amber-600: #d97706;

  /* Danger */
  --red-50:  #fef2f2;
  --red-500: #ef4444;
  --red-600: #dc2626;


  /* ── Color: Semantic Tokens ─────────────────────────────── */
  /* These map palette → meaning. Switch theme by reassigning these. */

  --color-bg:           #F8FAFC;
  --color-bg-raised:    #ffffff;
  --color-bg-sunken:    var(--gray-100);
  --color-bg-overlay:   rgba(0, 0, 0, 0.4);

  --color-surface:      #ffffff;
  --color-surface-alt:  var(--gray-50);

  --color-border:       #E2E8F0;
  --color-border-strong: var(--gray-300);
  --color-border-focus: var(--blue-500);

  --color-text:         #0F172A;
  --color-text-secondary: #64748B;
  --color-text-tertiary:  var(--gray-400);
  --color-text-inverse: #ffffff;
  --color-text-link:    var(--blue-600);
  --color-text-link-hover: var(--blue-700);

  --color-brand:        #2563EB;
  --color-brand-hover:  #1D4ED8;
  --color-brand-text:   #ffffff;

  --color-success:      var(--green-600);
  --color-warning:      var(--amber-500);
  --color-danger:       var(--red-600);
  --color-danger-bg:    var(--red-50);


  /* ── Typography ─────────────────────────────────────────── */
  /* Font stacks — system fonts, no external dependencies */
  --font-sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --font-mono:  ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", monospace;

  /* Modular scale — ratio 1.25 (Major Third) */
  --text-2xs:   0.64rem;    /* 10.24px */
  --text-xs:    0.8rem;     /* 12.8px */
  --text-sm:    0.875rem;   /* 14px */
  --text-base:  1rem;       /* 16px */
  --text-md:    1.125rem;   /* 18px */
  --text-lg:    1.25rem;    /* 20px */
  --text-xl:    1.5rem;     /* 24px */
  --text-2xl:   1.875rem;   /* 30px */
  --text-3xl:   2.25rem;    /* 36px */
  --text-4xl:   3rem;       /* 48px */

  /* Line heights */
  --leading-none:    1;
  --leading-tight:   1.25;
  --leading-snug:    1.375;
  --leading-normal:  1.5;
  --leading-relaxed: 1.625;

  /* Font weights */
  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* Letter spacing */
  --tracking-tight:  -0.025em;
  --tracking-normal: 0;
  --tracking-wide:   0.025em;
  --tracking-wider:  0.05em;
  --tracking-widest: 0.1em;


  /* ── Spacing ────────────────────────────────────────────── */
  /* 4px base unit. Every value is a multiple of 4. */
  --space-0:   0;
  --space-px:  1px;
  --space-0-5: 0.125rem;  /* 2px */
  --space-1:   0.25rem;   /* 4px */
  --space-1-5: 0.375rem;  /* 6px */
  --space-2:   0.5rem;    /* 8px */
  --space-3:   0.75rem;   /* 12px */
  --space-4:   1rem;      /* 16px */
  --space-5:   1.25rem;   /* 20px */
  --space-6:   1.5rem;    /* 24px */
  --space-8:   2rem;      /* 32px */
  --space-10:  2.5rem;    /* 40px */
  --space-12:  3rem;      /* 48px */
  --space-16:  4rem;      /* 64px */
  --space-20:  5rem;      /* 80px */
  --space-24:  6rem;      /* 96px */
  --space-32:  8rem;      /* 128px */


  /* ── Border Radius ──────────────────────────────────────── */
  --radius-none: 0;
  --radius-sm:   0.25rem;   /* 4px */
  --radius-md:   0.375rem;  /* 6px */
  --radius-lg:   0.5rem;    /* 8px */
  --radius-xl:   0.75rem;   /* 12px */
  --radius-2xl:  1rem;      /* 16px */
  --radius-full: 9999px;


  /* ── Shadows ────────────────────────────────────────────── */
  /* Elevation system — layered for realism */
  --shadow-xs:  0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md:  0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg:  0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl:  0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.06);


  /* ── Transitions ────────────────────────────────────────── */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in:      cubic-bezier(0.4, 0, 1, 1);
  --ease-out:     cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out:  cubic-bezier(0.4, 0, 0.2, 1);

  --duration-fast:    150ms;
  --duration-normal:  200ms;
  --duration-slow:    300ms;
  --duration-slower:  500ms;


  /* ── Z-Index ────────────────────────────────────────────── */
  --z-base:     0;
  --z-raised:   10;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;


  /* ── Layout ─────────────────────────────────────────────── */
  --content-width:  1200px;
  --narrow-width:   720px;
  --sidebar-width:  280px;
  --gutter:         var(--space-6);
}


/* ──────────────────────────────────────────────────────────────
   2. RESET & BASE
   ────────────────────────────────────────────────────────────── */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

::selection {
  background-color: var(--blue-100);
  color: var(--blue-700);
}

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

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

a:hover {
  color: var(--color-text-link-hover);
}

button {
  font: inherit;
  cursor: pointer;
}

ul, ol {
  list-style: none;
}


/* ──────────────────────────────────────────────────────────────
   3. TYPOGRAPHY
   ────────────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
}

h1 { font-size: var(--text-4xl); }
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-md);  }

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

p + p {
  margin-top: var(--space-4);
}

small {
  font-size: var(--text-sm);
}

.text-xs     { font-size: var(--text-xs); }
.text-sm     { font-size: var(--text-sm); }
.text-base   { font-size: var(--text-base); }
.text-lg     { font-size: var(--text-lg); }
.text-xl     { font-size: var(--text-xl); }
.text-2xl    { font-size: var(--text-2xl); }
.text-3xl    { font-size: var(--text-3xl); }
.text-4xl    { font-size: var(--text-4xl); }

.font-medium   { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold     { font-weight: var(--weight-bold); }

.tracking-tight  { letter-spacing: var(--tracking-tight); }
.tracking-wide   { letter-spacing: var(--tracking-wide); }
.tracking-wider  { letter-spacing: var(--tracking-wider); }
.tracking-widest { letter-spacing: var(--tracking-widest); }

.leading-none    { line-height: var(--leading-none); }
.leading-tight   { line-height: var(--leading-tight); }
.leading-snug    { line-height: var(--leading-snug); }
.leading-normal  { line-height: var(--leading-normal); }
.leading-relaxed { line-height: var(--leading-relaxed); }

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

code {
  font-size: 0.875em;
  padding: 0.125em 0.375em;
  background: var(--color-bg-sunken);
  border-radius: var(--radius-sm);
  color: var(--color-danger);
}

pre {
  font-size: var(--text-sm);
  padding: var(--space-4);
  background: var(--gray-900);
  color: var(--gray-100);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}


/* ──────────────────────────────────────────────────────────────
   4. LAYOUT
   ────────────────────────────────────────────────────────────── */

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

.container--narrow {
  max-width: var(--narrow-width);
}

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

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

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

/* Flex utilities */
.flex          { display: flex; }
.inline-flex   { display: inline-flex; }
.flex-col      { flex-direction: column; }
.flex-row      { flex-direction: row; }
.flex-wrap     { flex-wrap: wrap; }
.items-start   { align-items: flex-start; }
.items-center  { align-items: center; }
.items-end     { align-items: flex-end; }
.justify-start   { justify-content: flex-start; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.flex-1        { flex: 1; }
.shrink-0      { flex-shrink: 0; }

/* Grid */
.grid { display: grid; }

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.grid-flow-col { grid-auto-flow: column; }

/* Gap */
.gap-1  { gap: var(--space-1); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }
.gap-10 { gap: var(--space-10); }
.gap-12 { gap: var(--space-12); }

/* Spacing */
.mt-0  { margin-top: var(--space-0); }
.mt-2  { margin-top: var(--space-2); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mt-8  { margin-top: var(--space-8); }
.mt-10 { margin-top: var(--space-10); }
.mt-12 { margin-top: var(--space-12); }
.mt-16 { margin-top: var(--space-16); }

.mb-0  { margin-bottom: var(--space-0); }
.mb-2  { margin-bottom: var(--space-2); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.mb-8  { margin-bottom: var(--space-8); }
.mb-10 { margin-bottom: var(--space-10); }
.mb-12 { margin-bottom: var(--space-12); }
.mb-16 { margin-bottom: var(--space-16); }

.mx-auto { margin-inline: auto; }

.pt-0  { padding-top: var(--space-0); }
.pt-4  { padding-top: var(--space-4); }
.pt-8  { padding-top: var(--space-8); }
.pb-4  { padding-bottom: var(--space-4); }
.pb-8  { padding-bottom: var(--space-8); }

/* Width/Max */
.w-full    { width: 100%; }
.max-w-prose { max-width: 65ch; }


/* ──────────────────────────────────────────────────────────────
   5. SCROLL ANIMATIONS
   Minimal, purposeful — only what aids comprehension.
   ────────────────────────────────────────────────────────────── */

.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity var(--duration-slow) var(--ease-out),
    transform var(--duration-slow) var(--ease-out);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children inside a container */
.stagger > .reveal:nth-child(1)  { transition-delay: 0ms; }
.stagger > .reveal:nth-child(2)  { transition-delay: 60ms; }
.stagger > .reveal:nth-child(3)  { transition-delay: 120ms; }
.stagger > .reveal:nth-child(4)  { transition-delay: 180ms; }
.stagger > .reveal:nth-child(5)  { transition-delay: 240ms; }
.stagger > .reveal:nth-child(6)  { transition-delay: 300ms; }

/* Fade variants */
.reveal--left {
  transform: translateX(-20px);
}
.reveal--left.visible {
  transform: translateX(0);
}

.reveal--right {
  transform: translateX(20px);
}
.reveal--right.visible {
  transform: translateX(0);
}

.reveal--scale {
  transform: scale(0.96);
}
.reveal--scale.visible {
  transform: scale(1);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}


/* ──────────────────────────────────────────────────────────────
   6. FOCUS STYLES
   Accessibility-first focus indicators.
   ────────────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}


/* ──────────────────────────────────────────────────────────────
   7. SCREEN READER ONLY
   ────────────────────────────────────────────────────────────── */

.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;
}


/* ============================================================
   HERO / LANDING DESIGN TOKENS
   Spec: bg #F8FAFC · text #0F172A · secondary #64748B
        accent electric blue → cyan · cards white · subtle slate borders
   ============================================================ */
:root {
  --klh-bg:        #F8FAFC;
  --klh-ink:       #0F172A;
  --klh-muted:     #64748B;
  --klh-faint:     #94A3B8;
  --klh-line:      #E2E8F0;
  --klh-line-soft: #EDF2F7;
  --klh-card:      #FFFFFF;

  --klh-accent:      #2563EB;   /* electric blue  */
  --klh-accent-soft: #38BDF8;   /* cyan            */
  --klh-cyan:        #06B6D4;
  --klh-accent-tint: rgba(37,99,235,.08);
  --klh-cyan-tint:   rgba(6,182,212,.10);

  --klh-grad: linear-gradient(115deg, #2563EB 0%, #0891B2 55%, #06B6D4 100%);

  --klh-r-sm: 8px;
  --klh-r:    12px;
  --klh-r-lg: 16px;
  --klh-r-xl: 20px;
  --klh-r-2xl:24px;
  --klh-r-video: 30px;   /* spec: 28–32px */

  --klh-shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --klh-shadow:    0 1px 3px rgba(15,23,42,.06), 0 8px 24px -12px rgba(15,23,42,.12);
  --klh-shadow-lg: 0 2px 6px rgba(15,23,42,.06), 0 24px 48px -20px rgba(15,23,42,.18);

  --klh-max: 1440px;
  --klh-nav-h: 72px;

  /* display face: Geist, then Inter, then system */
  --klh-font: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --klh-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --klh-bg:        #080C14;
    --klh-ink:       #E8EEF7;
    --klh-muted:     #94A3B8;
    --klh-faint:     #64748B;
    --klh-line:      #1E293B;
    --klh-line-soft: #172033;
    --klh-card:      #0E1420;
    --klh-accent-tint: rgba(56,189,248,.10);
    --klh-shadow:    0 1px 3px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    --klh-shadow-lg: 0 2px 6px rgba(0,0,0,.5), 0 24px 48px -20px rgba(0,0,0,.7);
  }
}
