/* "Ask an AI" (public/ask-ai.js): the button at the bottom right and its panel, in the app and on Full page lessons.
   Study Space colours (ink, lime, soft green), light and dark: the app's [data-bs-theme], the lessons' [data-theme]
   or the system setting. */
:root {
  --ss-ask-bg: #ffffff; --ss-ask-ink: #25332c; --ss-ask-muted: #6b726d; --ss-ask-line: #e5e8e1; --ss-ask-soft: #eff3eb;
  --ss-ask-lime: #d9f578; --ss-ask-glow: rgba(190, 228, 70, .45); --ss-ask-focus: #245b89; --ss-ask-done: #2f6b3a;
  --ss-ask-bottom: 20px;
}
[data-bs-theme=dark], :root[data-theme=dark] {
  --ss-ask-bg: #1c2620; --ss-ask-ink: #eef3e9; --ss-ask-muted: #abb6ad; --ss-ask-line: #35433a; --ss-ask-soft: #29382e;
  --ss-ask-glow: rgba(217, 245, 120, .16); --ss-ask-focus: #9ecbfa; --ss-ask-done: #b9e4a3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]):not([data-bs-theme]) {
    --ss-ask-bg: #1c2620; --ss-ask-ink: #eef3e9; --ss-ask-muted: #abb6ad; --ss-ask-line: #35433a; --ss-ask-soft: #29382e;
    --ss-ask-glow: rgba(217, 245, 120, .16); --ss-ask-focus: #9ecbfa; --ss-ask-done: #b9e4a3;
  }
}
/* Phones: low in the corner on app pages (Matteo, 02/11/2026: the app has no bottom bar any more); above the highlighter
   bar in the app reader and on Full page lessons. */
@media (max-width: 700px) {
  :root { --ss-ask-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  :root:has(.lesson-view .hl-palette) { --ss-ask-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  :root[data-hl-pill] { --ss-ask-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
}

.ss-ask-fab {
  position: fixed; right: 20px; bottom: var(--ss-ask-bottom); z-index: 2147483000;
  display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px 0 18px; margin: 0;
  border: 0; border-radius: 999px; background: #25332c; color: #d9f578; cursor: pointer;
  font: 600 14px/1 system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; letter-spacing: .6px; text-transform:none;
  box-shadow: 0 8px 24px rgba(20, 30, 25, .28), 0 0 0 4px var(--ss-ask-glow);
  transition: transform .15s ease, box-shadow .15s ease;
}
@media (hover:hover) and (pointer:fine){.ss-ask-fab:hover{ background: #2f4238; }}
.ss-ask-fab:focus-visible { outline: 3px solid var(--ss-ask-focus); outline-offset: 3px; }
.ss-ask-fab > svg:last-child { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s ease; }
.ss-ask-fab[aria-expanded=true] > svg:last-child { transform: rotate(180deg); }
body.auth-page .ss-ask-fab, body.auth-page .ss-ask-panel { display: none; }
@media print { .ss-ask-fab, .ss-ask-panel { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .ss-ask-fab, .ss-ask-fab > svg:last-child { transition: none; } }

/* The AIs' logos in their colours (ChatGPT's is black or white). */
.ss-ask-mark { flex: none; width: 20px; height: 20px; fill: currentColor; stroke: none; }
.ss-ask-mark-claude { color: #d97757; }
.ss-ask-mark-chatgpt { color: var(--ss-ask-ink); }
.ss-ask-fab .ss-ask-mark-chatgpt { color: #ffffff; }
.ss-ask-mark-perplexity { color: #1fb8cd; }
.ss-ask-mark-link { color: var(--ss-ask-muted); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.ss-ask-panel {
  position: fixed; right: 20px; bottom: calc(var(--ss-ask-bottom) + 60px); z-index: 2147483001;
  box-sizing: border-box; width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - var(--ss-ask-bottom) - 80px); overflow: auto;
  padding: 14px 16px 16px; background: var(--ss-ask-bg); color: var(--ss-ask-ink);
  border: 1px solid var(--ss-ask-line); border-radius: 20px; box-shadow: 0 18px 50px rgba(15, 25, 20, .28);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; text-align: left;
  animation: ss-ask-in .16s ease-out;
}
@keyframes ss-ask-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ss-ask-panel { animation: none; } }
@media (max-width: 560px) { .ss-ask-panel { right: 8px; left: 8px; width: auto; } }
.ss-ask-panel *, .ss-ask-panel *::before, .ss-ask-panel *::after { box-sizing: border-box; }
.ss-ask-panel button, .ss-ask-panel input, .ss-ask-panel textarea { font: inherit; color: inherit; margin: 0; }
.ss-ask-panel button { cursor: pointer; }
.ss-ask-panel button:focus-visible, .ss-ask-panel input:focus-visible { outline: 3px solid var(--ss-ask-focus); outline-offset: 2px; }

.ss-ask-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ss-ask-about { flex: 1; min-width: 0; margin: 0; font-size: 12px; font-weight:600; letter-spacing: .5px; text-transform:none; color: var(--ss-ask-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-ask-link { padding: 6px 2px; border: 0; background: none; font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.ss-ask-x { width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; font-size: 22px; line-height: 1; color: var(--ss-ask-muted); }
@media (hover:hover) and (pointer:fine){.ss-ask-x:hover{ background: var(--ss-ask-soft); }}
.ss-ask-quote { margin: 0 0 10px; padding: 8px 12px; border: 0; border-left: 3px solid #b5d84a; border-radius: 0 10px 10px 0; background: var(--ss-ask-soft); font-style: italic; font-size: 13px; }

/* The bar: the AI's mark, the question, the microphone and a round send button, with a lime glow. */
.ss-ask-bar {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 8px 8px 8px 16px;
  border: 1.5px solid #b5d84a; border-radius: 26px; background: var(--ss-ask-bg);
  box-shadow: 0 0 0 4px var(--ss-ask-glow);
}
.ss-ask-input { flex: 1; min-width: 0; min-height: 24px; padding: 6px 0; border: 0; outline: none; background: transparent; resize: none; font-size: 15px; line-height: 1.4; }
.ss-ask-input::placeholder { color: var(--ss-ask-muted); opacity: 1; }
.ss-ask-icon { flex: none; display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--ss-ask-muted); }
.ss-ask-icon svg, .ss-ask-send svg { flex: none; min-width: 20px; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ss-ask-icon[aria-pressed=true] { background: #fbe1dc; color: #b8412b; }
.ss-ask-send { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: #d9f578; color: #25332c; }
.ss-ask-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
@media (hover:hover) and (pointer:fine){.ss-ask-send:hover{ background: #cdee5a; }}

.ss-ask-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ss-ask-chip { min-height: 34px; padding: 0 12px; border: 1.5px dashed var(--ss-ask-line); border-radius: 10px; background: transparent; font-size: 13px; font-weight: 600; }
@media (hover:hover) and (pointer:fine){.ss-ask-chip:hover{ border-style: solid; border-color: #b5d84a; background: var(--ss-ask-soft); }}
.ss-ask-status { margin: 10px 0 0; font-size: 13px; color: var(--ss-ask-muted); }
.ss-ask-status:empty { display: none; }
.ss-ask-status.ss-ask-done { color: var(--ss-ask-done); font-weight:600; }
.ss-ask-error { color: #b8412b; }
.ss-ask-manual { width: 100%; margin-top: 8px; padding: 8px; border: 1px solid var(--ss-ask-line); border-radius: 10px; background: var(--ss-ask-soft); font-size: 12px; }

/* Change chat: one row per AI, your saved chats, and the bar to paste a chat link. */
.ss-ask-options { display: grid; gap: 4px; }
.ss-ask-row { display: flex; align-items: center; gap: 4px; }
.ss-ask-option { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border: 0; border-radius: 12px; background: transparent; font-size: 15px; font-weight: 600; text-align: left; }
@media (hover:hover) and (pointer:fine){.ss-ask-option:hover{ background: var(--ss-ask-soft); }}
.ss-ask-option[aria-checked=true] { background: var(--ss-ask-soft); box-shadow: inset 3px 0 0 #b5d84a; }
.ss-ask-option span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-ask-remove { width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; font-size: 18px; color: var(--ss-ask-muted); }
.ss-ask-label { margin: 12px 0 4px; font-size: 12px; font-weight:600; letter-spacing: .5px; text-transform:none; color: var(--ss-ask-muted); }
.ss-ask-linkbar { margin-top: 14px; }
.ss-ask-hint { margin: 8px 0 0; font-size: 12px; color: var(--ss-ask-muted); }

/* "Watch tutorial": a row at the bottom of the panel, and the full-screen player (time left at the top, Skip at the bottom left). */
.ss-ask-panel .ss-ask-tutorial-open { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 14px; padding: 10px 14px; border: 0; border-radius: 12px; background: #234735; color: #fff; font-size: 14px; font-weight:600; text-align: left; }
@media (hover:hover) and (pointer:fine){.ss-ask-panel .ss-ask-tutorial-open:hover{ background: #1b3829; }}
.ss-ask-tutorial-play { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #d9f578; color: #234735; font-size: 10px; padding-left: 2px; }
.ss-ask-tutorial-copy { flex: 1; min-width: 0; display: grid; gap: 2px; line-height: 1.2; }
.ss-ask-tutorial-copy strong { font-size: 14px; }
.ss-ask-tutorial-copy small { font-size: 12px; font-weight: 500; color: #c9dccf; }
.ss-ask-tutorial-new { flex: none; padding: 4px 8px; border-radius: 999px; background: #d9f578; color: #234735; font-size: 11px; font-weight:600; letter-spacing: .4px; text-transform:none; }
.ss-ask-tutorial { position: fixed; inset: 0; z-index: 2147483003; display: grid; place-items: center; background: #0b0f0d; }
.ss-ask-tutorial-video { width: 100%; height: 100%; object-fit: contain; background: #0b0f0d; cursor: pointer; }
.ss-ask-tutorial-time { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px; background: rgba(11, 15, 13, .72); color: #fff; font: 500 14px/1 system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-variant-numeric: tabular-nums; }
.ss-ask-tutorial-time:empty { display: none; }
.ss-ask-tutorial-skip { position: absolute; left: 24px; bottom: 24px; min-height: 48px; padding: 0 22px; border: 0; border-radius: 999px; background: #d9f578; color: #25332c; font: 600 15px/1 system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; cursor: pointer; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
@media (hover:hover) and (pointer:fine){.ss-ask-tutorial-skip:hover{ background: #cdee5a; }}
.ss-ask-tutorial-skip:focus-visible { outline: 3px solid #9ecbfa; outline-offset: 3px; }
@media (max-width: 560px) { .ss-ask-tutorial-skip { left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); } }
@media print { .ss-ask-tutorial { display: none !important; } }

/* Apple-feel phase 2: press feedback (lesson pages have no tokens, values are literal). */
.ss-ask-fab, .ss-ask-send, .ss-ask-chip, .ss-ask-option, .ss-ask-x { transition: background-color 150ms ease, border-color 150ms ease, transform 120ms cubic-bezier(.23, 1, .32, 1); }
.ss-ask-fab:active, .ss-ask-send:active, .ss-ask-chip:active, .ss-ask-x:active { transform: scale(.97); }
.ss-ask-option:active { transform: scale(.98); }
@media (prefers-reduced-motion: reduce) { .ss-ask-fab:active, .ss-ask-send:active, .ss-ask-chip:active, .ss-ask-x:active, .ss-ask-option:active { transform: none; } }
/* Apple-feel phase 3-5: the panel grows from the button and shrinks back into it. */
.ss-ask-panel { transform-origin: bottom right; animation: ss-ask-in 180ms cubic-bezier(.23, 1, .32, 1); overscroll-behavior: contain; }
@keyframes ss-ask-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.ss-ask-panel.is-leaving { animation: ss-ask-out 120ms cubic-bezier(.23, 1, .32, 1) forwards; pointer-events: none; }
@keyframes ss-ask-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }
.ss-ask-input { font-size: 16px; }
@media (prefers-reduced-motion: reduce) { .ss-ask-panel { animation: none; } }

/* Kit pass (stageshow ai-chat / Menu): the option rows' hover fill sits inset (the list takes the negative margin, not the row),
   so logos and labels line up with the heading, the bar and the hint at 16px; 12px rows inside 8px of a 20px panel nest evenly.
   The bar is a true pill (half its 56px height), so the 40px send button sits 8px from every edge. */
.ss-ask-panel { padding: 16px; }
.ss-ask-top { margin-top: -2px; }
.ss-ask-options { margin-inline: -8px; }
.ss-ask-option { padding: 0 8px; }
.ss-ask-bar { border-radius: 999px; }
.ss-ask-panel .ss-ask-option:focus-visible { outline-offset: -3px; }

/* Mobile pass – shell (HANDBOOK), Ask AI panel.
   - The app's global `button:focus-visible{outline-offset:2px!important}` pushed the option ring outwards, 5px from the panel
     edge (near-tangent); the ring goes back inside the row, as the kit pass intended.
   - Close (36px) and send (40px) get a 44px hit area from an invisible ::after, so the bar and header keep their sizes.
   - The input fills the bar's 40px line (44px box, -2px margins) so a tap anywhere across the bar's middle lands in it.
   - The hint and the tutorial line wrap without a lone last word ("in.", "56 s") at 320–360px; "· 56 s" never splits
     (ask-ai.js wraps it in .ss-ask-nowrap). The link placeholder is short enough to read whole at 320px; the example
     link moved into the hint under the bar. */
.ss-ask-panel .ss-ask-option:focus-visible { outline-offset: -3px !important; }
.ss-ask-x, .ss-ask-send { position: relative; }
.ss-ask-x::after, .ss-ask-send::after { content: ''; position: absolute; inset: -4px; }
.ss-ask-send::after { inset: -2px; }
.ss-ask-panel .ss-ask-input { min-height: 44px; margin-block: -2px; }
.ss-ask-hint { text-wrap: pretty; }
.ss-ask-tutorial-copy small { text-wrap: balance; }
.ss-ask-nowrap { white-space: nowrap; }

/* Dark: the button is a raised surface with a faint lime ring, not a thick glow. */
[data-bs-theme=dark] .ss-ask-fab{background:var(--ss-ask-soft);box-shadow:0 0 0 1px rgb(255 255 255 / .08),0 8px 24px rgb(0 0 0 / .45),0 0 0 4px var(--ss-ask-glow)}
