/* Project OS design system — the shared tokens every surface is built from.
 *
 * From a brief pasted in: integrate Apple's design language -- materials,
 * spatial layout, motion, colour, typography -- with Project OS's own spatial
 * environment, keeping its capabilities and replacing what was inferior. The
 * audit, the decisions and the reasons are in docs/design-system.md; this file
 * is the vocabulary the rest of the stylesheets speak.
 *
 * Loaded before style.css on every page (index.html, login.html), so it only
 * defines: nothing here selects an element except the appearance switch on
 * <html> and the accessibility media queries. Components consume these in
 * their own files -- the window in atlas-themes.css, its title bar in
 * atlas-os-home.css, the toolbar in style.css.
 *
 * Two appearances, chosen by what the palette is rather than by a setting:
 * osAppearance.js reads the resolved window colour and writes
 * html[data-os-appearance="light"|"dark"], and the pre-paint script in
 * index.html writes the same from the saved palette before first paint. Every
 * token below that depends on the appearance is defined for dark on :root and
 * redefined for light, so a component never asks which one it is in.
 */

:root {
  /* ── Typography ──────────────────────────────────────────────────────────
   * One family. Windows were set in Inter and the shell around them in
   * system-ui, so on a Mac two sans faces sat side by side -- SF in the
   * toolbar, Inter in the window under it. The system face comes first, as
   * the HIG asks; Inter, self-hosted, is the fallback where the system face
   * is not SF. */
  --os-font-text: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, 'Segoe UI', Roboto, sans-serif;
  --os-font-mono: ui-monospace, 'SF Mono', 'Fira Code', Menlo, monospace;

  /* The type ramp: the HIG's styles at desktop density. Weight, size and
     colour make the hierarchy (Typography); tracking tightens as the size
     grows, as SF's own does. */
  --os-type-large-title: 700 26px/32px var(--os-font-text);
  --os-type-title-1: 700 22px/28px var(--os-font-text);
  --os-type-title-2: 600 17px/22px var(--os-font-text);
  --os-type-title-3: 600 15px/20px var(--os-font-text);
  --os-type-headline: 600 13px/18px var(--os-font-text);
  --os-type-body: 400 13px/18px var(--os-font-text);
  --os-type-callout: 400 12px/16px var(--os-font-text);
  --os-type-footnote: 400 11px/14px var(--os-font-text);
  --os-type-caption: 500 10px/13px var(--os-font-text);
  --os-tracking-display: -0.022em;
  --os-tracking-title: -0.014em;
  --os-tracking-text: -0.006em;
  --os-tracking-caption: 0.02em;

  /* ── Spacing: a 4px grid ─────────────────────────────────────────────── */
  --os-space-1: 4px;
  --os-space-2: 8px;
  --os-space-3: 12px;
  --os-space-4: 16px;
  --os-space-5: 20px;
  --os-space-6: 24px;
  --os-space-7: 32px;
  --os-space-8: 40px;

  /* ── Shape ───────────────────────────────────────────────────────────────
   * Radii nest: a shape inside another, inset by a padding, takes the outer
   * radius less that padding, so the two curves stay concentric. The
   * stylesheets carried fourteen radii between 2px and 18px for the same few
   * kinds of thing; these are the five. */
  --os-radius-window: 18px;
  --os-radius-card: 12px;
  --os-radius-control: 8px;
  --os-radius-small: 6px;
  --os-radius-capsule: 999px;
  /* Hit targets: 28px is the HIG's floor for a pointer, 44px for a finger. */
  --os-target: 28px;
  --os-target-touch: 44px;

  /* ── Materials ───────────────────────────────────────────────────────────
   * Glass is lit, not drawn: a specular rim along its top edge where the
   * light catches it, a hairline that separates it from what is behind, a
   * sheen that falls off down its face, and a shadow that says how far above
   * the content it floats. The tint and blur are Customize > Glass's
   * (style.css, html[data-atlas-glass]); these are the light on it. */
  --os-glass-rim: inset 0 1px 0 0 rgb(255 255 255 / 0.09), inset 0 0 0 1px rgb(255 255 255 / 0.035);
  --os-glass-sheen: linear-gradient(180deg, rgb(255 255 255 / 0.05), rgb(255 255 255 / 0.012) 96px, rgb(255 255 255 / 0) 220px);
  --os-glass-blur: blur(28px) saturate(180%);
  /* The rim of a control's glass: brighter than a window's, with a shade
     along its lower edge, so a capsule reads as a lens. */
  --os-control-rim: inset 0 1px 0 0 rgb(255 255 255 / 0.16), inset 0 -1px 0 0 rgb(0 0 0 / 0.18), inset 0 0 0 1px rgb(255 255 255 / 0.05);
  --os-control-blur: blur(20px) saturate(190%);

  /* ── Elevation ───────────────────────────────────────────────────────────
   * Diffuse, layered shadows in place of the coloured glow every window,
   * button and bar wore. A glow is light the surface makes; in this system
   * only live things make light -- the listening dot, the brain while it
   * works, the focused node. Chrome is lit from outside and casts shadow. */
  --os-shadow-1: 0 1px 2px rgb(0 0 0 / 0.28), 0 1px 1px rgb(0 0 0 / 0.16);
  --os-shadow-2: 0 0 0 0.5px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.3);
  --os-shadow-window: 0 0 0 0.5px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.22), 0 22px 56px -10px rgb(0 0 0 / 0.6);
  --os-shadow-window-key: 0 0 0 0.5px rgb(0 0 0 / 0.6), 0 3px 10px rgb(0 0 0 / 0.26), 0 30px 72px -12px rgb(0 0 0 / 0.68);

  /* ── Motion ──────────────────────────────────────────────────────────────
   * Springs, sampled from a damped oscillator's step response into
   * linear() (the curve generator is in docs/design-system.md). A spring is
   * defined by how long it takes and how much it overshoots, not by a bezier
   * shape, so things that move feel like the same physics everywhere.
   *   quick    response 0.26s, critically damped -- hover, press, toggles
   *   window   response 0.38s, damping 0.84, 0.8% overshoot -- windows, sheets
   *   bouncy   response 0.44s, damping 0.72, 3.8% overshoot -- a node landing */
  --os-spring-quick: linear(0, 0.0678, 0.2078, 0.3621, 0.5041, 0.6241, 0.7203, 0.7949, 0.8512, 0.8931, 0.9238, 0.9461, 0.962, 0.9734, 0.9814, 0.9871, 0.9911, 0.9938, 0.9957, 0.9971, 1);
  --os-spring-quick-duration: 350ms;
  --os-spring-window: linear(0, 0.0651, 0.2076, 0.3725, 0.5296, 0.6643, 0.7719, 0.8531, 0.9115, 0.9515, 0.9774, 0.9932, 1.002, 1.0062, 1.0077, 1.0075, 1.0065, 1.0053, 1.004, 1.0029, 1);
  --os-spring-window-duration: 489ms;
  --os-spring-bouncy: linear(0, 0.0585, 0.1936, 0.3589, 0.5241, 0.6714, 0.7926, 0.8855, 0.9519, 0.9958, 1.0218, 1.0346, 1.0384, 1.0365, 1.0314, 1.0251, 1.0187, 1.013, 1.0083, 1.0046, 1);
  --os-spring-bouncy-duration: 525ms;
  /* Fades and colour changes do not move, so they take a plain curve. */
  --os-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --os-ease-in: cubic-bezier(0.55, 0, 0.75, 0.06);
  --os-duration-fade: 180ms;
  --os-duration-exit: 200ms;
  /* How far a control gives under a press. */
  --os-press-scale: 0.96;

  /* ── System colours ──────────────────────────────────────────────────────
   * The HIG's, for status that should read the same on every palette: a
   * success is green whatever the accent is. Dark values here, light below. */
  --os-red: rgb(255 66 69);
  --os-orange: rgb(255 146 48);
  --os-yellow: rgb(255 214 0);
  --os-green: rgb(48 209 88);
  --os-mint: rgb(0 218 195);
  --os-cyan: rgb(60 211 254);
  --os-blue: rgb(0 145 255);
  --os-indigo: rgb(109 124 255);
  --os-purple: rgb(219 52 242);
  --os-pink: rgb(255 55 95);

  color-scheme: dark;
}

/* ── Tokens drawn from the palette ────────────────────────────────────────
 * Defined on body, not :root. A custom property that refers to another is
 * resolved where it is declared, and the palette is declared on body.atlas-os
 * (atlas-palettes.css): on :root these would read :root's own --atlas-text --
 * style.css's original blue-white -- and hand every element that, whatever
 * palette was chosen. */
body {
  /* Labels, fills and separators.
   * Tiers of the palette's own ink rather than greys of their own, so they
   * hold on every palette and every material (Materials: vibrant labels).
   * Quaternary is for disabled marks only, never text on thin glass. */
  --os-label: var(--atlas-text, var(--fg, #f5f5f7));
  --os-label-secondary: color-mix(in srgb, var(--os-label) 64%, transparent);
  --os-label-tertiary: color-mix(in srgb, var(--os-label) 42%, transparent);
  --os-label-quaternary: color-mix(in srgb, var(--os-label) 24%, transparent);
  --os-fill: color-mix(in srgb, var(--os-label) 11%, transparent);
  --os-fill-secondary: color-mix(in srgb, var(--os-label) 8%, transparent);
  --os-fill-tertiary: color-mix(in srgb, var(--os-label) 5%, transparent);
  --os-separator: color-mix(in srgb, var(--os-label) 12%, transparent);
  --os-tint: var(--atlas-primary, var(--red, #6d7cff));
  --os-focus-ring: 0 0 0 3px color-mix(in srgb, var(--os-tint) 46%, transparent);

  /* Controls float above content on a clearer glass than windows: the
     toolbar's capsule, the title bar's buttons (Materials: Liquid Glass is
     for the controls layer, Regular for windows). */
  --os-control-glass: color-mix(in srgb, var(--atlas-background, var(--bg, #111)) 46%, transparent);
  /* Ink on a filled control (--atlas-button), and that control hovered. On a
     dark ground the fill is a translucent accent and takes the palette's ink;
     on a light one it is the solid accent (atlas-palettes.css) and takes
     white, and hovering deepens it rather than washing it out. */
  --os-on-tinted: var(--os-label);
  --os-tinted-hover: color-mix(in srgb, var(--atlas-primary, var(--os-tint)) 50%, transparent);
  /* Where the backdrop falls off at the screen's edge (bg-backgrounds.css).
     Near-black on a dark ground, as it always was; on a light one a cool
     grey of the ground itself -- it was the same near-black, a dark frame
     round every light palette. */
  --os-backdrop-edge: #020508;
}

/* ── Light ────────────────────────────────────────────────────────────────
 * Glass over a light ground catches more light and casts a softer shadow; the
 * rim is near-white, the sheen stronger, and the shadows a third as dark. */
:root[data-os-appearance="light"] {
  --os-glass-rim: inset 0 1px 0 0 rgb(255 255 255 / 0.85), inset 0 0 0 1px rgb(255 255 255 / 0.4);
  --os-glass-sheen: linear-gradient(180deg, rgb(255 255 255 / 0.5), rgb(255 255 255 / 0.16) 96px, rgb(255 255 255 / 0) 240px);
  --os-control-rim: inset 0 1px 0 0 rgb(255 255 255 / 0.9), inset 0 -1px 0 0 rgb(0 0 0 / 0.04), inset 0 0 0 1px rgb(255 255 255 / 0.5);
  --os-shadow-1: 0 1px 2px rgb(0 0 0 / 0.08), 0 1px 1px rgb(0 0 0 / 0.04);
  --os-shadow-2: 0 0 0 0.5px rgb(0 0 0 / 0.08), 0 4px 14px rgb(0 0 0 / 0.08);
  --os-shadow-window: 0 0 0 0.5px rgb(0 0 0 / 0.1), 0 2px 6px rgb(0 0 0 / 0.05), 0 22px 56px -10px rgb(0 0 0 / 0.2);
  --os-shadow-window-key: 0 0 0 0.5px rgb(0 0 0 / 0.12), 0 3px 10px rgb(0 0 0 / 0.07), 0 30px 72px -12px rgb(0 0 0 / 0.26);
  --os-red: rgb(255 56 60);
  --os-orange: rgb(255 141 40);
  --os-yellow: rgb(255 204 0);
  --os-green: rgb(52 199 89);
  --os-mint: rgb(0 200 179);
  --os-cyan: rgb(0 192 232);
  --os-blue: rgb(0 136 255);
  --os-indigo: rgb(97 85 245);
  --os-purple: rgb(203 48 224);
  --os-pink: rgb(255 45 85);
  color-scheme: light;
}
:root[data-os-appearance="light"] body {
  --os-on-tinted: #fff;
  --os-tinted-hover: color-mix(in srgb, var(--atlas-primary, var(--os-tint)) 86%, #000);
  --os-backdrop-edge: color-mix(in srgb, var(--atlas-background, var(--bg, #fff)) 84%, #5d6474);
  --os-label-secondary: color-mix(in srgb, var(--os-label) 70%, transparent);
  --os-label-tertiary: color-mix(in srgb, var(--os-label) 48%, transparent);
  --os-label-quaternary: color-mix(in srgb, var(--os-label) 28%, transparent);
  --os-fill: color-mix(in srgb, var(--os-label) 9%, transparent);
  --os-fill-secondary: color-mix(in srgb, var(--os-label) 6%, transparent);
  --os-fill-tertiary: color-mix(in srgb, var(--os-label) 4%, transparent);
  --os-separator: color-mix(in srgb, var(--os-label) 13%, transparent);
  --os-control-glass: color-mix(in srgb, var(--atlas-background, var(--bg, #fff)) 58%, transparent);
}

/* ── Accessibility ────────────────────────────────────────────────────────
 * Reduce Motion: nothing travels or scales; things that appear fade
 * (Motion: "consider using fades"). The springs become the plain curve at
 * the fade's length, so a transition written with them still completes. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --os-spring-quick: var(--os-ease-out);
    --os-spring-window: var(--os-ease-out);
    --os-spring-bouncy: var(--os-ease-out);
    --os-spring-quick-duration: 1ms;
    --os-spring-window-duration: var(--os-duration-fade);
    --os-spring-bouncy-duration: 1ms;
    --os-press-scale: 1;
  }
}

/* Increase Contrast and Reduce Transparency: the HIG asks custom colours for
   clearly more differentiation, and materials for near-opacity (the glass
   itself goes opaque in style.css). Labels step up a tier and separators
   darken. */
@media (prefers-contrast: more), (prefers-reduced-transparency: reduce) {
  body {
    --os-label-secondary: color-mix(in srgb, var(--os-label) 82%, transparent);
    --os-label-tertiary: color-mix(in srgb, var(--os-label) 64%, transparent);
    --os-separator: color-mix(in srgb, var(--os-label) 26%, transparent);
    --os-control-glass: color-mix(in srgb, var(--atlas-background, var(--bg, #111)) 94%, transparent);
  }
}
