/* ===== IDAVOLL DESIGN SYSTEM ===== */
/* Theme-aware token architecture */
/* Invariants in :root, theme colors in [data-theme] selectors */

:root {
  /* ===== INVARIANT TOKENS ===== */
  /* These NEVER change between themes */

  /* ===== TYPOGRAPHY ===== */
  /* Archivo - Industrial, geometric, no-nonsense */
  --font-family: 'Archivo', system-ui, -apple-system, sans-serif;
  --font-family-display: 'Archivo', system-ui, sans-serif;
  /* JetBrains Mono - For data, stats, numbers */
  --font-family-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Font sizes - named by use, not tier */
  --font-size-tiny: 0.625rem; /* 10px - tiny labels */
  --font-size-caption: 0.6875rem; /* 11px - badges, captions */
  --font-size-label: 0.75rem; /* 12px - labels, metadata */
  --font-size-body: 0.8125rem; /* 13px - body text (BASE) */
  --font-size-body-large: 0.875rem; /* 14px - body large */
  --font-size-subheading: 1rem; /* 16px - subheadings */
  --font-size-heading-small: 1.125rem; /* 18px - small headings */
  --font-size-heading: 1.25rem; /* 20px - section headers */
  --font-size-title: 1.5rem; /* 24px - card titles */
  --font-size-display: 2rem; /* 32px - page titles */
  --font-size-hero: 2.5rem; /* 40px - hero numbers */
  --font-size-jumbo: 3rem; /* 48px - big stats */
  --font-size-avatar-micro: 0.5rem; /* 8px - micro avatar initials */

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

  /* Line heights */
  --line-height-tight: 1.2;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.7;

  /* Letter spacing */
  --letter-spacing-tight: -0.01em;
  --letter-spacing-normal: 0;
  --letter-spacing-wide: 0.06em;
  --letter-spacing-wider: 0.08em;
  --letter-spacing-widest: 0.12em;

  /* ===== SPACING ===== */
  /* Named by feel, not number */
  --space-pixel: 1px;
  --space-micro: 2px;
  --space-small: 3px;
  --space-hairline: 4px;
  --space-tight: 8px;
  --space-snug: 12px;
  --space-default: 16px;
  --space-comfortable: 20px;
  --space-loose: 24px;
  --space-roomy: 32px;
  --space-spacious: 40px;
  --space-airy: 48px;
  --space-generous: 64px;

  /* ===== BORDER RADIUS ===== */
  /* Sharp, not soft. Architectural, not friendly. */
  --radius-sharp: 2px;
  --radius-subtle: 3px;
  --radius-default: 4px;
  --radius-rounded: 6px;
  --radius-large: 8px;
  --radius-pill: 9999px;

  /* ===== PROGRESS / SEGMENTS ===== */
  --progress-height-thin: 4px;
  --progress-height-default: 6px;
  --progress-height-thick: 10px;

  --segment-width: 28px;
  --segment-height: 10px;
  --segment-gap: 3px;

  /* ===== CONTROL SIZES ===== */
  /* Button heights */
  --button-height-compact: 28px;
  --button-height-default: 36px;
  --button-height-large: 44px;

  /* Input/form control heights */
  --control-height-compact: 32px;
  --control-height-default: 40px;
  --control-height-large: 52px;

  --toggle-width: 52px;
  --toggle-height: 28px;
  --toggle-thumb-size: 20px;
  --toggle-thumb-inset: 4px;

  --checkbox-size: 22px;
  --radio-size: 18px;
  --radio-dot-size: 8px;

  /* Toast sizing */
  --toast-icon-badge-size: 22px;
  --toast-icon-size: 12px;

  /* Badge sizing */
  --badge-height: 18px;
  --badge-padding-y: 2px;
  --badge-padding-x: 6px;
  --badge-line-height: 14px;

  /* Activity grid legend */
  --activity-legend-cell-size: 12px;

  --icon-size-tiny: 12px;
  --icon-size-small: 14px;
  --icon-size-default: 16px;
  --icon-size-medium: 18px;
  --icon-size-large: 20px;
  --icon-size-xlarge: 24px;
  --icon-size-jumbo: 32px;

  /* Feature card play button */
  --play-button-size-default: 64px;
  --play-button-size-featured: 80px;
  --play-button-size-compact: 48px;
  --play-button-icon-default: 28px;
  --play-button-icon-featured: 36px;
  --play-button-icon-compact: 20px;
  --play-button-icon-offset: 3px;

  /* Action buttons (icon-only small buttons) */
  --action-button-size-default: 36px;
  --action-button-size-compact: 28px;

  /* Leaderboard sizing */
  --leaderboard-rank-width: 32px;
  --leaderboard-trend-width: 20px;
  --leaderboard-arrow-size: 5px;
  --leaderboard-arrow-height: 6px;
  --leaderboard-dash-width: 10px;
  --leaderboard-dash-height: 2px;

  /* Item card */
  --item-icon-container-size: 56px;
  --item-emoji-size: 36px;

  /* Rank card */
  --rank-icon-container-size: 80px;
  --rank-card-max-width: 480px;

  /* MMR display */
  --mmr-display-min-width: 420px;
  --mmr-display-min-width-compact: 320px;

  --avatar-size-micro: 20px;
  --avatar-size-tiny: 24px;
  --avatar-size-compact: 28px;
  --avatar-size-default: 36px;
  --avatar-size-large: 48px;
  --avatar-overlap-default: -8px;
  --avatar-overlap-compact: -6px;

  --status-dot-size-small: 5px;
  --status-dot-size: 6px;

  /* ===== LAYOUT ===== */
  --bottom-nav-height: 56px;
  --game-bar-height: 52px;
  --layout-max-width-narrow: 400px;
  --layout-max-width-medium: 540px;
  --layout-max-width-default: 740px;
  --layout-max-width-wide: 1600px;

  --card-image-height: 180px;

  --activity-cell-size: 20px;
  --activity-gap: 2px;

  /* ===== VIEWPORT BREAKPOINTS ===== */
  --viewport-phone-max: 639px;
  --viewport-tablet-min: 640px;
  --viewport-tablet-max: 1023px;
  --viewport-desktop-min: 1024px;

  /* ===== SAFE AREA INSETS ===== */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);

  /* ===== ANIMATION ===== */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.645, 0.045, 0.355, 1);
  /* why: Spring easing with overshoot for satisfying "pop" effects (bar charts, checkboxes, etc) */
  --ease-out-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --duration-instant: 50ms;
  --duration-fast: 100ms;
  --duration-default: 180ms;
  --duration-slow: 300ms;
  /* why: For staggered/sequenced animations where individual elements need quick pops */
  --duration-pop: 250ms;

  /* ===== Z-INDEX ===== */
  --z-dropdown: 100;
  --z-overlay: 150;
  --z-modal: 200;
  /* why: Portaled popups (select, popover, tooltip) must render above modals */
  --z-popover: 250;
  --z-toast: 300;

  /* ===== MISC (Invariant) ===== */
  --border-width: 1px;
  --border-width-thick: 2px;
  --outline-width: 2px;
  --outline-offset: 2px;
  --toast-border-width: 3px;
  --opacity-disabled: 0.5;
  --opacity-hover: 0.9;

  /* ===== COMPONENT-SPECIFIC SIZES ===== */
  --dialog-max-width: 28rem;
  --drawer-max-height: 96vh;
  --drawer-content-max-width: 480px;
  --focus-ring-width: 2px;
  --focus-ring-offset: 4px;

  /* Base colors (theme-independent) */
  --color-white: #ffffff;
  --color-black: #000000;
}

/* ===== DARK THEME ===== */
/* Sharp, architectural, immersive gaming UI */
[data-theme='dark'] {
  /* ===== BACKGROUND COLORS (Depth Layers) ===== */
  /* Darker = further back, lighter = closer/floating */
  --color-background-page: #08080a; /* Page background - the infinite back */
  --color-background-inset: #0c0c0e; /* Inset areas - recessed elements */
  --color-background-card: #111113; /* Card backgrounds - mid layer */
  --color-background-raised: #18181b; /* Raised surfaces - near layer */
  --color-background-surface: #1f1f23; /* Interactive surfaces */
  --color-background-surface-alt: #27272b; /* Alternate surface for patterns */
  --color-background-hover: #28282d; /* Hover states - floating */
  --color-background-floating: #323238; /* Tooltips, dropdowns - highest */

  /* ===== TEXT COLORS (Hierarchy) ===== */
  --color-text-primary: #ececee; /* Headings, important values */
  --color-text-secondary: #94949c; /* Body text */
  --color-text-tertiary: #5c5c63; /* Descriptions, hints */
  --color-text-disabled: #3a3a3f; /* Labels, disabled states */
  --color-text-inverse: #08080a; /* Text on light backgrounds */

  /* ===== ACCENT COLORS ===== */
  /* Warm cream - like a light source, not a highlight */
  --color-accent: #e8e4d9;
  --color-accent-light: #f0ede3;
  --color-accent-muted: #c9c5b8;
  --color-accent-dim: rgba(232, 228, 217, 0.08);
  --color-accent-glow: rgba(232, 228, 217, 0.3);

  /* Cream alias - for branding/logo use */
  --color-cream: #e8e4d9;
  --color-cream-glow: rgba(232, 228, 217, 0.4);
  --color-cream-dim: rgba(232, 228, 217, 0.15);

  /* Cool teal - primary interactive color */
  --color-teal: #5eead4;
  --color-teal-light: #7aeee0;
  --color-teal-hover: #4dd4be;
  --color-teal-muted: rgba(94, 234, 212, 0.15);
  --color-teal-dim: rgba(94, 234, 212, 0.1);
  --color-teal-glow: rgba(94, 234, 212, 0.3);
  --color-teal-glow-strong: rgba(94, 234, 212, 0.5);
  --color-teal-border: rgba(94, 234, 212, 0.2);

  /* Teal intensity scale (for heatmaps/activity grids) */
  --color-teal-intensity-1: rgba(94, 234, 212, 0.2);
  --color-teal-intensity-2: rgba(94, 234, 212, 0.4);
  --color-teal-intensity-3: rgba(94, 234, 212, 0.6);

  /* ===== SEMANTIC COLORS ===== */
  --color-green: #4ade80; /* Success, positive delta, wins */
  --color-green-dim: rgba(74, 222, 128, 0.1);
  --color-green-glow: rgba(74, 222, 128, 0.3);
  --color-green-glow-strong: rgba(74, 222, 128, 0.5);
  --color-green-border: rgba(74, 222, 128, 0.2);

  --color-red: #f87171; /* Error, negative delta, losses */
  --color-red-light: #ff8a8a;
  --color-red-dark: #e05858;
  --color-red-dim: rgba(248, 113, 113, 0.1);
  --color-red-glow: rgba(248, 113, 113, 0.3);
  --color-red-glow-strong: rgba(248, 113, 113, 0.5);
  --color-red-border: rgba(248, 113, 113, 0.15);

  --color-amber: #fbbf24; /* Warning, gold ranks, streaks */
  --color-amber-dim: rgba(251, 191, 36, 0.1);
  --color-amber-glow: rgba(251, 191, 36, 0.3);
  --color-amber-glow-strong: rgba(251, 191, 36, 0.5);
  --color-amber-border: rgba(251, 191, 36, 0.15);

  /* Chart series colors — for multi-cohort visualizations (retention curves, etc.) */
  --color-blue: #60a5fa;
  --color-blue-dim: rgba(96, 165, 250, 0.1);
  --color-blue-glow: rgba(96, 165, 250, 0.3);

  --color-purple: #a78bfa;
  --color-purple-dim: rgba(167, 139, 250, 0.1);
  --color-purple-glow: rgba(167, 139, 250, 0.3);

  --color-pink: #f472b6;
  --color-pink-dim: rgba(244, 114, 182, 0.1);
  --color-pink-glow: rgba(244, 114, 182, 0.3);

  /* ===== FILL COLORS ===== */
  /* Solid, juicy backgrounds for interactive surfaces on dark canvases */
  /* Derived at ~40% lightness (fill) and ~55% lightness (fill-active) */
  --color-teal-fill: #17615a;
  --color-teal-fill-active: #1f877d;

  --color-green-fill: #1a6b3a;
  --color-green-fill-active: #25944f;

  --color-blue-fill: #2a5a99;
  --color-blue-fill-active: #3a78c4;

  --color-purple-fill: #4a3599;
  --color-purple-fill-active: #6548c4;

  --color-amber-fill: #8a6b10;
  --color-amber-fill-active: #b58c18;

  --color-pink-fill: #8a2e5e;
  --color-pink-fill-active: #b53d7a;

  --color-red-fill: #993030;
  --color-red-fill-active: #c44040;

  /* ===== RANK COLORS ===== */
  --color-rank-gold: #d4a656;
  --color-rank-silver: #a8a8a8;
  --color-rank-bronze: #b87333;

  /* Tier colors for MMR */
  --color-tier-bronze: #b87333;
  --color-tier-silver: #a8a8a8;
  --color-tier-gold: #d4a656;
  --color-tier-platinum: #5eead4;
  --color-tier-plat: #5eead4; /* alias for platinum */
  --color-tier-diamond: #a855f7;

  /* Rarity colors */
  --color-rarity-legendary: #d4a656;
  --color-rarity-epic: #a855f7;
  --color-rarity-rare: #3b82f6;
  --color-rarity-common: #5c5c63;

  /* Rarity border colors - 30% opacity for subtle card borders */
  --color-rarity-legendary-border: rgba(212, 166, 86, 0.3);
  --color-rarity-epic-border: rgba(168, 85, 247, 0.3);
  --color-rarity-rare-border: rgba(59, 130, 246, 0.3);
  --color-rarity-common-border: rgba(92, 92, 99, 0.3);

  /* Rarity dim backgrounds - for badges */
  --color-rarity-legendary-dim: rgba(212, 166, 86, 0.15);
  --color-rarity-epic-dim: rgba(168, 85, 247, 0.15);
  --color-rarity-rare-dim: rgba(59, 130, 246, 0.15);
  --color-rarity-common-dim: rgba(92, 92, 99, 0.15);

  /* ===== BORDER COLORS ===== */
  /* Subtle - edges feel like light catching geometry */
  --color-border-subtle: rgba(255, 255, 255, 0.03);
  --color-border-default: rgba(255, 255, 255, 0.06);
  --color-border-emphasis: rgba(255, 255, 255, 0.09);
  --color-border-focus: #c9c5b8;

  /* ===== SHADOW PRIMITIVES ===== */
  /* Inset highlights for button depth */
  --shadow-highlight-subtle: rgba(255, 255, 255, 0.06);
  --shadow-highlight-default: rgba(255, 255, 255, 0.12);
  --shadow-highlight-medium: rgba(255, 255, 255, 0.15);
  --shadow-highlight-strong: rgba(255, 255, 255, 0.2);
  --shadow-highlight-intense: rgba(255, 255, 255, 0.25);
  --shadow-highlight-max: rgba(255, 255, 255, 0.3);

  /* Drop shadows */
  --shadow-drop-subtle: rgba(0, 0, 0, 0.2);
  --shadow-drop-default: rgba(0, 0, 0, 0.3);

  /* Elevated button shadows (dark theme: depth only, no highlights) */
  --shadow-button-inner: 0 0 0 0 transparent;
  --shadow-button-depth: 0 2px 6px rgba(0, 0, 0, 0.6);
  --shadow-button-rim: 0 0 0 0 transparent;

  /* ===== FOCUS RINGS ===== */
  --focus-ring: 0 0 0 2px var(--color-accent-muted);
  --focus-ring-teal: 0 0 0 2px var(--color-teal-dim);
  --focus-ring-error: 0 0 0 2px var(--color-red-dim);

  /* ===== OVERLAY COLORS ===== */
  /* For gradient overlays on images/media */
  /* why: CSS variables can't be used in rgba() for alpha manipulation */
  --color-overlay-light: rgba(17, 17, 19, 0.2);
  --color-overlay-medium: rgba(17, 17, 19, 0.5);
  --color-overlay-heavy: rgba(17, 17, 19, 0.7);

  /* ===== HATCH PATTERN ===== */
  /* Diagonal hatch for empty/unfilled areas */
  /* why: CSS variables can't be used in gradient stops reliably, so we hardcode the colors */
  /* Colors match --color-background-surface (#1f1f23) and --color-background-surface-alt (#27272b) */
  --hatch-pattern: repeating-linear-gradient(
    -45deg,
    #1f1f23 0px,
    #1f1f23 3px,
    #27272b 3px,
    #27272b 6px
  );
}

/* ===== LIGHT THEME ===== */
/* Cool slate palette - sophisticated, muted, professional */
[data-theme='light'] {
  /* ===== BACKGROUND COLORS (Depth Layers - Cool Slate) ===== */
  /* Darker = further back (void), lighter = closer/floating */
  --color-background-page: #c4c7cc; /* The void - cool slate base */
  --color-background-inset: #cccfd4; /* Recessed areas */
  --color-background-card: #d5d8dc; /* Card backgrounds */
  --color-background-raised: #dee0e4; /* Raised surfaces */
  --color-background-surface: #e7e9ec; /* Interactive surfaces */
  --color-background-surface-alt: #eff1f3; /* Alternate surface */
  --color-background-hover: #f7f8f9; /* Hover states */
  --color-background-floating: #ffffff; /* Tooltips, dropdowns - highest */

  /* ===== TEXT COLORS (Hierarchy) ===== */
  --color-text-primary: #1a1d21; /* Headings, important values */
  --color-text-secondary: #4a4f57; /* Body text */
  --color-text-tertiary: #7a7f88; /* Descriptions, hints */
  --color-text-disabled: #a5aab3; /* Labels, disabled states */
  --color-text-inverse: #ffffff; /* Text on dark backgrounds */

  /* ===== ACCENT COLORS (Dark Slate) ===== */
  /* Inverted from dark theme - accent is now dark on light */
  --color-accent: #2d3139;
  --color-accent-light: #3d424c;
  --color-accent-muted: #454b55;
  --color-accent-dim: rgba(45, 49, 57, 0.08);
  --color-accent-glow: rgba(45, 49, 57, 0.12);
  /* Button gradient stops for light theme */
  --color-accent-gradient-start: #3d434d;
  --color-accent-gradient-hover: #4d535d;

  /* Cream alias - uses teal glow in light mode for contrast */
  --color-cream: #1a1d21;
  --color-cream-glow: rgba(45, 122, 90, 0.3);
  --color-cream-dim: rgba(45, 122, 90, 0.15);

  /* ===== TEAL (Forest Green) ===== */
  /* Deeper, more saturated green for light backgrounds */
  --color-teal: #2d7a5a;
  --color-teal-light: #3d8a6a;
  --color-teal-hover: #1d6a4a;
  --color-teal-muted: rgba(45, 122, 90, 0.15);
  --color-teal-dim: rgba(45, 122, 90, 0.12);
  --color-teal-glow: rgba(45, 122, 90, 0.2);
  --color-teal-glow-strong: rgba(45, 122, 90, 0.35);
  --color-teal-border: rgba(45, 122, 90, 0.2);
  /* Button gradient stops for light theme */
  --color-teal-gradient-start: #3d9a72;
  --color-teal-gradient-hover: #4daa82;

  /* Teal intensity scale (for heatmaps/activity grids) */
  --color-teal-intensity-1: rgba(45, 122, 90, 0.25);
  --color-teal-intensity-2: rgba(45, 122, 90, 0.45);
  --color-teal-intensity-3: rgba(45, 122, 90, 0.65);

  /* ===== SEMANTIC COLORS ===== */
  --color-green: #059669; /* Success - emerald */
  --color-green-dim: rgba(5, 150, 105, 0.1);
  --color-green-glow: rgba(5, 150, 105, 0.2);
  --color-green-glow-strong: rgba(5, 150, 105, 0.35);
  --color-green-border: rgba(5, 150, 105, 0.2);

  --color-red: #dc2626; /* Error - vivid red */
  --color-red-light: #ef4444;
  --color-red-dark: #b91c1c;
  --color-red-dim: rgba(220, 38, 38, 0.1);
  --color-red-glow: rgba(220, 38, 38, 0.2);
  --color-red-glow-strong: rgba(220, 38, 38, 0.35);
  --color-red-border: rgba(220, 38, 38, 0.15);

  --color-amber: #d97706; /* Warning - deep amber */
  --color-amber-dim: rgba(217, 119, 6, 0.1);
  --color-amber-glow: rgba(217, 119, 6, 0.2);
  --color-amber-glow-strong: rgba(217, 119, 6, 0.35);
  --color-amber-border: rgba(217, 119, 6, 0.15);

  /* Chart series colors — for multi-cohort visualizations (retention curves, etc.) */
  --color-blue: #2563eb;
  --color-blue-dim: rgba(37, 99, 235, 0.1);
  --color-blue-glow: rgba(37, 99, 235, 0.2);

  --color-purple: #7c3aed;
  --color-purple-dim: rgba(124, 58, 237, 0.1);
  --color-purple-glow: rgba(124, 58, 237, 0.2);

  --color-pink: #db2777;
  --color-pink-dim: rgba(219, 39, 119, 0.1);
  --color-pink-glow: rgba(219, 39, 119, 0.2);

  /* ===== FILL COLORS ===== */
  --color-teal-fill: #d0f5ed;
  --color-teal-fill-active: #a8eadb;

  --color-green-fill: #d1f5dc;
  --color-green-fill-active: #a8eab8;

  --color-blue-fill: #d0e4f7;
  --color-blue-fill-active: #a8cff0;

  --color-purple-fill: #e0d4f7;
  --color-purple-fill-active: #c8b4f0;

  --color-amber-fill: #f5e8c4;
  --color-amber-fill-active: #ecd89a;

  --color-pink-fill: #f5d0e4;
  --color-pink-fill-active: #eaa8cc;

  --color-red-fill: #f5d0d0;
  --color-red-fill-active: #eaa8a8;

  /* ===== RANK COLORS ===== */
  /* Richer, more saturated for light backgrounds */
  --color-rank-gold: #b8860b;
  --color-rank-silver: #64748b;
  --color-rank-bronze: #92400e;

  /* Tier colors for MMR */
  --color-tier-bronze: #92400e;
  --color-tier-silver: #64748b;
  --color-tier-gold: #b8860b;
  --color-tier-platinum: #2d7a5a;
  --color-tier-plat: #2d7a5a;
  --color-tier-diamond: #7c3aed;

  /* Rarity colors */
  --color-rarity-legendary: #b8860b;
  --color-rarity-epic: #7c3aed;
  --color-rarity-rare: #2563eb;
  --color-rarity-common: #64748b;

  /* Rarity border colors */
  --color-rarity-legendary-border: rgba(184, 134, 11, 0.3);
  --color-rarity-epic-border: rgba(124, 58, 237, 0.3);
  --color-rarity-rare-border: rgba(37, 99, 235, 0.3);
  --color-rarity-common-border: rgba(100, 116, 139, 0.3);

  /* Rarity dim backgrounds - for badges */
  --color-rarity-legendary-dim: rgba(184, 134, 11, 0.15);
  --color-rarity-epic-dim: rgba(124, 58, 237, 0.15);
  --color-rarity-rare-dim: rgba(37, 99, 235, 0.15);
  --color-rarity-common-dim: rgba(100, 116, 139, 0.15);

  /* ===== BORDER COLORS ===== */
  /* Crisp edges on cool slate backgrounds */
  --color-border-subtle: rgba(0, 0, 0, 0.05);
  --color-border-default: rgba(0, 0, 0, 0.08);
  --color-border-emphasis: rgba(0, 0, 0, 0.12);
  --color-border-focus: rgba(45, 122, 90, 0.4);

  /* ===== SHADOW PRIMITIVES ===== */
  /* Inset highlights - white for depth on slate backgrounds */
  --shadow-highlight-subtle: rgba(255, 255, 255, 0.4);
  --shadow-highlight-default: rgba(255, 255, 255, 0.55);
  --shadow-highlight-medium: rgba(255, 255, 255, 0.65);
  --shadow-highlight-strong: rgba(255, 255, 255, 0.75);
  --shadow-highlight-intense: rgba(255, 255, 255, 0.85);
  --shadow-highlight-max: rgba(255, 255, 255, 0.95);

  /* Drop shadows - subtle on light backgrounds */
  --shadow-drop-subtle: rgba(0, 0, 0, 0.08);
  --shadow-drop-default: rgba(0, 0, 0, 0.15);

  /* Elevated button shadows (light theme: dark shadows only) */
  --shadow-button-inner: 0 0 0 0 transparent;
  --shadow-button-depth: 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-button-rim: 0 0 0 0 transparent;

  /* ===== FOCUS RINGS ===== */
  --focus-ring: 0 0 0 2px var(--color-accent-muted);
  --focus-ring-teal: 0 0 0 2px var(--color-teal-dim);
  --focus-ring-error: 0 0 0 2px var(--color-red-dim);

  /* ===== OVERLAY COLORS ===== */
  /* For gradient overlays on images/media */
  --color-overlay-light: rgba(196, 199, 204, 0.3);
  --color-overlay-medium: rgba(196, 199, 204, 0.55);
  --color-overlay-heavy: rgba(196, 199, 204, 0.75);

  /* ===== HATCH PATTERN ===== */
  /* why: CSS variables can't be used in gradient stops reliably */
  /* Colors match light theme surface (#e7e9ec) and surface-alt (#eff1f3) */
  --hatch-pattern: repeating-linear-gradient(
    -45deg,
    #e7e9ec 0px,
    #e7e9ec 3px,
    #eff1f3 3px,
    #eff1f3 6px
  );
}

/* ===== INPUT COMPONENT (BEM) ===== */
/* Sharp form controls with subtle depth */

.input {
  /* why: Size modifiers override this for consistent textarea sizing */
  --input-control-height: var(--control-height-default);

  display: block;
  width: 100%;
  padding: var(--space-tight) var(--space-default);
  min-height: var(--input-control-height);

  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  caret-color: var(--color-teal);

  -webkit-appearance: none;
  appearance: none;
  background-color: var(--color-background-inset);
  border: var(--border-width) solid var(--color-border-default);
  border-radius: var(--radius-subtle);
  box-shadow: inset 0 1px 0 var(--shadow-highlight-subtle);

  transition:
    border-color var(--duration-fast) var(--ease-default),
    background-color var(--duration-fast) var(--ease-default);
}

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

@media (hover: hover) {
  .input:hover:not(:disabled) {
    border-color: var(--color-border-emphasis);
    background-color: var(--color-background-card);
  }
}

.input:focus {
  border-color: var(--color-teal);
  /* why: Double ring matches other controls (e.g. select trigger) for crisp focus */
  box-shadow:
    inset 0 1px 0 var(--shadow-highlight-default),
    0 0 0 2px var(--color-background-page),
    0 0 0 4px var(--color-teal-border);
  outline: none;
}

.input:disabled {
  background-color: var(--color-background-raised);
  color: var(--color-text-disabled);
  box-shadow: inset 0 1px 0 transparent;
  cursor: not-allowed;
}

/* ===== VARIANTS ===== */

.input--error {
  border-color: var(--color-red);
  caret-color: var(--color-red);
}

.input--error:focus {
  border-color: var(--color-red);
  box-shadow:
    inset 0 1px 0 var(--shadow-highlight-default),
    0 0 0 2px var(--color-background-page),
    0 0 0 4px var(--color-red-border);
}

/* ===== SIZES ===== */

.input--compact {
  --input-control-height: var(--control-height-compact);
  padding: var(--space-hairline) var(--space-tight);
  font-size: var(--font-size-tiny);
}

.input--large {
  --input-control-height: var(--control-height-large);
  padding: var(--space-default);
  font-size: var(--font-size-body-large);
}

/* ===== TEXTAREA ===== */

textarea.input {
  /* why: Baseline gives ~3 lines of readable text without feeling enormous */
  min-height: calc(var(--input-control-height) * 3);
  resize: none;
}

@media (hover: hover) {
  textarea.input {
    resize: vertical;
  }
}

/* ===== REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {
  .input {
    transition: none;
  }
}

/* ===== BUTTON COMPONENT (BEM) ===== */
/* Sharp interactive controls with depth and polish */

.button {
  /* Reset browser defaults */
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  background-color: transparent;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-tight);
  height: var(--button-height-default);
  padding: 0 var(--space-default);
  font-family: var(--font-family);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  text-decoration: none;
  border: none;
  border-radius: var(--radius-subtle);
  cursor: pointer;
  /* why: Motion handles transform transitions via spring physics */
  transition: box-shadow var(--duration-fast) var(--ease-default);
  position: relative;
  user-select: none;
}

.button:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--color-background-page),
    0 0 0 4px var(--color-accent);
}

.button:disabled,
.button--disabled {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== VARIANTS ===== */

/* Primary - elevated warm accent (kargul-style: inner highlight + dark stroke) */
.button--primary {
  background: linear-gradient(0deg, var(--color-accent-muted) 0%, var(--color-accent) 100%);
  color: var(--color-background-page);
  border: 1px solid var(--color-accent-muted);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.3);
}

@media (hover: hover) {
  .button--primary:hover {
    background: linear-gradient(0deg, var(--color-accent) 0%, var(--color-accent-light) 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.6),
      0 4px 8px rgba(0, 0, 0, 0.35);
  }
}

/* why: Motion handles tap transform via interactiveProps.standard */
.button--primary:active {
  background: var(--color-accent-muted);
  border-color: var(--color-accent-muted);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Secondary - elevated dark (dark-on-dark: depth shadow only) */
.button--secondary {
  background: linear-gradient(
    180deg,
    var(--color-background-card) 0%,
    var(--color-background-hover) 100%
  );
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-subtle);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

@media (hover: hover) {
  .button--secondary:hover {
    background: linear-gradient(
      180deg,
      var(--color-background-raised) 0%,
      var(--color-background-floating) 100%
    );
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
  }
}

.button--secondary:active {
  background: var(--color-background-card);
  border-color: var(--color-border-subtle);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Outline - bordered */
.button--outline {
  background: transparent;
  color: var(--color-text-secondary);
  box-shadow: inset 0 0 0 1px var(--color-border-emphasis);
}

@media (hover: hover) {
  .button--outline:hover {
    background: var(--color-background-card);
    color: var(--color-text-primary);
    box-shadow: inset 0 0 0 1px var(--shadow-highlight-default);
  }
}

.button--outline:active {
  background: var(--color-background-raised);
}

/* Ghost - minimal */
.button--ghost {
  background: transparent;
  color: var(--color-text-tertiary);
  box-shadow: none;
}

@media (hover: hover) {
  .button--ghost:hover {
    background: var(--color-background-card);
    color: var(--color-text-primary);
  }
}

.button--ghost:active {
  background: var(--color-background-raised);
}

/* Teal - elevated positive/confirm with layered shadows */
.button--teal {
  background: linear-gradient(180deg, var(--color-teal-hover) 0%, var(--color-teal) 100%);
  color: var(--color-background-page);
  border: 1px solid var(--color-teal-hover);
  box-shadow:
    var(--shadow-button-depth),
    0 4px 4px -3px var(--color-teal-glow);
}

@media (hover: hover) {
  .button--teal:hover {
    background: linear-gradient(180deg, var(--color-teal) 0%, var(--color-teal-light) 100%);
    box-shadow:
      var(--shadow-button-depth),
      0 4px 8px -2px var(--color-teal-glow-strong);
  }
}

.button--teal:active {
  background: var(--color-teal-hover);
  border-color: var(--color-teal-hover);
  box-shadow: inset 0 2px 4px var(--shadow-drop-subtle);
}

/* Teal outline variant */
.button--teal-outline {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--color-teal);
  color: var(--color-teal);
}

@media (hover: hover) {
  .button--teal-outline:hover {
    background: var(--color-teal-dim);
  }
}

/* Danger - elevated destructive with layered shadows */
.button--danger {
  background: linear-gradient(180deg, var(--color-red-dark) 0%, var(--color-red) 100%);
  color: var(--color-white);
  border: 1px solid var(--color-red-dark);
  box-shadow:
    var(--shadow-button-depth),
    0 4px 4px -3px var(--color-red-glow);
}

@media (hover: hover) {
  .button--danger:hover {
    background: linear-gradient(180deg, var(--color-red) 0%, var(--color-red-light) 100%);
    box-shadow:
      var(--shadow-button-depth),
      0 4px 8px -2px var(--color-red-glow-strong);
  }
}

.button--danger:active {
  background: var(--color-red-dark);
  border-color: var(--color-red-dark);
  box-shadow: inset 0 2px 4px var(--shadow-drop-default);
}

/* ===== SIZES ===== */

.button--compact {
  height: var(--button-height-compact);
  padding: 0 var(--space-snug);
  font-size: var(--font-size-tiny);
}

.button--large {
  height: var(--button-height-large);
  padding: 0 var(--space-loose);
  font-size: var(--font-size-label);
}

/* ===== ICON ONLY ===== */

.button--icon {
  width: var(--button-height-default);
  padding: 0;
}

.button--icon.button--compact {
  width: var(--button-height-compact);
}

.button--icon.button--large {
  width: var(--button-height-large);
}

/* ===== ICON STYLING ===== */

.button__icon {
  width: var(--icon-size-default);
  height: var(--icon-size-default);
  flex-shrink: 0;
}

.button--compact .button__icon {
  width: var(--icon-size-small);
  height: var(--icon-size-small);
}

.button--large .button__icon {
  width: var(--icon-size-medium);
  height: var(--icon-size-medium);
}

/* ===== FULL WIDTH ===== */

.button--full {
  width: 100%;
}

/* ===== LIGHT MODE OVERRIDES ===== */

[data-theme='light'] .button--teal {
  background: linear-gradient(180deg, var(--color-teal) 0%, var(--color-teal-gradient-start) 100%);
  color: var(--color-white);
  border-color: var(--color-teal);
}

@media (hover: hover) {
  [data-theme='light'] .button--teal:hover {
    background: linear-gradient(
      180deg,
      var(--color-teal-gradient-start) 0%,
      var(--color-teal-gradient-hover) 100%
    );
  }
}

[data-theme='light'] .button--teal:active {
  background: var(--color-teal-hover);
  border-color: var(--color-teal-hover);
}

[data-theme='light'] .button--secondary {
  background: linear-gradient(180deg, var(--color-background-raised) 0%, var(--color-white) 100%);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-emphasis);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.08);
  /* 0 4px 6px -2px rgba(0, 0, 0, 0.12); */
}

[data-theme='light'] .button--primary {
  background: linear-gradient(
    180deg,
    var(--color-accent) 0%,
    var(--color-accent-gradient-start) 100%
  );
  color: var(--color-white);
  border-color: var(--color-accent);
  box-shadow:
    var(--shadow-button-inner),
    var(--shadow-button-depth),
    0 4px 4px -3px var(--color-accent-glow);
}

@media (hover: hover) {
  [data-theme='light'] .button--secondary:hover {
    background: linear-gradient(
      180deg,
      var(--color-background-surface) 0%,
      var(--color-white) 100%
    );
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.9),
      0 4px 8px rgba(0, 0, 0, 0.1),
      0 6px 12px -3px rgba(0, 0, 0, 0.15);
  }

  [data-theme='light'] .button--primary:hover {
    background: linear-gradient(
      180deg,
      var(--color-accent-gradient-start) 0%,
      var(--color-accent-gradient-hover) 100%
    );
    box-shadow:
      var(--shadow-button-inner),
      var(--shadow-button-depth),
      0 4px 8px -2px var(--color-accent-glow);
  }
}

[data-theme='light'] .button--secondary:active {
  background: var(--color-background-raised);
  color: var(--color-text-primary);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12);
}

[data-theme='light'] .button--primary:active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: inset 0 2px 4px var(--shadow-drop-default);
}

/* ===== REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}

/** @fileoverview Native login/session layout and public-only filing footer using shared design tokens. */
.local-login {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(var(--space-loose), env(safe-area-inset-top)) max(var(--space-loose), env(safe-area-inset-right)) max(var(--space-loose), env(safe-area-inset-bottom)) max(var(--space-loose), env(safe-area-inset-left));
  box-sizing: border-box;
  background: var(--color-background-page);
  color: var(--color-text-primary);
  color-scheme: dark;
  font-family: var(--font-family);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.local-login__card {
  box-sizing: border-box;
  width: min(100%, 26rem);
  padding: var(--space-roomy);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-large);
  background: var(--color-background-card);
}

.local-login__eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-snug);
  margin: 0 0 var(--space-loose);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-label);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wider);
  color: var(--color-teal);
}

.local-login__mark { width: var(--space-roomy); height: var(--space-roomy); flex-shrink: 0; }
.local-login__title { margin: 0; font-size: var(--font-size-title); font-weight: var(--font-weight-semibold); line-height: var(--line-height-tight); }
.local-login__description { margin: var(--space-snug) 0 0; font-size: var(--font-size-body-large); color: var(--color-text-secondary); line-height: var(--line-height-relaxed); }
.local-login__form { display: grid; gap: var(--space-snug); margin-top: var(--space-loose); min-width: 0; }
.local-login__label { font-size: var(--font-size-body-large); font-weight: var(--font-weight-medium); }

/* Native login is served without the app reset; include padding in control widths. */
.local-login__form .input { box-sizing: border-box; min-width: 0; min-height: var(--space-airy); font-size: var(--font-size-subheading); border-radius: var(--radius-rounded); }
.local-login__form .button { box-sizing: border-box; min-height: var(--space-airy); margin-top: var(--space-hairline); font-size: var(--font-size-subheading); letter-spacing: var(--letter-spacing-normal); border-radius: var(--radius-rounded); }
.local-login__error { margin: var(--space-default) 0 0; font-size: var(--font-size-body-large); line-height: var(--line-height-normal); color: var(--color-red); overflow-wrap: anywhere; }
.local-login__back { display: inline-flex; align-items: center; min-height: var(--button-height-large); margin-top: var(--space-tight); font-size: var(--font-size-body-large); color: var(--color-text-primary); text-underline-offset: var(--space-hairline); }

@media (max-width: 600px), (max-height: 540px) {
  /* Top alignment keeps the heading reachable when the keyboard reduces the viewport. */
  .local-login { align-items: start; padding-top: max(var(--space-airy), env(safe-area-inset-top)); }
  .local-login__card { padding: var(--space-loose); }
}

@media (max-height: 540px) {
  .local-login { padding-top: max(var(--space-loose), env(safe-area-inset-top)); }
}

.local-session { position: fixed; z-index: 20; top: var(--space-tight); right: var(--space-tight); color: var(--color-text-secondary); background: var(--color-background-card); padding: var(--space-hairline) var(--space-tight); border-radius: var(--radius-subtle); font: var(--font-size-label) system-ui, sans-serif; text-decoration: none; }

.local-filing { box-sizing: border-box; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; align-content: center; gap: var(--space-hairline) var(--space-snug); padding: var(--space-tight); color: var(--color-text-secondary); font: var(--font-size-caption)/var(--line-height-normal) var(--font-family); }
.local-filing a { display: inline-flex; align-items: center; gap: var(--space-hairline); color: inherit; text-decoration: none; }
.local-filing a:hover { text-decoration: underline; }
.local-filing img { height: var(--space-default); width: auto; }
.local-login:has(> .local-filing) { grid-template-rows: 1fr auto; }
.cmux-public-page { --cmux-filing-height: calc(var(--space-airy) + env(safe-area-inset-bottom, 0px)); }
.cmux-public-page .cmux-app { height: calc(var(--cmux-viewport-height, 100dvh) - var(--cmux-filing-height)); }
.cmux-public-page > .local-filing { position: fixed; inset: auto 0 0; height: var(--cmux-filing-height); padding-bottom: calc(var(--space-tight) + env(safe-area-inset-bottom, 0px)); background: var(--color-background-page); }
