/* ===========================================
   10MinuteMail Design System
   Aesthetic: Cipher Terminal - Technical Minimalist
   Version: 1.0.0
   =========================================== */

/* ========================================
   FONT LOADING
   ======================================== */

/* Fonts are loaded via <link> tags in layout.html to avoid @import render-blocking */

/* ========================================
   CSS CUSTOM PROPERTIES (VARIABLES)
   ======================================== */

:root {
  /* ----------------------------------------
     COLOR SYSTEM - RAW VALUES
     Using RGB for flexible alpha manipulation
     ---------------------------------------- */

  /* Slate Scale (Primary Neutrals) */
  --raw-slate-950: 15 23 42;
  --raw-slate-900: 30 41 59;
  --raw-slate-800: 51 65 85;
  --raw-slate-700: 71 85 105;
  --raw-slate-600: 100 116 139;
  --raw-slate-500: 148 163 184;
  --raw-slate-400: 178 190 205;
  --raw-slate-300: 203 213 225;
  --raw-slate-200: 226 232 240;
  --raw-slate-100: 241 245 249;
  --raw-slate-50: 248 250 252;

  /* Accent - Electric Cyan (Privacy/Tech feel) */
  --raw-accent: 34 211 238;
  --raw-accent-bright: 103 232 249;
  --raw-accent-dim: 22 178 202;

  /* Timer States */
  --raw-safe: 52 211 153;
  --raw-warning: 251 191 36;
  --raw-danger: 248 113 113;
  --raw-danger-bright: 254 142 142;

  /* Legacy Brand Colors (for gradual migration) */
  --raw-brand-navy: 80 89 123;
  --raw-brand-blue: 97 144 211;
  --raw-brand-link: 52 152 219;

  /* ----------------------------------------
     SEMANTIC COLORS - DARK THEME (Default)
     ---------------------------------------- */

  /* Backgrounds */
  --color-bg-base: rgb(var(--raw-slate-950));
  --color-bg-elevated: rgb(var(--raw-slate-900));
  --color-bg-surface: rgb(var(--raw-slate-800));
  --color-bg-hover: rgba(var(--raw-slate-700), 0.5);
  --color-bg-active: rgba(var(--raw-slate-600), 0.3);
  --color-bg-overlay: rgba(var(--raw-slate-950), 0.85);

  /* Text */
  --color-text-primary: rgb(var(--raw-slate-100));
  --color-text-secondary: rgb(var(--raw-slate-400));
  --color-text-tertiary: rgb(var(--raw-slate-500));
  --color-text-muted: rgb(var(--raw-slate-600));
  --color-text-inverse: rgb(var(--raw-slate-900));

  /* Borders */
  --color-border-subtle: rgba(var(--raw-slate-700), 0.5);
  --color-border-default: rgba(var(--raw-slate-600), 0.4);
  --color-border-strong: rgba(var(--raw-slate-500), 0.5);
  --color-border-accent: rgba(var(--raw-accent), 0.5);

  /* Interactive/Accent */
  --color-accent: rgb(var(--raw-accent));
  --color-accent-hover: rgb(var(--raw-accent-bright));
  --color-accent-muted: rgba(var(--raw-accent), 0.15);
  --color-accent-glow: rgba(var(--raw-accent), 0.4);

  /* Buttons */
  --color-btn-primary-bg: linear-gradient(135deg, rgba(var(--raw-accent), 0.9) 0%, rgba(var(--raw-accent-dim), 1) 100%);
  --color-btn-primary-hover: linear-gradient(135deg, rgb(var(--raw-accent-bright)) 0%, rgb(var(--raw-accent)) 100%);
  --color-btn-secondary-bg: rgba(var(--raw-slate-700), 0.6);
  --color-btn-secondary-hover: rgba(var(--raw-slate-600), 0.8);

  /* Legacy button color (for migration) */
  --color-btn-legacy: rgb(var(--raw-brand-navy));
  --color-btn-legacy-hover: rgb(93 102 144);

  /* Timer States */
  --color-timer-safe: rgb(var(--raw-safe));
  --color-timer-safe-bg: rgba(var(--raw-safe), 0.1);
  --color-timer-safe-glow: rgba(var(--raw-safe), 0.3);

  --color-timer-warning: rgb(var(--raw-warning));
  --color-timer-warning-bg: rgba(var(--raw-warning), 0.1);
  --color-timer-warning-glow: rgba(var(--raw-warning), 0.35);

  --color-timer-danger: rgb(var(--raw-danger));
  --color-timer-danger-bright: rgb(var(--raw-danger-bright));
  --color-timer-danger-bg: rgba(var(--raw-danger), 0.12);
  --color-timer-danger-glow: rgba(var(--raw-danger), 0.4);

  /* Status Colors */
  --color-success: rgb(var(--raw-safe));
  --color-success-bg: rgba(var(--raw-safe), 0.12);
  --color-error: rgb(var(--raw-danger));
  --color-error-bg: rgba(var(--raw-danger), 0.12);
  --color-warning: rgb(var(--raw-warning));
  --color-warning-bg: rgba(var(--raw-warning), 0.12);

  /* Links */
  --color-link: rgb(var(--raw-accent));
  --color-link-hover: rgb(var(--raw-accent-bright));
  --color-link-visited: rgb(var(--raw-accent-dim));

  /* Focus */
  --color-focus: rgb(255 215 0);
  --color-focus-shadow: rgba(255, 215, 0, 0.25);

  /* ----------------------------------------
     TYPOGRAPHY
     ---------------------------------------- */

  /* Font Families */
  --font-display: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  --font-body: 'Space Grotesk', 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Legacy font stack (for gradual migration) */
  --font-legacy: Helvetica, Arial, sans-serif;

  /* Font Sizes - Fluid Scale */
  --text-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);      /* ~12px */
  --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);     /* ~14px */
  --text-base: clamp(0.9rem, 0.85rem + 0.25vw, 1rem);       /* ~16px */
  --text-lg: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);       /* ~18px */
  --text-xl: clamp(1.15rem, 1.05rem + 0.5vw, 1.25rem);      /* ~20px */
  --text-2xl: clamp(1.35rem, 1.2rem + 0.75vw, 1.5rem);      /* ~24px */
  --text-3xl: clamp(1.6rem, 1.4rem + 1vw, 1.875rem);        /* ~30px */
  --text-4xl: clamp(2rem, 1.7rem + 1.5vw, 2.25rem);         /* ~36px */
  --text-5xl: clamp(2.5rem, 2rem + 2.5vw, 3rem);            /* ~48px */
  --text-6xl: clamp(3rem, 2.5rem + 2.5vw, 3.75rem);         /* ~60px */

  /* Timer-specific sizes */
  --text-timer: clamp(2.5rem, 2rem + 4vw, 5rem);
  --text-timer-mobile: clamp(1.8rem, 1.5rem + 2vw, 2.5rem);

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line Heights */
  --leading-none: 1;
  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;
  --leading-loose: 1.8;

  /* Letter Spacing */
  --tracking-tighter: -0.03em;
  --tracking-tight: -0.015em;
  --tracking-normal: 0;
  --tracking-wide: 0.015em;
  --tracking-wider: 0.03em;
  --tracking-widest: 0.06em;
  --tracking-mono: 0.02em;

  /* ----------------------------------------
     SPACING SCALE
     Based on 4px grid
     ---------------------------------------- */

  --space-px: 1px;
  --space-0: 0;
  --space-0-5: 0.125rem;  /* 2px */
  --space-1: 0.25rem;     /* 4px */
  --space-1-5: 0.375rem;  /* 6px */
  --space-2: 0.5rem;      /* 8px */
  --space-2-5: 0.625rem;  /* 10px */
  --space-3: 0.75rem;     /* 12px */
  --space-3-5: 0.875rem;  /* 14px */
  --space-4: 1rem;        /* 16px */
  --space-5: 1.25rem;     /* 20px */
  --space-6: 1.5rem;      /* 24px */
  --space-7: 1.75rem;     /* 28px */
  --space-8: 2rem;        /* 32px */
  --space-9: 2.25rem;     /* 36px */
  --space-10: 2.5rem;     /* 40px */
  --space-11: 2.75rem;    /* 44px */
  --space-12: 3rem;       /* 48px */
  --space-14: 3.5rem;     /* 56px */
  --space-16: 4rem;       /* 64px */
  --space-20: 5rem;       /* 80px */
  --space-24: 6rem;       /* 96px */
  --space-28: 7rem;       /* 112px */
  --space-32: 8rem;       /* 128px */

  /* ----------------------------------------
     BORDER RADIUS
     ---------------------------------------- */

  --radius-none: 0;
  --radius-sm: 0.25rem;   /* 4px */
  --radius-default: 0.375rem;  /* 6px - matches legacy */
  --radius-md: 0.5rem;    /* 8px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-xl: 1rem;      /* 16px */
  --radius-2xl: 1.25rem;  /* 20px */
  --radius-3xl: 1.5rem;   /* 24px */
  --radius-full: 9999px;

  /* Component-specific */
  --radius-button: var(--radius-default);
  --radius-card: var(--radius-lg);
  --radius-input: var(--radius-default);
  --radius-timer: var(--radius-lg);
  --radius-badge: var(--radius-full);
  --radius-modal: var(--radius-xl);

  /* ----------------------------------------
     SHADOWS
     ---------------------------------------- */

  /* Elevation Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2), 0 4px 8px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.25), 0 8px 16px rgba(0, 0, 0, 0.15);
  --shadow-2xl: 0 24px 64px rgba(0, 0, 0, 0.3), 0 12px 24px rgba(0, 0, 0, 0.2);

  /* Inset Shadows */
  --shadow-inset-sm: inset 0 1px 2px rgba(0, 0, 0, 0.15);
  --shadow-inset-md: inset 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.05);

  /* Glow Shadows */
  --shadow-glow-accent: 0 0 20px var(--color-accent-glow), 0 0 40px rgba(var(--raw-accent), 0.2);
  --shadow-glow-safe: 0 0 20px var(--color-timer-safe-glow);
  --shadow-glow-warning: 0 0 20px var(--color-timer-warning-glow);
  --shadow-glow-danger: 0 0 25px var(--color-timer-danger-glow), 0 0 50px rgba(var(--raw-danger), 0.2);

  /* Component Shadows */
  --shadow-card: var(--shadow-md), var(--shadow-inset-top);
  --shadow-button: var(--shadow-sm);
  --shadow-button-hover: var(--shadow-md), 0 0 20px rgba(var(--raw-accent), 0.2);
  --shadow-timer: var(--shadow-lg), var(--shadow-inset-top);
  --shadow-modal: var(--shadow-2xl);
  --shadow-toast: var(--shadow-lg);

  /* Focus Shadow */
  --shadow-focus: 0 0 0 3px var(--color-focus-shadow);

  /* ----------------------------------------
     TRANSITIONS & ANIMATIONS
     ---------------------------------------- */

  /* Durations */
  --duration-instant: 50ms;
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 400ms;
  --duration-slowest: 500ms;

  /* Easings */
  --ease-linear: linear;
  --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);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);

  /* Common Transitions */
  --transition-fast: var(--duration-fast) var(--ease-out);
  --transition-normal: var(--duration-normal) var(--ease-out);
  --transition-slow: var(--duration-slow) var(--ease-out);
  --transition-bounce: var(--duration-slow) var(--ease-bounce);
  --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-out);
  --transition-all: all var(--duration-normal) var(--ease-out);

  /* ----------------------------------------
     Z-INDEX SCALE
     ---------------------------------------- */

  --z-below: -1;
  --z-base: 0;
  --z-raised: 10;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;
  --z-tooltip: 600;
  --z-max: 9999;

  /* ----------------------------------------
     LAYOUT
     ---------------------------------------- */

  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1200px;
  --container-2xl: 1400px;

  /* Content Width */
  --content-width: min(100% - var(--space-8), var(--container-lg));
  --content-width-narrow: min(100% - var(--space-8), 800px);

  /* Legacy max-width (for migration) */
  --content-max-width-legacy: 1000px;

  /* ----------------------------------------
     EFFECTS & DECORATIVE
     ---------------------------------------- */

  /* Backdrop Blur */
  --blur-sm: 4px;
  --blur-md: 8px;
  --blur-lg: 16px;
  --blur-xl: 24px;

  /* Glass Effect */
  --glass-bg: rgba(var(--raw-slate-900), 0.8);
  --glass-border: rgba(var(--raw-slate-600), 0.2);
  --glass-blur: var(--blur-lg);

  /* Noise Texture (inline SVG for grain effect) */
  --noise-texture: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  --noise-opacity: 0.03;

  /* Gradient Definitions */
  --gradient-radial-accent: radial-gradient(ellipse at 50% 0%, rgba(var(--raw-accent), 0.15) 0%, transparent 70%);
  --gradient-fade-down: linear-gradient(180deg, transparent 0%, var(--color-bg-base) 100%);
  --gradient-surface: linear-gradient(135deg, rgba(var(--raw-slate-800), 0.5) 0%, rgba(var(--raw-slate-900), 0.8) 100%);

  /* Legacy gradients (for migration) */
  --gradient-footer-legacy: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  --gradient-warning-legacy: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
  --gradient-expired-legacy: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ========================================
   LIGHT THEME
   ======================================== */

@media (prefers-color-scheme: light) {
  :root {
    /* Background overrides */
    --color-bg-base: rgb(var(--raw-slate-50));
    --color-bg-elevated: rgb(var(--raw-slate-100));
    --color-bg-surface: #ffffff;
    --color-bg-hover: rgba(var(--raw-slate-200), 0.7);
    --color-bg-active: rgba(var(--raw-slate-300), 0.5);
    --color-bg-overlay: rgba(0, 0, 0, 0.5);

    /* Text overrides */
    --color-text-primary: rgb(var(--raw-slate-900));
    --color-text-secondary: rgb(var(--raw-slate-600));
    --color-text-tertiary: rgb(var(--raw-slate-500));
    --color-text-muted: rgb(var(--raw-slate-400));
    --color-text-inverse: rgb(var(--raw-slate-50));

    /* Border overrides */
    --color-border-subtle: rgba(var(--raw-slate-300), 0.5);
    --color-border-default: rgba(var(--raw-slate-300), 0.8);
    --color-border-strong: rgba(var(--raw-slate-400), 0.6);

    /* Adjusted accent for light mode (deeper for contrast) */
    --raw-accent: 14 165 233;
    --color-accent: rgb(var(--raw-accent));
    --color-accent-muted: rgba(var(--raw-accent), 0.1);
    --color-accent-glow: rgba(var(--raw-accent), 0.25);

    /* Adjusted button colors */
    --color-btn-secondary-bg: rgba(var(--raw-slate-200), 0.8);
    --color-btn-secondary-hover: rgba(var(--raw-slate-300), 0.9);

    /* Adjusted shadows for light mode */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);

    /* Inset shadows */
    --shadow-inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.8);

    /* Glass for light mode */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(var(--raw-slate-300), 0.3);

    /* Adjusted noise for light */
    --noise-opacity: 0.015;
  }
}

/* ========================================
   MANUAL THEME TOGGLE SUPPORT
   ======================================== */

[data-theme="dark"] {
  --color-bg-base: rgb(var(--raw-slate-950));
  --color-bg-elevated: rgb(var(--raw-slate-900));
  --color-bg-surface: rgb(var(--raw-slate-800));
  --color-bg-hover: rgba(var(--raw-slate-700), 0.5);
  --color-text-primary: rgb(var(--raw-slate-100));
  --color-text-secondary: rgb(var(--raw-slate-400));
  --color-border-subtle: rgba(var(--raw-slate-700), 0.5);
  --color-border-default: rgba(var(--raw-slate-600), 0.4);
}

[data-theme="light"] {
  --color-bg-base: rgb(var(--raw-slate-50));
  --color-bg-elevated: rgb(var(--raw-slate-100));
  --color-bg-surface: #ffffff;
  --color-bg-hover: rgba(var(--raw-slate-200), 0.7);
  --color-text-primary: rgb(var(--raw-slate-900));
  --color-text-secondary: rgb(var(--raw-slate-600));
  --color-border-subtle: rgba(var(--raw-slate-300), 0.5);
  --color-border-default: rgba(var(--raw-slate-300), 0.8);
}

/* ========================================
   TIMER STATE UTILITY CLASSES
   ======================================== */

.timer-state-safe {
  --timer-color: var(--color-timer-safe);
  --timer-bg: var(--color-timer-safe-bg);
  --timer-glow: var(--shadow-glow-safe);
}

.timer-state-warning {
  --timer-color: var(--color-timer-warning);
  --timer-bg: var(--color-timer-warning-bg);
  --timer-glow: var(--shadow-glow-warning);
}

.timer-state-danger {
  --timer-color: var(--color-timer-danger);
  --timer-bg: var(--color-timer-danger-bg);
  --timer-glow: var(--shadow-glow-danger);
}

/* ========================================
   ACCESSIBILITY: REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-instant: 0ms;
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
    --duration-slower: 0ms;
    --duration-slowest: 0ms;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   ACCESSIBILITY: HIGH CONTRAST
   ======================================== */

@media (prefers-contrast: high) {
  :root {
    --color-border-subtle: var(--color-text-secondary);
    --color-border-default: var(--color-text-primary);
    --color-accent: rgb(0 200 255);
    --color-focus: rgb(255 255 0);
  }
}

/* ========================================
   BASE RESET WITH DESIGN SYSTEM
   ======================================== */

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

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
}

body {
  min-height: 100vh;
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Visually hidden but accessible */
.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;
}

/* Focus visible utility */
.focus-ring:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
  box-shadow: var(--shadow-focus);
}
