/* ==============================================================================
   Subro design tokens — the contract between the component library and an app.

   Every Subro component references these and only these; no component ever
   contains a literal colour, radius or font. An app themes the library by
   redeclaring the same names under a theme class, which is all Vesta's
   theme.css already does.

   Values are bare HSL triplets ("220 47% 19%") rather than finished colours, so
   a component can vary alpha at the point of use: hsl(var(--primary) / 0.9).

   Themes are plain classes, so an app is not limited to these: .theme-print works
   the same way.

   .theme-system is the default: it reads as whichever of the others the device
   asks for, through media queries, so it needs no JS, is right during prerendering
   and follows the device while the page is open. CSS cannot name a block of
   declarations, so its queries at the end of the themes repeat the dark and contrast
   values; ThemeTokensCssTests fails when they drift apart.
   ============================================================================== */

.theme-light,
.theme-system,
.theme-light-contrast {
    /* Scrollbars and native controls, which the tokens do not reach. */
    color-scheme: light;

    --background: 0 0% 100%;
    --foreground: 222 47% 11%;

    --card: 0 0% 100%;
    --card-foreground: 222 47% 11%;

    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 11%;

    --primary: 222 47% 11%;
    --primary-foreground: 210 40% 98%;

    --secondary: 210 40% 96%;
    --secondary-foreground: 222 47% 11%;

    --muted: 210 40% 96%;
    --muted-foreground: 215 16% 47%;

    --accent: 210 40% 96%;
    --accent-foreground: 222 47% 11%;

    --destructive: 0 84% 60%;
    --destructive-foreground: 210 40% 98%;

    --success: 142 71% 45%;
    --success-foreground: 0 0% 100%;

    --warning: 38 92% 50%;
    --info: 217 91% 60%;

    --border: 214 32% 91%;
    --input: 214 32% 91%;
    --ring: 222 47% 11%;

    --radius: 0.5rem;

    /* A chat balloon, one's own and someone else's. Their own entries, as --primary can be anything an app makes it. */
    --s-bubble-own: 221 83% 53%;
    --s-bubble-own-foreground: 0 0% 100%;
    --s-bubble: 210 40% 96%;
    --s-bubble-foreground: 222 47% 11%;
}

.theme-dark,
.theme-dark-contrast {
    color-scheme: dark;

    --background: 222 47% 11%;
    --foreground: 210 40% 98%;

    --card: 222 47% 11%;
    --card-foreground: 210 40% 98%;

    --popover: 222 47% 11%;
    --popover-foreground: 210 40% 98%;

    --primary: 210 40% 98%;
    --primary-foreground: 222 47% 11%;

    --secondary: 217 33% 17%;
    --secondary-foreground: 210 40% 98%;

    --muted: 217 33% 17%;
    --muted-foreground: 215 20% 65%;

    --accent: 217 33% 17%;
    --accent-foreground: 210 40% 98%;

    --destructive: 0 63% 31%;
    --destructive-foreground: 210 40% 98%;

    --success: 142 71% 45%;
    --success-foreground: 0 0% 100%;

    --warning: 38 92% 50%;
    --info: 217 91% 60%;

    --border: 217 33% 17%;
    --input: 217 33% 17%;
    --ring: 213 27% 84%;

    --radius: 0.5rem;

    --s-bubble-own: 217 70% 35%;
    --s-bubble-own-foreground: 0 0% 100%;
    --s-bubble: 217 33% 17%;
    --s-bubble-foreground: 210 40% 98%;
}

/* The high-contrast pair: what differs from light and dark. */
.theme-light-contrast {
    --background: 0 0% 100%;
    --foreground: 0 0% 0%;
    --card-foreground: 0 0% 0%;
    --popover-foreground: 0 0% 0%;
    --primary: 0 0% 0%;
    --primary-foreground: 0 0% 100%;
    --secondary: 0 0% 90%;
    --secondary-foreground: 0 0% 0%;
    --muted: 0 0% 93%;
    --muted-foreground: 0 0% 20%;
    --accent: 0 0% 90%;
    --accent-foreground: 0 0% 0%;
    --destructive: 0 80% 35%;
    --destructive-foreground: 0 0% 100%;
    --success: 142 80% 22%;
    --warning: 30 100% 30%;
    --info: 217 90% 35%;
    --border: 0 0% 20%;
    --input: 0 0% 20%;
    --ring: 0 0% 0%;
    --s-bubble-own: 221 83% 35%;
    --s-bubble: 0 0% 90%;
    --s-bubble-foreground: 0 0% 0%;
}

.theme-dark-contrast {
    --background: 0 0% 0%;
    --foreground: 0 0% 100%;
    --card: 0 0% 0%;
    --card-foreground: 0 0% 100%;
    --popover: 0 0% 0%;
    --popover-foreground: 0 0% 100%;
    --primary: 0 0% 100%;
    --primary-foreground: 0 0% 0%;
    --secondary: 0 0% 18%;
    --secondary-foreground: 0 0% 100%;
    --muted: 0 0% 15%;
    --muted-foreground: 0 0% 85%;
    --accent: 0 0% 20%;
    --accent-foreground: 0 0% 100%;
    --destructive: 0 90% 70%;
    --destructive-foreground: 0 0% 0%;
    --success: 142 70% 60%;
    --success-foreground: 0 0% 0%;
    --warning: 45 100% 60%;
    --info: 210 100% 75%;
    --border: 0 0% 80%;
    --input: 0 0% 80%;
    --ring: 0 0% 100%;
    --s-bubble-own: 217 80% 30%;
    --s-bubble: 0 0% 18%;
    --s-bubble-foreground: 0 0% 100%;
}

/* What the device asks for. The same values as .theme-dark, .theme-light-contrast and .theme-dark-contrast. */
@media (prefers-color-scheme: dark) {
    .theme-system {
        color-scheme: dark;

        --background: 222 47% 11%;
        --foreground: 210 40% 98%;

        --card: 222 47% 11%;
        --card-foreground: 210 40% 98%;

        --popover: 222 47% 11%;
        --popover-foreground: 210 40% 98%;

        --primary: 210 40% 98%;
        --primary-foreground: 222 47% 11%;

        --secondary: 217 33% 17%;
        --secondary-foreground: 210 40% 98%;

        --muted: 217 33% 17%;
        --muted-foreground: 215 20% 65%;

        --accent: 217 33% 17%;
        --accent-foreground: 210 40% 98%;

        --destructive: 0 63% 31%;
        --destructive-foreground: 210 40% 98%;

        --success: 142 71% 45%;
        --success-foreground: 0 0% 100%;

        --warning: 38 92% 50%;
        --info: 217 91% 60%;

        --border: 217 33% 17%;
        --input: 217 33% 17%;
        --ring: 213 27% 84%;

        --radius: 0.5rem;

        --s-bubble-own: 217 70% 35%;
        --s-bubble-own-foreground: 0 0% 100%;
        --s-bubble: 217 33% 17%;
        --s-bubble-foreground: 210 40% 98%;
    }
}

@media (prefers-contrast: more) {
    .theme-system {
        --background: 0 0% 100%;
        --foreground: 0 0% 0%;
        --card-foreground: 0 0% 0%;
        --popover-foreground: 0 0% 0%;
        --primary: 0 0% 0%;
        --primary-foreground: 0 0% 100%;
        --secondary: 0 0% 90%;
        --secondary-foreground: 0 0% 0%;
        --muted: 0 0% 93%;
        --muted-foreground: 0 0% 20%;
        --accent: 0 0% 90%;
        --accent-foreground: 0 0% 0%;
        --destructive: 0 80% 35%;
        --destructive-foreground: 0 0% 100%;
        --success: 142 80% 22%;
        --warning: 30 100% 30%;
        --info: 217 90% 35%;
        --border: 0 0% 20%;
        --input: 0 0% 20%;
        --ring: 0 0% 0%;
        --s-bubble-own: 221 83% 35%;
        --s-bubble: 0 0% 90%;
        --s-bubble-foreground: 0 0% 0%;
    }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
    .theme-system {
        --background: 0 0% 0%;
        --foreground: 0 0% 100%;
        --card: 0 0% 0%;
        --card-foreground: 0 0% 100%;
        --popover: 0 0% 0%;
        --popover-foreground: 0 0% 100%;
        --primary: 0 0% 100%;
        --primary-foreground: 0 0% 0%;
        --secondary: 0 0% 18%;
        --secondary-foreground: 0 0% 100%;
        --muted: 0 0% 15%;
        --muted-foreground: 0 0% 85%;
        --accent: 0 0% 20%;
        --accent-foreground: 0 0% 100%;
        --destructive: 0 90% 70%;
        --destructive-foreground: 0 0% 0%;
        --success: 142 70% 60%;
        --success-foreground: 0 0% 0%;
        --warning: 45 100% 60%;
        --info: 210 100% 75%;
        --border: 0 0% 80%;
        --input: 0 0% 80%;
        --ring: 0 0% 100%;
        --s-bubble-own: 217 80% 30%;
        --s-bubble: 0 0% 18%;
        --s-bubble-foreground: 0 0% 100%;
    }
}

/* The page around the themed root: its scrollbar, and the canvas before the first paint and on overscroll. */
:root:has(.s-root.theme-system) {
    color-scheme: light dark;
}

:root:has(.s-root.theme-dark, .s-root.theme-dark-contrast) {
    color-scheme: dark;
}

/* --------------------------------------------------------------------------
   Non-themed tokens: the same in every theme unless an app overrides them.
   -------------------------------------------------------------------------- */
:root {
    --s-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --s-font-size: 0.875rem;

    /* The text scale components choose from (Tailwind's xs, sm, base), rather than a size of their own: 12px for what a
       reader may skip, 14px for what they read to decide, 16px for running text. All in rem, so a reader's text size
       (data-text-size below) scales them with everything else. */
    --s-text-xs: 0.75rem;
    --s-text-sm: 0.875rem;
    --s-text-base: 1rem;

    /* The line height that goes with each size, as Tailwind pairs them: tighter for small text than a flat ratio gives. */
    --s-text-xs-line: 1rem;
    --s-text-sm-line: 1.25rem;
    --s-text-base-line: 1.5rem;

    /* Space between the lines of text. A control with a fixed height (a button, a chip) sets its own. */
    --s-line-height: 1.5;

    --s-space-1: 0.25rem;
    --s-space-2: 0.5rem;
    --s-space-3: 0.75rem;
    --s-space-4: 1rem;
    --s-space-6: 1.5rem;

    --s-shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.05);
    --s-shadow-md: 0 4px 6px -1px hsl(0 0% 0% / 0.1), 0 2px 4px -2px hsl(0 0% 0% / 0.1);

    --s-duration: 150ms;

    /* How far a button gives way while it is pressed: 1 for not at all. A place sets its own on the button or around it. */
    --s-press-scale: 0.97;

    /* How round a chat balloon is, the corner nearest its sender, and all of them on a square one. */
    --s-bubble-radius: 1rem;
    --s-bubble-tail-radius: 0.25rem;
    --s-bubble-square-radius: 0.125rem;

    /* A timer's bar between the warning and the danger colour; the other timer colours fall back on the theme. See subro.components.css. */
    --s-timer-caution: 25 95% 53%;

    /* What a reply quotes: a grey laid over whatever it stands on, so that it needs no entry per balloon. */
    --s-message-quote-background: 220 10% 50% / 0.25;

    /* The colour SAvatar gives initials from a name: its hue from the name, the rest from here. */
    --s-avatar-saturation: 45%;
    --s-avatar-lightness: 42%;
    --s-avatar-foreground: 0 0% 100%;

    /* An SQrCode's colours, the same in every theme: plenty of scanners do not read an inverted code. */
    --s-qr-foreground: 0 0% 0%;
    --s-qr-background: 0 0% 100%;
}

/* The corners, as shadcn/ui and Tailwind derive them from --radius: a card or dialog (lg) has the theme's radius, a button or
   field (md) 2px less, a small part inside one (sm) 4px less, so what sits inside is never rounder than what holds it.
   Worked out where --radius is known: a custom property is resolved on the element declaring it, so on :root alone these came
   out empty when a theme class further down holds --radius, and every corner in the library was square. Both, for an app that
   declares it on :root itself and has no SThemeProvider. */
:root,
.s-root {
    --s-radius-sm: calc(var(--radius) - 4px);
    --s-radius-md: calc(var(--radius) - 2px);
    --s-radius-lg: var(--radius);
}

/* The page's column, per display type (Subro.Razor.Display): its widest, and its margin at the sides. Relative where the
   screen is large: a share of the screen, capped in rem so that lines stay readable and grow with the reader's text size.
   A phone uses its whole width. The breakpoints are DisplayBreakpoints'; media queries cannot read custom properties. */
:root {
    --s-page-gutter: 1rem;
    --s-page-max-width: 100%;

    /* What a page's content takes inside the column, by kind (README, "Display types"): text read or acted on at most
       the readable width; collections scanned in a grid of cards at least --s-card-min-width wide; a side column at least
       --s-aside-min-width. */
    --s-readable-width: 48rem;
    --s-card-min-width: 18rem;
    --s-aside-min-width: 20rem;
}

@media (min-width: 48rem) {
    :root {
        --s-page-gutter: 1.5rem;
        --s-page-max-width: 42rem;
    }
}

@media (min-width: 64rem) {
    :root {
        --s-page-max-width: min(88%, 80rem);
    }
}

@media (min-width: 96rem) {
    :root {
        --s-page-max-width: min(85%, 100rem);
    }
}

/* The themed root. Placed on the element SThemeProvider renders, not on <html>,
   so theming needs no JS and survives prerendering. */
.s-root {
    min-block-size: 100%;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: var(--s-font-sans);
    font-size: var(--s-font-size);
    line-height: var(--s-line-height);
}

/* The reader's text size (TextSize), on <html> because every size in the library is in rem: the root's font size scales
   text, controls and spacing together, the way the browser's own text-size setting does. */
:root[data-text-size="large"] {
    font-size: 112.5%;
}

:root[data-text-size="larger"] {
    font-size: 125%;
}

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