/* ==========================================================================
   apple-ui — design tokens
   Single source of truth. No numeric value in this system is defined
   anywhere else. Every other file in this skill refers to these by name.

   Three layers, isolated with @layer so an existing project always wins:
     1. apple-tokens     — custom properties only. Always safe to import.
     2. apple-base       — opt-in reset + body typography. Adds `.apple-ui` scope.
     3. apple-utilities  — opt-in helper classes.

   Because layered CSS loses to unlayered CSS regardless of specificity,
   importing this file cannot silently override an existing stylesheet.

   Usage:
     @import url("tokens.css");            // all three layers
     <div class="apple-ui"> … </div>       // activates layer 2 styling

   Dark mode: follows the OS by default. To force it, set data-theme="dark"
   or data-theme="light" on <html>.

   Contrast: every text/background pair defined here is verified against
   WCAG 2.1 AA (4.5:1 body text, 3:1 large text and UI components).
   Ratios are noted inline. See rules.md AP-COL-01.
   ========================================================================== */

@layer apple-tokens, apple-base, apple-utilities;

@layer apple-tokens {
  :root {
    /* ---------------------------------------------------------------
       TYPOGRAPHY — sizes in rem so they scale with the user's browser
       font size and with page zoom. Never redefine these in px.
       Base assumption: 1rem = 16px (browser default).
       --------------------------------------------------------------- */

    --font-system:
      -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto,
      "Helvetica Neue", Arial, sans-serif;
    --font-mono:
      ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    /* ui-rounded is the real generic. There is no `-apple-system-rounded`. */
    --font-rounded: ui-rounded, "SF Pro Rounded", var(--font-system);

    --text-caption2: 0.6875rem; /* 11px — smallest legible size */
    --text-caption1: 0.75rem; /* 12px */
    --text-footnote: 0.8125rem; /* 13px — macOS body */
    --text-subheadline: 0.9375rem; /* 15px */
    --text-callout: 1rem; /* 16px */
    --text-body: 1.0625rem; /* 17px — iOS body, the default */
    --text-headline: 1.0625rem; /* 17px at weight 600 */
    --text-title3: 1.25rem; /* 20px — display face starts here */
    --text-title2: 1.375rem; /* 22px */
    --text-title1: 1.75rem; /* 28px */
    --text-largetitle: 2.125rem; /* 34px */
    --text-display1: 2.5rem; /* 40px — marketing only */
    --text-display2: 3.5rem; /* 56px */
    --text-display3: 5rem; /* 80px */

    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;

    --leading-tight: 1.1; /* display and large titles */
    --leading-snug: 1.25; /* titles */
    --leading-normal: 1.47; /* body — 17px × 1.47 ≈ 25px */
    --leading-relaxed: 1.6; /* long-form reading */

    --tracking-display: -0.022em; /* large type closes up */
    --tracking-title: -0.015em;
    --tracking-normal: 0;
    --tracking-wide: 0.04em; /* all-caps labels only */

    /* ---------------------------------------------------------------
       COLOR — light. Dark overrides live in one block further down.

       Two families of accent token:
         --accent-*       surface colour. Buttons, switches, fills, icons.
                          Meets 3:1 against the page background (AP-COL-02).
         --accent-*-text  text colour. Meets 4.5:1. Use for links and any
                          coloured text below 24px.
       The system accent (#007AFF) reaches only 4.02:1 on white, so it must
       not be used for body-sized text. This is why apple.com links are
       #0066CC, not #007AFF.
       --------------------------------------------------------------- */

    --accent-blue: #007aff;
    --accent-green: #34c759;
    --accent-indigo: #5856d6;
    --accent-orange: #ff9500;
    --accent-pink: #ff2d55;
    --accent-purple: #af52de;
    --accent-red: #ff3b30;
    --accent-teal: #30b0c7; /* not #5AC8FA — that is the iOS 12 cyan */
    --accent-cyan: #32ade6; /* not #32D74B — that value is a green */
    --accent-yellow: #ffcc00;
    --accent-brown: #a2845e;
    --accent-mint: #00c7be;

    /* Measured against white. These clear the 3:1 needed to stand alone as
       a control surface:  blue 4.02 · red 3.55 · indigo 5.65 · purple 4.13
                           pink 3.65
       These do NOT:       green 2.22 · teal 2.57 · cyan 2.54 · orange 2.20
                           yellow 1.51 · mint · brown
       The second group is fine as a fill *behind* dark text, but must never
       be the only signal that something is there or that a state changed —
       give it a --border-control outline or a glyph. See rules.md AP-COL-03.
       On dark backgrounds every accent clears 3:1; this is a light-mode
       constraint only. */

    --accent-blue-text: #0066cc; /* 5.57:1 on white */
    --accent-green-text: #1d7a32; /* 5.41:1 on white */
    --accent-orange-text: #c93400; /* 5.28:1 on white */
    --accent-red-text: #d70015; /* 5.38:1 on white */

    /* Filled surfaces that carry white text. #007AFF only reaches 4.02:1
       against white, so a 17px white label on it fails AA. #0071E3 — the
       blue apple.com uses on buttons — reaches 4.70:1 and works on both
       light and dark backgrounds, so it is the same value in both modes.
       Same problem, same fix for destructive: white on #FF3B30 is 3.55:1,
       white on #D70015 is 5.38:1. Both surfaces also clear 3:1 against the
       page in either scheme, so neither needs a dark override. */
    --tint-surface: #0071e3;
    --danger-surface: #d70015;

    /* Four tokens, four jobs. Using the wrong one is the single most common
       contrast failure in Apple-style UI:
         --tint            icons, switches, indicators, borders  (needs 3:1)
         --tint-text       links and coloured text               (needs 4.5:1)
         --tint-surface    filled button with a white label      (needs 4.5:1
                           between the label and the fill)
         --tint-fill       soft secondary button, paired with
                           --tint-fill-text                      (needs 4.5:1)
       Retheming the whole system means overriding these four plus
       --tint-fill-text and --tint-fill-hover. */
    --tint: var(--accent-blue);
    --tint-text: var(--accent-blue-text);

    /* The tinted (secondary) button. A translucent tint over an unknown
       background gives a contrast ratio that changes with whatever is
       underneath — 4.76:1 on white but 4.32:1 on the grouped canvas, and
       3.75:1 inside a dark card. A solid pair is deterministic instead:
       these two are verified against each other, not against the page. */
    --tint-fill: #e1edfb;
    --tint-fill-hover: #d3e4f9;
    --tint-fill-text: #0059b3; /* 5.75:1 on --tint-fill */

    /* Badge fills, same reasoning. Pair each with the matching *-text token;
       the ratio quoted is the pair, and it holds on any page background
       because the fill is opaque. */
    --badge-success-fill: #e7f8eb; /* 4.90:1 with --accent-green-text  */
    --badge-warning-fill: #fff2e0; /* 4.79:1 with --accent-orange-text */
    --badge-error-fill: #ffeceb; /* 4.73:1 with --accent-red-text    */
    --badge-neutral-fill: #f1f1f2; /* 5.30:1 with --label-secondary    */

    /* Neutrals, ordered lightest surface to darkest */
    --gray-1: #8e8e93;
    --gray-2: #aeaeb2;
    --gray-3: #c7c7cc;
    --gray-4: #d1d1d6;
    --gray-5: #e5e5ea;
    --gray-6: #f2f2f7;

    /* Text. Solid values, not alpha: alpha over a grey background silently
       drops below AA. The UIKit alpha equivalents are noted for reference. */
    --label-primary: #000000; /* 21:1 on white */
    --label-secondary: #636366; /* 5.99 white · 5.37 canvas · 4.72 on a fill */
    --label-tertiary: #86868b; /* 3.62 white · 3.24 canvas — ≥24px or icons */
    --label-placeholder: #636366; /* placeholders are text: they need 4.5:1 */
    --label-disabled: #aeaeb2; /* exempt from contrast rules (WCAG 1.4.3) */
    --label-on-tint: #ffffff; /* for --tint-surface / --danger-surface,
                                      never for --tint or --accent-* */
    --label-inverted: #ffffff;

    /* Backgrounds. `plain` for standard views, `grouped` for settings-style
       lists where cards sit on a tinted canvas. */
    --bg-primary: #ffffff;
    --bg-secondary: #f2f2f7;
    --bg-tertiary: #ffffff;
    --bg-grouped-primary: #f2f2f7; /* the canvas */
    --bg-grouped-secondary: #ffffff; /* the cards on it */
    --bg-grouped-tertiary: #f2f2f7;

    /* Fills — translucent overlays for controls that sit on unknown
       backgrounds (segmented tracks, search fields, slider tracks). */
    --fill-primary: rgba(120, 120, 128, 0.2);
    --fill-secondary: rgba(120, 120, 128, 0.16);
    --fill-tertiary: rgba(118, 118, 128, 0.12);
    --fill-quaternary: rgba(116, 116, 128, 0.08);

    /* Separators are decorative: WCAG exempts them, and they must stay
       light or the UI looks caged. When a line is the ONLY thing marking
       where a control is — an input outline, a checkbox box — it is no
       longer decoration and needs --border-control instead. */
    --separator: rgba(60, 60, 67, 0.29); /* hairline, lets colour through */
    --separator-opaque: #c6c6c8; /* full-width dividers */
    --border-control: #86868b; /* 3.62 white · 3.24 canvas */

    /* ---------------------------------------------------------------
       SPACING — 8pt grid, 4pt for optical adjustment.
       In rem so padding grows with text and layouts stop clipping at
       large font sizes.
       --------------------------------------------------------------- */

    --space-1: 0.25rem; /*  4px */
    --space-2: 0.5rem; /*  8px */
    --space-3: 0.75rem; /* 12px */
    --space-4: 1rem; /* 16px — default gutter */
    --space-5: 1.25rem; /* 20px */
    --space-6: 1.5rem; /* 24px */
    --space-8: 2rem; /* 32px */
    --space-10: 2.5rem; /* 40px */
    --space-12: 3rem; /* 48px */
    --space-16: 4rem; /* 64px */
    --space-20: 5rem; /* 80px */
    --space-24: 6rem; /* 96px */

    /* ---------------------------------------------------------------
       RADII — px, because corner radius should not scale with text.
       One scale only. Semantic aliases below; prefer those.
       Concentricity: inner = outer − padding. See components.md.
       --------------------------------------------------------------- */

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    --radius-button: var(--radius-full);
    --radius-input: var(--radius-md);
    --radius-card: var(--radius-lg);
    --radius-sheet: var(--radius-xl);
    --radius-alert: 14px; /* fixed by the platform, not on the scale */

    /* ---------------------------------------------------------------
       ELEVATION — two layers each: a tight contact shadow plus a wide
       ambient one. A single-layer shadow always reads as fake.
       --------------------------------------------------------------- */

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 8px 20px rgba(0, 0, 0, 0.08), 0 20px 60px rgba(0, 0, 0, 0.14);
    --shadow-modal: 0 12px 28px rgba(0, 0, 0, 0.1), 0 32px 80px rgba(0, 0, 0, 0.18);

    /* ---------------------------------------------------------------
       MOTION
       --------------------------------------------------------------- */

    --duration-instant: 100ms; /* state flips: press, check, toggle */
    --duration-fast: 200ms; /* hover, small reveals */
    --duration-normal: 300ms; /* sheets, modals, page transitions */
    --duration-slow: 500ms; /* full-screen or hero transitions */

    --ease-default: cubic-bezier(0.25, 0.1, 0.25, 1);
    --ease-in: cubic-bezier(0.42, 0, 1, 1);
    --ease-out: cubic-bezier(0, 0, 0.58, 1);
    --ease-in-out: cubic-bezier(0.42, 0, 0.58, 1);
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275); /* overshoots */

    /* ---------------------------------------------------------------
       MATERIALS — see materials.md for when each level applies and for
       the two required fallbacks.
       --------------------------------------------------------------- */

    --material-thin-bg: rgba(255, 255, 255, 0.6);
    --material-thin-blur: blur(12px) saturate(160%);
    --material-regular-bg: rgba(255, 255, 255, 0.72);
    --material-regular-blur: blur(20px) saturate(180%);
    --material-thick-bg: rgba(255, 255, 255, 0.86);
    --material-thick-blur: blur(40px) saturate(180%);
    --material-border: rgba(0, 0, 0, 0.08);
    /* Opaque stand-ins used by the @supports and reduced-transparency
       fallbacks. Never referenced directly. */
    --material-thin-solid: #fafafc;
    --material-regular-solid: #f7f7f9;
    --material-thick-solid: #ffffff;

    --blur-sm: 4px;
    --blur-md: 12px;
    --blur-lg: 24px;
    --blur-xl: 40px;

    /* ---------------------------------------------------------------
       HIT TARGETS — px. These are physical ergonomics, not typography,
       so they must not scale. See rules.md AP-A11Y-03.
       --------------------------------------------------------------- */

    --target-min: 44px; /* iOS / iPadOS / web touch floor */
    --target-comfort: 48px;
    --target-pointer: 28px; /* macOS with a precise pointer */
    --target-spatial: 60px; /* visionOS */

    --control-height-sm: 32px;
    --control-height-md: 44px;
    --control-height-lg: 56px;

    /* ---------------------------------------------------------------
       LAYOUT
       --------------------------------------------------------------- */

    --container-sm: 34rem; /*  544px — prose */
    --container-md: 48rem; /*  768px */
    --container-lg: 61.25rem; /*  980px — the apple.com content width */
    --container-xl: 75rem; /* 1200px */

    --gutter-mobile: var(--space-4);
    --gutter-tablet: var(--space-6);
    --gutter-desktop: var(--space-8);

    /* Breakpoints. CSS cannot read a custom property inside a media
       query, so these are documentation; the literals in layout.md must
       match. Device-derived, not framework-derived. */
    --bp-compact: 430px; /* largest phone in CSS px */
    --bp-medium: 744px; /* small tablet portrait */
    --bp-regular: 1024px; /* tablet landscape / small laptop */
    --bp-wide: 1280px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* ---------------------------------------------------------------
       STACKING — one scale, so nothing gets a z-index of 99999
       --------------------------------------------------------------- */

    --z-base: 0;
    --z-raised: 10;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-scrim: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;
    --z-toast: 800;

    /* The dimming layer behind a modal. Same in both schemes: it darkens
       whatever is behind it, and in dark mode there is still something to
       darken. */
    --scrim: rgba(0, 0, 0, 0.4);

    /* ---------------------------------------------------------------
       FOCUS — a 3:1 ring is a WCAG 2.2 requirement (SC 1.4.11 / 2.4.13),
       not decoration. Never set outline: none without replacing it.
       --------------------------------------------------------------- */

    --focus-ring-width: 3px;
    --focus-ring-offset: 2px;
    --focus-ring-color: var(--accent-blue);
    --focus-ring-error: var(--accent-red);
    --focus-ring-shadow: 0 0 0 4px rgba(0, 122, 255, 0.3);
  }

  /* ================================================================
     DARK
     Applies from the OS, or from data-theme="dark" for a manual toggle.
     Contrast is re-verified against --bg-secondary (#1C1C1E), the
     darkest surface text sits on.
     ================================================================ */

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --accent-blue: #0a84ff;
      --accent-green: #30d158;
      --accent-indigo: #5e5ce6;
      --accent-orange: #ff9f0a;
      --accent-pink: #ff375f;
      --accent-purple: #bf5af2;
      --accent-red: #ff453a;
      --accent-teal: #40c8e0;
      --accent-cyan: #64d2ff;
      --accent-yellow: #ffd60a;
      --accent-brown: #ac8e68;
      --accent-mint: #63e6e2;

      /* On dark surfaces the system accents already clear 4.5:1, so the
         text variants collapse back onto them. */
      --accent-blue-text: var(--accent-blue);
      --accent-green-text: var(--accent-green);
      --accent-orange-text: var(--accent-orange);
      --accent-red-text: var(--accent-red);

      --tint-fill: #10304f;
      --tint-fill-hover: #163c61;
      --tint-fill-text: #63b3ff; /* 6.05:1 on --tint-fill */

      --badge-success-fill: #1e2e24; /* 7.06:1 with --accent-green-text  */
      --badge-warning-fill: #33291c; /* 6.93:1 with --accent-orange-text */
      --badge-error-fill: #2a1e1f; /* 4.73:1 with --accent-red-text    */
      --badge-neutral-fill: #28282b; /* 5.12:1 with --label-secondary    */

      --gray-1: #8e8e93;
      --gray-2: #636366;
      --gray-3: #48484a;
      --gray-4: #3a3a3c;
      --gray-5: #2c2c2e;
      --gray-6: #1c1c1e;

      --label-primary: #ffffff; /* 17.7:1 on --bg-secondary */
      --label-secondary: #98989d; /* 5.94:1 on --bg-secondary */
      --label-tertiary: #6e6e73; /* icons and ≥24px text only */
      --label-placeholder: #98989d;
      --label-disabled: #545458;
      --label-on-tint: #ffffff;
      --label-inverted: #000000;

      --bg-primary: #000000;
      --bg-secondary: #1c1c1e;
      --bg-tertiary: #2c2c2e;
      --bg-grouped-primary: #000000;
      --bg-grouped-secondary: #1c1c1e;
      --bg-grouped-tertiary: #2c2c2e;

      --fill-primary: rgba(120, 120, 128, 0.36);
      --fill-secondary: rgba(120, 120, 128, 0.32);
      --fill-tertiary: rgba(118, 118, 128, 0.24);
      --fill-quaternary: rgba(116, 116, 128, 0.18);

      --separator: rgba(84, 84, 88, 0.6);
      --separator-opaque: #38383a;
      --border-control: #8e8e93; /* 6.44 on black · 5.22 on --bg-secondary */

      /* Shadows read as almost nothing on black. Elevation in dark mode
         comes mostly from the lighter surface, so the shadow only needs
         to seat the edge. */
      --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
      --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.36), 0 2px 8px rgba(0, 0, 0, 0.3);
      --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.36);
      --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.44), 0 12px 32px rgba(0, 0, 0, 0.4);
      --shadow-xl: 0 8px 20px rgba(0, 0, 0, 0.5), 0 20px 60px rgba(0, 0, 0, 0.44);
      --shadow-modal: 0 12px 28px rgba(0, 0, 0, 0.55), 0 32px 80px rgba(0, 0, 0, 0.5);

      --material-thin-bg: rgba(30, 30, 32, 0.6);
      --material-regular-bg: rgba(30, 30, 32, 0.72);
      --material-thick-bg: rgba(30, 30, 32, 0.88);
      --material-border: rgba(255, 255, 255, 0.1);
      --material-thin-solid: #1a1a1c;
      --material-regular-solid: #1c1c1e;
      --material-thick-solid: #202022;

      --focus-ring-shadow: 0 0 0 4px rgba(10, 132, 255, 0.4);
    }
  }

  /* Manual override: same block, applied when the OS says light. */
  :root[data-theme="dark"] {
    --accent-blue: #0a84ff;
    --accent-green: #30d158;
    --accent-indigo: #5e5ce6;
    --accent-orange: #ff9f0a;
    --accent-pink: #ff375f;
    --accent-purple: #bf5af2;
    --accent-red: #ff453a;
    --accent-teal: #40c8e0;
    --accent-cyan: #64d2ff;
    --accent-yellow: #ffd60a;
    --accent-brown: #ac8e68;
    --accent-mint: #63e6e2;

    --accent-blue-text: var(--accent-blue);
    --accent-green-text: var(--accent-green);
    --accent-orange-text: var(--accent-orange);
    --accent-red-text: var(--accent-red);

    --tint-fill: #10304f;
    --tint-fill-hover: #163c61;
    --tint-fill-text: #63b3ff; /* 6.05:1 on --tint-fill */

    --badge-success-fill: #1e2e24; /* 7.06:1 with --accent-green-text  */
    --badge-warning-fill: #33291c; /* 6.93:1 with --accent-orange-text */
    --badge-error-fill: #2a1e1f; /* 4.73:1 with --accent-red-text    */
    --badge-neutral-fill: #28282b; /* 5.12:1 with --label-secondary    */

    --gray-1: #8e8e93;
    --gray-2: #636366;
    --gray-3: #48484a;
    --gray-4: #3a3a3c;
    --gray-5: #2c2c2e;
    --gray-6: #1c1c1e;

    --label-primary: #ffffff;
    --label-secondary: #98989d;
    --label-tertiary: #6e6e73;
    --label-placeholder: #98989d;
    --label-disabled: #545458;
    --label-on-tint: #ffffff;
    --label-inverted: #000000;

    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --bg-grouped-primary: #000000;
    --bg-grouped-secondary: #1c1c1e;
    --bg-grouped-tertiary: #2c2c2e;

    --fill-primary: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.32);
    --fill-tertiary: rgba(118, 118, 128, 0.24);
    --fill-quaternary: rgba(116, 116, 128, 0.18);

    --separator: rgba(84, 84, 88, 0.6);
    --separator-opaque: #38383a;
    --border-control: #8e8e93; /* 6.44 on black · 5.22 on --bg-secondary */

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.36), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.36);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.44), 0 12px 32px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 8px 20px rgba(0, 0, 0, 0.5), 0 20px 60px rgba(0, 0, 0, 0.44);
    --shadow-modal: 0 12px 28px rgba(0, 0, 0, 0.55), 0 32px 80px rgba(0, 0, 0, 0.5);

    --material-thin-bg: rgba(30, 30, 32, 0.6);
    --material-regular-bg: rgba(30, 30, 32, 0.72);
    --material-thick-bg: rgba(30, 30, 32, 0.88);
    --material-border: rgba(255, 255, 255, 0.1);
    --material-thin-solid: #1a1a1c;
    --material-regular-solid: #1c1c1e;
    --material-thick-solid: #202022;

    --focus-ring-shadow: 0 0 0 4px rgba(10, 132, 255, 0.4);
  }

  /* ================================================================
     ACCESSIBILITY PREFERENCES
     Four of them. Most design systems ship one.
     ================================================================ */

  /* Increase Contrast — darkens secondary text and makes hairlines solid. */
  @media (prefers-contrast: more) {
    :root {
      --label-secondary: #48484a;
      --label-tertiary: #6e6e73;
      --label-placeholder: #48484a;
      --separator: rgba(60, 60, 67, 0.6);
      --material-border: rgba(0, 0, 0, 0.24);
      --focus-ring-width: 3px;
    }
    :root[data-theme="dark"],
    :root:not([data-theme="light"]) {
      --label-secondary: #d1d1d6;
      --label-tertiary: #98989d;
      --label-placeholder: #d1d1d6;
      --separator: rgba(255, 255, 255, 0.4);
      --material-border: rgba(255, 255, 255, 0.24);
    }
  }

  /* Reduce Motion — durations shrink but stay non-zero, so transitionend
     still fires and JS that waits on it does not hang. Springs flatten,
     because overshoot is the part that triggers vestibular symptoms. */
  @media (prefers-reduced-motion: reduce) {
    :root {
      --duration-instant: 1ms;
      --duration-fast: 1ms;
      --duration-normal: 1ms;
      --duration-slow: 1ms;
      --ease-spring: var(--ease-out);
    }
  }

  /* Reduce Transparency — materials become opaque. Blur is dropped
     entirely; a translucent panel is exactly what this setting removes. */
  @media (prefers-reduced-transparency: reduce) {
    :root {
      --material-thin-bg: var(--material-thin-solid);
      --material-regular-bg: var(--material-regular-solid);
      --material-thick-bg: var(--material-thick-solid);
      --material-thin-blur: none;
      --material-regular-blur: none;
      --material-thick-blur: none;
    }
  }

  /* No backdrop-filter support — same substitution, different trigger. */
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    :root {
      --material-thin-bg: var(--material-thin-solid);
      --material-regular-bg: var(--material-regular-solid);
      --material-thick-bg: var(--material-thick-solid);
    }
  }
}

/* ==========================================================================
   LAYER 2 — BASE (opt-in)
   Scoped to `.apple-ui` so importing this file never restyles an existing
   page. Put the class on <body> or on the subtree you are styling.
   ========================================================================== */

@layer apple-base {
  .apple-ui {
    font-family: var(--font-system);
    font-size: var(--text-body);
    line-height: var(--leading-normal);
    letter-spacing: var(--tracking-normal);
    color: var(--label-primary);
    background-color: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Tells the browser to render native controls (scrollbars, form widgets,
     spellcheck underlines) for the right scheme. */
  .apple-ui {
    color-scheme: light dark;
  }
  :root[data-theme="light"] .apple-ui {
    color-scheme: light;
  }
  :root[data-theme="dark"] .apple-ui {
    color-scheme: dark;
  }

  .apple-ui *,
  .apple-ui *::before,
  .apple-ui *::after {
    box-sizing: border-box;
  }

  .apple-ui h1,
  .apple-ui h2,
  .apple-ui h3,
  .apple-ui h4,
  .apple-ui h5,
  .apple-ui h6,
  .apple-ui p,
  .apple-ui figure,
  .apple-ui blockquote {
    margin: 0;
  }

  .apple-ui h1 {
    font-size: var(--text-largetitle);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-display);
    font-weight: var(--weight-bold);
  }
  .apple-ui h2 {
    font-size: var(--text-title1);
    line-height: var(--leading-snug);
    letter-spacing: var(--tracking-title);
    font-weight: var(--weight-bold);
  }
  .apple-ui h3 {
    font-size: var(--text-title2);
    line-height: var(--leading-snug);
    letter-spacing: var(--tracking-title);
    font-weight: var(--weight-semibold);
  }
  .apple-ui h4 {
    font-size: var(--text-title3);
    line-height: var(--leading-snug);
    font-weight: var(--weight-semibold);
  }

  .apple-ui a {
    color: var(--tint-text);
    text-decoration: none;
  }
  .apple-ui a:hover {
    text-decoration: underline;
  }

  /* Links inside running text must stay underlined: colour alone is not a
     sufficient distinction (WCAG SC 1.4.1). See rules.md AP-A11Y-05. */
  .apple-ui p a,
  .apple-ui li a {
    text-decoration: underline;
    text-underline-offset: 0.15em;
  }

  .apple-ui button,
  .apple-ui input,
  .apple-ui select,
  .apple-ui textarea {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
  }

  /* Strip native chrome from text-like fields only. Checkboxes and radios
     are deliberately excluded — resetting them makes them invisible, which
     is a bug several published Apple-style stylesheets ship with. */
  .apple-ui
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not(
      [type="file"]
    ),
  .apple-ui textarea,
  .apple-ui select {
    appearance: none;
    -webkit-appearance: none;
  }

  .apple-ui input::placeholder,
  .apple-ui textarea::placeholder {
    color: var(--label-placeholder);
    opacity: 1; /* Firefox dims placeholders by default; that breaks AA */
  }

  .apple-ui :focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-sm);
  }
  /* Only suppress the ring for pointer input — never unconditionally. */
  .apple-ui :focus:not(:focus-visible) {
    outline: none;
  }

  .apple-ui img,
  .apple-ui svg,
  .apple-ui video {
    max-width: 100%;
    height: auto;
    display: block;
  }

  .apple-ui ::selection {
    background-color: color-mix(in srgb, var(--tint) 25%, transparent);
  }

  .apple-ui hr {
    border: none;
    border-top: 1px solid var(--separator);
    margin: var(--space-4) 0;
  }
}

/* ==========================================================================
   LAYER 3 — UTILITIES (opt-in)
   A deliberately small set: the things needed on almost every screen.
   This is not a utility framework; reach for real CSS beyond these.
   ========================================================================== */

@layer apple-utilities {
  /* Visible to screen readers, invisible on screen. Required by several
     rules in rules.md — do not replace with display:none, which hides it
     from assistive tech too. */
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .container {
    width: 100%;
    max-width: var(--container-lg);
    margin-inline: auto;
    padding-inline: var(--gutter-mobile);
  }
  @media (min-width: 744px) {
    .container {
      padding-inline: var(--gutter-tablet);
    }
  }
  @media (min-width: 1024px) {
    .container {
      padding-inline: var(--gutter-desktop);
    }
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }
  .stack-tight {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }
  .row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .text-secondary {
    color: var(--label-secondary);
  }
  .text-tint {
    color: var(--tint-text);
  }
  .text-balance {
    text-wrap: balance;
  } /* headlines */
  .text-pretty {
    text-wrap: pretty;
  } /* paragraphs */

  .surface {
    background-color: var(--bg-grouped-secondary);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-sm);
  }

  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
