/* Ask AI: align the app with the site design system, to
 * design_handoff/pages/ask-ai.md (artboard 14b, "input first").
 *
 * The app (Vite + Preact, deployed separately in public_html/ask/) was built for
 * the previous design. Rather than fork it, re-point its custom properties at the
 * site tokens and restyle its parts here. Its CSS is entirely variable-driven, so
 * the token half of this survives an app redeploy untouched.
 *
 * Loaded AFTER the app stylesheet so these win.
 *
 * Scoped to body.ask-app, never :root: the two systems share token NAMES
 * (--ink, --accent, --line). Redefining those on :root would either leak into the
 * site header, or — where the name is identical — create a `--ink: var(--ink)`
 * cycle, which makes the property invalid and blanks every piece of text.
 */

body.ask-app {
  /* ---- tokens ---- */
  --paper: var(--pg);
  --surface: var(--band);
  --surface-warm: var(--feat);
  /* --ink is the same name and value in both systems: deliberately not redefined */
  --ink-soft: var(--ink-2);
  --ink-mute: var(--ink-3);
  --line: var(--line-mid);
  --line-soft: var(--line-faint);
  --shadow-card: var(--shadow);
  --shadow-card-hover: var(--shadow-hover);
  --font: 'DM Sans', system-ui, sans-serif;

  /* The system now carries a radius (README: --r / --r-ctl), so the app's own
     radius variables point at it rather than being flattened to zero.
     --radius-pill is the app's own and stays. */
  --radius-s: var(--r-ctl);
  --radius-m: var(--r-ctl);

  /* ---- release the app's full-viewport lock ----
     The app was a standalone screen: height:100dvh + overflow:hidden, with the
     thread scrolling inside. This page has real sections below it (source cards,
     honesty columns, CTA, footer), so the document must scroll normally. */
  height: auto;
  min-height: 0;
  overflow: visible;
  display: block;
}

body.ask-app #app,
body.ask-app #app .shell,
body.ask-app #app .stream {
  height: auto;
  min-height: 0;
  max-height: none;
  overflow: visible;
}

/* ---- the composer docks to the foot of the screen ----
 * The app pinned its .dock by being a 100dvh flex column with the dock as the
 * last child. Releasing that lock above — which this page needs, so the source
 * cards and footer below can scroll — also unpinned the dock: it came to rest
 * in normal flow, mid-screen, and the ask bar arriving from the home page
 * morphed to that spot instead of travelling down to the bottom.
 *
 * Pin it again without re-locking the page. Once a conversation exists, #app
 * fills the screen below the header, so the dock lands at the foot of it, and
 * sticky holds it there as the thread grows past a screenful. It lets go when
 * you scroll on into the source cards, which is right: the composer belongs to
 * the conversation, not to the whole page.
 *
 * Gated on :has(.dock) so the landing state is untouched — there the composer
 * sits in .welcome, and a viewport-filling #app would only push the tours down.
 */
body.ask-app #app:has(.dock) {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--hdr-h));
}
body.ask-app #app:has(.dock) .shell {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}
body.ask-app #app:has(.dock) .stream {
  flex: 1 1 auto;
}
body.ask-app #app .dock {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--pg);
  border-top: 1px solid var(--line);
}

/* Arriving from the home page with a question. If the app has not replaced the
 * skeleton by the time the browser takes the transition's "after" snapshot, the
 * ask bar would morph to the skeleton composer's mid-page position and then jump
 * when the real dock appeared. Put the skeleton composer where the dock is about
 * to be, so the travel is downward either way. Matches the dock's geometry:
 * 12px 24px padding, composer capped at --col-read, footnote row beneath.
 * Harmless once the app has booted — .welcome no longer exists.
 */
html.ask-arriving-pending body.ask-app #app .welcome > h1,
html.ask-arriving-pending body.ask-app #app .welcome > .chips,
html.ask-arriving-pending body.ask-app #app .welcome::before {
  display: none;
}
html.ask-arriving-pending body.ask-app #app .welcome .composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(36px, env(safe-area-inset-bottom));
  z-index: 5;
  width: min(46rem, 100% - 48px);
  margin: 0 auto;
}

/* ---- the 860px column: the only page that does this ----
   The column lives on the INNER elements; .stream keeps the page gutter, so the
   860 is the readable measure rather than the padded box. Capping .shell as well
   would nest two caps and squeeze the column to ~668px. */
body.ask-app #app .shell {
  max-width: none;
  width: 100%;
}
/* 56px below the header, which is where every other page starts its H1. The
   app's own .welcome adds 48px on top of the stream's padding, which is what
   put this heading 112px down — twice as far as anywhere else on the site. */
body.ask-app #app .stream {
  padding: 56px var(--gutter) 0;
}
body.ask-app #app .stream-inner,
body.ask-app #app .welcome {
  max-width: 860px;
  margin-inline: auto;
  width: 100%;
}
body.ask-app #app .welcome {
  padding-top: 0;
}

/* ---- hero ---- */
/* No eyebrow above the H1. It was decorative — the H1 says what the page is and
   the nav marks Ask AI as current — and the other page headings dropped theirs
   too. The flex order below starts at 2 so it stays in step with the source
   order rather than being renumbered every time something changes. */
body.ask-app #app .welcome h1 {
  order: 2;
  font: 400 52px/1.1 'DM Sans', system-ui, sans-serif;
  letter-spacing: -0.014em;
  color: var(--ink);
  max-width: none;
}

/* ---- ask bar: the page's primary control ---- */
body.ask-app #app .composer {
  order: 3;
  margin-top: 36px;
  padding: 12px 12px 12px 22px;
  border: 1px solid var(--ink);
  background: var(--pg);
  border-radius: var(--r-ctl);
  gap: 12px;
}
body.ask-app #app .composer textarea {
  min-height: 46px;
  font: 300 19px/1.4 'DM Sans', system-ui, sans-serif;
  color: var(--ink);
}
/* Solid accent, 44px, control radius. A pale-yellow pill is the old design. */
body.ask-app #app .composer .send {
  box-sizing: border-box;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: var(--r-ctl);
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  font: 400 17px/1 'DM Sans', system-ui, sans-serif;
  opacity: 1;
}
body.ask-app #app .composer .send:disabled {
  opacity: 0.5;
}
body.ask-app #app .composer .send:not(:disabled):hover {
  background: var(--accent-hi);
}

/* ---- the docked bar, once a conversation exists (Danny, 31 Oct: "it takes up
 * too much height") ----
 * The rules above are for the landing bar, the page's hero control. Docked, the
 * same rules made it about 168px tall on desktop: it kept the hero's 36px
 * margin-top, 12px padding and a 46px field, plus a footnote with 12px above it.
 * This is the conversation's input, not the hero, so it gets tight geometry.
 * The phone block further down still wins under 780px. */
body.ask-app #app .dock {
  padding: 8px var(--gutter) max(8px, env(safe-area-inset-bottom));
}
body.ask-app #app .dock .composer {
  margin-top: 0;
  padding: 5px 5px 5px 18px;
  gap: 10px;
}
body.ask-app #app .dock .composer textarea {
  min-height: 40px;
  padding: 8px 0;
  font-size: 17px;
}
/* Same reason as the phone rule below: an empty box is sized from the wrapped
   placeholder, so hold it at one line until something is typed. */
body.ask-app #app .dock .composer textarea:placeholder-shown {
  height: 40px !important;
}
body.ask-app #app .dock .composer .send {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
}
body.ask-app #app .dock .footnote {
  margin-top: 4px; /* top only: the app's auto side margins centre it under the composer */
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

/* ---- source cards: a card you can click is raised ----
   The site-wide frame rule (tokens.css, "Frames"; Danny, 17 Sep): an --ink
   outline with the hard shadow, not the app's faint outline that only
   darkened on hover. The app's own hover already lifts the card. */
body.ask-app #app .card {
  border-color: var(--ink);
}

/* ---- suggestion chips ---- */
body.ask-app #app .chips {
  order: 4;
}
/* Follow-ups are written for each answer (31 Oct), so they are longer than the
   welcome chips and wrap to two lines on a phone. The height grows with the
   text. At 14px with 8px padding and 1.3 leading, a wrapped question sat tight
   against its border and read small next to the answer (Danny, 31 Oct), so:
   16px text, 1.4 leading, 10px padding. One line comes out at 44px, a
   comfortable tap target, and the 22px radius makes that a full pill; a wrapped
   one becomes a soft rounded box whose corners stay clear of the text. */
body.ask-app #app .chips .chip {
  min-height: 44px;
  height: auto;
  padding: 10px 18px;
  border-radius: 22px;
  border: 1px solid var(--line-mid);
  background: transparent;
  font: 400 16px/1.4 'DM Sans', system-ui, sans-serif;
  color: var(--ink-2);
  text-align: left;
}
body.ask-app #app .chips .chip:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* ---- honesty line: sits under the bar, before the tours ---- */
body.ask-app #app .footnote {
  order: 5;
  font: 300 14px/1.7 'DM Sans', system-ui, sans-serif;
  color: var(--ink-3);
}
body.ask-app #app .footnote a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

/* ---- short tours ---- */
body.ask-app #app .tours {
  order: 6;
  margin-top: 56px;
  display: flex;
  flex-direction: column;
}
body.ask-app #app .tours h2 {
  font: 500 11px/1 'DM Sans', system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
body.ask-app #app .tours .tour {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 22px 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
  width: 100%;
}
body.ask-app #app .tours .tour:first-of-type {
  border-top-color: var(--line-hard);
}
body.ask-app #app .tours .tour:last-of-type {
  border-bottom: 1px solid var(--line);
}
body.ask-app #app .tours .tour:hover {
  background: transparent;
}

/* ---- the site footer is NOT hidden on this page ----
   The app's stylesheet hides .site-footer / #colophon / footer[role=contentinfo]
   from the old theme. The new footer is .ftr and is not matched, which is
   correct: the spec ends the page with the CTA band and the footer. */

body.ask-app .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The app names the old WordPress header for its cross-document view
   transition. That element no longer exists; the site header is .hdr. */
body.ask-app .hdr {
  view-transition-name: site-header;
}

@media (max-width: 780px) {
  body.ask-app #app .stream {
    padding: 32px var(--gutter-m) 0;
  }
  body.ask-app #app .welcome h1 {
    font-size: 32px;
  }
  body.ask-app #app .composer textarea {
    font-size: 17px;
  }

  /* The docked bar was eating about a sixth of a phone screen: 12/24 dock
     padding around a composer with its own 12/22, a 46px input, and a footnote
     wrapping to two lines under it. Tightened, and the footnote goes — the same
     honesty line is a full section further down this page, so on a phone it was
     paying for itself twice. The landing state keeps its copy. */
  body.ask-app #app .dock {
    padding: 8px var(--gutter-m) max(8px, env(safe-area-inset-bottom));
  }
  body.ask-app #app .dock .footnote {
    display: none;
  }
  body.ask-app #app .dock .composer {
    margin-top: 0;
    padding: 6px 6px 6px 14px;
    gap: 8px;
  }
  body.ask-app #app .dock .composer textarea {
    min-height: 38px;
    padding: 7px 0;
  }
  /* The app auto-grows the field from scrollHeight and writes the result as an
     inline height. At 390px the placeholder wraps to two lines, so an empty box
     was being sized to 62px for text nobody had typed. Collapse it while the
     placeholder is showing; the moment anything is typed the selector stops
     matching and the app's own sizing takes back over. !important is the only
     thing that beats an inline style, and this is what it is for. */
  body.ask-app #app .dock .composer textarea:placeholder-shown {
    height: 38px !important;
  }
  body.ask-app #app .dock .composer .send {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }
}

/* Tour row type, to spec: title 500 20/1.34, sub 300 15.5/1.7, arrow right.
   The app ships 700/15px and 300/13px. */
body.ask-app #app .tours .tour .tour-title {
  font: 500 20px/1.34 'DM Sans', system-ui, sans-serif;
  color: var(--ink);
  flex: 0 0 auto;
}
body.ask-app #app .tours .tour .tour-sub {
  font: 300 15.5px/1.7 'DM Sans', system-ui, sans-serif;
  color: var(--ink-2);
}
body.ask-app #app .tours .tour .tour-arrow {
  margin-left: auto;
  color: var(--ink-3);
  transition: transform 0.18s;
}
body.ask-app #app .tours .tour:hover .tour-title {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
body.ask-app #app .tours .tour:hover .tour-arrow {
  transform: translateX(3px);
  color: var(--ink);
}

@media (max-width: 780px) {
  body.ask-app #app .tours .tour {
    flex-wrap: wrap;
    gap: 6px 16px;
  }
  body.ask-app #app .tours .tour .tour-title { font-size: 17px; }
  body.ask-app #app .tours .tour .tour-sub { font-size: 14px; line-height: 1.65; }
}
