/* Kite's shared stylesheet. Every page links this before its own <style>.
 * Plan and reasoning: docs/plans/design-system.md. Live reference: /styleguide
 * (signed-in users only).
 *
 * How it's organized
 * ------------------
 * Layers decide which rule wins, in the order declared below -- a later
 * layer beats an earlier one regardless of selector specificity. Any CSS
 * that is NOT in a layer (every page's own <style> today) beats all of them,
 * which is what keeps this file from changing pages that haven't moved over.
 *
 * Browser floor for the layered parts: iOS Safari 15.4+, Chrome/Android
 * 99+ (both early 2022). Older browsers skip layers, so the original tokens
 * stay outside them (see below) and existing pages keep working there.
 *
 *   reset       the few rules that must hold everywhere ([hidden])
 *   tokens      colors, fonts and the size scale, as custom properties
 *   base        element defaults -- only inside <body class="k-page">
 *   components  the shared .k-* components
 *   pages       a templated page's own small tweaks: <style>@layer pages{...}</style>
 *   utilities   small single-purpose helpers
 *
 * Naming
 * ------
 * Components use a k- prefix (.k-btn, .k-panel). Several pages already have
 * their own .btn/.panel/.chip, and an unprefixed shared version would leak
 * properties into them. Variants use BEM-style modifiers: .k-btn--secondary.
 *
 * Tokens come in two kinds:
 *   - the original names (--ink, --teal, --hair, ...), which the existing
 *     pages use; values and dark-mode behavior unchanged since phase 0
 *   - semantic names (--color-text, --color-primary, ...) and the size scale
 *     (--space-md, --text-sm, ...) for new code. The semantic names point at
 *     the original ones, so dark mode follows automatically.
 */

@layer reset, tokens, base, components, pages, utilities;

/* ── reset ─────────────────────────────────────────────────────────────── */
@layer reset {
  /* The browser's own hidden attribute always wins. This is the fix for the
     ".hidden" trap: a component's display:flex can't un-hide an element.
     Use el.hidden = true in JS, not a .hidden class, in new code. */
  [hidden]{ display:none !important; }
}

/* ── original tokens: deliberately NOT in a layer ───────────────────────── */
/* Browsers older than iOS 15.4 / Chrome 99 (early 2022) ignore @layer blocks
   entirely. The pages that haven't moved over depend on these names, so they
   stay unlayered, exactly as in phase 0, and still work on an old phone. */
:root{
  /* neutrals */
  --steel-900:#1E242B; --steel-700:#384552; --steel-500:#616F82;
  --steel-300:#9BA7B5; --steel-100:#D7DDE4; --steel-50:#EEF1F4;
  --ink:#16181B; --secondary:#4F5156; --surface:#F6F6F3; --hair:#E2E2DE;
  --paper:#FBFBF9; --card:#FFF;

  /* brand and status */
  --teal:#5E8A7D; --teal-hover:#4E7A6D;
  --danger:#A0686E; --danger-hover:#8C575C;
  --attention:#A67C42; --critical:#B5443C;

  /* category colors (dashboard mix, logo) */
  --cat-social:#6B7A8F; --cat-gaming:#8A6E9B; --cat-music:#5E8A7D; --cat-video:#B0785A;
  --cat-messaging:#7C93A8; --cat-school:#B3A76B; --cat-other:#9BA7B5; --cat-shopping:#A0868F;

  /* fonts */
  --sans:'Helvetica Neue',Helvetica,Arial,sans-serif;
  --mono:'Menlo','Courier New',monospace;
  --read:'Iowan Old Style','Palatino Linotype',Palatino,'Book Antiqua',Georgia,serif;
}

@media (prefers-color-scheme: dark){
  :root{
    --steel-900:#EDF0F3; --steel-700:#B7C1CC; --steel-500:#8B9AA8;
    --steel-300:#48525C; --steel-100:#1B2129; --steel-50:#14181A;
    --ink:#ECEEF0; --secondary:#A7AEB6; --surface:#181D22; --hair:#2A323A;
    --card:#1E252B; --paper:#1E252B;
  }
}

/* ── new tokens, for new code ──────────────────────────────────────────── */
@layer tokens {
  :root{
    --success:#2FA35A;  /* the "on" green of today's toggle switches */

    /* semantic colors */
    --color-bg:var(--steel-50);          /* page background */
    --color-surface:var(--surface);      /* panels */
    --color-field:var(--card);           /* inputs, chips, cards inside panels */
    --color-border:var(--hair);
    --color-border-strong:var(--steel-300);
    --color-text:var(--ink);
    --color-text-muted:var(--secondary);
    --color-text-faint:var(--steel-500);
    --color-primary:var(--teal);
    --color-primary-hover:var(--teal-hover);
    --color-primary-soft:rgba(94,138,125,.08);  /* teal tint for hovers/selected */
    --color-on-primary:#FFF;
    --color-selected:var(--steel-700);   /* segmented control "on" */
    --color-danger:var(--danger);
    --color-danger-hover:var(--danger-hover);
    --color-danger-soft:rgba(160,104,110,.08);
    --color-attention:var(--attention);
    --color-success:var(--success);

    /* fonts, by role. Interface text uses the phone's own font (San
       Francisco on iPhone, Roboto on Android); brand accents keep Kite's. */
    --font-ui:system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
    --font-mono:var(--mono);   /* labels, numbers, domains */
    --font-read:var(--read);   /* headings and reading text */

    /* size scale -- deliberately few steps */
    --space-xs:4px; --space-sm:8px; --space-md:16px; --space-lg:24px; --space-xl:40px;
    --text-xs:11px;  /* smallest readable size on a phone; nothing smaller */
    --text-sm:13px; --text-md:16px; --text-lg:18px; --text-xl:21px; --text-2xl:26px;
    --radius-sm:4px; --radius-md:6px; --radius-lg:12px; --radius-full:999px;
    --shadow-sm:0 1px 3px rgba(0,0,0,.25);
    --shadow-md:0 4px 14px rgba(0,0,0,.14);
    --shadow-lg:0 12px 40px rgba(0,0,0,.22);

    --touch-min:44px;  /* Apple 44pt / Google 48dp, in practice */
  }

  @media (prefers-color-scheme: dark){
    :root{
      /* steel-700 turns light in dark mode; "selected" stays a dark slate,
         matching what kite-live.html does today */
      --color-selected:#384552;
    }
  }
}

/* ── base: only pages that opt in with <body class="k-page"> ───────────── */
@layer base {
  .k-page{
    color-scheme:light dark;   /* native controls and scrollbars follow dark mode */
    margin:0; background:var(--color-bg); color:var(--color-text);
    font-family:var(--font-ui); font-size:var(--text-md); line-height:1.5;
    -webkit-font-smoothing:antialiased;
    -webkit-text-size-adjust:100%;
  }
  .k-page *, .k-page *::before, .k-page *::after{ box-sizing:border-box; }
  .k-page h1, .k-page h2, .k-page h3{
    font-family:var(--font-read); font-weight:400; line-height:1.25; margin:0 0 var(--space-sm);
  }
  .k-page h1{ font-size:var(--text-2xl); }
  .k-page h2{ font-size:var(--text-xl); }
  .k-page h3{ font-size:var(--text-lg); }
  .k-page p{ margin:0 0 var(--space-md); }
  .k-page a{ color:var(--color-primary); }
  .k-page :focus-visible{ outline:2px solid var(--color-primary); outline-offset:2px; }
  @media (prefers-reduced-motion: reduce){
    .k-page *, .k-page *::before, .k-page *::after{
      transition-duration:0s !important; animation-duration:0s !important;
    }
  }
}

/* ── components ────────────────────────────────────────────────────────── */
@layer components {

  /* Page container: centered column with room for the notch and home bar. */
  .k-sheet{
    max-width:760px; margin:0 auto;
    padding:var(--space-xl) max(var(--space-md), env(safe-area-inset-right))
            calc(var(--space-xl) * 2) max(var(--space-md), env(safe-area-inset-left));
    padding-top:max(var(--space-xl), env(safe-area-inset-top));
  }
  .k-sheet--narrow{ max-width:460px; }

  /* Brand lockup above the panel on sign-in/setup pages: logo + "kite".
     Markup: {% include "partials/brand.html" %} */
  .k-brand{
    display:flex; align-items:center; justify-content:center; gap:11px;
    margin-bottom:var(--space-xl);
  }
  .k-brand svg{ display:block; width:44px; height:auto; }
  .k-brand__name{ font-family:var(--font-ui); font-size:var(--text-md); letter-spacing:.18em; color:var(--color-text-muted); }

  /* "KITE  tethered not tightened" wordmark at the top of a panel. */
  .k-wordmark{
    display:flex; align-items:baseline; justify-content:center; gap:9px;
    margin-bottom:var(--space-sm);
  }
  .k-wordmark__name{ font-size:19px; letter-spacing:.2em; text-transform:uppercase; }
  .k-wordmark__tag{ font-family:var(--font-read); font-style:italic; font-size:var(--text-sm); color:var(--color-primary); }

  /* Centered reading-text intro under a heading or wordmark. */
  .k-lede{
    font-family:var(--font-read); font-size:var(--text-md); line-height:1.55;
    color:var(--color-text-muted); text-align:center; margin:0 auto var(--space-lg); max-width:38ch;
  }

  /* Round status icon (✓ sent, ✗ invalid) centered above a result message. */
  .k-status{
    display:flex; align-items:center; justify-content:center;
    width:44px; height:44px; margin:0 auto var(--space-md); border-radius:50%;
    font-size:19px; color:var(--color-primary);
    background:var(--color-primary-soft); border:1px solid var(--color-primary);
  }
  .k-status--danger{ color:var(--color-danger); background:var(--color-danger-soft); border-color:var(--color-danger); }

  /* Small mono reassurance line under a panel ("Kite never stores a password"). */
  .k-fine{
    font-family:var(--font-mono); font-size:var(--text-xs); letter-spacing:.06em; line-height:1.8;
    text-transform:uppercase; color:var(--color-text-muted); text-align:center; margin-top:var(--space-lg);
  }

  /* Panel: the bordered surface most content sits on. */
  .k-panel{
    background:var(--color-surface); border:1px solid var(--color-border);
    border-radius:var(--radius-md); padding:var(--space-xl) var(--space-xl);
  }
  .k-panel + .k-panel{ margin-top:var(--space-lg); }
  .k-panel--tight{ padding:var(--space-md) var(--space-lg); }
  @media (max-width:520px){
    .k-panel{ padding:var(--space-lg) var(--space-md); }
  }

  /* Button. Default is the solid teal primary. */
  .k-btn{
    display:inline-flex; align-items:center; justify-content:center; gap:var(--space-sm);
    min-height:var(--touch-min); padding:0 var(--space-md);
    font:inherit; font-family:var(--font-ui); font-size:var(--text-md); line-height:1.2;
    color:var(--color-on-primary); background:var(--color-primary);
    border:1px solid var(--color-primary); border-radius:var(--radius-md);
    cursor:pointer; text-decoration:none; transition:background-color .15s, border-color .15s;
  }
  .k-btn:hover{ background:var(--color-primary-hover); border-color:var(--color-primary-hover); }
  .k-btn:disabled{ opacity:.6; cursor:default; }
  .k-btn--secondary{ color:var(--color-primary); background:var(--color-field); }
  .k-btn--secondary:hover{ background:var(--color-primary-soft); border-color:var(--color-primary); }
  .k-btn--danger{ background:var(--color-danger); border-color:var(--color-danger); }
  .k-btn--danger:hover{ background:var(--color-danger-hover); border-color:var(--color-danger-hover); }
  .k-btn--quiet{  /* the small underlined mono "links" used for secondary actions */
    min-height:var(--touch-min); padding:0 var(--space-xs); background:none; border:0;
    font-family:var(--font-mono); font-size:var(--text-xs); letter-spacing:.1em;
    text-transform:uppercase; text-decoration:underline; color:var(--color-text-faint);
  }
  .k-btn--quiet:hover{ background:none; color:var(--color-text); }
  .k-btn--block{ display:flex; width:100%; }
  .k-btn--sm{ min-height:36px; font-size:var(--text-sm); padding:0 var(--space-md); }

  /* Form field: label above control, optional hint and error below. */
  .k-field{ display:block; margin-bottom:var(--space-md); }
  .k-label{
    display:block; margin-bottom:var(--space-sm);
    font-family:var(--font-mono); font-size:var(--text-xs); letter-spacing:.12em;
    text-transform:uppercase; color:var(--color-text-muted);
  }
  .k-input, .k-select, .k-textarea{
    display:block; width:100%; min-height:var(--touch-min);
    padding:10px 14px; font-family:var(--font-ui);
    font-size:var(--text-md);  /* 16px or iOS Safari zooms in on focus */
    color:var(--color-text); background:var(--color-field);
    border:1px solid var(--color-border); border-radius:var(--radius-md);
  }
  .k-input:focus, .k-select:focus, .k-textarea:focus{
    outline:none; border-color:var(--color-primary);
    box-shadow:0 0 0 3px var(--color-primary-soft);
  }
  .k-textarea{ min-height:96px; font-family:var(--font-read); line-height:1.5; resize:vertical; }
  .k-select{
    appearance:none; -webkit-appearance:none; padding-right:36px; cursor:pointer;
    background-image:linear-gradient(45deg, transparent 50%, currentColor 50%),
                     linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position:calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size:5px 5px; background-repeat:no-repeat;
  }
  .k-hint{ display:block; margin-top:var(--space-xs); font-size:var(--text-sm); color:var(--color-text-muted); }
  .k-error{ display:block; margin-top:var(--space-xs); font-size:var(--text-sm); color:var(--color-danger); }
  .k-field--invalid .k-input, .k-field--invalid .k-select, .k-field--invalid .k-textarea{
    border-color:var(--color-danger);
  }

  /* Choice cards: a few big options, pick one. Real radio buttons inside
     <label class="k-choice">, so keyboards and screen readers work for free.
     The selected card is highlighted with :has(); on a browser without
     :has() the radio dot still shows the choice. */
  .k-choices{ display:flex; flex-direction:column; gap:var(--space-sm); }
  .k-choice{
    display:flex; align-items:flex-start; gap:14px; min-height:var(--touch-min);
    padding:var(--space-md); cursor:pointer; transition:.15s;
    background:var(--color-field); border:1px solid var(--color-border); border-radius:var(--radius-md);
  }
  .k-choice:hover{ border-color:var(--color-border-strong); }
  .k-choice:has(input:checked){ border-color:var(--color-primary); background:var(--color-primary-soft); }
  .k-choice input{ flex:none; width:18px; height:18px; margin:3px 0 0; accent-color:var(--color-primary); }
  .k-choice__body{ flex:1; min-width:0; }
  .k-choice__title{ display:block; font-family:var(--font-read); font-size:var(--text-lg); margin-bottom:2px; }
  .k-choice__desc{ display:block; font-size:var(--text-sm); color:var(--color-text-muted); }

  /* Chips: selectable pills (filters, categories). Use aria-pressed="true"
     for the selected state so screen readers announce it. */
  .k-chips{ display:flex; flex-wrap:wrap; gap:var(--space-sm); }
  .k-chip{
    display:inline-flex; align-items:center; min-height:36px; padding:0 14px;
    font-family:var(--font-ui); font-size:var(--text-sm); color:var(--color-text-muted);
    background:var(--color-field); border:1px solid var(--color-border);
    border-radius:var(--radius-full); cursor:pointer; transition:.15s;
  }
  .k-chip:hover{ border-color:var(--color-primary); color:var(--color-text); }
  .k-chip[aria-pressed="true"]{
    background:var(--color-primary); border-color:var(--color-primary); color:var(--color-on-primary);
  }

  /* Segmented control: one choice of a few (time range, which person).
     Buttons inside get aria-pressed="true" for the selected one. */
  .k-segmented{
    display:inline-flex; background:var(--color-field);
    border:1px solid var(--color-border); border-radius:var(--radius-md); overflow:hidden;
  }
  .k-segmented > button{
    min-height:36px; padding:0 var(--space-md); background:none; border:0;
    border-right:1px solid var(--color-border); cursor:pointer;
    font-family:var(--font-mono); font-size:var(--text-xs); letter-spacing:.08em;
    text-transform:uppercase; color:var(--color-text-muted);
  }
  .k-segmented > button:last-child{ border-right:0; }
  .k-segmented > button:hover{ background:var(--color-primary-soft); color:var(--color-text); }
  .k-segmented > button[aria-pressed="true"]{ background:var(--color-selected); color:#FFF; }

  /* Switch: <button class="k-switch" role="switch" aria-checked="false">.
     Same look as today's .toggle-switch, on both iPhone and Android. */
  .k-switch{
    position:relative; flex:none; width:44px; height:26px; padding:0;
    border:0; border-radius:var(--radius-full); background:var(--color-border-strong);
    cursor:pointer; transition:background-color .15s;
  }
  .k-switch::after{
    content:""; position:absolute; top:3px; left:3px; width:20px; height:20px;
    border-radius:50%; background:#FFF; box-shadow:var(--shadow-sm); transition:left .15s;
  }
  .k-switch[aria-checked="true"]{ background:var(--color-success); }
  .k-switch[aria-checked="true"]::after{ left:21px; }
  .k-switch:disabled{ opacity:.5; cursor:default; }

  /* List row: label and description on the left, a control on the right. */
  .k-list{ list-style:none; margin:0; padding:0; }
  .k-list-row{
    display:flex; align-items:center; gap:var(--space-md);
    min-height:var(--touch-min); padding:var(--space-md) 0;
    border-bottom:1px solid var(--color-border);
  }
  .k-list-row:last-child{ border-bottom:0; }
  .k-list-row__body{ flex:1; min-width:0; }
  .k-list-row__title{ display:block; font-size:var(--text-md); color:var(--color-text); }
  .k-list-row__desc{ display:block; font-family:var(--font-read); font-size:var(--text-sm); color:var(--color-text-muted); }

  /* Badge: a small status label. */
  .k-badge{
    display:inline-flex; align-items:center; padding:2px var(--space-sm);
    font-family:var(--font-mono); font-size:var(--text-xs); letter-spacing:.08em;
    text-transform:uppercase; border-radius:var(--radius-sm);
    color:var(--color-text-muted); background:var(--color-field); border:1px solid var(--color-border);
  }
  .k-badge--primary{ color:var(--color-primary); border-color:var(--color-primary); }
  .k-badge--attention{ color:var(--color-attention); border-color:var(--color-attention); }
  .k-badge--danger{ color:var(--color-danger); border-color:var(--color-danger); }

  /* Notice: an inline message block (success, problem, info). */
  .k-notice{
    padding:var(--space-md); border-radius:var(--radius-md); font-size:var(--text-sm);
    background:var(--color-primary-soft); border:1px solid var(--color-primary); color:var(--color-text);
  }
  .k-notice--danger{ background:var(--color-danger-soft); border-color:var(--color-danger); }

  /* Toast: a short message that slides up and goes away. kite.js toast(). */
  .k-toast-region{
    position:fixed; left:0; right:0; bottom:max(var(--space-lg), env(safe-area-inset-bottom));
    display:flex; flex-direction:column; align-items:center; gap:var(--space-sm);
    pointer-events:none; z-index:1000; padding:0 var(--space-md);
  }
  .k-toast{
    max-width:420px; padding:12px var(--space-md); border-radius:var(--radius-md);
    background:var(--color-selected); color:#FFF; font-size:var(--text-sm);
    box-shadow:var(--shadow-md); pointer-events:auto;
    animation:k-toast-in .2s ease-out;
  }
  .k-toast--danger{ background:var(--color-danger); }
  @keyframes k-toast-in{ from{ opacity:0; transform:translateY(8px); } }

  /* Dialog: the native <dialog> element, opened with showModal(). */
  .k-dialog{
    width:min(440px, calc(100vw - 2 * var(--space-md)));
    padding:var(--space-lg); border:1px solid var(--color-border); border-radius:var(--radius-lg);
    background:var(--color-surface); color:var(--color-text); box-shadow:var(--shadow-lg);
  }
  .k-dialog::backdrop{ background:rgba(0,0,0,.45); }
  .k-dialog__actions{ display:flex; justify-content:flex-end; gap:var(--space-sm); margin-top:var(--space-lg); }

  /* ── Ask Kite (docs/plans/ask-kite-stage1.md, build step 4) ──
     The kite glyph: the logo's sail without its tail, one colour plus a
     "cut" colour for the spars. Markup: {% include "partials/kite-glyph.html" %} */
  .k-glyph{ display:block; flex:none; width:18px; height:22px; color:var(--color-primary); --k-glyph-cut:var(--color-surface); }

  /* The launcher: a pill fixed bottom right, above the home bar. Hidden
     while the sheet is open. Pages that show it add .k-ask-room to <body>
     so the last card's buttons never sit under it. */
  .k-ask-fab{
    position:fixed; z-index:900;
    right:max(var(--space-md), env(safe-area-inset-right));
    bottom:max(var(--space-md), env(safe-area-inset-bottom));
    display:inline-flex; align-items:center; gap:var(--space-sm);
    min-height:var(--touch-min); padding:0 18px 0 14px;
    font-family:var(--font-mono); font-size:var(--text-sm); letter-spacing:.06em;
    color:var(--color-on-primary); background:var(--color-primary);
    border:1px solid var(--color-primary); border-radius:var(--radius-full);
    box-shadow:var(--shadow-md); cursor:pointer; transition:background-color .15s, transform .15s;
  }
  .k-ask-fab:hover{ background:var(--color-primary-hover); border-color:var(--color-primary-hover); }
  .k-ask-fab:active{ transform:scale(.97); }
  .k-ask-fab .k-glyph{ color:var(--color-on-primary); --k-glyph-cut:var(--color-primary); }
  .k-ask-fab[hidden]{ display:none; }
  .k-ask-room{ padding-bottom:calc(var(--touch-min) + 2 * var(--space-md) + env(safe-area-inset-bottom)); }

  /* The sheet: a native <dialog> (focus stays inside, Esc closes). Fills a
     phone's screen; a drawer on the right from 720px up. */
  .k-ask-sheet{
    position:fixed; inset:0; margin:0; padding:0; border:0;
    width:100%; max-width:none; height:100%; height:100dvh; max-height:none;
    background:var(--color-surface); color:var(--color-text);
    font-family:var(--font-ui); font-size:var(--text-md); line-height:1.5;
  }
  .k-ask-sheet[open]{ display:flex; flex-direction:column; }
  /* What .k-page gives a templated page, so the sheet looks the same on the
     older pages (account, dashboard) that don't opt in. :where() keeps these
     at zero specificity, below every k-ask rule. */
  :where(.k-ask-sheet, .k-ask-fab){ box-sizing:border-box; -webkit-font-smoothing:antialiased; }
  :where(.k-ask-sheet){ color-scheme:light dark; }
  :where(.k-ask-sheet) *, :where(.k-ask-sheet) *::before, :where(.k-ask-sheet) *::after{ box-sizing:border-box; }
  :where(.k-ask-sheet) p{ margin:0 0 var(--space-md); }
  :where(.k-ask-sheet) a{ color:var(--color-primary); }
  :where(.k-ask-sheet) :focus-visible, :where(.k-ask-fab):focus-visible{ outline:2px solid var(--color-primary); outline-offset:2px; }
  .k-ask-sheet::backdrop{ background:rgba(0,0,0,.35); }
  .k-ask-sheet [hidden]{ display:none !important; }
  @media (min-width:720px){
    .k-ask-sheet{ left:auto; width:420px; border-left:1px solid var(--color-border); box-shadow:var(--shadow-lg); }
    .k-ask-size{ display:none; }
  }
  /* A phone: a sheet over the bottom ~60% of the screen, full while typing or
     after the size control (ask-kite.js sets the exact height and top). */
  @media (max-width:719.98px){
    .k-ask-sheet:not(.k-ask-sheet--full){
      top:auto; bottom:0; height:60dvh;
      border-radius:var(--radius-lg) var(--radius-lg) 0 0; box-shadow:var(--shadow-lg);
    }
    .k-ask-sheet:not(.k-ask-sheet--full) .k-ask-head{ padding-top:var(--space-sm); }
  }

  .k-ask-head{
    display:flex; align-items:center; gap:var(--space-sm); flex:none;
    padding:max(var(--space-sm), env(safe-area-inset-top)) var(--space-sm) var(--space-sm) var(--space-md);
    border-bottom:1px solid var(--color-border);
  }
  .k-ask-head__title{ font-family:var(--font-read); font-size:var(--text-lg); margin-right:auto; }
  .k-ask-close{
    width:var(--touch-min); height:var(--touch-min); flex:none; padding:0;
    display:inline-flex; align-items:center; justify-content:center;
    background:none; border:0; border-radius:var(--radius-full); cursor:pointer;
    color:var(--color-text-muted); font-size:26px; line-height:1;
  }
  .k-ask-close:hover{ background:var(--color-primary-soft); color:var(--color-text); }
  .k-ask-size{
    width:var(--touch-min); height:var(--touch-min); flex:none; padding:0;
    display:inline-flex; align-items:center; justify-content:center;
    background:none; border:0; border-radius:var(--radius-full); cursor:pointer;
    color:var(--color-text-muted);
  }
  .k-ask-size:hover{ background:var(--color-primary-soft); color:var(--color-text); }
  .k-ask-size svg{ transition:transform .15s ease; }
  .k-ask-size[aria-pressed="true"] svg{ transform:rotate(180deg); }

  /* The conversation. Parent's messages right, Kite's left. */
  .k-ask-log{
    flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain;
    display:flex; flex-direction:column; gap:var(--space-md); padding:var(--space-md);
  }
  .k-ask-msg{ max-width:88%; padding:10px 14px; border-radius:var(--radius-lg); overflow-wrap:anywhere; }
  .k-ask-msg > :last-child{ margin-bottom:0; }
  .k-ask-msg p, .k-ask-msg ul, .k-ask-msg ol{ margin:0 0 var(--space-sm); }
  .k-ask-msg ul, .k-ask-msg ol{ padding-left:1.3em; }
  .k-ask-msg li + li{ margin-top:2px; }
  .k-ask-msg--parent{
    align-self:flex-end; white-space:pre-wrap;
    background:var(--color-primary-soft); border:1px solid var(--color-primary);
    border-bottom-right-radius:var(--radius-sm);
  }
  .k-ask-msg--kite{
    align-self:flex-start; font-family:var(--font-read);
    background:var(--color-field); border:1px solid var(--color-border);
    border-bottom-left-radius:var(--radius-sm);
  }
  /* The welcome (an empty conversation) and its suggestions. */
  .k-ask-welcome{ display:flex; flex-direction:column; gap:var(--space-sm); }
  .k-ask-welcome[hidden]{ display:none; }
  .k-ask-welcome__title{ font-family:var(--font-read); font-size:var(--text-lg); margin:0; }
  .k-ask-welcome__lead{ color:var(--color-text-muted); font-size:var(--text-sm); margin:0; }
  .k-ask-suggest{ display:flex; flex-direction:column; align-items:flex-start; gap:var(--space-xs); }
  .k-ask-chip{
    min-height:var(--touch-min); padding:8px 14px; text-align:left; cursor:pointer;
    font:inherit; font-size:var(--text-sm); color:var(--color-text);
    background:var(--color-field); border:1px solid var(--color-border); border-radius:var(--radius-full);
  }
  .k-ask-chip:hover{ border-color:var(--color-primary); background:var(--color-primary-soft); }
  .k-ask-welcome .k-fine{ margin:var(--space-xs) 0 0; }
  .k-ask-link{
    padding:0; background:none; border:0; cursor:pointer; font:inherit;
    color:var(--color-primary); text-decoration:underline;
  }

  /* "Thinking": three dots while a whole reply is on its way (S1). */
  .k-ask-thinking{ align-self:flex-start; display:inline-flex; gap:5px; padding:14px 16px; }
  .k-ask-thinking i{
    width:7px; height:7px; border-radius:50%; background:var(--color-text-faint);
    animation:k-ask-dot 1.2s infinite ease-in-out;
  }
  .k-ask-thinking i:nth-child(2){ animation-delay:.15s; }
  .k-ask-thinking i:nth-child(3){ animation-delay:.3s; }
  @keyframes k-ask-dot{ 0%,60%,100%{ opacity:.3; transform:none; } 30%{ opacity:1; transform:translateY(-3px); } }

  /* A send that didn't go through (S2): never resent by itself. */
  .k-ask-retry{
    align-self:flex-end; display:flex; align-items:center; gap:var(--space-sm); flex-wrap:wrap;
    font-size:var(--text-sm); color:var(--color-danger);
  }

  /* The feedback draft (K3): the parent reads, edits, and presses Send. */
  .k-ask-draft{
    align-self:stretch; padding:var(--space-md); border-radius:var(--radius-lg);
    background:var(--color-surface); border:1px dashed var(--color-border-strong);
  }
  .k-ask-draft .k-textarea{ min-height:88px; margin:var(--space-xs) 0 var(--space-sm); }
  .k-ask-draft__actions{ display:flex; justify-content:flex-end; gap:var(--space-sm); }

  /* Composer, pinned to the bottom above the home bar. */
  .k-ask-compose{
    flex:none; display:flex; align-items:flex-end; gap:var(--space-sm);
    padding:var(--space-sm) var(--space-md) max(var(--space-sm), env(safe-area-inset-bottom));
    border-top:1px solid var(--color-border); background:var(--color-surface);
  }
  .k-ask-compose .k-textarea{ flex:1; min-height:var(--touch-min); max-height:30vh; margin:0; padding:10px 12px; resize:none; overflow-y:hidden; }
  .k-ask-compose .k-textarea.k-ask-tall{ overflow-y:auto; }
  /* Thin scroll bars where a desktop shows them all the time (a Mac with a mouse). */
  .k-ask-log, .k-ask-about, .k-ask-compose .k-textarea{ scrollbar-width:thin; }
  .k-ask-long{ align-items:center; }
  .k-ask-long .k-fine{ flex:1; margin:0; }
  .k-ask-new{ align-self:center; }
  .k-ask-sent{ margin:0; }

  /* The disclosure (D10) before Start, and "About Ask Kite" after. */
  .k-ask-about{ flex:1; min-height:0; overflow-y:auto; padding:var(--space-lg) var(--space-md); font-family:var(--font-read); }
  .k-ask-about h3{ font-family:var(--font-ui); font-size:var(--text-md); font-weight:600; margin:var(--space-md) 0 var(--space-xs); }
  .k-ask-about p, .k-ask-about ul{ margin:0 0 var(--space-sm); }
  .k-ask-about ul{ padding-left:1.3em; }
  .k-ask-about__start{
    flex:none; padding:var(--space-md) var(--space-md) max(var(--space-md), env(safe-area-inset-bottom));
    border-top:1px solid var(--color-border);
  }

  /* Resting, limit: a message in place of the composer. */
  .k-ask-state{ flex:1; display:flex; flex-direction:column; justify-content:center; gap:var(--space-md); padding:var(--space-lg); text-align:center; font-family:var(--font-read); }
  .k-ask-state .k-glyph{ width:36px; height:44px; margin:0 auto; color:var(--color-text-faint); }
}

/* ── utilities ─────────────────────────────────────────────────────────── */
@layer utilities {
  .k-muted{ color:var(--color-text-muted); }
  .k-center{ text-align:center; }
  .k-mono{ font-family:var(--font-mono); }
  .k-read{ font-family:var(--font-read); }
  .k-stack > * + *{ margin-top:var(--space-md); }
  .k-row{ display:flex; flex-wrap:wrap; align-items:center; gap:var(--space-sm); }
  .k-visually-hidden{
    position:absolute !important; width:1px; height:1px; overflow:hidden;
    clip:rect(0 0 0 0); white-space:nowrap;
  }
}
