/* ==========================================================================
   AllCalci.com — global.css
   Reset, design tokens, typography, layout primitives
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. MODERN RESET
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
  text-rendering: optimizeLegibility;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
input, button, textarea, select { font: inherit; color: inherit; }
p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
ul[role='list'], ol[role='list'] { list-style: none; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

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

::selection { background: var(--color-primary); color: #fff; }

/* --------------------------------------------------------------------------
   2. DESIGN TOKENS — LIGHT (DEFAULT)
   -------------------------------------------------------------------------- */
:root {
  /* Brand — locked to logo */
  --color-primary:          #2563EB;
  --color-primary-hover:    #1D4ED8;
  --color-primary-active:   #1E40AF;
  --color-primary-subtle:   #EFF6FF;
  --color-primary-muted:    #DBEAFE;
  --color-primary-border:   #BFDBFE;
  --color-on-primary:       #FFFFFF;

  /* Semantic */
  --color-success:          #059669;
  --color-success-subtle:   #ECFDF5;
  --color-warning:          #D97706;
  --color-warning-subtle:   #FFFBEB;
  --color-danger:           #DC2626;
  --color-danger-subtle:    #FEF2F2;
  --color-info:             #0891B2;
  --color-info-subtle:      #ECFEFF;

  /* Category identity */
  --color-financial:        #059669;
  --color-financial-subtle: #ECFDF5;
  --color-india:            #EA580C;
  --color-india-subtle:     #FFF7ED;
  --color-health:           #DC2626;
  --color-health-subtle:    #FEF2F2;
  --color-math:             #7C3AED;
  --color-math-subtle:      #F5F3FF;
  --color-other:            #0891B2;
  --color-other-subtle:     #ECFEFF;

  /* Surfaces */
  --color-bg:               #FFFFFF;
  --color-bg-alt:           #F8FAFC;
  --color-bg-sunken:        #F1F5F9;
  --color-bg-card:          #FFFFFF;
  --color-bg-hover:         #F8FAFC;
  --color-bg-inset:         #F8FAFC;

  /* Lines */
  --color-border:           #E2E8F0;
  --color-border-strong:    #CBD5E1;
  --color-border-subtle:    #F1F5F9;

  /* Text */
  --color-text:             #0F172A;
  --color-text-secondary:   #475569;
  --color-text-muted:       #64748B;
  --color-text-faint:       #94A3B8;

  /* Elevation */
  --shadow-xs:  0 1px 2px 0 rgba(15, 23, 42, .04);
  --shadow-sm:  0 1px 3px 0 rgba(15, 23, 42, .06), 0 1px 2px -1px rgba(15, 23, 42, .04);
  --shadow-md:  0 4px 12px -2px rgba(15, 23, 42, .07), 0 2px 4px -2px rgba(15, 23, 42, .04);
  --shadow-lg:  0 12px 28px -6px rgba(15, 23, 42, .10), 0 4px 10px -4px rgba(15, 23, 42, .05);
  --shadow-xl:  0 24px 48px -12px rgba(15, 23, 42, .16);
  --shadow-focus: 0 0 0 3px var(--color-primary-muted);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --text-xs:    0.75rem;    /* 12 */
  --text-sm:    0.8125rem;  /* 13 */
  --text-base:  0.9375rem;  /* 15 */
  --text-md:    1rem;       /* 16 */
  --text-lg:    1.125rem;   /* 18 */
  --text-xl:    1.375rem;   /* 22 */
  --text-2xl:   1.75rem;    /* 28 */
  --text-3xl:   2.25rem;    /* 36 */
  --text-4xl:   3rem;       /* 48 */

  /* Spacing — 4pt base */
  --sp-1: 0.25rem;  --sp-2: 0.5rem;   --sp-3: 0.75rem;  --sp-4: 1rem;
  --sp-5: 1.25rem;  --sp-6: 1.5rem;   --sp-8: 2rem;     --sp-10: 2.5rem;
  --sp-12: 3rem;    --sp-16: 4rem;    --sp-20: 5rem;    --sp-24: 6rem;

  /* Radii */
  --radius-xs: 4px;   --radius-sm: 6px;   --radius-md: 8px;
  --radius-lg: 12px;  --radius-xl: 16px;  --radius-2xl: 24px;
  --radius-full: 999px;

  /* Layout */
  --container:      1200px;
  --container-wide: 1360px;
  --container-prose: 720px;
  --header-h:       60px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  color-scheme: light;
}

/* --------------------------------------------------------------------------
   3. DESIGN TOKENS — DARK
   -------------------------------------------------------------------------- */
[data-theme='dark'] {
  --color-primary:          #3B82F6;
  --color-primary-hover:    #60A5FA;
  --color-primary-active:   #93C5FD;
  --color-primary-subtle:   #172554;
  --color-primary-muted:    #1E3A8A;
  --color-primary-border:   #1E40AF;
  --color-on-primary:       #FFFFFF;

  --color-success:          #34D399;
  --color-success-subtle:   #052E23;
  --color-warning:          #FBBF24;
  --color-warning-subtle:   #37220A;
  --color-danger:           #F87171;
  --color-danger-subtle:    #3B1214;
  --color-info:             #22D3EE;
  --color-info-subtle:      #0A2E33;

  --color-financial:        #34D399;
  --color-financial-subtle: #052E23;
  --color-india:            #FB923C;
  --color-india-subtle:     #3A1E08;
  --color-health:           #F87171;
  --color-health-subtle:    #3B1214;
  --color-math:             #A78BFA;
  --color-math-subtle:      #241B4A;
  --color-other:            #22D3EE;
  --color-other-subtle:     #0A2E33;

  --color-bg:               #0B1120;
  --color-bg-alt:           #111827;
  --color-bg-sunken:        #0A0F1C;
  --color-bg-card:          #131C2E;
  --color-bg-hover:         #1A2438;
  --color-bg-inset:         #0F1626;

  --color-border:           #253045;
  --color-border-strong:    #34405A;
  --color-border-subtle:    #1A2334;

  --color-text:             #F1F5F9;
  --color-text-secondary:   #CBD5E1;
  --color-text-muted:       #94A3B8;
  --color-text-faint:       #64748B;

  --shadow-xs:  0 1px 2px 0 rgba(0, 0, 0, .3);
  --shadow-sm:  0 1px 3px 0 rgba(0, 0, 0, .4), 0 1px 2px -1px rgba(0, 0, 0, .3);
  --shadow-md:  0 4px 12px -2px rgba(0, 0, 0, .45), 0 2px 4px -2px rgba(0, 0, 0, .3);
  --shadow-lg:  0 12px 28px -6px rgba(0, 0, 0, .55), 0 4px 10px -4px rgba(0, 0, 0, .35);
  --shadow-xl:  0 24px 48px -12px rgba(0, 0, 0, .7);
  --shadow-focus: 0 0 0 3px rgba(59, 130, 246, .35);

  color-scheme: dark;
}

/* System preference when user has made no explicit choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-primary:          #3B82F6;
    --color-primary-hover:    #60A5FA;
    --color-primary-active:   #93C5FD;
    --color-primary-subtle:   #172554;
    --color-primary-muted:    #1E3A8A;
    --color-primary-border:   #1E40AF;

    --color-success:          #34D399;
    --color-success-subtle:   #052E23;
    --color-warning:          #FBBF24;
    --color-warning-subtle:   #37220A;
    --color-danger:           #F87171;
    --color-danger-subtle:    #3B1214;
    --color-info:             #22D3EE;
    --color-info-subtle:      #0A2E33;

    --color-financial:        #34D399;
    --color-financial-subtle: #052E23;
    --color-india:            #FB923C;
    --color-india-subtle:     #3A1E08;
    --color-health:           #F87171;
    --color-health-subtle:    #3B1214;
    --color-math:             #A78BFA;
    --color-math-subtle:      #241B4A;
    --color-other:            #22D3EE;
    --color-other-subtle:     #0A2E33;

    --color-bg:               #0B1120;
    --color-bg-alt:           #111827;
    --color-bg-sunken:        #0A0F1C;
    --color-bg-card:          #131C2E;
    --color-bg-hover:         #1A2438;
    --color-bg-inset:         #0F1626;

    --color-border:           #253045;
    --color-border-strong:    #34405A;
    --color-border-subtle:    #1A2334;

    --color-text:             #F1F5F9;
    --color-text-secondary:   #CBD5E1;
    --color-text-muted:       #94A3B8;
    --color-text-faint:       #64748B;

    --shadow-xs:  0 1px 2px 0 rgba(0, 0, 0, .3);
    --shadow-sm:  0 1px 3px 0 rgba(0, 0, 0, .4), 0 1px 2px -1px rgba(0, 0, 0, .3);
    --shadow-md:  0 4px 12px -2px rgba(0, 0, 0, .45), 0 2px 4px -2px rgba(0, 0, 0, .3);
    --shadow-lg:  0 12px 28px -6px rgba(0, 0, 0, .55), 0 4px 10px -4px rgba(0, 0, 0, .35);
    --shadow-xl:  0 24px 48px -12px rgba(0, 0, 0, .7);
    --shadow-focus: 0 0 0 3px rgba(59, 130, 246, .35);

    color-scheme: dark;
  }
}

/* Theme transition — only after first paint (set by theme.js) */
.theme-ready,
.theme-ready *,
.theme-ready *::before,
.theme-ready *::after {
  transition: background-color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              fill var(--dur) var(--ease),
              stroke var(--dur) var(--ease);
}

/* --------------------------------------------------------------------------
   4. TYPOGRAPHY
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--color-text);
}
h1 { font-size: var(--text-3xl); letter-spacing: -0.03em; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  letter-spacing: -0.02em;
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.lead {
  font-size: var(--text-lg);
  line-height: 1.65;
  color: var(--color-text-secondary);
}

/* --------------------------------------------------------------------------
   5. LAYOUT PRIMITIVES
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-5);
}
.container--wide { max-width: var(--container-wide); }
.container--prose { max-width: var(--container-prose); }

.section { padding-block: var(--sp-16); }
.section--tight { padding-block: var(--sp-10); }
.section--alt { background: var(--color-bg-alt); }

.stack > * + * { margin-top: var(--flow, var(--sp-4)); }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.cluster { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }

/* --------------------------------------------------------------------------
   6. UTILITIES
   -------------------------------------------------------------------------- */
.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;
}

.skip-link {
  position: absolute; top: -100px; left: var(--sp-4); z-index: 999;
  background: var(--color-primary); color: #fff;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-md); font-weight: 600;
}
.skip-link:focus { top: var(--sp-4); }

.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.hide { display: none !important; }

@media print {
  .site-header, .site-footer, .ad-slot, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}
