/* ============================================================
   CalcNook Design System v2.0
   A premium, dark-first design system using modern CSS.
   
   Design Philosophy:
   - Dark mode DEFAULT — easier on the eyes for tool-heavy usage
   - oklch colors — perceptually uniform, vibrant, and future-proof
   - Glassmorphism + subtle glow — premium without being gaudy
   - Generous whitespace — tools need breathing room
   ============================================================ */

/* ──────────────────────────────────────────────────────────────
   1. COLOR SYSTEM (oklch)
   
   Why oklch? Unlike hsl, oklch is perceptually uniform — 
   a 50% lightness actually LOOKS 50% bright. This means our 
   palette feels balanced and intentional across all hues.
   ────────────────────────────────────────────────────────────── */
:root {
  /* === Brand Colors === */
  /* Primary: Electric indigo — conveys intelligence & precision */
  --color-primary: oklch(0.65 0.28 265);
  --color-primary-light: oklch(0.75 0.22 265);
  --color-primary-dark: oklch(0.50 0.30 265);
  --color-primary-glow: oklch(0.65 0.28 265 / 0.4);

  /* Accent: Vibrant cyan — freshness, modernity */
  --color-accent: oklch(0.78 0.18 195);
  --color-accent-light: oklch(0.85 0.14 195);
  --color-accent-dark: oklch(0.65 0.20 195);
  --color-accent-glow: oklch(0.78 0.18 195 / 0.35);

  /* Secondary: Warm amber — for highlights, warnings, warmth */
  --color-secondary: oklch(0.80 0.18 75);
  --color-secondary-light: oklch(0.88 0.14 75);
  --color-secondary-glow: oklch(0.80 0.18 75 / 0.35);

  /* Success / Error / Warning */
  --color-success: oklch(0.72 0.20 145);
  --color-success-light: oklch(0.82 0.14 145);
  --color-error: oklch(0.65 0.25 25);
  --color-error-light: oklch(0.75 0.18 25);
  --color-warning: oklch(0.80 0.18 85);

  /* === Surface Colors (Dark Theme) === */
  /* Layered surfaces create depth without heavy shadows */
  --surface-0: oklch(0.13 0.01 265);        /* Deepest background */
  --surface-1: oklch(0.16 0.015 265);       /* Cards, panels */
  --surface-2: oklch(0.20 0.02 265);        /* Elevated elements */
  --surface-3: oklch(0.24 0.02 265);        /* Hover states */
  --surface-4: oklch(0.28 0.02 265);        /* Active states */

  /* === Text Colors === */
  --text-primary: oklch(0.95 0.01 265);     /* High emphasis */
  --text-secondary: oklch(0.72 0.02 265);   /* Medium emphasis */
  --text-tertiary: oklch(0.55 0.02 265);    /* Low emphasis */
  --text-disabled: oklch(0.40 0.01 265);    /* Disabled */

  /* === Border Colors === */
  --border-subtle: oklch(0.25 0.02 265 / 0.6);
  --border-default: oklch(0.35 0.02 265 / 0.5);
  --border-strong: oklch(0.45 0.03 265 / 0.5);

  /* ──────────────────────────────────────────────────────────
     2. SPACING SCALE
     
     Based on 4px base unit with a modular scale.
     Consistent spacing = visual harmony.
     ────────────────────────────────────────────────────────── */
  --space-0: 0;
  --space-1: 0.25rem;    /* 4px  — micro gaps */
  --space-2: 0.5rem;     /* 8px  — tight spacing */
  --space-3: 0.75rem;    /* 12px — compact elements */
  --space-4: 1rem;       /* 16px — default spacing */
  --space-5: 1.5rem;     /* 24px — section gaps */
  --space-6: 2rem;       /* 32px — generous spacing */
  --space-7: 3rem;       /* 48px — large gaps */
  --space-8: 4rem;       /* 64px — section separators */
  --space-9: 6rem;       /* 96px — hero-level spacing */
  --space-10: 8rem;      /* 128px — page-level spacing */

  /* ──────────────────────────────────────────────────────────
     3. TYPOGRAPHY SCALE
     
     Using system font stack for speed, with a clear hierarchy.
     Clamp() for fluid typography — no breakpoint jumps.
     ────────────────────────────────────────────────────────── */
  --font-sans: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-display: 'Inter', 'SF Pro Display', -apple-system, sans-serif;

  /* Fluid type scale — min at 320px, max at 1200px */
  --text-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);
  --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --text-base: clamp(0.9rem, 0.85rem + 0.25vw, 1rem);
  --text-lg: clamp(1.05rem, 0.95rem + 0.5vw, 1.25rem);
  --text-xl: clamp(1.2rem, 1rem + 1vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
  --text-3xl: clamp(1.8rem, 1.4rem + 2vw, 2.5rem);
  --text-4xl: clamp(2.2rem, 1.6rem + 3vw, 3.5rem);
  --text-5xl: clamp(2.8rem, 2rem + 4vw, 5rem);

  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;

  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;
  --tracking-wider: 0.05em;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-extrabold: 800;

  /* ──────────────────────────────────────────────────────────
     4. RADII, SHADOWS & EFFECTS
     ────────────────────────────────────────────────────────── */
  --radius-sm: 0.375rem;     /* 6px — small chips */
  --radius-md: 0.625rem;     /* 10px — buttons */
  --radius-lg: 0.875rem;     /* 14px — cards */
  --radius-xl: 1.25rem;      /* 20px — panels */
  --radius-2xl: 1.75rem;     /* 28px — hero elements */
  --radius-full: 9999px;     /* Pills */

  /* Layered shadows for depth */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3), 0 1px 3px oklch(0 0 0 / 0.2);
  --shadow-lg: 0 8px 30px oklch(0 0 0 / 0.35), 0 2px 8px oklch(0 0 0 / 0.2);
  --shadow-xl: 0 16px 50px oklch(0 0 0 / 0.4), 0 4px 16px oklch(0 0 0 / 0.25);

  /* Glow shadows — these make elements "pop" */
  --glow-primary: 0 0 20px var(--color-primary-glow), 0 0 60px oklch(0.65 0.28 265 / 0.15);
  --glow-accent: 0 0 20px var(--color-accent-glow), 0 0 60px oklch(0.78 0.18 195 / 0.15);
  --glow-secondary: 0 0 20px var(--color-secondary-glow);

  /* ──────────────────────────────────────────────────────────
     5. TRANSITIONS & ANIMATIONS
     ────────────────────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
  --duration-slower: 600ms;

  --transition-colors: color var(--duration-normal) var(--ease-out),
                        background-color var(--duration-normal) var(--ease-out),
                        border-color var(--duration-normal) var(--ease-out);
  --transition-transform: transform var(--duration-normal) var(--ease-spring);
  --transition-shadow: box-shadow var(--duration-normal) var(--ease-out);
  --transition-all: all var(--duration-normal) var(--ease-out);
}

/* ──────────────────────────────────────────────────────────────
   6. LIGHT MODE OVERRIDE
   
   Dark is default. Light is opt-in via [data-theme="light"]
   or system preference.
   ────────────────────────────────────────────────────────────── */
[data-theme="light"],
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --surface-0: oklch(0.97 0.005 265);
    --surface-1: oklch(0.99 0.003 265);
    --surface-2: oklch(0.95 0.005 265);
    --surface-3: oklch(0.92 0.008 265);
    --surface-4: oklch(0.88 0.01 265);

    --text-primary: oklch(0.15 0.02 265);
    --text-secondary: oklch(0.40 0.02 265);
    --text-tertiary: oklch(0.55 0.02 265);
    --text-disabled: oklch(0.70 0.01 265);

    --border-subtle: oklch(0.80 0.01 265 / 0.4);
    --border-default: oklch(0.70 0.01 265 / 0.4);
    --border-strong: oklch(0.60 0.02 265 / 0.4);

    --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.08);
    --shadow-md: 0 4px 12px oklch(0 0 0 / 0.08), 0 1px 3px oklch(0 0 0 / 0.05);
    --shadow-lg: 0 8px 30px oklch(0 0 0 / 0.1), 0 2px 8px oklch(0 0 0 / 0.05);
  }
}

/* ──────────────────────────────────────────────────────────────
   7. CSS RESET & BASE STYLES
   ────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
  -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(--text-primary);
  background-color: var(--surface-0);
  min-height: 100dvh;
}

/* ──────────────────────────────────────────────────────────────
   8. UTILITY CLASSES
   ────────────────────────────────────────────────────────────── */

/* --- Glassmorphism ---
   The signature "frosted glass" effect. Works best on 
   dark backgrounds with colorful elements behind. */
.glass {
  background: oklch(0.20 0.02 265 / 0.4);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid oklch(1 0 0 / 0.08);
}

.glass-light {
  background: oklch(0.30 0.02 265 / 0.25);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid oklch(1 0 0 / 0.1);
}

.glass-strong {
  background: oklch(0.18 0.02 265 / 0.6);
  backdrop-filter: blur(30px) saturate(1.8);
  -webkit-backdrop-filter: blur(30px) saturate(1.8);
  border: 1px solid oklch(1 0 0 / 0.12);
}

/* --- Grain Texture ---
   Adds a subtle noise overlay for organic, premium feel.
   Uses SVG filter for performance. */
.grain::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  z-index: 1;
  border-radius: inherit;
}

.grain {
  position: relative;
}

/* --- Gradient Text ---
   Bold gradient text for headings and emphasis. */
.text-gradient-primary {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.text-gradient-warm {
  background: linear-gradient(135deg, var(--color-secondary), var(--color-error-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.text-gradient-cool {
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.text-gradient-hero {
  background: linear-gradient(
    135deg,
    oklch(0.90 0.15 265),
    oklch(0.80 0.22 220),
    oklch(0.75 0.18 195),
    oklch(0.85 0.15 145)
  );
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradient-shift 8s ease infinite;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* --- Glow Borders ---
   Subtle glowing border effect for interactive elements. */
.glow-border {
  position: relative;
  overflow: hidden;
}

.glow-border::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    135deg,
    var(--color-primary-glow),
    transparent 40%,
    transparent 60%,
    var(--color-accent-glow)
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.glow-border-animated::before {
  background: conic-gradient(
    from var(--glow-angle, 0deg),
    var(--color-primary-glow),
    var(--color-accent-glow),
    var(--color-secondary-glow),
    var(--color-primary-glow)
  );
  animation: rotate-glow 4s linear infinite;
}

@keyframes rotate-glow {
  to { --glow-angle: 360deg; }
}

/* Register custom property for animation */
@property --glow-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

/* --- Animated Gradient Mesh Background ---
   Creates a beautiful, organic-feeling background. 
   Pure CSS — no JavaScript needed. */
.gradient-mesh {
  position: relative;
  overflow: hidden;
}

.gradient-mesh::before {
  content: '';
  position: absolute;
  inset: -50%;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(ellipse at 20% 50%, oklch(0.45 0.25 265 / 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, oklch(0.40 0.20 195 / 0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 40% 80%, oklch(0.35 0.18 145 / 0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 60%, oklch(0.38 0.15 75 / 0.15) 0%, transparent 40%);
  animation: mesh-drift 20s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes mesh-drift {
  0% { transform: translate(0, 0) rotate(0deg) scale(1); }
  33% { transform: translate(-5%, 3%) rotate(2deg) scale(1.05); }
  66% { transform: translate(3%, -5%) rotate(-1deg) scale(0.98); }
  100% { transform: translate(-2%, 2%) rotate(1deg) scale(1.02); }
}

/* --- Shimmer / Skeleton Loading --- */
.shimmer {
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Focus Ring ---
   Accessible, beautiful focus indicators. */
.focus-ring:focus-visible,
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

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

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

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

/* ──────────────────────────────────────────────────────────────
   9. COMPONENT BASE STYLES
   ────────────────────────────────────────────────────────────── */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-all);
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--color-primary-light);
  box-shadow: var(--glow-primary);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn-accent {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent-dark));
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-accent:hover {
  box-shadow: var(--glow-accent);
  transform: translateY(-1px);
}

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-7);
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
}

/* --- Cards --- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: var(--transition-all);
}

.card:hover {
  background: var(--surface-2);
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  box-shadow: var(--shadow-lg), 0 0 30px oklch(0.65 0.28 265 / 0.08);
}

/* --- Input Fields --- */
.input-group {
  position: relative;
  width: 100%;
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: var(--transition-all);
  outline: none;
}

.input::placeholder {
  color: var(--text-tertiary);
}

.input:hover {
  border-color: var(--border-strong);
}

.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* Floating label */
.input-float {
  padding-top: var(--space-5);
}

.input-float ~ .input-label {
  position: absolute;
  top: 50%;
  left: var(--space-4);
  transform: translateY(-50%);
  font-size: var(--text-base);
  color: var(--text-tertiary);
  pointer-events: none;
  transition: var(--transition-all);
}

.input-float:focus ~ .input-label,
.input-float:not(:placeholder-shown) ~ .input-label {
  top: var(--space-2);
  transform: translateY(0);
  font-size: var(--text-xs);
  color: var(--color-primary-light);
}

/* Validation states */
.input-success {
  border-color: var(--color-success) !important;
}

.input-success:focus {
  box-shadow: 0 0 0 3px oklch(0.72 0.20 145 / 0.3) !important;
}

.input-error {
  border-color: var(--color-error) !important;
}

.input-error:focus {
  box-shadow: 0 0 0 3px oklch(0.65 0.25 25 / 0.3) !important;
}

/* --- Badge / Tag --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.badge-primary {
  background: oklch(0.65 0.28 265 / 0.15);
  color: var(--color-primary-light);
  border-color: oklch(0.65 0.28 265 / 0.25);
}

.badge-accent {
  background: oklch(0.78 0.18 195 / 0.15);
  color: var(--color-accent);
  border-color: oklch(0.78 0.18 195 / 0.25);
}

/* ──────────────────────────────────────────────────────────────
   10. ANIMATIONS LIBRARY
   ────────────────────────────────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in-down {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes count-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in { animation: fade-in var(--duration-slow) var(--ease-out) forwards; }
.animate-fade-in-up { animation: fade-in-up var(--duration-slow) var(--ease-out) forwards; }
.animate-fade-in-down { animation: fade-in-down var(--duration-slow) var(--ease-out) forwards; }
.animate-scale-in { animation: scale-in var(--duration-slow) var(--ease-spring) forwards; }

/* Stagger animation delays */
.delay-1 { animation-delay: 100ms; }
.delay-2 { animation-delay: 200ms; }
.delay-3 { animation-delay: 300ms; }
.delay-4 { animation-delay: 400ms; }
.delay-5 { animation-delay: 500ms; }
.delay-6 { animation-delay: 600ms; }

/* ──────────────────────────────────────────────────────────────
   11. RESPONSIVE UTILITIES
   ────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Container queries — modern responsive components */
@container (min-width: 400px) {
  .cq-responsive {
    flex-direction: row;
  }
}
