/*
 * Prompt Generator + Prompt Optimizer · design tokens            (docs/09-VISUAL-SPEC.md §3)
 *
 * Loaded FIRST. Its first statement fixes the cascade order for every stylesheet of both tools:
 *   reset < tokens < base < layout < components < utilities
 * Everything ships inside @layer except the SITE-CHROME BRIDGE in site-chrome.css (see that file: foreign,
 * unlayered widgets can only be adjusted by unlayered rules).
 *
 * Rules for every author (the gate `node mock/harness/lint-css.mjs` enforces the first four):
 *   - No raw colour outside this file. Components read var(--…) only.
 *   - No !important outside utilities.css.
 *   - No nested @media; never a layout query inside a prefers-reduced-motion block.
 *   - Every z-index is a var(--z-…) from the scale below.
 *   - 4px grid. One filled (primary) button per surface. Indigo = primary / yours / AI is live. Green and red mean
 *     inserted and removed words ONLY. Amber means attention. Nothing else is coloured.
 *
 * Themes: light is the default. Dark follows the OS (prefers-color-scheme), the SAME signal the site's shared upgrade
 * modal follows (includes/upgrade_modal.php), so modal and page always agree. There is no in-page theme toggle.
 */
@layer reset, tokens, base, layout, components, utilities;

@layer tokens {
  :root {
    /* ---- Surfaces ---- */
    --canvas: #F6F6FA;            /* the tool page: cool near-white, so white cards read as raised */
    --surface-1: #FFFFFF;         /* cards: composer, result, dialogs, drawer */
    --surface-2: #F0F0F6;         /* insets: segmented track, code/prompt well, chip rest */
    --surface-3: #E6E6EF;         /* hover / pressed / current row */
    --scrim: rgba(15, 17, 26, .46);

    /* ---- Lines ---- */
    --border: #E3E3EC;            /* hairlines (decorative) */
    --border-strong: #CFCFDC;     /* resting outline of controls that are also identified by label/fill */
    --border-control: #8A8AA0;    /* 3:1 non-text: text fields, checkboxes, the selected-segment ring */

    /* ---- Text ---- */
    --text: #17162A;
    --text-2: #45445A;
    --text-3: #5F5E73;            /* meta, hints, placeholders: ≥ 4.5:1 on every surface incl. --surface-3 */
    --text-disabled: #A3A2B4;     /* disabled labels only */

    /* ---- Accent (the site's indigo) ---- */
    --accent: #4F46E5;            /* primary fill, links, focus ring */
    --accent-hover: #4338CA;
    --accent-text: #4338CA;       /* accent-coloured TEXT on tints (≥ 4.5:1 on --accent-tint over white) */
    --accent-tint: rgba(79, 70, 229, .09);
    --accent-tint-strong: rgba(79, 70, 229, .16);
    --on-accent: #FFFFFF;

    /* ---- Prompt decorations ---- */
    --var-bg: rgba(79, 70, 229, .10);     /* {{VARIABLE}} chip */
    --var-text: #3730A3;
    --var-ring: rgba(79, 70, 229, .40);
    --var-filled-bg: rgba(22, 163, 74, .12);
    --var-filled-text: #14532D;
    --ins: #116A3A;               /* inserted words */
    --ins-tint: rgba(22, 163, 74, .13);
    --del: #B42318;               /* removed words (also danger text) */
    --del-tint: rgba(220, 38, 38, .09);

    /* ---- Status ---- */
    --warning: #8A4B0C;
    --warning-tint: rgba(245, 158, 11, .14);
    --warning-rule: #B45309;      /* 3:1 non-text rule on canvas */
    --success: #15803D;
    --danger: #B42318;
    --danger-hover: #912018;
    --on-danger: #FFFFFF;

    /* ---- Offer card (the ONE on-page offer; site promo gradient family) ---- */
    --offer-bg: #F3F1FF;
    --offer-border: #DAD4FF;
    --offer-text: #2A2466;
    --offer-code-bg: #FFFFFF;

    /* ---- Site chrome palette (frozen copy of index1.css :root; used only by site-chrome.css) ---- */
    --site-bg: #0D0C1D;
    --site-bg-2: #1A1A2E;
    --site-primary: #4F46E5;
    --site-secondary: #7C3AED;
    --site-primary-dark: #4A44C8;
    --site-text: #FFFFFF;
    --site-text-2: #9CA3AF;
    --site-text-head: #E5E7EB;
    --site-glass: rgba(255, 255, 255, .05);
    --site-glass-hover: rgba(255, 255, 255, .08);
    --site-glass-border: rgba(255, 255, 255, .10);
    --site-glass-border-hover: rgba(255, 255, 255, .20);
    --site-card: rgba(255, 255, 255, .03);
    --site-focus: #A78BFA;
    --site-profile: #EB7113;
    --site-white: #FFFFFF;
    /* Upgrade-modal readability fixes (same values the deployed WA ships, release 60): light card / dark card */
    --tpi-muted-on-light: #555A67;
    --tpi-muted-2-on-light: #4A4F5C;
    --tpi-muted-on-dark: #B9BDCA;
    --tpi-muted-2-on-dark: #C8CCD8;
    --tpi-focus: #5B3DF5;
    --tpi-plan-on-dark: #B8ABFF;
    /* the modal's FREE ribbon: the same indigo→violet→pink family, deep enough that its white text is ≥ 4.5:1 on every
       pixel (the site's #6a5cff→#ff6ec7 measured 2.97:1 at the 10th percentile, pixel-sampled, round 2) */
    --tpi-ribbon-1: #5B3DF5;
    --tpi-ribbon-2: #7A3BD6;
    --tpi-ribbon-3: #B0217A;
    --tpi-ribbon-code-bg: rgba(20, 10, 60, .30);   /* plan name + ✓ glyphs on the modal's DARK plan card (#1f2233–#23263a): ≥ 7:1; was #5B3DF5 at 2.44:1 */

    /* ---- Shadows ---- */
    --shadow-rgb: 23, 22, 42;
    --e-1: 0 1px 2px rgba(var(--shadow-rgb), .06);
    --e-2: 0 1px 2px rgba(var(--shadow-rgb), .05), 0 6px 20px rgba(var(--shadow-rgb), .07);
    --e-3: 0 2px 6px rgba(var(--shadow-rgb), .08), 0 24px 64px rgba(var(--shadow-rgb), .20);
    --ring-shadow: 0 0 0 3px var(--accent-tint-strong);

    color-scheme: light;

    /* ---- Type ---- */
    --font-ui: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --fs-12: 12px;  --lh-12: 16px;
    --fs-13: 13px;  --lh-13: 20px;
    --fs-14: 14px;  --lh-14: 20px;
    --fs-15: 15px;  --lh-15: 24px;
    --fs-16: 16px;  --lh-16: 24px;
    --fs-18: 18px;  --lh-18: 28px;
    --fs-20: 20px;  --lh-20: 28px;
    --fs-h1: 36px;  --lh-h1: 44px;       /* 30/38 at <1024, 28/34 at <768 (layout.css) */
    --fs-prompt: 15px; --lh-prompt: 26px; /* the prompt block: long-form reading */
    --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;
    --tracking-tight: -0.02em;

    /* ---- Space (4px grid) ---- */
    --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;

    /* ---- Radius ---- */
    --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-pill: 999px;

    /* ---- Controls ---- */
    --control-h: 40px;            /* buttons, selects */
    --control-h-sm: 32px;         /* chips, tabs (hit area padded to ≥ 24px, visible ≥ 32px) */
    --control-h-lg: 48px;         /* the Generate / Improve button */
    --focus-w: 2px;
    --focus-offset: 2px;

    /* ---- Motion ---- */
    --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms; --dur-caret: 1.05s;
    --ease: cubic-bezier(.2, 0, 0, 1);

    /* ---- Layout ---- */
    --col: 768px;                 /* the tool column (header, composer, result) */
    --col-wide: 1120px;           /* the SEO body below the tool */
    --gutter: 32px;               /* 24 at <1024, 16 at <768 (layout.css) */
    --drawer-w: 420px;
    --keeper-clear: var(--s-6);   /* r3: the Keeper sits in the page flow when closed, so the page only needs its normal end space */
    --head-h: 72px;               /* r3: the sticky result head's height; core/sticky.js keeps it equal to the MEASURED head */
    --scroll-top: calc(var(--head-h) + var(--s-4));   /* scroll-padding-top: a focused control scrolls clear of the stuck head */
    --reserve-generate: 520px;    /* reserved result height while streaming (Generate): p50 v2 output, 04 §4 */
    --reserve-improve: 360px;     /* reserved result height while streaming (Improve) */

    /* ---- z-index scale (one scale; the site's own layers are listed for reference) ---- */
    --z-base: 0;
    --z-sticky: 10;               /* the result head (sticky inside the result card) */
    --z-sitenav: 50;              /* the site nav wrapper (render_navigation; nav-shared.css .nav-container = 50) */
    --z-popover: 60;              /* target menu, Open-in menu, More menu (below the site nav's own dropdowns: 1001) */
    --z-keeper: 900;              /* the Prompt Keeper launcher + panel, LOWERED from 2147483000 on these pages */
    --z-toast: 950;               /* toasts: above the Keeper, below every modal */
    --z-dialog: 1000;             /* our <dialog>s use the top layer (showModal); this is the non-modal fallback */
    --z-upgrade: 1000000;         /* the site's TPIUpgradeModal overlay (includes/upgrade_modal.php); NOT changed */
  }

  /* Responsive tokens (the only size tokens that change with the viewport) */
  @media (max-width: 1023.98px) {
    :root { --gutter: 24px; --fs-h1: 30px; --lh-h1: 38px; }
  }
  @media (max-width: 767.98px) {
    :root { --gutter: 16px; --fs-h1: 28px; --lh-h1: 34px; --scroll-top: var(--s-4); }   /* the head is not sticky here */
  }
  @media (max-height: 560px) {
    :root { --scroll-top: var(--s-4); }   /* short viewports (keyboard open, 200% zoom): the head is not sticky */
  }

  /* Dark: follows the OS. Same component code; only colour tokens change. */
  @media (prefers-color-scheme: dark) {
    :root {
      --canvas: #0D0C1D;          /* = the site background, so nav, tool and footer are one plane */
      --surface-1: #15142A;
      --surface-2: #1C1B36;
      --surface-3: #262546;
      --scrim: rgba(4, 3, 12, .66);

      --border: #2A2947;
      --border-strong: #3B3A62;
      --border-control: #8584AD;

      --text: #EDEDF6;
      --text-2: #BDBCD3;
      --text-3: #A09FBA;
      --text-disabled: #5E5D7C;

      --accent: #5750E0;          /* primary FILL (white text 5.8:1) */
      --accent-hover: #6860F0;
      --accent-text: #A5B4FC;     /* accent TEXT / links / focus ring on dark */
      --accent-tint: rgba(165, 180, 252, .10);
      --accent-tint-strong: rgba(165, 180, 252, .20);
      --on-accent: #FFFFFF;

      --var-bg: rgba(165, 180, 252, .14);
      --var-text: #C7D2FE;
      --var-ring: rgba(165, 180, 252, .45);
      --var-filled-bg: rgba(134, 239, 172, .14);
      --var-filled-text: #BBF7D0;
      --ins: #86EFAC;
      --ins-tint: rgba(134, 239, 172, .14);
      --del: #FCA5A5;
      --del-tint: rgba(252, 165, 165, .12);

      --warning: #FCD34D;
      --warning-tint: rgba(252, 211, 77, .12);
      --warning-rule: #FCD34D;
      --success: #86EFAC;
      --danger: #F87171;
      --danger-hover: #FCA5A5;
      --on-danger: #1A0606;

      --offer-bg: #1E1B44;
      --offer-border: #3B3680;
      --offer-text: #E4E1FF;
      --offer-code-bg: #2E2A66;

      --shadow-rgb: 0, 0, 0;
      --e-1: 0 1px 2px rgba(var(--shadow-rgb), .30);
      --e-2: 0 1px 2px rgba(var(--shadow-rgb), .30), 0 8px 24px rgba(var(--shadow-rgb), .30);
      --e-3: 0 2px 8px rgba(var(--shadow-rgb), .40), 0 24px 64px rgba(var(--shadow-rgb), .55);
      color-scheme: dark;
    }
  }
}
