/* ------------------------------------------------------------------
   Ask Rideau: the round button in the corner and the panel it opens.
   Built by ask.js.
   After the Groundswell helper (site.css, .helper-*), in the Ottawa night
   tokens.

   Corner: a 56px button at the bottom right; the panel opens above it,
   360px wide, non-modal, so the page stays usable. Under 640px the panel
   is a sheet with 16px gutters that takes the button's place.
   It opens in place and stays in the corner; it does not dock into
   "Ask Rideau anything" (Michael, December 2, 2026).

   Pairs (WCAG): ink-100 #ECECEC on the panel ink-900 #131313 15.7, on the
   question bubble ink-750 #212121 13.6; ink-400 #9E9E9E on ink-900 6.9;
   ink-200 #C8C8C8 (the field label) 11.1; signal-400 #F26A6E links 6.3;
   white on the signal-600 #C92A2F action 5.45; the signal-500 mark on the
   ink-750 button 4.0 (a graphic: 3:1 needed; the brand puts the mark in
   red on dark grounds, AGENTS.md). Edges: the button and the question choices take a
   mix of ink-400 and ink-700 (#646464), 3.3 on the canvas and 3.1 on the
   panel. The corner button is white on signal-500, 4.15:1, above the 3:1 an icon needs.
   Focus is signal-500, 4.7 on the canvas and 4.5 on the panel.
   ------------------------------------------------------------------ */

.ask-launcher,
.ask {
  --ask-button: 56px;
  --ask-right: calc(20px + env(safe-area-inset-right, 0px));
  --ask-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  --ask-above: calc(var(--ask-bottom) + var(--ask-button) + 12px);
  --ask-edge: color-mix(in srgb, var(--ink-400) 50%, var(--ink-700));
  --ask-bar: var(--bar-h, 64px);
}

@media (min-width: 640px) {
  .ask-launcher,
  .ask {
    --ask-right: calc(24px + env(safe-area-inset-right, 0px));
    --ask-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
}

/* --- the button --------------------------------------------------------- */
.ask-launcher {
  position: fixed;
  right: var(--ask-right);
  bottom: var(--ask-bottom);
  z-index: 9; /* over the page, under the header (10) and every dialog */
  display: grid;
  place-items: center;
  width: var(--ask-button);
  height: var(--ask-button);
  padding: 0;
  border: 0;
  border-radius: 50%;
  /* The app's corner button (rideau-app CORNER_DISC): the brand red disc,
     a white bubble, the app's shadow, deepening on hover. */
  background-color: var(--signal-500, #E8383D);
  color: #FFFFFF;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: background-color 150ms ease;
}
.ask-launcher:hover { background-color: #A82328; }
.ask-launcher[hidden] { display: none; }
.ask-launcher svg { width: 24px; height: 24px; fill: currentColor; }

/* --- the panel ---------------------------------------------------------- */
.ask {
  position: fixed;
  right: var(--ask-right);
  bottom: var(--ask-above);
  z-index: 9;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 360px;
  height: min(560px, calc(100vh - var(--ask-above) - var(--ask-bar) - 16px));
  height: min(560px, calc(100dvh - var(--ask-above) - var(--ask-bar) - 16px));
  overflow: hidden;
  border: var(--hairline);
  border-radius: var(--radius-md);
  background-color: var(--ink-900);
  color: var(--ink-100);
  color-scheme: dark;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}
.ask[hidden] { display: none; }
.ask:focus, .ask:focus-visible { outline: none; }
.ask [hidden] { display: none !important; }

.ask-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 20px;
  border-bottom: var(--hairline);
}
.ask-title {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.ask-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-button);
  background: none;
  color: var(--ink-100);
  cursor: pointer;
  transition: background-color 150ms ease;
}
.ask-close:hover { background-color: var(--ink-800); }
.ask-close svg { width: 18px; height: 18px; }

/* The thread: the intro, the turns, then the questions not yet asked. */
.ask-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 20px;
}
.ask-intro, .ask-empty { margin: 0; color: var(--ink-400); }
.ask-log { display: flex; flex-direction: column; gap: 24px; }
.ask-log:empty { display: none; }

.ask-turn { display: flex; flex-direction: column; gap: 12px; }
.ask-q {
  align-self: flex-end;
  max-width: 85%;
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px; /* a sent message, as on the wall */
  background-color: var(--ink-750);
  overflow-wrap: anywhere;
}
.ask-a { display: flex; flex-direction: column; gap: 10px; }
.ask-text { display: grid; gap: 10px; overflow-wrap: anywhere; }
.ask-text p { margin: 0; }
.ask-text strong { font-weight: 600; }
.ask-text a, .ask-sources a { color: var(--signal-400); text-underline-offset: 2px; }
.ask-text a:hover, .ask-sources a:hover { color: var(--ink-100); }

.ask-sources { display: grid; }
.ask-sources a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding-block: 4px;
  font-size: 14px;
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.ask-sources a:hover { text-decoration: underline; }
.ask-time { margin: 0; font-size: 13px; color: var(--ink-400); }

/* The reveal: every word is laid out from the start (the space is held)
   and fades in turn; ask.js sets each word's delay. */
.ask-a.is-filling .ask-w { opacity: 0; }
.ask-a.is-filling .ask-after { opacity: 0; }
.ask-w, .ask-after { transition: opacity 160ms linear; }

.ask-starters { display: grid; justify-items: start; gap: 8px; }
.ask-starter {
  min-height: 44px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--ask-edge);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-100);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}
.ask-starter:hover { border-color: var(--ink-400); background-color: var(--ink-800); }

/* Ask your own: no field, its action is the demo. */
.ask-own {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 16px;
  border-top: var(--hairline);
}
.ask-own p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink-200);
}
.ask-own .button { flex: none; border: 0; cursor: pointer; }

.ask-launcher:focus-visible,
.ask button:focus-visible,
.ask a:focus-visible {
  outline: 2px solid var(--signal-500);
  outline-offset: 2px;
}

/* --- phones: the corner panel is a sheet that takes the button's place -- */
@media (max-width: 639px) {
  .ask {
    inset: auto max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    width: auto;
    height: min(560px, calc(100vh - var(--ask-bar) - 32px));
    height: min(560px, calc(100dvh - var(--ask-bar) - 32px - env(safe-area-inset-bottom, 0px)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .ask-w, .ask-after { transition: none; }
}
