/* Sistum design tokens.
   Three levels, each one only refers to the level above it:
   1. Primitives  raw scales with no meaning (colour ramps, 4px spacing grid, type scale, durations...)
   2. Semantic    what a value is for (surface, text, border, accent, status), themed light / dark
   3. Applied     per-component values (button padding, avatar size...) built from semantic / primitive tokens
   Components in style.css use semantic or applied tokens only. Breakpoints cannot be variables in CSS, they are listed in design-system.md. */

:root {

  /* ---- 1. PRIMITIVES: colour ---- */
  --color-neutral-0: #fff;
  --color-neutral-100: #edeff3;
  --color-neutral-200: #bcd1dc;
  --color-neutral-300: #95cee6;
  --color-neutral-400: #3d6677;
  --color-neutral-500: #3c778f;
  --color-neutral-600: #4d7caf;
  --color-neutral-700: #00445a;
  --color-neutral-800: #002a3f;
  --color-neutral-900: #07131b;
  --color-neutral-950: #02070b;
  --color-blue-600: #1f5b9b;
  --color-cyan-400: #2fd0ff;
  --color-cyan-950: #04121a;
  --color-green-100: #dcfce7;
  --color-green-400: #4ade80;
  --color-green-700: #15803d;
  --color-green-950: #052e16;
  --color-amber-100: #fef3c7;
  --color-amber-400: #fbbf24;
  --color-amber-700: #b45309;
  --color-amber-950: #3a2a05;
  --color-red-100: #fee2e2;
  --color-red-400: #f87171;
  --color-red-700: #b91c1c;
  --color-red-950: #3b0d0d;
  --color-ink-35: rgb(10 10 10 / .35); /* scrim behind dialogs and sheets */
  --color-ink-45: rgb(10 10 10 / .45); /* scrim behind mobile sheets */
  --color-shadow-20: rgb(0 0 0 / .05);
  --color-shadow-22: rgb(0 0 0 / .22);
  --color-shadow-25: rgb(0 0 0 / .25);

  /* ---- 1. PRIMITIVES: spacing (4px grid; also used for sizes up to 96px) ---- */
  --space-0: 0px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-9: 36px;
  --space-10: 40px;
  --space-12: 48px;
  --space-13: 52px;
  --space-14: 56px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* ---- 1. PRIMITIVES: sizes above the spacing scale (multiples of 16px) ---- */
  --size-112: 112px;
  --size-128: 128px;
  --size-144: 144px;
  --size-160: 160px;
  --size-176: 176px;
  --size-192: 192px;
  --size-208: 208px;
  --size-224: 224px;
  --size-240: 240px;
  --size-256: 256px;
  --size-272: 272px;
  --size-288: 288px;
  --size-304: 304px;
  --size-320: 320px;
  --size-336: 336px;
  --size-352: 352px;
  --size-368: 368px;
  --size-384: 384px;
  --size-400: 400px;
  --size-416: 416px;
  --size-432: 432px;
  --size-448: 448px;
  --size-464: 464px;
  --size-480: 480px;
  --size-496: 496px;
  --size-512: 512px;
  --size-640: 640px;
  --size-704: 704px;
  --size-768: 768px;
  --size-800: 800px;
  --size-992: 992px;
  --size-1024: 1024px;
  --size-1184: 1184px;

  /* ---- 1. PRIMITIVES: strokes ---- */
  --stroke-1: 1px;
  --stroke-2: 2px;

  /* ---- 1. PRIMITIVES: type ---- */
  --font-family-mono: ui-monospace, Menlo, monospace;
  --font-family-sans: Arial, Helvetica, Arial, sans-serif;
  --font-family-display: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-md: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 28px;
  --font-size-4xl: 32px;
  --font-size-5xl: 40px;
  --font-size-6xl: 48px;
  --font-size-7xl: 64px;
  --font-weight-light: 300;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --leading-none: 1;
  --leading-snug: 1.25;
  --leading-normal: 1.5;
  --tracking-tight: -.02em;
  --tracking-normal: 0;
  --tracking-wide: .04em;

  /* ---- 1. PRIMITIVES: shape ---- */
  --radius-0: 0;
  --radius-1: 4px;
  --radius-2: 8px;
  --radius-3: 16px;
  --radius-4: 24px;
  --radius-full: 9999px;
  --radius-circle: 50%;

  /* ---- 1. PRIMITIVES: motion, depth, opacity ---- */
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 400ms;
  --duration-draw: 900ms;
  --duration-spin: 1000ms;
  --ease-standard: cubic-bezier(.2, .7, .2, 1);
  --z-behind: -1;
  --z-raised: 1;
  --z-float: 2;
  --z-sticky: 4; /* sticky bars (page tabs, table heads) sit below dropdowns, so an open menu is never covered by them */
  --z-dropdown: 5;
  --z-menu: 20;
  --z-nav: 30;
  --z-nav-top: 31;
  --z-panel: 40;
  --z-sheet: 60;
  --z-tooltip: 1000;
  --opacity-disabled: .5;
  --opacity-muted: .7;
  --opacity-soft: .8;
  --blur-scrim: 8px;
}

/* 2. SEMANTIC: light theme (default) */
:root {
  color-scheme: light;
  --surface-page: var(--color-neutral-100);
  --surface-raised: var(--color-neutral-0);
  --surface-upraised: var(--color-neutral-100);
  --text-default: var(--color-neutral-700);
  --text-muted: var(--color-neutral-400);
  --border-default: var(--color-neutral-200);
  --border-control: var(--color-neutral-500); /* edge of a form control: 3:1 or more against the surface (WCAG 1.4.11); --border-default is for decoration */
  --accent: var(--color-blue-600);
  --accent-contrast: var(--color-neutral-0);
  --status-good: var(--color-green-700);
  --status-warn: var(--color-amber-700);
  --status-bad: var(--color-red-700);
  --status-good-subtle: var(--color-green-100);
  --status-warn-subtle: var(--color-amber-100);
  --status-bad-subtle: var(--color-red-100);
}

/* 2. SEMANTIC: dark theme, from the system preference unless the user picked light... */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-page: var(--color-neutral-950);
    --surface-raised: var(--color-neutral-900);
    --surface-upraised: var(--color-neutral-950);
    --text-default: var(--color-neutral-200);
    --text-muted: var(--color-neutral-300);
    --border-default: var(--color-neutral-700);
    --border-control: var(--color-neutral-500);
    --accent: var(--color-cyan-400);
    --accent-contrast: var(--color-cyan-950);
    --status-good: var(--color-green-400);
    --status-warn: var(--color-amber-400);
    --status-bad: var(--color-red-400);
    --status-good-subtle: var(--color-green-950);
    --status-warn-subtle: var(--color-amber-950);
    --status-bad-subtle: var(--color-red-950);
  }
}
/* ...or picked dark explicitly */
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-page: var(--color-neutral-950);
  --surface-raised: var(--color-neutral-900);
  --surface-upraised: var(--color-neutral-950);
  --text-default: var(--color-neutral-200);
  --text-muted: var(--color-neutral-300);
  --border-default: var(--color-neutral-700);
  --border-control: var(--color-neutral-500);
  --accent: var(--color-cyan-400);
  --accent-contrast: var(--color-cyan-950);
  --status-good: var(--color-green-400);
  --status-warn: var(--color-amber-400);
  --status-bad: var(--color-red-400);
  --status-good-subtle: var(--color-green-950);
  --status-warn-subtle: var(--color-amber-950);
  --status-bad-subtle: var(--color-red-950);
}
:root[data-theme="light"] {
  color-scheme: light;
}

:root {

  /* ---- 2. SEMANTIC: tints (a semantic colour at a given strength over transparent or another surface) ---- */
  --tint-todo: color-mix(in srgb, var(--accent) 12%, transparent);
  --tint-accent-12: color-mix(in srgb, var(--accent) 12%, transparent);
  --tint-accent-14-on-page: color-mix(in srgb, var(--accent) 20%, var(--surface-page));
  --tint-text-22: color-mix(in srgb, var(--text-default) 22%, transparent);
  --tint-text-7: color-mix(in srgb, var(--text-default) 7%, transparent);
  --tint-text-9: color-mix(in srgb, var(--text-default) 9%, transparent);

  /* ---- 1. PRIMITIVE: device safe areas (notch, home indicator, rounded corners); 0 in a normal browser window ---- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* ---- 2. SEMANTIC: overlays and depth ---- */
  --scrim: var(--color-ink-35);
  --scrim-strong: var(--color-ink-45);
  --shadow-overlay: 0 12px 40px var(--color-shadow-22); /* menus, dialogs */
  --shadow-sheet: 0 -12px 40px var(--color-shadow-25); /* mobile bottom sheets */
  --shadow-nav-bar: 0 -8px 48px var(--color-shadow-25); /* mobile bottom navigation */
  --shadow-tooltip: 0 6px 24px var(--color-shadow-25);
  --shadow-panel: -12px 0 40px var(--color-shadow-22); /* desktop side panel */
  --shadow-drawer: 0 8px 28px var(--color-shadow-20); /* mobile navigation */
  --shadow-drop-marker: 0 -2px 0 var(--accent); /* drag-and-drop insert marker */
  --shadow-inset-accent: inset 0 0 0 var(--stroke-1) var(--accent);
  --shadow-inset-fade: inset 0 0 var(--space-24) var(--space-10) var(--surface-page); /* fades screenshots into the page on the website */
  --shadow-edge-below: 0 1px 0 var(--border-default);
  --shadow-ring-border: 0 0 0 var(--stroke-1) var(--border-default);
  --shadow-card-lift: 0 4px 10px var(--color-shadow-20); /* elevation of a clickable card on hover or focus */
  --card-lift-scale: 1.02; /* how much a clickable card grows on hover (about 6px on a 300px card) */
  --row-lift-scale: 1.006; /* the same growth in pixels on a table row, which is about three times wider */

  /* ---- 2. SEMANTIC: shape (the whole app is square today: point these at --radius-2 / --radius-4 to round it) ---- */
  --radius-control: var(--radius-3); /* buttons, fields, menu items */
  --radius-container: var(--radius-4); /* cards, dialogs, menus */
  --radius-pill: var(--radius-3); /* pills, avatars, chips */
  --radius-sheet: var(--radius-4); /* top corners of mobile sheets */
  --preview-surface: var(--color-neutral-100); /* box behind a component picture: light in both themes, because components are drawn for a light page */

  /* ---- 2. SEMANTIC: typography ---- */
  --font-body: var(--font-family-sans);
  --font-mono: var(--font-family-mono);
  --font-display: var(--font-family-display);
}

:root:lang(zh) { --font-body: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif; --font-display: var(--font-body); }
:root:lang(ja) { --font-body: "IBM Plex Sans", "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", "Noto Sans JP", sans-serif; --font-display: var(--font-body); }
:root:lang(ko) { --font-body: "IBM Plex Sans", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Noto Sans KR", sans-serif; --font-display: var(--font-body); }
:root:lang(ar) { --font-body: "IBM Plex Sans Arabic", "IBM Plex Sans", "Geeza Pro", "Segoe UI", "Noto Sans Arabic", sans-serif; --font-display: var(--font-body); }

:root {

  /* ---- 3. APPLIED: component tokens ---- */
  --btn-padding-y: var(--space-5);
  --btn-padding-x: var(--space-6);
  --icon-btn-size: var(--space-12);
  --close-btn-size: var(--space-8);
  --card-padding: var(--space-6);
  --list-item-padding: var(--space-4);
  --todo-padding: var(--space-4);
  --todo-gap: var(--space-2);
  --metric-gap: var(--space-3);
  --pill-padding-y: var(--space-1);
  --pill-padding-x: var(--space-2);
  --pill-font-size: var(--font-size-xs);
  --msg-padding: var(--space-3);
  --msg-font-size: var(--font-size-sm);
  --field-label-size: var(--font-size-md);
  --field-hint-size: var(--font-size-sm);
  --field-hint-gap: var(--space-1); /* label to hint: close */
  --field-control-gap: var(--space-2); /* label or hint to the control: further */
  --menu-padding: var(--space-2);
  --menu-item-padding-y: var(--space-2);
  --menu-item-padding-x: var(--space-3);
  --dialog-padding: var(--space-6);
  --tab-padding-y: var(--space-3);
  --tab-padding-x: var(--space-4);
  --sidebar-padding: 0;
  --sidebar-gap: var(--space-2);
  --page-head-gap: var(--space-3);
  --avatar-size: var(--space-10);
  --ring-size: var(--size-128);
  --text-body: var(--text-default); /* body copy colour, follows the theme */
  --zoom-hero: 1.5; /* score ring on phones, Today only */
  --ring-size-sm: var(--space-16); /* the small ring on a published story */
  --ring-size-md: var(--size-128); /* the score ring on the Vitals pages */
  --ring-size-lg: var(--size-176); /* the Sistum score on Today and in the Story */
  --spinner-size: var(--space-4);
  --sidebar-width: var(--size-240);
  --sidebar-width-min: var(--space-16);
  --sheet-max-height: calc(100dvh - var(--space-12) - var(--safe-top)); /* mobile bottom sheets grow with their content up to this height, then scroll */
  --segmented-padding-y: var(--btn-padding-y); /* same as a button */
  --segmented-padding-x: var(--btn-padding-y);
  --spark-axis-block: calc(var(--space-4) + var(--space-1)); /* time axis under a card graph (height + gap) */
  --tg-control-height: var(--space-8); /* target field and Save button in the card settings menu */
  --panel-width: var(--size-480); /* desktop side panel */
  --cmap-good: var(--status-good);
  --cmap-warn: var(--status-warn);
  --cmap-bad: var(--status-bad);
  --cmap-none: var(--text-muted);
  --topbar-top: var(--space-7); /* mobile: distance from the top edge to the logo, avatar and scope selector */
  --check-size: var(--space-5);
  --check-border: var(--text-muted);
  --check-bg: var(--surface-raised);
  --check-bg-on: var(--accent);
  --check-border-on: var(--accent);
  --check-mark: var(--accent-contrast);
  --check-mark-size: var(--space-3);
  --radio-dot-size: var(--space-2);
  --avatar-font-size: var(--font-size-md);
  --avatar-xl-font-size: var(--font-size-5xl);
  --avatar-bg: var(--color-red-400);
  --avatar-fg: var(--color-neutral-950);
}
