:root {
    /* Color primitives (ADR 0031): one midnight-blue hue, from very pale blue
       "paper" to near-black blue "ink". The interface is monochrome in both themes:
       every neutral, border and highlight is a strength of this blue, and colour
       belongs to content (organizer logos, category badges, status, countdowns).
       Do not use these in components; use the semantic tokens below. */
    --ink-0: #F1F5FA; /* pale-blue paper */
    --ink-50: #E8EEF6;
    --ink-100: #E1E8F2;
    --ink-150: #D9E2EE;
    --ink-200: #C8D3E2;
    --ink-300: #B6C1CE;
    --ink-400: #8E9BAE;
    --ink-500: #5E6B7E;
    --ink-600: #434F61;
    --ink-700: #2C3646;
    --ink-750: #1A2230;
    --ink-800: #121821;
    --ink-850: #0F1520; /* ink */
    --ink-900: #0C1015;
    --ink-950: #090C10;
    --cream: #F2F4F7; /* ink-on-dark: cool off-white, never pure white */

    /* The globe's glow and highlights on dark surfaces. */
    --sky-300: #D3E1F0;
    --sky-400: #B5CCE5;
    --sky-500: #83A2C7;
    --sky-700: #3A5A8A;

    /* Shades used by the dark theme, and tints as "r, g, b" for rgba(). A colour
       theme (palettes.css, generated) overrides every primitive in this block and
       the two above; nothing below this block names a colour directly. */
    --ink-450: #7D8998; /* muted text on dark */
    --ink-550: #56627A; /* disabled text on dark */
    --ink-875: #141B26; /* raised panel on dark */
    --ink-925: #0F141B; /* subtle surface on dark */
    --ink-975: #06080B; /* sunken surface on dark */
    --rgb-tint-on-light: 15, 40, 80; /* borders and shadows on light surfaces */
    --rgb-tint-on-dark: 225, 239, 255; /* borders on dark surfaces */
    --rgb-tint-on-dark-soft: 196, 211, 224;
    --rgb-ink-850: 15, 21, 32;
    --rgb-sky-700: 58, 90, 138;
    --rgb-sky-400: 181, 204, 229;
    --rgb-cream: 242, 244, 247;
    --rgb-glass-1: 219, 234, 255;
    --rgb-glass-2: 197, 222, 255;
    --rgb-glass-3: 179, 216, 234;
    --rgb-glass-4: 239, 247, 255;
    --rgb-glass-light: 232, 240, 250;

    /* Semantic: surface */
    --color-surface-page: var(--ink-0);
    --color-surface-subtle: var(--ink-50);
    --color-surface-sunken: var(--ink-100);
    --color-surface-inverse: var(--ink-850);
    /* Panels inside an inverse surface (the destinations finder). Dark in both themes. */
    --color-surface-inverse-raised: var(--ink-800);
    --color-surface-inverse-overlay: var(--ink-750);

    /* Semantic: text */
    --color-text-primary: var(--ink-850);
    --color-text-secondary: var(--ink-600);
    --color-text-muted: var(--ink-500);
    --color-text-inverse: var(--cream);
    --color-text-inverse-muted: var(--ink-400);
    --color-text-link: var(--ink-850);
    --color-text-link-hover: var(--ink-600);
    --color-text-accent: var(--sky-700);

    /* Semantic: border */
    --color-border-subtle: rgba(var(--rgb-tint-on-light), 0.08);
    --color-border-default: rgba(var(--rgb-tint-on-light), 0.14);
    --color-border-strong: rgba(var(--rgb-tint-on-light), 0.3);
    --color-border-focus: var(--sky-700);

    /* Semantic: brand */
    --color-brand-primary: var(--ink-850);
    --color-brand-primary-hover: var(--ink-700);
    --color-brand-primary-active: var(--ink-950);
    --color-brand-primary-subtle: var(--ink-50);
    --color-on-brand-primary: var(--ink-0);
    --color-action-bg: var(--ink-850);
    --color-action-bg-hover: var(--ink-700);
    --color-action-bg-active: var(--ink-950);
    --color-on-action: var(--ink-0);
    --color-action-on-dark-bg: var(--cream);
    --color-action-on-dark-bg-hover: var(--ink-0);
    --color-on-action-on-dark: var(--ink-850);
    /* Pale blue: highlights on inverse (always dark) surfaces, in both themes. */
    --color-brand-accent: var(--sky-400);
    --color-brand-accent-hover: var(--sky-300);
    --color-brand-accent-active: var(--sky-500);
    --color-brand-accent-subtle: var(--ink-50);
    --color-on-brand-accent: var(--ink-850);

    /* Semantic: disabled */
    --color-disabled-bg: var(--ink-100);
    --color-disabled-fg: var(--ink-400);

    /* Semantic: status (never rely on color alone) */
    --color-success-bg: #E6F4EC;
    --color-success-text: #1E5C3A;
    --color-success-border: #9FD0B3;
    --color-success-solid: #2F7A4D;
    --color-warning-bg: #FEF1DF;
    --color-warning-text: #8A4308;
    --color-warning-border: #F0C089;
    --color-warning-solid: #B45309;
    --color-danger-bg: #FCE9E7;
    --color-danger-text: #8F1D17;
    --color-danger-border: #EFA9A3;
    --color-danger-solid: #B3261E;
    --color-info-bg: #E6F0FA;
    --color-info-text: #1D4F85;
    --color-info-border: #A3C4E6;
    --color-info-solid: #2563A8;

    /* Semantic: category badges (no status meaning) */
    --color-cat-teal-bg: #E3F3F2;
    --color-cat-teal-text: #0B5553;
    --color-cat-teal-dot: #14948F;
    --color-cat-violet-bg: #EDEAFA;
    --color-cat-violet-text: #43358F;
    --color-cat-violet-dot: #6C5CC9;
    --color-cat-plum-bg: #F8E8F2;
    --color-cat-plum-text: #7A2760;
    --color-cat-plum-dot: #B34A92;
    --color-cat-olive-bg: #EEF2DC;
    --color-cat-olive-text: #4D5C12;
    --color-cat-olive-dot: #86A026;
    --color-cat-clay-bg: #F5EAE2;
    --color-cat-clay-text: #6E4325;
    --color-cat-clay-dot: #B07548;
    --color-cat-steel-bg: #E4EEF4;
    --color-cat-steel-text: #214F69;
    --color-cat-steel-dot: #3F86AB;

    /* Legacy aliases: existing templates use these. Migrate to the semantic tokens and remove. */
    --color-ink: var(--color-text-primary);
    --color-ink-muted: var(--color-text-secondary);
    --color-paper: var(--color-surface-page);
    --color-border: var(--color-border-default);
    --color-accent: var(--color-brand-primary);
    --color-accent-contrast: var(--color-on-brand-primary);

    /* Typography */
    --font-family-base: "Manrope", "Vazirmatn", system-ui, sans-serif;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 700;
    /* Body 17px and small text 15px (were 16 and 14): easier to read (ADR 0032). */
    --font-size-sm: 0.9375rem;
    --font-size-base: 1.0625rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.75rem;
    --font-size-2xl: 2.5rem;
    --font-size-3xl: 3.5rem;
    --line-height-base: 1.5;
    --line-height-tight: 1.15;

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2rem;
    --space-6: 3rem;
    --space-7: 4.5rem;
    --space-8: 6rem;

    /* Layout */
    --container-max-width: 72rem;
    --container-padding: var(--space-4);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;

    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(var(--rgb-tint-on-light), 0.06);
    --shadow-md: 0 4px 14px rgba(var(--rgb-tint-on-light), 0.08);

    /* Footer */
    --color-footer-bg: var(--color-surface-inverse);
    --color-footer-text: var(--ink-200);
    --color-footer-text-muted: var(--color-text-inverse-muted);

    /* Behind organizer logos (stays light in the dark theme). */
    --color-logo-plate: #FFFFFF;

    /* Homepage globe (r, g, b): land dots and lit destinations */
    --globe-dot: var(--rgb-ink-850);
    --globe-lit: var(--rgb-sky-700);
    --globe-glow: rgba(var(--rgb-sky-700), 0.05);

    /* Frosted-glass search field */
    --glass-bg: linear-gradient(120deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.6) 48%, rgba(var(--rgb-glass-light), 0.75));
    --glass-border: rgba(var(--rgb-tint-on-light), 0.14);
    --glass-highlight: rgba(255, 255, 255, 0.9);
    --glass-shadow: 0 12px 40px rgba(var(--rgb-tint-on-light), 0.08);

    /* Countdown urgency */
    --color-urgency-soon: var(--color-danger-solid);
    --color-urgency-approaching: var(--color-warning-solid);
    --color-urgency-plenty: var(--color-success-solid);
}

/* Phones: one step down for the large sizes, so section headings stay below the
   page title (28px on phones) instead of matching it. */
@media (max-width: 40rem) {
    :root {
        --font-size-lg: 1.125rem;
        --font-size-xl: 1.375rem;
    }
}

/* Dark theme (the default): <html data-theme="dark">. Only semantic tokens change;
   components never need theme-specific rules. Every text/background pair here meets
   WCAG AA (most pass AAA). */
:root[data-theme="dark"] {
    color-scheme: dark;

    --color-surface-page: var(--ink-950);
    --color-surface-subtle: var(--ink-925);
    --color-surface-sunken: var(--ink-975);
    --color-surface-inverse: var(--ink-975);

    --color-text-primary: var(--cream);
    --color-text-secondary: var(--ink-300);
    --color-text-muted: var(--ink-450);
    --color-text-link: var(--cream);
    --color-text-link-hover: #FFFFFF;
    --color-text-accent: var(--sky-400);

    --color-border-subtle: rgba(var(--rgb-tint-on-dark-soft), 0.1);
    --color-border-default: rgba(var(--rgb-tint-on-dark), 0.16);
    --color-border-strong: rgba(var(--rgb-tint-on-dark), 0.3);
    --color-border-focus: var(--sky-400);

    --color-brand-primary: var(--cream);
    --color-brand-primary-hover: #FFFFFF;
    --color-brand-primary-active: var(--ink-300);
    --color-brand-primary-subtle: var(--ink-875);
    --color-on-brand-primary: var(--ink-950);
    --color-action-bg: var(--cream);
    --color-action-bg-hover: #FFFFFF;
    --color-action-bg-active: var(--ink-300);
    --color-on-action: var(--ink-950);
    --color-brand-accent-subtle: var(--ink-875);

    --color-disabled-bg: var(--ink-800);
    --color-disabled-fg: var(--ink-550);

    --color-success-bg: #12301F;
    --color-success-text: #9FDDB8;
    --color-success-border: #2C6A47;
    --color-warning-bg: #3A2410;
    --color-warning-text: #F5C98E;
    --color-warning-border: #7A4B1C;
    --color-danger-bg: #3D1614;
    --color-danger-text: #F3A9A3;
    --color-danger-border: #8A332C;
    --color-info-bg: #132A45;
    --color-info-text: #A9CBF0;
    --color-info-border: #2E5885;

    --color-cat-teal-bg: #0E302F;
    --color-cat-teal-text: #8FDAD6;
    --color-cat-violet-bg: #26214A;
    --color-cat-violet-text: #C4BBF2;
    --color-cat-plum-bg: #3A1A31;
    --color-cat-plum-text: #EBB0D6;
    --color-cat-olive-bg: #262E10;
    --color-cat-olive-text: #CBDB8A;
    --color-cat-clay-bg: #33241A;
    --color-cat-clay-text: #E3BFA3;
    --color-cat-steel-bg: #14293A;
    --color-cat-steel-text: #A9CDE2;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.55);

    --color-footer-bg: var(--color-surface-inverse);

    /* Organizer logos are usually dark on transparent: keep them on a light plate. */
    --color-logo-plate: var(--ink-0);

    --globe-dot: var(--rgb-sky-400);
    --globe-lit: var(--rgb-cream);
    --globe-glow: rgba(var(--rgb-sky-400), 0.05);

    --glass-bg: linear-gradient(120deg, rgba(var(--rgb-glass-1), 0.11), rgba(var(--rgb-glass-2), 0.03) 48%, rgba(var(--rgb-glass-3), 0.07));
    --glass-border: rgba(var(--rgb-tint-on-dark), 0.19);
    --glass-highlight: rgba(var(--rgb-glass-4), 0.19);
    --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

/* Atmosphere: the page sits on soft glows (terracotta, teal and blue) instead of a
   flat colour, and raised panels let them show through. Form fields, menus and
   other overlays keep the solid page colour so text on them always reads. */
:root[data-palette="atmosphere"] {
    --atmosphere: radial-gradient(90% 70% at 15% 10%, rgba(214, 150, 108, 0.22), transparent 55%),
        radial-gradient(70% 60% at 85% 20%, rgba(110, 160, 140, 0.2), transparent 50%),
        radial-gradient(80% 50% at 50% 100%, rgba(120, 150, 170, 0.18), transparent 60%),
        linear-gradient(165deg, var(--ink-0), var(--ink-50));
    --color-surface-subtle: color-mix(in srgb, var(--ink-50) 70%, transparent);
    /* Stronger muted text: it must still read where the glows are brightest
       (checked by scripts/build_palettes.py --check). */
    --color-text-muted: var(--ink-600);
}

:root[data-palette="atmosphere"][data-theme="dark"] {
    --atmosphere: radial-gradient(90% 70% at 15% 10%, rgba(196, 122, 74, 0.24), transparent 55%),
        radial-gradient(70% 60% at 85% 20%, rgba(46, 107, 94, 0.32), transparent 50%),
        radial-gradient(80% 50% at 50% 100%, rgba(28, 58, 72, 0.5), transparent 60%),
        linear-gradient(165deg, var(--ink-925), var(--ink-950) 45%, var(--ink-975));
    --color-surface-subtle: color-mix(in srgb, var(--ink-925) 62%, transparent);
    --color-text-muted: var(--ink-400);
}

/* The glows live on their own fixed layer behind the page, not on body as a
   `fixed` background: that made the browser repaint the whole multi-gradient in
   tile strips on every page load and scroll, which flashed as horizontal coloured
   bars. The canvas underneath is a solid page colour, so nothing shows through
   while the layer is drawn. */
:root[data-palette="atmosphere"] {
    background-color: var(--color-surface-page);
}

:root[data-palette="atmosphere"] body {
    background: transparent;
}

:root[data-palette="atmosphere"] body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--atmosphere);
    pointer-events: none;
    transform: translateZ(0);
}

/* Chinese pages: the system's Chinese fonts (no download), Manrope for Latin text,
   roomier lines, and no letter-spacing (it breaks up CJK characters). */
:lang(zh) {
    --font-family-base: "Manrope", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
        "Noto Sans CJK SC", "Noto Sans SC", system-ui, sans-serif;
    --line-height-base: 1.75;
    --line-height-tight: 1.4;
    letter-spacing: 0;
}

/* Persian pages (ADR 0032): Vazirmatn first, taller lines, never any letter-spacing. */
:lang(fa) {
    --font-family-base: "Vazirmatn", "Manrope", system-ui, sans-serif;
    /* Vazirmatn's letters are smaller than Manrope's at the same size. */
    --font-size-sm: 1rem;
    --font-size-base: 1.125rem;
    --line-height-base: 1.85;
    --line-height-tight: 1.5;
    letter-spacing: 0;
}
