/*
 * components.css · every component and state of Create (/prompt_generator/), Improve (/prompt_optimizer/) and the
 * public share page (/o/<slug>)                                             (docs/09-VISUAL-SPEC.md §5, §6)
 *
 * Colour, type, borders and component internals. Page layout (grid, gaps between regions, responsive stacking) is in
 * layout.css and is never repeated here. Tokens only; z-index only from the scale.
 */
@layer components {

  /* ================================================================ head */
  .pg-title { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); color: var(--text); }
  .pg-lede { font-size: var(--fs-16); line-height: var(--lh-16); color: var(--text-2); max-width: 60ch; }

  /* Create | Improve: two real links (each page keeps its own title/H1/canonical) */
  .pg-switch { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); }
  .pg-switch__link { display: inline-flex; align-items: center; gap: var(--s-2); height: var(--control-h-sm); padding: 0 var(--s-4); border-radius: var(--r-pill); font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text-2); text-decoration: none; transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
  .pg-switch__link:hover { color: var(--text); background: var(--surface-3); }
  .pg-switch__link[aria-current="page"] { background: var(--surface-1); color: var(--text); box-shadow: var(--e-1), inset 0 0 0 1px var(--border-strong); }

  .pg-usage { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); display: inline-flex; align-items: center; gap: var(--s-2); white-space: nowrap; }
  .pg-usage__dot { width: 6px; height: 6px; border-radius: var(--r-pill); background: var(--success); }
  .pg-usage[data-left="0"] .pg-usage__dot { background: var(--warning-rule); }
  .pg-usage a { color: var(--accent-text); font-weight: var(--fw-semibold); display: inline-flex; align-items: center; min-height: 24px; }   /* folded from app.css (frontend DESIGN REQUEST 2) */

  /* ================================================================ cards */
  .pg-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--e-1); }

  /* ================================================================ buttons */
  .pg-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); height: var(--control-h); padding: 0 var(--s-4); border: 1px solid transparent; border-radius: var(--r-md); font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); white-space: nowrap; text-decoration: none; transition: background-color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
  .pg-btn--primary { background: var(--accent); color: var(--on-accent); }
  .pg-btn--primary:hover { background: var(--accent-hover); }
  .pg-btn--secondary { background: var(--surface-1); border-color: var(--border-strong); color: var(--text); }
  .pg-btn--secondary:hover { background: var(--surface-3); }
  .pg-btn--ghost { background: transparent; color: var(--text-2); }
  .pg-btn--ghost:hover { background: var(--surface-3); color: var(--text); }
  .pg-btn--danger { background: var(--danger); color: var(--on-danger); }
  .pg-btn--danger:hover { background: var(--danger-hover); }
  .pg-btn--offer { background: var(--surface-1); border-color: var(--offer-border); color: var(--accent-text); }
  .pg-btn--offer:hover { background: var(--accent-tint); }
  .pg-btn--lg { height: var(--control-h-lg); padding: 0 var(--s-5); font-size: var(--fs-15); line-height: var(--lh-15); border-radius: var(--r-md); }
  .pg-btn--sm { height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--fs-13); line-height: var(--lh-13); }
  .pg-btn:disabled, .pg-btn[aria-disabled="true"]:not([data-busy]) { background: var(--surface-2); border-color: transparent; color: var(--text-disabled); cursor: not-allowed; }
  /* busy primary: keeps its fill (not a greyed button), spinner + label, announced by the status line */
  .pg-btn[data-busy] { cursor: progress; }
  .pg-spinner { width: 16px; height: 16px; border-radius: var(--r-pill); border: 2px solid currentColor; border-right-color: transparent; animation: pg-spin .8s linear infinite; flex: none; }

  .pg-iconbtn { display: inline-flex; align-items: center; justify-content: center; width: var(--control-h); height: var(--control-h); border-radius: var(--r-md); color: var(--text-2); border: 1px solid transparent; transition: background-color var(--dur-1) var(--ease); }
  .pg-iconbtn:hover { background: var(--surface-3); color: var(--text); }
  .pg-iconbtn--sm { width: var(--control-h-sm); height: var(--control-h-sm); }
  .pg-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-12); line-height: var(--lh-12); font-weight: var(--fw-semibold); }

  /* ================================================================ mode tabs (Quick · Gauntlet · Expert) */
  .pg-modes { display: flex; flex-wrap: wrap; gap: var(--s-1); }   /* r3: wraps at 320 instead of spilling past the card */
  .pg-mode { display: inline-flex; align-items: center; gap: 6px; height: var(--control-h-sm); padding: 0 var(--s-3); border-radius: var(--r-pill); font-size: var(--fs-13); line-height: var(--lh-13); font-weight: var(--fw-semibold); color: var(--text-2); }
  .pg-mode:hover { background: var(--surface-3); color: var(--text); }
  .pg-mode[aria-selected="true"] { background: var(--accent-tint); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-tint-strong); }
  .pg-mode__lock { color: var(--text-3); }

  /* ================================================================ fields */
  .pg-label { font-size: var(--fs-15); line-height: var(--lh-15); font-weight: var(--fw-semibold); color: var(--text); }
  .pg-sublabel { font-size: var(--fs-13); line-height: var(--lh-13); font-weight: var(--fw-semibold); color: var(--text-2); }
  .pg-help { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); }
  .pg-textarea, .pg-input {
    width: 100%;
    background: var(--surface-1);
    color: var(--text);
    border: 1px solid var(--border-control);
    border-radius: var(--r-md);
    font-size: var(--fs-16);                 /* ≥ 16px: iOS never zooms on focus */
    line-height: var(--lh-16);
    transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
  }
  .pg-textarea { display: block; min-height: 132px; padding: var(--s-3) var(--s-4); resize: vertical; }
  .pg-textarea--tall { min-height: 176px; }
  .pg-input { height: var(--control-h); padding: 0 var(--s-3); }
  .pg-textarea::placeholder, .pg-input::placeholder { color: var(--text-3); opacity: 1; }
  .pg-textarea:hover, .pg-input:hover { border-color: var(--text-3); }
  .pg-textarea:focus-visible, .pg-input:focus-visible { outline: var(--focus-w) solid var(--accent-text); outline-offset: 0; border-color: var(--accent-text); }
  /* the input frame: textarea + its own bar (target · count · Generate), one focus ring on the frame */
  .pg-inputframe { background: var(--surface-1); border: 1px solid var(--border-control); border-radius: var(--r-lg); transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }
  .pg-inputframe:hover { border-color: var(--text-3); }
  .pg-inputframe:focus-within { border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-text), var(--ring-shadow); }
  .pg-textarea--bare { border: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; background: transparent; }
  .pg-textarea--bare:hover { border-color: transparent; }
  .pg-textarea--bare:focus-visible { outline: none; }          /* the frame draws the ring (:focus-within above) */
  .pg-inputframe .pg-select { border-color: transparent; background: var(--surface-2); }
  .pg-inputframe .pg-select:hover { background: var(--surface-3); }
  .pg-count-chars { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .pg-count-chars[data-over="true"] { color: var(--del); font-weight: var(--fw-semibold); }
  .pg-fieldmeta { display: flex; justify-content: space-between; gap: var(--s-3); font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-3); font-variant-numeric: tabular-nums; }
  .pg-fieldmeta > :last-child { white-space: nowrap; flex: none; }
  .pg-fieldmeta[data-over="true"] { color: var(--del); font-weight: var(--fw-semibold); }

  /* ================================================================ example chips */
  .pg-chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
  .pg-chips__label { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); margin-right: var(--s-1); }
  .pg-chip { display: inline-flex; align-items: center; gap: 6px; height: var(--control-h-sm); padding: 0 var(--s-3); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-2); font-size: var(--fs-13); line-height: var(--lh-13); font-weight: var(--fw-medium); transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
  .pg-chip:hover { background: var(--surface-3); color: var(--text); }
  .pg-chip[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent-text); color: var(--accent-text); }

  /* ================================================================ target selector (menu button + listbox) */
  .pg-select { white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s-2); height: var(--control-h); padding: 0 var(--s-2) 0 var(--s-3); border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface-1); font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text); }
  .pg-select:hover { background: var(--surface-3); }
  .pg-select__k { color: var(--text-3); font-weight: var(--fw-medium); }
  .pg-select__v { font-weight: var(--fw-semibold); }
  .pg-select[aria-expanded="true"] { border-color: var(--accent-text); box-shadow: var(--ring-shadow); }

  .pg-menu { overflow-y: auto; overscroll-behavior: contain; position: absolute; z-index: var(--z-popover); top: calc(100% + var(--s-1)); left: 0; min-width: 248px; max-width: min(320px, calc(100vw - 2 * var(--gutter))); padding: var(--s-1); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--e-2); display: grid; row-gap: 2px; scroll-padding-block: var(--s-1); }
  .pg-menu--up { top: auto; bottom: calc(100% + var(--s-1)); }
  .pg-menu--end { left: auto; right: 0; }
  .pg-menu__item { display: grid; grid-template-columns: 20px 1fr; column-gap: var(--s-2); align-items: center; min-height: 40px; padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2); border-radius: var(--r-sm); font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text); text-align: left; text-decoration: none; width: 100%; }
  .pg-menu__item:hover, .pg-menu__item[data-active="true"] { background: var(--surface-3); }
  .pg-menu__item[aria-selected="true"] { font-weight: var(--fw-semibold); }
  .pg-menu__check { color: var(--accent-text); visibility: hidden; }
  .pg-menu__item[aria-selected="true"] .pg-menu__check { visibility: visible; }
  .pg-menu__desc { grid-column: 2; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-2); font-weight: var(--fw-regular); }
  .pg-menu__sep { height: 1px; background: var(--border); margin: var(--s-1) var(--s-2); }

  /* ================================================================ consent line (inline, under the button) */
  .pg-consent { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); display: flex; gap: var(--s-2); align-items: flex-start; }
  .pg-consent .pg-icon { color: var(--text-3); margin-top: 1px; }
  .pg-consent a { color: var(--accent-text); font-weight: var(--fw-semibold); }
  /* the consent line's box never changes height between "before" and "recorded" (M5): both texts share one grid cell,
     the cell is as tall as the taller one, and only visibility swaps */
  .pg-consent__swap { display: grid; }
  .pg-consent__swap > * { grid-area: 1 / 1; }
  .pg-consent[data-consent="recorded"] .pg-consent__pre, .pg-consent:not([data-consent="recorded"]) .pg-consent__post { visibility: hidden; }
  .pg-consent__icons { display: grid; flex: none; width: 16px; margin-top: 2px; }
  .pg-consent__icons > * { grid-area: 1 / 1; }
  .pg-consent[data-consent="recorded"] .pg-consent__icons .i-pre, .pg-consent:not([data-consent="recorded"]) .pg-consent__icons .i-post { visibility: hidden; }
  .pg-consent[data-consent="recorded"] .pg-consent__icons .i-post { color: var(--success); }
  .pg-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 var(--s-2); border-radius: var(--r-pill); font-size: var(--fs-12); line-height: var(--lh-12); font-weight: var(--fw-semibold); background: var(--accent-tint); color: var(--accent-text); white-space: nowrap; }
  .pg-badge--warn { background: var(--warning-tint); color: var(--warning); }
  .pg-badge--muted { background: var(--surface-2); color: var(--text-2); }

  /* ================================================================ hints + notices */
  .pg-hint { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); background: var(--accent-tint); color: var(--text); font-size: var(--fs-13); line-height: var(--lh-13); }
  .pg-hint .pg-icon { color: var(--accent-text); }
  .pg-hint__go { color: var(--accent-text); font-weight: var(--fw-semibold); display: inline-flex; align-items: center; gap: var(--s-1); min-height: 24px; }

  .pg-notice { display: grid; grid-template-columns: auto 1fr; column-gap: var(--s-3); row-gap: var(--s-2); align-items: start; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text-2); }
  .pg-notice > .pg-icon { margin-top: 1px; color: var(--text-3); }
  .pg-notice__title { color: var(--text); font-weight: var(--fw-semibold); }
  .pg-notice__actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-1); }
  .pg-notice--info { background: var(--accent-tint); border-color: transparent; }
  .pg-notice--info > .pg-icon { color: var(--accent-text); }
  .pg-notice--warn { background: var(--warning-tint); border-color: transparent; }
  .pg-notice--warn > .pg-icon { color: var(--warning); }
  .pg-notice--error { background: var(--del-tint); border-color: transparent; }
  .pg-notice--error > .pg-icon { color: var(--del); }
  .pg-notice--ok { background: var(--ins-tint); border-color: transparent; }
  .pg-notice--ok > .pg-icon { color: var(--ins); }
  .pg-notice--compact { padding: var(--s-2) var(--s-3); display: flex; align-items: center; column-gap: var(--s-3); }
  .pg-notice--compact .pg-notice__actions { margin: 0 0 0 auto; }
  .pg-linkbtn { color: var(--accent-text); font-weight: var(--fw-semibold); text-decoration: underline; text-underline-offset: 3px; min-height: 24px; display: inline-flex; align-items: center; }

  /* ================================================================ disclosure (Tune / Advanced / Gauntlet setup) */
  .pg-disclosure { border-top: 1px solid var(--border); padding-top: var(--s-2); }
  .pg-disclosure > summary { width: fit-content; list-style: none; display: flex; align-items: center; gap: var(--s-2); min-height: var(--control-h); cursor: pointer; font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text); border-radius: var(--r-sm); }
  .pg-disclosure > summary::-webkit-details-marker { display: none; }
  .pg-disclosure > summary .pg-disclosure__chev { color: var(--text-3); transition: transform var(--dur-2) var(--ease); }
  .pg-disclosure[open] > summary .pg-disclosure__chev { transform: rotate(180deg); }
  .pg-result__section > .pg-qs { border-top: 0; padding-top: 0; }
  .pg-qs[open] > summary { margin-bottom: var(--s-3); }
  .pg-disclosure__meta { font-weight: var(--fw-regular); color: var(--text-3); font-size: var(--fs-13); }

  /* segmented radio group (every Tune row has a visible Auto) */
  .pg-seg { display: flex; flex-wrap: wrap; gap: 6px; }
  .pg-seg__opt { position: relative; display: inline-flex; align-items: center; gap: 6px; height: var(--control-h-sm); padding: 0 var(--s-3); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface-1); font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); cursor: pointer; }
  .pg-seg__opt:hover { background: var(--surface-3); color: var(--text); }
  .pg-seg__opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
  .pg-seg__opt:has(input:checked) { background: var(--accent-tint); border-color: var(--accent-text); color: var(--accent-text); font-weight: var(--fw-semibold); }
  .pg-seg__opt:has(input:focus-visible) { outline: var(--focus-w) solid var(--accent-text); outline-offset: var(--focus-offset); }
  .pg-seg__tick { display: none; }
  .pg-seg__opt:has(input:checked) .pg-seg__tick { display: block; }
  .pg-seg__opt:has(input:disabled) { color: var(--text-disabled); cursor: not-allowed; }

  /* view toggle (Inline · Side by side · Result only; Filled · Template) */
  .pg-toggle { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--border); }
  .pg-toggle__btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--s-3); border-radius: 7px; font-size: var(--fs-13); line-height: var(--lh-13); font-weight: var(--fw-semibold); color: var(--text-2); }
  .pg-toggle__btn:hover { color: var(--text); }
  .pg-toggle__btn[aria-pressed="true"] { background: var(--surface-1); color: var(--text); box-shadow: var(--e-1), inset 0 0 0 1px var(--border-strong); }

  /* ================================================================ result card */
  .pg-result__head { background: var(--surface-1); border-bottom: 1px solid var(--border); border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .pg-result__h { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: var(--fw-semibold); color: var(--text); display: flex; align-items: center; gap: var(--s-2); }
  .pg-result__h { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .pg-result__meta, .pg-live { max-width: 100%; min-height: 24px; display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; }   /* r3: may wrap (the <480 title slot reserves 2 lines); 24px tall so a head note's link never changes the head height */
  .pg-result__meta { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); font-variant-numeric: tabular-nums; }
  .pg-result__section { border-top: 1px solid var(--border); }
  .pg-result__section--bar { border-top: 0; }
  .pg-result__sh { font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text); display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
  .pg-result__sh small { font-weight: var(--fw-regular); color: var(--text-3); font-size: var(--fs-13); }
  .pg-live { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); }
  .pg-live__dot { width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--accent-text); animation: pg-pulse 1.2s var(--ease) infinite; }
  .pg-stopped { color: var(--warning); }
  /* result confirmations (Copied, Saved, Opened in…) replace the head's meta line IN PLACE for a few seconds: same one
     line, same slot, so they can never cover the prompt, a control, or the Keeper */
  .pg-headnote { color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
  .pg-headnote .pg-icon { color: var(--success); }
  .pg-headnote a { color: var(--accent-text); font-weight: var(--fw-semibold); display: inline-flex; align-items: center; min-height: 24px; min-width: 24px; }   /* r3 m-4: a 24px target */
  /* a detail that is not in the user's request (done.ungrounded): a hint, not an error */
  mark.pg-ungrounded { background: transparent; color: inherit; text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--warning-rule); text-decoration-thickness: 2px; text-underline-offset: .28em; text-decoration-skip-ink: none; border-radius: 2px; }
  mark.pg-ungrounded:hover, mark.pg-seam:hover { background: var(--warning-tint); }
  /* a Continue join the server could not verify (done.seams, v1.4): the same dotted "check this" cue on ONE character */
  mark.pg-seam { background: transparent; color: inherit; padding: 0 1px; text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--warning-rule); text-decoration-thickness: 2px; text-underline-offset: .28em; text-decoration-skip-ink: none; }
  /* R7: the checklist shows PRESENT items only, as one line; never a ○ */
  .pg-includes { font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text); display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--s-2); row-gap: var(--s-1); }
  .pg-includes__k { color: var(--text-3); font-weight: var(--fw-medium); }
  .pg-includes__item { display: inline-flex; align-items: center; gap: 4px; font-weight: var(--fw-semibold); }
  .pg-includes__item .pg-icon { color: var(--success); }
  .pg-includes__sep { color: var(--text-3); }
  .pg-counts { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); font-variant-numeric: tabular-nums; }
  /* selects (Expert "Add a section", Critic setup): the native control, framed like .pg-input, with our chevron */
  .pg-selectwrap { position: relative; display: inline-grid; align-items: center; }
  .pg-selectwrap > select.pg-input { appearance: none; -webkit-appearance: none; padding-right: var(--s-8); cursor: pointer; }
  .pg-selectwrap__chev { position: absolute; right: var(--s-3); pointer-events: none; color: var(--text-2); }
  /* the framework picker (a .pg-modal): search + category filter + a checkbox list, max 2 */
  .pg-fwlist { display: grid; row-gap: 2px; max-height: 320px; overflow-y: auto; overscroll-behavior: contain; padding: 4px; margin: -4px; }
  .pg-fwopt { display: grid; grid-template-columns: 24px 1fr; column-gap: var(--s-2); align-items: start; padding: var(--s-2) var(--s-3); border-radius: var(--r-md); cursor: pointer; }
  .pg-fwopt:hover { background: var(--surface-2); }
  .pg-fwopt input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--accent); }
  .pg-fwopt:has(input:checked) { background: var(--accent-tint); }
  .pg-fwopt__name { font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text); }
  .pg-fwopt__meaning { grid-column: 2; font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); }
  .pg-fwopt:has(input:disabled) { cursor: not-allowed; }
  .pg-fwopt:has(input:disabled) .pg-fwopt__name { color: var(--text-disabled); }
  /* the SEO framework catalogue: indexable, calm, two/three columns */
  .pg-seo__cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-2) var(--s-6); list-style: none; padding: 0; margin: 0; }
  .pg-seo__cats li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text); }
  .pg-seo__cats li span { color: var(--text-3); font-variant-numeric: tabular-nums; }
  /* disabled toolbar (Improve while streaming: in place from submit, frontend DESIGN REQUEST 3) */
  .pg-toggle__btn:disabled { color: var(--text-disabled); cursor: default; }
  .pg-toggle__btn:disabled[aria-pressed="true"] { background: var(--surface-2); box-shadow: none; }
  .pg-ungrounded-note { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); }
  .pg-ungrounded-note .pg-icon { color: var(--warning); }
  .pg-ungrounded-sample { text-decoration: underline dotted var(--warning-rule) 2px; text-underline-offset: .28em; }

  /* the prompt */
  .pg-prompt { font-size: var(--fs-prompt); line-height: var(--lh-prompt); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
  .pg-prompt[data-mono="true"] { font-family: var(--font-mono); font-size: var(--fs-14); line-height: var(--lh-prompt); }
  .pg-prompt--well { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-4); }
  .pg-caret { display: inline-block; width: 2px; height: 1.1em; margin-left: 1px; vertical-align: text-bottom; background: var(--accent-text); animation: pg-blink var(--dur-caret) steps(1) infinite; }
  .pg-skel { display: grid; row-gap: 14px; padding-top: var(--s-2); }
  .pg-skel__line { height: 10px; border-radius: var(--r-pill); background: var(--surface-2); }
  .pg-skel__line:nth-child(3n+2) { width: 86%; }
  .pg-skel__line:nth-child(3n) { width: 64%; }

  /* {{VARIABLE}} chips inside the prompt (text only, built with DOM APIs by core/variables.js) */
  .pg-var { font-family: var(--font-mono); font-size: .9em; padding: 1px 5px; border-radius: 5px; background: var(--var-bg); color: var(--var-text); box-shadow: inset 0 0 0 1px var(--var-ring); white-space: nowrap; }
  .pg-var[data-filled="true"] { font-family: var(--font-ui); font-size: 1em; background: var(--var-filled-bg); color: var(--var-filled-text); box-shadow: none; white-space: pre-wrap; }

  /* variables form */
  .pg-varfield { display: grid; row-gap: 6px; }
  .pg-varfield__name { font-family: var(--font-mono); font-size: var(--fs-13); line-height: var(--lh-13); color: var(--var-text); font-weight: var(--fw-semibold); }

  /* questions: "Answer to sharpen" */
  .pg-q { display: grid; row-gap: 6px; }
  .pg-q__text { font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text); font-weight: var(--fw-medium); }
  .pg-q__n { color: var(--text-3); font-variant-numeric: tabular-nums; margin-right: var(--s-1); }
  .pg-sharpen { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
  .pg-cost { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-3); }

  /* what changed & why */
  .pg-changes { display: grid; row-gap: var(--s-3); counter-reset: chg; }
  .pg-change { display: grid; grid-template-columns: auto 1fr; column-gap: var(--s-3); font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text-2); }
  .pg-change::before { counter-increment: chg; content: counter(chg); width: 22px; height: 22px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-12); line-height: 22px; text-align: center; font-weight: var(--fw-semibold); }
  .pg-datanote__quote { padding: var(--s-3) var(--s-4); border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 0 var(--r-md) var(--r-md) 0; font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); }
  .pg-change strong { color: var(--text); font-weight: var(--fw-semibold); }
  .pg-change q { quotes: "“" "”"; color: var(--text); font-style: normal; }

  /* Make it… chips reuse .pg-chip */

  /* computed checklist: ✓ / ○, never a score */
  .pg-check { display: grid; grid-template-columns: 20px 1fr; column-gap: var(--s-2); row-gap: 2px; font-size: var(--fs-14); line-height: var(--lh-14); }
  .pg-check__icon { grid-row: 1 / span 2; margin-top: 0; }
  .pg-check[data-pass="true"] .pg-check__icon { color: var(--success); }
  .pg-check[data-pass="false"] .pg-check__icon { color: var(--text-3); }
  .pg-check__label { color: var(--text); font-weight: var(--fw-medium); }
  .pg-check__why { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); }
  .pg-check__value { color: var(--text-2); font-variant-numeric: tabular-nums; font-weight: var(--fw-regular); }

  /* ================================================================ diff (Improve; <ins>/<del> from core/diff.js) */
  .pg-diff ins { background: var(--ins-tint); color: var(--text); box-shadow: inset 0 -2px 0 var(--ins); border-radius: 2px; }
  .pg-diff del { background: var(--del-tint); color: var(--del); text-decoration: line-through; text-decoration-thickness: 1.5px; border-radius: 2px; }
  .pg-diff ins.pg-diff__rep { margin-left: .25em; }   /* a replacement reads "old new", never "oldnew" (class set by core/diff.js) */
  .pg-diff del.pg-diff__pb { text-decoration: none; font-weight: var(--fw-semibold); padding: 0 2px; }
  .pg-pane { display: grid; row-gap: var(--s-2); min-width: 0; align-content: start; }
  .pg-pane__label { font-size: var(--fs-12); line-height: var(--lh-12); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
  .pg-pane .pg-prompt { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-4); }
  .pg-diffstats { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); font-variant-numeric: tabular-nums; }
  .pg-diffstats__add { color: var(--ins); font-weight: var(--fw-semibold); }
  .pg-diffstats__del { color: var(--del); font-weight: var(--fw-semibold); }

  /* ================================================================ offer card (the ONE on-page offer; after a first result) */
  .pg-offer { background: var(--offer-bg); border: 1px solid var(--offer-border); border-radius: var(--r-lg); color: var(--offer-text); }
  .pg-offer__icon { width: 40px; height: 40px; border-radius: var(--r-md); display: inline-flex; align-items: center; justify-content: center; background: var(--surface-1); color: var(--accent-text); }
  .pg-offer__title { font-size: var(--fs-15); line-height: var(--lh-15); font-weight: var(--fw-semibold); color: var(--offer-text); }
  .pg-offer__body { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--offer-text); }
  .pg-offer__code { font-family: var(--font-mono); font-weight: var(--fw-bold); padding: 0 6px; border-radius: 5px; background: var(--offer-code-bg); border: 1px solid var(--offer-border); }

  /* ================================================================ Expert builder */
  .pg-section-card { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-1); }
  .pg-section-card__name { font-size: var(--fs-13); line-height: var(--lh-13); font-weight: var(--fw-semibold); color: var(--text); display: inline-flex; align-items: center; gap: var(--s-2); }
  .pg-section-card .pg-textarea { min-height: 72px; font-size: var(--fs-15); line-height: var(--lh-15); }

  /* ================================================================ drawer (Library / Recent) + dialogs */
  .pg-dialog { color: var(--text); background: var(--surface-1); border: 1px solid var(--border); box-shadow: var(--e-3); }   /* padding: layout.css (.pg-modal / .pg-drawer) — never reset here (a later layer would win) */
  .pg-dialog::backdrop { background: var(--scrim); }
  .pg-drawer { border-radius: var(--r-xl) 0 0 var(--r-xl); border-right: 0; }
  .pg-drawer__toast { margin: 0 var(--s-3) var(--s-3); }
  .pg-drawer__title { font-size: var(--fs-18); line-height: var(--lh-18); font-weight: var(--fw-semibold); }
  .pg-tabs { display: flex; gap: var(--s-4); border-bottom: 1px solid var(--border); }
  .pg-tab { display: inline-flex; align-items: center; gap: var(--s-2); height: var(--control-h); font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text-2); box-shadow: inset 0 -2px 0 transparent; }
  .pg-tab:hover { color: var(--text); }
  .pg-tab[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent-text); }
  .pg-item { display: grid; grid-template-columns: 1fr auto; column-gap: var(--s-2); row-gap: 2px; align-items: start; padding: var(--s-3); border-radius: var(--r-md); }
  .pg-item:hover { background: var(--surface-2); }
  .pg-item + .pg-item { box-shadow: 0 -1px 0 var(--border); }
  .pg-item__open { grid-column: 1; text-align: left; display: grid; row-gap: 2px; min-width: 0; border-radius: var(--r-sm); }
  .pg-item__title { font-size: var(--fs-14); line-height: var(--lh-14); font-weight: var(--fw-semibold); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pg-item__snippet { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .pg-item__meta { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-3); }
  .pg-item__acts { grid-column: 2; grid-row: 1 / span 3; display: flex; gap: 2px; }
  .pg-empty { display: grid; justify-items: center; text-align: center; row-gap: var(--s-3); padding: var(--s-10) var(--s-6); color: var(--text-2); font-size: var(--fs-14); line-height: var(--lh-14); }
  .pg-empty__icon { width: 48px; height: 48px; border-radius: var(--r-pill); display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--text-3); }
  .pg-empty__title { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: var(--fw-semibold); color: var(--text); }

  .pg-modal { border-radius: var(--r-xl); }
  .pg-modal__title { font-size: var(--fs-18); line-height: var(--lh-18); font-weight: var(--fw-semibold); color: var(--text); }
  .pg-modal__body { font-size: var(--fs-14); line-height: var(--lh-14); color: var(--text-2); display: grid; row-gap: var(--s-3); }
  .pg-copyfield { display: flex; gap: var(--s-2); }
  .pg-copyfield .pg-input { font-family: var(--font-mono); font-size: var(--fs-14); }
  .pg-dests { display: flex; flex-wrap: wrap; gap: var(--s-2); }

  /* ================================================================ toasts */
  .pg-toast { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--text); color: var(--canvas); box-shadow: var(--e-2); font-size: var(--fs-14); line-height: var(--lh-14); }
  .pg-toast .pg-icon { color: var(--canvas); }
  .pg-toast :focus-visible { outline-color: var(--canvas); }   /* inverted surface: the ring inverts too (≥ 3:1 on the toast) */
  .pg-toast__act { margin-left: auto; font-weight: var(--fw-semibold); text-decoration: underline; text-underline-offset: 3px; min-height: 24px; }

  /* ================================================================ SEO body (indexable copy, below the tool) */
  .pg-seo h2 { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: var(--fw-bold); letter-spacing: -0.01em; color: var(--text); margin-bottom: var(--s-3); }
  .pg-seo p { color: var(--text-2); max-width: 70ch; }
  .pg-step { padding: var(--s-5); display: grid; row-gap: var(--s-2); align-content: start; }
  .pg-step__n { width: 28px; height: 28px; border-radius: var(--r-pill); background: var(--accent-tint); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-13); font-weight: var(--fw-bold); }
  .pg-step__t { font-weight: var(--fw-semibold); color: var(--text); }
  .pg-faq { border-top: 1px solid var(--border); }
  .pg-faq > summary { min-height: 48px; display: flex; align-items: center; font-weight: var(--fw-semibold); cursor: pointer; }
  .pg-faq > p { padding-bottom: var(--s-4); }

  /* ================================================================ share page */
  .pg-share__eyebrow { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-3); font-weight: var(--fw-semibold); }
  .pg-share__h { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
  .pg-legacy { display: inline-flex; align-items: baseline; gap: var(--s-2); font-size: var(--fs-14); color: var(--text-2); }
  .pg-legacy strong { font-size: var(--fs-18); color: var(--text); font-variant-numeric: tabular-nums; }

  /* ================================================================ skip link */
  .pg-skip { position: absolute; left: var(--s-4); top: var(--s-2); z-index: var(--z-dialog); padding: var(--s-2) var(--s-4); border-radius: var(--r-md); background: var(--surface-1); color: var(--text); font-weight: var(--fw-semibold); transform: translateY(-200%); }
  .pg-skip:focus-visible { transform: none; outline: var(--focus-w) solid var(--accent-text); outline-offset: var(--focus-offset); }

  @keyframes pg-spin { to { transform: rotate(360deg); } }
  @keyframes pg-blink { 50% { opacity: 0; } }
  @keyframes pg-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
  @keyframes pg-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .pg-rise { animation: pg-rise var(--dur-3) var(--ease) both; }
}

/* phone overrides of COMPONENT internals live here, in the components layer, never in layout.css: a layout.css rule
   loses to any components.css rule on the same element (round 1: the phone Save button kept .pg-btn's 16px padding
   and its bookmark glyph was squeezed to 6px) */
@layer components {
  @media (max-width: 767.98px) {
    .pg-btn--iconsm { width: var(--control-h); padding: 0; }
    .pg-toggle { width: 100%; }
    .pg-toggle__btn { flex: 1; justify-content: center; white-space: nowrap; padding: 0 var(--s-2); }
    .pg-toggle__btn .pg-icon { display: none; }
    .pg-switch__link { padding: 0 var(--s-3); }
    .pg-toggle__btn, .pg-result .pg-result__actions > .pg-btn--primary { --pg-stretch: 1; }   /* designed to stretch (harness `width`) */
    /* bottom sheet: round the TOP corners (round 1 kept the side-drawer radius) */
    .pg-drawer { border-radius: var(--r-xl) var(--r-xl) 0 0; border-right: 1px solid var(--border); border-bottom: 0; }
    /* the character count only shows near/over the limit on phones (it made the input bar wrap on "Generate again") */
    .pg-count-chars:not([data-over="true"]) { display: none; }
    /* 4 lines on phones (grows as you type): keeps the chips row above the Keeper launcher in the first screen */
    .pg-textarea--bare, .pg-textarea--tall { min-height: 96px; }
    /* example chips: ONE horizontally scrollable row with a fade at the right edge (the affordance) so the zero-typing
       path stays in the first screen under the consent line (critic r1 M-3) */
    .pg-chips--scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;   /* r3: NO scroll-snap: proximity snapping undid the browser's focus scroll and left a focused chip half hidden */
      margin: calc(var(--s-1) * -1.5) calc(var(--s-2) * -1); padding: 6px var(--s-8) 6px var(--s-2);   /* r3 m-3: 6px around the chips so a 2px ring at a 2px offset is never clipped */
      -webkit-mask-image: linear-gradient(to right, black calc(100% - 40px), transparent); mask-image: linear-gradient(to right, black calc(100% - 40px), transparent); }
    .pg-chips--scroll::-webkit-scrollbar { display: none; }
    .pg-chips--scroll { scroll-padding-inline: var(--s-2) var(--s-12); }   /* a focused chip scrolls clear of the fade, ring included */
    .pg-chips--scroll .pg-chip { flex: none; }
    .pg-chips--scroll .pg-chips__label { display: none; }
    .pg-chips--scroll .pg-chip.pg-hide-sm { display: inline-flex; }
  }
}

/* r3 m-1: Windows High Contrast / forced colours. Colour is replaced by system colours, so every STATE carried by a tint
   or a fill gets a shape: insertions are underlined, selected toggles/tabs/switch/segments get a Highlight outline,
   variable chips keep a border, the pressed chip keeps its ✓ and a border. Checked by the forced-colors pass. */
@layer components {
  @media (forced-colors: active) {
    .pg-diff ins { text-decoration-line: underline; text-decoration-thickness: 2px; text-underline-offset: .2em; box-shadow: none; }
    .pg-diff del { text-decoration-line: line-through; }
    .pg-switch__link[aria-current="page"], .pg-mode[aria-selected="true"], .pg-toggle__btn[aria-pressed="true"], .pg-tab[aria-selected="true"], .pg-chip[aria-pressed="true"], .pg-seg__opt:has(input:checked), .pg-fwopt:has(input:checked) { outline: 2px solid Highlight; outline-offset: 1px; }
    .pg-var { border: 1px solid CanvasText; }
    mark.pg-ungrounded, mark.pg-seam { text-decoration-color: Highlight; }
    .pg-toggle__btn:disabled { color: GrayText; }
    .pg-live__dot, .pg-usage__dot { forced-color-adjust: none; background: Highlight; }
  }
}
