/**
 * =================================================================
 * Global Reset — Document Shell (Light DOM only)
 * =================================================================
 *
 * Sets up the <html> and <body> for a Lit-based application where
 * all UI lives inside web components. This file handles only what
 * CAN'T be done from inside Shadow DOM:
 *
 *   - color-scheme on the document root
 *   - Margin reset on <body>
 *   - First-paint background on <html> (see below)
 *   - Reduced-motion preference (global fallback)
 *
 * Component-level resets (box-sizing, typography, etc.) are handled
 * by DUI's `duiBase` style (`base` from `@dui/primitives/core`) in
 * every Lit component.
 * =================================================================
 */

/**
 * =================================================================
 * Webfonts, self-hosted
 * =================================================================
 *
 * The two faces the app names: Inter for --font-sans (`sans: "Inter"`
 * in client/styles.ts, which DUI resolves to --font-sans) and JetBrains
 * Mono, the first family in DUI's default --font-mono stack. Both are
 * served from our own origin rather than Google Fonts so a page renders
 * in its real typefaces with no third-party request: the workshop stage
 * must not depend on fonts.gstatic.com being reachable from the room,
 * and a same-origin face is also readable by anything that has to
 * inline the font (a DOM-to-image capture cannot fetch across origins).
 *
 * Declaring @font-face is what makes a family name in a stack mean
 * anything — a name with no face behind it is skipped silently, and the
 * next entry in the stack wins.
 *
 * Variable fonts, so one file per subset covers every weight the app
 * uses. Two subsets each — latin and latin-ext — which together cover
 * Western European text; Google also serves cyrillic, greek and
 * vietnamese, and nothing here needs them. Files and licences (both SIL
 * OFL 1.1) are in static/fonts/. To refresh, re-fetch the URLs in
 * https://fonts.googleapis.com/css2?family=Inter:wght@100..900 and
 * https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@100..800
 * with a browser User-Agent, which is what selects woff2.
 * =================================================================
 */

/* --- Inter (--font-sans) --- */

/* latin */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/inter-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;
}

/* latin-ext */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/inter-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;
}

/* --- JetBrains Mono (--font-mono) --- */

/* latin */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/static/fonts/jetbrains-mono-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;
}

/* latin-ext */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/static/fonts/jetbrains-mono-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;
}

html {
  box-sizing: border-box;
  overscroll-behavior: none;
}

/**
 * First-paint background. DUI's --background / --foreground tokens
 * are injected into adoptedStyleSheets by JavaScript and are not
 * available at first paint, so `var()` cannot be used here — these
 * values are a literal copy of the DUI default tokens. Keep in sync
 * with packages/dui-components/src/tokens/tokens.css, and note that
 * `client/styles.ts` deliberately overrides no color primitives, so
 * that file is *not* a third place these values live.
 *
 * The bare `html` rule and the @media query cover the pre-JS state
 * (no data-theme attribute) using the OS preference. The
 * [data-theme] rules are higher-specificity and win once theme.ts
 * has run — which, thanks to blocking="render" on the client
 * bundle, is always before first paint.
 */
html {
  background: oklch(0.97 0 0);
  color: oklch(0.15 0 0);
}

@media (prefers-color-scheme: dark) {
  html {
    background: oklch(0.15 0.015 260);
    color: oklch(0.93 0 0);
  }
}

html[data-theme="light"] {
  background: oklch(0.97 0 0);
  color: oklch(0.15 0 0);
}

html[data-theme="dark"] {
  background: oklch(0.15 0.015 260);
  color: oklch(0.93 0 0);
}

body {
  box-sizing: border-box;
  margin: 0;
  min-height: 100dvh;
}

/**
 * Cross-document View Transitions. Opts every same-origin
 * page-to-page navigation into the default transition — the MPA
 * gets smooth navigation with no client-side router.
 */
@view-transition {
  navigation: auto;
}

/**
 * Reduced-motion handling. Catches any light-DOM
 * animations and reduces the duration and intensity.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
