/*
 * tokens.css — the primitive scale, and nothing else.
 *
 * Every number the UI may use is named here once. A value that is not on a scale below cannot
 * be given a name: stylelint (fsm/token-scales) checks each family against the scale it belongs
 * to, and rejects a custom property that belongs to no family.
 *
 * Nothing outside this file writes a raw colour, length, duration, font size, weight, line
 * height or letter spacing. semantic.css gives these primitives roles; control CSS uses roles.
 *
 * The first line fixes the cascade order for every sheet that follows. The theme layer wins.
 */
@layer tokens, semantic, layout, components, themes, schemes;

/* The faces the font-family primitives name, self-hosted from design/fonts (SIL OFL 1.1; the
   licences sit beside the files). Latin and Latin Extended, variable weight. */
@layer tokens {
    @font-face {
        font-family: "Public Sans";
        font-style: normal;
        font-weight: 400 700;
        font-display: swap;
        src: url("../fonts/public-sans-latin-ext.woff2") format("woff2");
        unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
    }

    @font-face {
        font-family: "Public Sans";
        font-style: normal;
        font-weight: 400 700;
        font-display: swap;
        src: url("../fonts/public-sans-latin.woff2") format("woff2");
        unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
    }

    @font-face {
        font-family: "Schibsted Grotesk";
        font-style: normal;
        font-weight: 500 700;
        font-display: swap;
        src: url("../fonts/schibsted-grotesk-latin-ext.woff2") format("woff2");
        unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
    }

    @font-face {
        font-family: "Schibsted Grotesk";
        font-style: normal;
        font-weight: 500 700;
        font-display: swap;
        src: url("../fonts/schibsted-grotesk-latin.woff2") format("woff2");
        unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
    }

    @font-face {
        font-family: "Source Code Pro";
        font-style: normal;
        font-weight: 400 600;
        font-display: swap;
        src: url("../fonts/source-code-pro-latin-ext.woff2") format("woff2");
        unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
    }

    @font-face {
        font-family: "Source Code Pro";
        font-style: normal;
        font-weight: 400 600;
        font-display: swap;
        src: url("../fonts/source-code-pro-latin.woff2") format("woff2");
        unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
    }
}

@layer tokens {
    :root {
        /* Space — the 4-point scale. The step number is the value of data-gap. */
        --app-space-1: 4px;
        --app-space-2: 8px;
        --app-space-3: 12px;
        --app-space-4: 16px;
        --app-space-5: 20px;
        --app-space-6: 24px;
        --app-space-8: 32px;
        --app-space-12: 48px;

        /* Radius — 6 and 8 for small parts and compact controls, 10 for buttons at the
           regular height, 14 for cards and dialogs, full for pills. */
        --app-radius-6: 6px;
        --app-radius-8: 8px;
        --app-radius-10: 10px;
        --app-radius-14: 14px;
        --app-radius-full: 999px;

        /* Control heights. 40 is regular, 32 is compact density, 28 is a chip, 48 a button in a
           phone's action bar on a touch screen. */
        --app-control-28: 28px;
        --app-control-32: 32px;
        --app-control-40: 40px;
        --app-control-48: 48px;

        /* Touch target. On a coarse pointer the hit area is never smaller than this,
           whatever the visible height of the control is. */
        --app-touch-44: 44px;

        /* Icon sizes. 16 is the default. */
        --app-icon-16: 16px;
        --app-icon-20: 20px;
        --app-icon-24: 24px;

        /* Measures — the widths a surface or a fixed track may have. 80 to 240 are the widths a
           table column may ask for; 160 is also the label column of a form with labels beside
           the fields, 240 the navigation, 400 the list of a split view. */
        --app-measure-80: 80px;
        --app-measure-120: 120px;
        --app-measure-160: 160px;
        --app-measure-240: 240px;
        --app-measure-320: 320px;
        --app-measure-400: 400px;
        --app-measure-480: 480px;
        --app-measure-560: 560px;
        --app-measure-800: 800px;

        /* Border widths. */
        --app-border-1: 1px;
        --app-border-2: 2px;

        /* Strokes, unitless (SVG user units): icons on a 24 grid, and ink in CSS px as drawn. */
        --app-stroke-thin: 1.5;
        --app-stroke-regular: 2;
        --app-stroke-ink: 3;

        /* Type — five sizes, three weights, four line heights. No 10px, no 12.5px.
           Line heights are lengths on the 4px grid, not ratios: every line box is 16, 20, 24
           or 32 tall, so text stacks on the same rhythm as the space scale and the controls. */
        --app-font-size-caption: 12px;
        --app-font-size-meta: 13px;
        --app-font-size-body: 14px;
        --app-font-size-title: 18px;
        --app-font-size-display: 24px;

        --app-font-weight-regular: 400;
        --app-font-weight-medium: 500;
        --app-font-weight-semibold: 600;

        --app-line-height-16: 16px;
        --app-line-height-20: 20px;
        --app-line-height-24: 24px;
        --app-line-height-32: 32px;

        --app-letter-spacing-normal: 0;
        --app-letter-spacing-tight: -0.01em;

        /* Families every platform already has. A theme names its own faces in front of these. */
        --app-font-family-system: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
        --app-font-family-system-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
        --app-font-family-sans: "Public Sans", var(--app-font-family-system);
        --app-font-family-grotesk: "Schibsted Grotesk", "Public Sans", var(--app-font-family-system);
        --app-font-family-code: "Source Code Pro", var(--app-font-family-system-mono);

        /* Colour — quiet blue-grey neutrals and one blue. Tones for state. */
        --app-gray-0: #ffffff;
        --app-gray-25: #f5f7fb;
        --app-gray-50: #eef1f5;
        --app-gray-100: #e4e8ee;
        --app-gray-200: #cdd4de;
        --app-gray-400: #8a94a3; /* 3:1 on white — the floor for a control's outline */
        --app-gray-450: #6c788c; /* 3:1 on night-700 — a control's outline in the dark */
        --app-gray-500: #5f6d82; /* 4.5:1 on gray-25 — the lightest text */
        --app-gray-700: #4a5568;
        --app-gray-900: #162033;

        /* Night: the dark scheme's surfaces, darkest first; each step up is nearer the eye.
           Its text is the light end of gray (50, 200, 400). */
        --app-night-900: #0b111b;
        --app-night-800: #121a27;
        --app-night-700: #192232;
        --app-night-600: #202a3c;
        --app-night-500: #263044;
        --app-night-400: #344056;

        --app-blue-50: #f3f8fd;
        --app-blue-100: #e8f1fb;
        --app-blue-600: #1f4fd1;
        --app-blue-700: #1a43b3;
        --app-blue-800: #163a9a;

        --app-red-50: #fdecea;
        --app-red-600: #c24a3a;
        --app-red-700: #a8352a;
        --app-red-800: #8a2a21;
        /* The tones in the dark: 300 text, 400 lines and icons, 950 the wash behind them. */
        --app-red-300: #f39a8f;
        --app-red-400: #e06a5c;
        --app-red-950: #3b1c1a;

        --app-green-50: #e6f4ea;
        --app-green-600: #2e8b4a;
        --app-green-700: #1f6b37;
        --app-green-300: #7dd39a;
        --app-green-400: #4fb873;
        --app-green-950: #13301f;

        --app-amber-50: #fff4e0;
        --app-amber-600: #d08a2a;
        --app-amber-700: #8a5a10;
        --app-amber-300: #f2bd6c;
        --app-amber-400: #e2a13f;
        --app-amber-950: #3a2a12;

        /* Violet: information and planned work, so blue stays for "act here". 700 is 6.9:1 on
           its 50 wash, 600 is 4.9:1 there (icons). */
        --app-violet-50: #f3effc;
        --app-violet-600: #7354c7;
        --app-violet-700: #5b3ea8;
        --app-violet-300: #bfaef3;
        --app-violet-400: #9c86e8;
        --app-violet-950: #261f47;

        --app-overlay-32: rgb(22 32 51 / 32%);
        --app-overlay-56: rgb(0 0 0 / 56%);

        /* Breakpoints — the widths at which a layout changes. A query cannot read var(), so
           @media and @container write these numbers literally; fsm/breakpoints only lets them
           write a number declared here. They are the width of the region being laid out
           (a container query) unless a rule says viewport.
             480  viewport: a phone — narrow page gutter, actions share the width
             560  region: 4 columns become 8; a page header puts its actions beside the title
             960  region: 8 columns become 12; a split view shows list and detail side by side;
                  viewport: the navigation is a column instead of a drawer */
        --app-breakpoint-480: 480px;
        --app-breakpoint-560: 560px;
        --app-breakpoint-960: 960px;

        /* The page height. dvh follows a phone's moving toolbars; 100vh does not. */
        --app-viewport-height: 100dvh;
        /* What the on-screen keyboard covers, where the browser reports it (Chromium, once the
           page lets the keyboard lie over it); fsm-ui.js writes the role for every browser. */
        --app-viewport-keyboard: env(keyboard-inset-height, 0px);
        /* What the device covers at each edge (a status bar, a gesture bar, a notch, a rounded
           corner), where the browser reports it: WKWebView and Chrome do, a desktop as 0. The
           Android app writes these on the root itself, as its WebView reports 0 while the app
           draws under the system bars. */
        --app-viewport-safe-top: env(safe-area-inset-top, 0px);
        --app-viewport-safe-right: env(safe-area-inset-right, 0px);
        --app-viewport-safe-bottom: env(safe-area-inset-bottom, 0px);
        --app-viewport-safe-left: env(safe-area-inset-left, 0px);

        /* Colour scheme the browser draws its own parts in (scrollbars, autofill). */
        --app-scheme-light: light;
        --app-scheme-dark: dark;

        /* Shadow — four named steps. A resting surface takes a border or shadow-resting,
           never both. */
        /* The system's own colours. Only forced-colours mode (a Windows contrast theme) uses
           them, where nothing else would show. */
        --app-system-canvas: Canvas;
        --app-system-text: CanvasText;
        --app-system-highlight: Highlight;
        --app-system-highlight-text: HighlightText;
        --app-system-gray: GrayText;

        --app-shadow-resting: 0 1px 3px rgb(22 32 51 / 6%);
        --app-shadow-raised: 0 4px 14px rgb(22 32 51 / 8%);
        --app-shadow-overlay: 0 8px 24px -8px rgb(22 32 51 / 18%);
        --app-shadow-modal: 0 24px 60px rgb(15 23 42 / 28%);
        /* In the dark a shadow barely shows: elevation is the surface's step (night), and the
           shadow only deepens the edge. */
        --app-shadow-resting-dark: 0 1px 2px rgb(0 0 0 / 40%);
        --app-shadow-overlay-dark: 0 8px 24px -8px rgb(0 0 0 / 64%);
        --app-shadow-modal-dark: 0 24px 60px rgb(0 0 0 / 64%);

        /* Motion — three durations for state, one for a busy spinner, one for the pulse of a
           loading placeholder, three easings. */
        --app-duration-fast: 120ms;
        --app-duration-base: 180ms;
        --app-duration-slow: 260ms;
        --app-duration-spin: 900ms;
        --app-duration-pulse: 1200ms;

        --app-easing-standard: cubic-bezier(0.2, 0.6, 0.2, 1);
        --app-easing-enter: cubic-bezier(0, 0, 0.2, 1);
        --app-easing-exit: cubic-bezier(0.4, 0, 1, 1);
        --app-easing-linear: linear;

        /* Stacking. */
        --app-z-sticky: 10;
        --app-z-popover: 100;
        --app-z-drawer: 200;
        --app-z-dialog: 300;
    }

    /* Movement for state collapses to nothing. A busy spinner keeps turning: it is the only
       sign that work is going on. */
    @media (prefers-reduced-motion: reduce) {
        :root {
            --app-duration-fast: 0ms;
            --app-duration-base: 0ms;
            --app-duration-slow: 0ms;
        }
    }
}
