/**
 * Design tokens.
 *
 * Two layers, deliberately separated:
 *
 * 1. Primitives (--tq-*) — the raw palette. The browns and golds are sampled
 *    from the Titan Quest II concept art (the Hall of the Fates), so the site
 *    and the game share a hue family. Primitives never change between themes.
 * 2. Semantic tokens (--color-*, --space-*, …) — what components actually use.
 *    Only this layer is redefined per theme, which is why a second theme costs
 *    one block of overrides instead of a sweep through every component.
 *
 * Dark is the default and the only theme currently shipped. The light block is
 * complete and applies when the document carries data-theme="light"; to follow
 * the operating system instead, uncomment the media query at the bottom.
 * Components must never reference a --tq-* primitive directly.
 */

:root {
    /* ---- Primitives: browns and golds from the concept art ---- */
    --tq-brown-950: #150d0a;
    --tq-brown-900: #281814;
    --tq-brown-800: #3a2118;
    --tq-brown-700: #512e1f;
    --tq-brown-600: #74462c;
    --tq-brown-500: #965933;
    --tq-brown-400: #b37445;
    --tq-brown-300: #d49558;
    --tq-brown-200: #e3b985;
    --tq-brown-100: #d3bb94;
    --tq-brown-050: #f2e6d2;

    /* ---- Primitives: near-black neutrals ---- */
    --tq-ink-990: #07070a;
    --tq-ink-950: #0c0c0f;
    --tq-ink-900: #121215;
    --tq-ink-850: #17171b;
    --tq-ink-800: #1d1d22;
    --tq-ink-700: #26262d;
    --tq-ink-600: #33333c;
    --tq-ink-500: #4a4a55;
    --tq-ink-400: #6d6d79;
    --tq-ink-300: #9a9aa5;
    --tq-ink-200: #c6c6ce;
    --tq-ink-100: #e6e6ea;
    --tq-ink-000: #ffffff;

    /*
     * ---- Primitives: the engraved-frame greys ----
     * Sampled straight off the frame drawn around the Titan Quest II art: its
     * brightest pixel is #554f47, which is hue 34 at 9% saturation - a warm
     * grey, not a colour. That restraint is the whole character of the game's
     * UI, so this scale replaces the ember orange that served as the secondary
     * accent. The orange competed with the gold instead of supporting it; a
     * neutral of the same hue family sits beside it without fighting.
     */
    --tq-ash-700: #3a352f;
    --tq-ash-600: #554f47;
    --tq-ash-500: #7a7166;
    --tq-ash-400: #9c9182;
    --tq-ash-300: #bdb0a0;
    --tq-ash-200: #d8cdbc;

    /*
     * ---- Primitives: the in-game UI palette ----
     * Sampled from a Titan Quest II skill panel, which sets its body copy in a
     * warm cream (#e3d8cc). The mint cyan the game uses on panel headings was
     * tried as the accent and dropped: it belongs to the game but not to this
     * page, where it read as a foreign colour against the browns. The orange
     * the game puts on numbers is likewise deliberately not borrowed.
     */
    --tq-cream-050: #f6f1e8;
    --tq-cream-100: #e3d8cc;
    --tq-cream-200: #c8bba6;
    --tq-cream-300: #a89982;

    --tq-green-500: #4fae87;
    --tq-blue-500: #5b8ec4;
    --tq-red-500: #c85a4a;
    /* Warm amber: a caution that is neither a refusal nor the gold accent. */
    --tq-amber-500: #d2924a;

    /* ---- Spacing scale ---- */
    --space-3xs: 0.25rem;
    --space-2xs: 0.5rem;
    --space-xs: 0.75rem;
    --space-s: 1rem;
    --space-m: 1.5rem;
    --space-l: 2rem;
    --space-xl: 3rem;
    --space-2xl: 4rem;
    --space-3xl: 6rem;

    /* ---- Typography ---- */
    --font-main: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-heading: 'Roboto Condensed', 'Roboto', system-ui, sans-serif;
    --font-mono: ui-monospace, 'SFMono-Regular', 'Menlo', monospace;

    --text-3xs: 0.6875rem;
    --text-2xs: 0.75rem;
    --text-xs: 0.8125rem;
    --text-s: 0.9375rem;
    --text-m: 1rem;
    --text-l: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --text-3xl: 2.25rem;
    --text-hero: clamp(2.75rem, 8vw, 5.5rem);

    --leading-tight: 1.15;
    --leading-snug: 1.35;
    --leading-normal: 1.45;
    --leading-reading: 1.75;
    --tracking-wide: 0.08em;
    --tracking-wider: 0.14em;

    /* ---- Radii, borders, motion ---- */
    --radius-s: 3px;
    --radius-m: 6px;
    --radius-l: 10px;
    --border-thin: 1px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --duration: 180ms;

    /* ---- Layout ---- */
    --container: 1200px;
    --container-narrow: 820px;
    --gutter: clamp(1rem, 4vw, 2rem);
    --header-height: 78px;
}

/* ---- Semantic tokens: dark theme (default) ---- */
:root,
:root[data-theme='dark'] {
    color-scheme: dark;

    --color-canvas: var(--tq-ink-990);
    --color-canvas-alt: var(--tq-ink-950);
    --color-surface: var(--tq-ink-900);
    --color-surface-raised: var(--tq-ink-850);
    --color-surface-sunken: var(--tq-ink-950);
    --color-surface-hover: var(--tq-ink-800);

    --color-border: #262229;
    /*
     * Both of these used to be brown. The brown was strong enough to read as a
     * colour rather than as an edge, which made every hovered card and every
     * heavier rule look tinted. They are neutral now; the warmth comes from
     * the text and the accent instead.
     */
    --color-border-strong: var(--tq-ink-600);
    --color-border-accent: var(--tq-ash-500);

    --color-text: var(--tq-ink-200);
    --color-text-strong: var(--tq-ink-100);
    --color-text-muted: var(--tq-ink-400);
    --color-heading: var(--tq-cream-100);

    /*
     * The arrow of a <select>, drawn by us rather than by the browser - see
     * base.css. It has to be a whole image, so the colour is written out
     * instead of naming a token: an SVG in a data URI cannot read a custom
     * property. Keep it in step with --color-text-muted above.
     */
    --field-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%236d6d79' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");

    /*
     * Long-form reading colour, for forum posts and article bodies. Deliberately
     * short of --color-text-strong: a near-white on near-black runs at about
     * 17:1, which is punishing over hundreds of lines. This sits near 9:1 and
     * is warm rather than blue, which reads softer at the same contrast.
     */
    --color-text-reading: #bdb5ab;

    /*
     * A step lighter than --color-text and warmer than it, so a link separates
     * from body copy by both tone and temperature. Cream-200 was tried first
     * and sat at almost the same lightness as the text, which made links
     * disappear into the paragraph.
     */
    --color-accent: var(--tq-cream-100);
    --color-accent-hover: var(--tq-cream-050);
    --color-accent-soft: rgba(227, 216, 204, 0.12);
    --color-on-accent: var(--tq-ink-990);

    /*
     * Headings on the key art are not flat - the lettering runs from near-white
     * at the top into a deeper tone at the baseline, which is what makes it
     * read as engraved rather than typed. Large headings take this instead of
     * --color-heading; that token stays as the fallback and for small ones.
     */
    --gradient-heading: linear-gradient(
        180deg,
        var(--tq-cream-050) 0%,
        var(--tq-cream-100) 45%,
        var(--tq-cream-300) 100%
    );

    --color-highlight: var(--tq-ash-300);
    --color-highlight-soft: rgba(189, 176, 160, 0.14);
    --color-on-highlight: var(--tq-ink-990);

    /* Engraved rules and corner meanders, at the strength they have on the art. */
    --color-ornament: var(--tq-ash-600);

    --color-link: var(--tq-cream-100);
    --color-link-hover: var(--tq-cream-050);

    --color-success: var(--tq-green-500);
    --color-info: var(--tq-blue-500);
    --color-warning: var(--tq-amber-500);
    --color-danger: var(--tq-red-500);
    /* The hero's pools, in the game's colours: life red, energy blue. */
    --color-life: var(--tq-red-500);
    --color-energy: var(--tq-blue-500);
    /*
     * Item names by rarity, the game's hues (TQVault's ItemStyle colours: yellow,
     * green, blue, purple; artifacts turquoise), a touch softer on the dark page.
     */
    --color-rarity-magical: #e8d44d;
    --color-rarity-rare: #5fd35f;
    --color-rarity-epic: #3fa9f5;
    --color-rarity-legendary: #c45ef0;
    --color-rarity-artifact: #3fe0c5;

    --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.6);
    --shadow-m: 0 4px 18px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 22px rgba(189, 176, 160, 0.22);

    /*
     * Veil laid over the art behind the hero so headings stay legible. Two
     * layers: the darkening itself in percentages, and above it a band of a
     * fixed height that lands the art on the page background. The band is in
     * rem on purpose - with the whole fade in percentages a shorter hero
     * squeezed the last stop into a few pixels and the picture ended on a
     * visible edge. A short banner sets its own `--hero-fade`.
     */
    --hero-veil:
        linear-gradient(to top, var(--color-canvas) 0, rgba(7, 7, 10, 0) var(--hero-fade, 9rem)),
        linear-gradient(
            180deg,
            rgba(7, 7, 10, 0.32) 0%,
            rgba(7, 7, 10, 0.58) 48%,
            rgba(7, 7, 10, 0.84) 100%
        );
}

/* ---- Semantic tokens: light theme (ready, opt-in) ---- */
:root[data-theme='light'] {
    color-scheme: light;

    --color-canvas: #f6f1e7;
    --color-canvas-alt: #efe7d8;
    --color-surface: #fffdf8;
    --color-surface-raised: #ffffff;
    --color-surface-sunken: #ebe2d1;
    --color-surface-hover: #f4ecdd;

    --color-border: #ded2ba;
    --color-border-strong: #c2b296;
    --color-border-accent: var(--tq-ash-500);

    --color-text: #3a2f24;
    --color-text-strong: var(--tq-brown-950);
    --color-text-muted: #7c6b57;
    --color-text-reading: #40362a;

    /* The select's arrow, in step with --color-text-muted (see the dark set). */
    --field-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%237c6b57' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
    --color-heading: var(--tq-brown-700);

    --color-accent: var(--tq-ash-700);
    --color-accent-hover: var(--tq-brown-800);
    --color-accent-soft: rgba(168, 153, 130, 0.14);
    --color-on-accent: #fffdf8;

    --gradient-heading: linear-gradient(180deg, #4a3c2d 0%, #2f261c 100%);

    --color-highlight: var(--tq-ash-700);
    --color-highlight-soft: rgba(58, 53, 47, 0.10);
    --color-on-highlight: #fffdf8;

    /* Engraving reads as pressed into the page here, so it darkens instead. */
    --color-ornament: var(--tq-ash-500);

    --color-link: var(--tq-ash-700);
    --color-link-hover: var(--tq-brown-950);

    --shadow-s: 0 1px 2px rgba(60, 40, 20, 0.12);
    --shadow-m: 0 6px 20px rgba(60, 40, 20, 0.14);
    --shadow-glow: 0 0 20px rgba(58, 53, 47, 0.16);

    --hero-veil:
        linear-gradient(to top, var(--color-canvas) 0, rgba(246, 241, 231, 0) var(--hero-fade, 9rem)),
        linear-gradient(
            180deg,
            rgba(246, 241, 231, 0.35) 0%,
            rgba(246, 241, 231, 0.72) 55%,
            rgba(246, 241, 231, 0.9) 100%
        );
}

/*
 * To follow the operating system once the light theme ships, uncomment this and
 * copy the light block's declarations into it. The :not() guard keeps an
 * explicit choice from being overridden.
 *
 * @media (prefers-color-scheme: light) {
 *     :root:not([data-theme]) { … }
 * }
 */

@media (prefers-reduced-motion: reduce) {
    :root {
        --duration: 0ms;
    }
}
