/* ---------- Base & Font Setup ---------- */

:root {
  --sans: system-ui, 'Segoe UI', Roboto, sans-serif;
  --heading: system-ui, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, 'Courier New', monospace;

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --error: #e53e3e;

  font: 16px/1.5 var(--sans);
  color-scheme: light dark;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Theme: Light (default) ---------- */

:root,
[data-theme="light"] {
  --text: #6b6375;
  --text-h: #08060d;
  --bg: #fff;
  --bg-secondary: #f8f9fa;
  --border: #e5e4e7;
  --code-bg: #f4f3ec;
  --accent: #6366f1;
  --accent-bg: rgba(99, 102, 241, 0.1);
  --accent-border: rgba(99, 102, 241, 0.5);
  --stripe: rgba(0, 0, 0, 0.02);

  --syntax-variable: #4f46e5;
  --syntax-number: #0d9488;
  --syntax-operator: #6b6375;
  --syntax-keyword: #7c3aed;
  --syntax-function: #2563eb;
  --syntax-currency: #d97706;
  --syntax-comment: rgba(107, 99, 117, 0.5);
  --syntax-heading: #08060d;

  --result-number: #374151;
  --result-unit: #0d9488;
  --result-currency: #d97706;
  --result-datetime: #7c3aed;
  --result-boolean: #6366f1;
}

/* ---------- Theme: Dark ---------- */

[data-theme="dark"] {
  --text: #9ca3af;
  --text-h: #f3f4f6;
  --bg: #16171d;
  --bg-secondary: #1a1b23;
  --border: #2e303a;
  --code-bg: #1f2028;
  --accent: #818cf8;
  --accent-bg: rgba(129, 140, 248, 0.15);
  --accent-border: rgba(129, 140, 248, 0.5);
  --stripe: rgba(255, 255, 255, 0.025);

  --syntax-variable: #a5b4fc;
  --syntax-number: #5eead4;
  --syntax-operator: #9ca3af;
  --syntax-keyword: #c4b5fd;
  --syntax-function: #93c5fd;
  --syntax-currency: #fcd34d;
  --syntax-comment: rgba(156, 163, 175, 0.5);
  --syntax-heading: #f3f4f6;

  --result-number: #d1d5db;
  --result-unit: #5eead4;
  --result-currency: #fcd34d;
  --result-datetime: #c4b5fd;
  --result-boolean: #818cf8;
}

/* ---------- Theme: Matrix ---------- */

[data-theme="matrix"] {
  --text: #00ff41;
  --text-h: #33ff66;
  --bg: #0a0a0a;
  --bg-secondary: #0f1a0f;
  --border: #003300;
  --code-bg: #0a0f0a;
  --accent: #00ff41;
  --accent-bg: rgba(0, 255, 65, 0.1);
  --accent-border: rgba(0, 255, 65, 0.4);
  --stripe: rgba(0, 255, 65, 0.03);

  --syntax-variable: #00ff41;
  --syntax-number: #00cc33;
  --syntax-operator: #00ff41;
  --syntax-keyword: #39ff14;
  --syntax-function: #00ff41;
  --syntax-currency: #ffff00;
  --syntax-comment: rgba(0, 255, 65, 0.4);
  --syntax-heading: #33ff66;

  --result-number: #00ff41;
  --result-unit: #00cc33;
  --result-currency: #ffff00;
  --result-datetime: #39ff14;
  --result-boolean: #00ff41;

  --mono: 'JetBrains Mono', 'Courier New', 'Fira Code', monospace;
  --success: #00ff41;
  --error: #ff0000;
}

/* Matrix special effects */
[data-theme="matrix"] .calcpad-app::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  z-index: 9999;
}

[data-theme="matrix"] .cm-cursor {
  border-color: #00ff41 !important;
  box-shadow: 0 0 4px #00ff41, 0 0 8px rgba(0, 255, 65, 0.3);
}

/* ---------- Theme: Midnight ---------- */

[data-theme="midnight"] {
  --text: #94a3b8;
  --text-h: #e2e8f0;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --border: #334155;
  --code-bg: #1e293b;
  --accent: #38bdf8;
  --accent-bg: rgba(56, 189, 248, 0.12);
  --accent-border: rgba(56, 189, 248, 0.5);
  --stripe: rgba(56, 189, 248, 0.03);

  --syntax-variable: #7dd3fc;
  --syntax-number: #5eead4;
  --syntax-operator: #94a3b8;
  --syntax-keyword: #c4b5fd;
  --syntax-function: #7dd3fc;
  --syntax-currency: #fcd34d;
  --syntax-comment: rgba(148, 163, 184, 0.5);
  --syntax-heading: #e2e8f0;

  --result-number: #cbd5e1;
  --result-unit: #5eead4;
  --result-currency: #fcd34d;
  --result-datetime: #c4b5fd;
  --result-boolean: #38bdf8;
}

/* ---------- Theme: Warm ---------- */

[data-theme="warm"] {
  --text: #78716c;
  --text-h: #1c1917;
  --bg: #fffbf5;
  --bg-secondary: #fef3e2;
  --border: #e7e5e4;
  --code-bg: #fef3e2;
  --accent: #f97316;
  --accent-bg: rgba(249, 115, 22, 0.1);
  --accent-border: rgba(249, 115, 22, 0.5);
  --stripe: rgba(249, 115, 22, 0.03);

  --syntax-variable: #c2410c;
  --syntax-number: #0d9488;
  --syntax-operator: #78716c;
  --syntax-keyword: #7c3aed;
  --syntax-function: #2563eb;
  --syntax-currency: #d97706;
  --syntax-comment: rgba(120, 113, 108, 0.5);
  --syntax-heading: #1c1917;

  --result-number: #44403c;
  --result-unit: #0d9488;
  --result-currency: #d97706;
  --result-datetime: #7c3aed;
  --result-boolean: #f97316;
}

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

body {
  margin: 0;
}

h1,
h2 {
  font-family: var(--heading);
  font-weight: 600;
  color: var(--text-h);
}
