/*
 * DESIGN TOKENS
 * ---------------------------------------------------------------------------
 * Semantic tokens used by every component. No raw colours here: everything maps to the
 * OnCue brand palette (--oc-* in brand/brand.css, from the brand kit). Theme is driven by
 * <html data-theme="light|dark">, which js/boot.js sets before first paint.
 *
 * Brand rules baked in (branding/BRAND-GUIDE.md):
 *  - Cue Orange is the one accent: primary actions, "now", alarms, room pills.
 *  - Text on orange is Midnight, never white (white only reaches 3.3:1).
 *  - Orange *text* on light surfaces uses Cue Strong.
 */

/* ---------- Theme-independent ---------- */
:root {
  /* Typography */
  --font-sans: var(--oc-font-ui);
  --font-display: var(--oc-font-display);
  --font-features: "cv11", "ss01", "ss03";   /* Inter: single-storey a, open digits, curved r */

  --text-caption: 0.75rem;       /* 12 */
  --text-footnote: 0.8125rem;    /* 13 */
  --text-subhead: 0.9375rem;     /* 15 */
  --text-body: 1rem;             /* 16 (17 on iOS via Dynamic Type) */
  --text-callout: 1.0625rem;     /* 17 */
  --text-title3: 1.25rem;        /* 20 */
  --text-title2: 1.5rem;         /* 24 */
  --text-title1: 1.875rem;       /* 30 */
  --text-large-title: 2.25rem;   /* 36 */
  --text-display: 3.5rem;        /* 56 – alarm cards */
  --text-hero: var(--oc-text-clock); /* 72 – ringing clock */

  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.45;

  --weight-regular: var(--oc-weight-regular);
  --weight-medium: var(--oc-weight-medium);
  --weight-semibold: var(--oc-weight-semibold);
  --weight-bold: var(--oc-weight-bold);

  --tracking-tight: -0.015em;
  --tracking-display: -0.02em;
  --tracking-caps: 0.06em;

  /* Spacing (4 px grid) */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radii (the logo's corner language) */
  --radius-xs: var(--oc-radius-xs);
  --radius-sm: var(--oc-radius-sm);
  --radius-md: var(--oc-radius-md);
  --radius-lg: var(--oc-radius-lg);
  --radius-xl: var(--oc-radius-xl);
  --radius-pill: var(--oc-radius-pill);

  /* Sizing */
  --touch-target: 44px;
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;
  --tabbar-height: 64px;
  --topbar-height: 52px;
  --sidebar-width: 264px;
  --page-max: 760px;
  --page-max-wide: 1180px;       /* desktop Today and Plan */
  --page-max-full: 1800px;       /* desktop Calendar and project pages */
  --side-panel-width: 400px;     /* desktop event details */
  --fab-size: 60px;

  /* Safe areas: env() on iOS; native heads may also inject --native-inset-* */
  --safe-top: max(env(safe-area-inset-top, 0px), var(--native-inset-top, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--native-inset-right, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--native-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--native-inset-left, 0px));

  /* Motion */
  --dur-instant: 90ms;
  --dur-fast: 160ms;
  --dur-base: 240ms;
  --dur-slow: 380ms;
  --dur-slower: 560ms;
  --stagger: 40ms;

  --ease-out: var(--oc-ease-out);
  --ease-in-out: var(--oc-ease-in-out);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  /* Fallbacks for engines without linear(); overridden below. */
  --ease-spring: cubic-bezier(0.2, 0.9, 0.25, 1);
  --ease-spring-bouncy: cubic-bezier(0.34, 1.45, 0.64, 1);

  /* Animated icons (brand/motion/oncue-motion.css) use the app's easings */
  --oca-out: var(--ease-out);
  --oca-bounce: var(--ease-spring-bouncy);
  --oca-inout: var(--ease-in-out);

  /* Calendar colours: the keys Core uses (EventColors) mapped onto the brand's 8 calendar colours. */
  --event-coral: var(--oc-cal-1);
  --event-amber: var(--oc-cal-2);
  --event-green: var(--oc-cal-3);
  --event-teal: var(--oc-cal-4);
  --event-sky: var(--oc-cal-5);
  --event-iris: var(--oc-cal-6);
  --event-violet: var(--oc-cal-7);
  --event-rose: var(--oc-cal-8);

  /* Signature backgrounds (ringing screen, hero). Built from brand colours only. */
  --gradient-night: linear-gradient(165deg, var(--oc-n-950) 0%, var(--oc-midnight) 45%, color-mix(in srgb, var(--oc-cue) 55%, var(--oc-midnight)) 100%);
  --gradient-dawn: linear-gradient(180deg, var(--oc-dawn) 0%, var(--oc-cue) 100%);

  /* Layers */
  --z-content: 1;
  --z-nav: 10;
  --z-fab: 20;
  --z-sheet: 40;
  --z-toast: 60;
}

@supports (transition-timing-function: linear(0, 1)) {
  :root {
    /* The brand spring: settles with a hint of overshoot. Most movement. */
    --ease-spring: var(--oc-ease-spring);
    /* Livelier spring (ζ≈0.6, ~9% overshoot): toggles, success, playful moments. */
    --ease-spring-bouncy: linear(0, 0.1013 5%, 0.3224 10%, 0.5684 15%, 0.783 20%, 0.9407 25%,
                                 1.0381 30%, 1.0846 35%, 1.0945 40%, 1.0826 45%, 1.0608 50%,
                                 1.018 60%, 0.9955 70%, 0.9911 80%, 0.9946 90%, 1);
  }
}

/* ---------- Light ---------- */
:root,
:root[data-theme="light"] {
  --color-bg: var(--oc-bg);
  --color-bg-grouped: var(--oc-bg);
  --color-surface: var(--oc-surface);
  --color-surface-raised: var(--oc-surface);
  --color-surface-sunken: var(--oc-surface-2);
  --color-chrome: color-mix(in srgb, var(--oc-paper) 84%, transparent);
  --color-chrome-solid: var(--oc-paper);

  --color-text: var(--oc-text);
  --color-text-secondary: var(--oc-n-700);
  --color-text-tertiary: var(--oc-text-muted);
  --color-text-disabled: var(--oc-n-400);
  --color-text-inverse: var(--oc-paper);
  --color-inverse: var(--oc-midnight);
  --color-on-inverse-accent: var(--oc-cue);

  --color-border: var(--oc-border);
  --color-separator: color-mix(in srgb, var(--oc-n-500) 22%, transparent);
  --color-fill: color-mix(in srgb, var(--oc-n-500) 10%, transparent);
  --color-fill-strong: color-mix(in srgb, var(--oc-n-500) 18%, transparent);
  --color-fill-pressed: color-mix(in srgb, var(--oc-n-500) 24%, transparent);

  /* Primary = Cue Orange with Midnight text */
  --color-primary: var(--oc-cue);
  --color-primary-hover: color-mix(in srgb, var(--oc-cue) 88%, var(--oc-midnight));
  --color-primary-pressed: color-mix(in srgb, var(--oc-cue) 78%, var(--oc-midnight));
  --color-on-primary: var(--oc-on-accent);
  --color-primary-soft: var(--oc-cue-soft);
  --color-primary-soft-strong: color-mix(in srgb, var(--oc-cue) 26%, var(--oc-surface));
  --color-primary-text: var(--oc-accent-text);

  --color-accent: var(--oc-cue);
  --color-accent-strong: var(--oc-cue);
  --color-accent-soft: var(--oc-cue-soft);
  --color-accent-text: var(--oc-accent-text);

  --color-success: var(--oc-success);
  --color-success-soft: color-mix(in srgb, var(--oc-success) 14%, var(--oc-surface));
  --color-success-text: color-mix(in srgb, var(--oc-success) 70%, var(--oc-midnight));
  --color-warning: var(--oc-warning);
  --color-warning-soft: color-mix(in srgb, var(--oc-warning) 18%, var(--oc-surface));
  --color-warning-text: color-mix(in srgb, var(--oc-warning) 50%, var(--oc-midnight));
  --color-danger: var(--oc-danger);
  --color-danger-soft: color-mix(in srgb, var(--oc-danger) 12%, var(--oc-surface));
  --color-danger-text: color-mix(in srgb, var(--oc-danger) 72%, var(--oc-midnight));

  /* Hero ("Next up") card: a Midnight tile in both themes */
  --color-hero: var(--oc-midnight);
  --color-on-hero: var(--oc-paper);
  --color-on-hero-muted: var(--oc-n-300);

  --color-now-line: var(--oc-cue);
  --color-focus-ring: var(--oc-focus);
  --color-scrim: color-mix(in srgb, var(--oc-midnight) 40%, transparent);
  --color-skeleton: var(--oc-n-100);
  --color-skeleton-shine: var(--oc-n-50);
  --color-toggle-off: var(--oc-n-200);
  --color-toggle-thumb: var(--oc-surface);

  --shadow-color: color-mix(in srgb, var(--oc-midnight) 12%, transparent);
  --shadow-xs: 0 1px 2px var(--shadow-color);
  --shadow-sm: 0 1px 2px var(--shadow-color), 0 2px 8px -2px var(--shadow-color);
  --shadow-md: var(--oc-shadow);
  --shadow-lg: 0 6px 16px -4px var(--shadow-color), 0 24px 48px -12px var(--shadow-color);
  --shadow-sheet: 0 -8px 40px -12px var(--shadow-color);
  --shadow-primary: 0 8px 24px -8px color-mix(in srgb, var(--oc-cue) 55%, transparent);
}

/* ---------- Dark ---------- */
:root[data-theme="dark"] {
  --color-bg: var(--oc-bg);
  --color-bg-grouped: var(--oc-bg);
  --color-surface: var(--oc-surface);
  --color-surface-raised: var(--oc-surface-2);
  --color-surface-sunken: var(--oc-n-950);
  --color-chrome: color-mix(in srgb, var(--oc-n-950) 80%, transparent);
  --color-chrome-solid: var(--oc-n-950);

  --color-text: var(--oc-text);
  --color-text-secondary: var(--oc-n-300);
  --color-text-tertiary: var(--oc-text-muted);
  --color-text-disabled: var(--oc-n-600);
  --color-text-inverse: var(--oc-midnight);
  --color-inverse: var(--oc-paper);
  --color-on-inverse-accent: var(--oc-cue-strong);

  --color-border: var(--oc-border);
  --color-separator: color-mix(in srgb, var(--oc-n-400) 18%, transparent);
  --color-fill: color-mix(in srgb, var(--oc-n-400) 12%, transparent);
  --color-fill-strong: color-mix(in srgb, var(--oc-n-400) 20%, transparent);
  --color-fill-pressed: color-mix(in srgb, var(--oc-n-400) 28%, transparent);

  --color-primary: var(--oc-cue);
  --color-primary-hover: color-mix(in srgb, var(--oc-cue) 88%, var(--oc-paper));
  --color-primary-pressed: color-mix(in srgb, var(--oc-cue) 80%, var(--oc-midnight));
  --color-on-primary: var(--oc-on-accent);
  --color-primary-soft: var(--oc-today-bg);
  --color-primary-soft-strong: color-mix(in srgb, var(--oc-cue) 26%, transparent);
  --color-primary-text: color-mix(in srgb, var(--oc-accent-text) 85%, var(--oc-paper)); /* AA on raised surfaces (4.9:1 on sheets) */

  --color-accent: var(--oc-cue);
  --color-accent-strong: var(--oc-cue);
  --color-accent-soft: var(--oc-today-bg);
  --color-accent-text: color-mix(in srgb, var(--oc-accent-text) 85%, var(--oc-paper)); /* AA on raised surfaces (4.9:1 on sheets) */

  --color-success: var(--oc-success);
  --color-success-soft: color-mix(in srgb, var(--oc-success) 18%, transparent);
  --color-success-text: color-mix(in srgb, var(--oc-success) 70%, var(--oc-paper));
  --color-warning: var(--oc-warning);
  --color-warning-soft: color-mix(in srgb, var(--oc-warning) 18%, transparent);
  --color-warning-text: var(--oc-warning);
  --color-danger: var(--oc-danger);
  --color-danger-soft: color-mix(in srgb, var(--oc-danger) 18%, transparent);
  --color-danger-text: color-mix(in srgb, var(--oc-danger) 70%, var(--oc-paper));

  --color-hero: var(--oc-n-800);
  --color-on-hero: var(--oc-paper);
  --color-on-hero-muted: var(--oc-n-300);

  --color-now-line: var(--oc-cue);
  --color-focus-ring: var(--oc-focus);
  --color-scrim: color-mix(in srgb, var(--oc-n-950) 64%, transparent);
  --color-skeleton: var(--oc-n-800);
  --color-skeleton-shine: var(--oc-n-700);
  --color-toggle-off: var(--oc-n-700);
  --color-toggle-thumb: var(--oc-paper);

  --shadow-color: color-mix(in srgb, var(--oc-n-950) 70%, transparent);
  --shadow-xs: 0 1px 2px var(--shadow-color);
  --shadow-sm: 0 1px 3px var(--shadow-color);
  --shadow-md: var(--oc-shadow);
  --shadow-lg: 0 12px 40px -8px var(--shadow-color);
  --shadow-sheet: 0 -8px 40px -8px var(--shadow-color);
  --shadow-primary: 0 8px 24px -10px color-mix(in srgb, var(--oc-cue) 50%, transparent);
}
