/* Prakses, the AI assistant: its mascot and chat panel. Self-contained: its own --pkc-* / --pka-* tokens, never the host page's
   (--ink is the background on the public pages but the text colour on the student site). Dark by default; the student
   site and the family portal set data-mode / data-theme on <html>. */
.pk-chat {
  --pkc-bg: #1b212c; --pkc-surface: #232a37; --pkc-text: #e9ecf2; --pkc-muted: #9da7ba; --pkc-line: #2e3746; --pkc-edge: rgb(123 145 245 / .45);
  --pkc-link: #7b91f5; --pkc-focus: #7b91f5; --pkc-user-bg: #3d57d8; --pkc-user-text: #fff; --pkc-error: #ff9d92;
  --pkc-shadow: 0 18px 48px -12px rgb(0 0 0 / .65), 0 2px 8px rgb(0 0 0 / .35);
  --pka-ink: #2b4677; --pka-ink-2: #1d3156; --pka-cast: rgb(0 0 0 / .55); --pka-z: #5a9bff; --pka-spot: #7b91f5;
  --pka-w: 72px; --pka-h: 90px;
  display: contents; font-size: 15px; line-height: 1.5; color: var(--pkc-text); -webkit-text-size-adjust: 100%;
}
:root[data-mode="dark"] .pk-chat, :root[data-theme="dark"] .pk-chat { --pkc-bg: #18181a; --pkc-surface: #222225; --pkc-line: rgb(255 255 255 / .1); --pka-cast: rgb(0 0 0 / .6); }
:root[data-mode="light"] .pk-chat, :root[data-theme="light"] .pk-chat {
  --pkc-bg: #faf9f7; --pkc-surface: #fff; --pkc-text: #141414; --pkc-muted: #5a5753; --pkc-line: rgb(20 20 20 / .11); --pkc-edge: rgb(61 87 216 / .4);
  --pkc-link: #3349c9; --pkc-focus: #3d57d8; --pkc-error: #b3261e; --pkc-shadow: 0 18px 48px -14px rgb(20 20 20 / .35), 0 2px 8px rgb(20 20 20 / .12);
  --pka-ink: #12263f; --pka-ink-2: #0e1d33; --pka-cast: rgb(18 38 63 / .2); --pka-z: #1f5fdb; --pka-spot: #3d57d8;
}
.pk-chat *, .pk-chat *::before, .pk-chat *::after { box-sizing: border-box; }
.pk-chat button, .pk-chat textarea { font: inherit; color: inherit; letter-spacing: normal; text-transform: none; }
.pk-chat button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.pk-chat :focus-visible { outline: 2px solid var(--pkc-focus); outline-offset: 2px; }
.pk-chat [hidden] { display: none !important; }
.pk-chat .pk-chat-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.pk-chat[data-covered] :is(.pk-ast, .pk-ast-spot, .pk-chat-panel) { visibility: hidden; }

/* The mascot: a blue figure in a graduation cap on a stack of books. Its place is a transform; a flight sets the duration. */
.pk-ast { position: fixed; top: 0; left: 0; z-index: 61; width: var(--pka-w); height: var(--pka-h); visibility: hidden; transition: transform 0ms cubic-bezier(.45, 0, .25, 1); will-change: transform; }
.pk-ast.is-ready { visibility: visible; }
.pk-ast-btn { display: block; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 18px; background: none; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.pk-ast[data-mode="dragging"] .pk-ast-btn { cursor: grabbing; }
.pk-ast-btn:focus-visible { outline: 2px solid var(--pkc-focus); outline-offset: 4px; }
.pk-ast-hop { display: block; width: 100%; height: 100%; pointer-events: none; }
.pk-fig { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 6px 8px var(--pka-cast)); transform-origin: 50% 90%; transition: transform .25s ease, filter .25s ease; }
.pk-ast-btn:hover .pk-fig { transform: scale(1.06); }
.pk-fig-ink { fill: var(--pka-ink); }
.pk-fig-ink2 { fill: var(--pka-ink-2); }
.pk-fig-shadow { fill: var(--pka-cast); }

/* Always moving a little: breathing, blinking, a swinging tassel */
.pk-fig-body { transform-box: view-box; transform-origin: 40px 80px; animation: pk-fig-bob 2.6s ease-in-out infinite; }
.pk-fig-eyes-open { transform-box: fill-box; transform-origin: center; animation: pk-fig-blink 5.2s infinite; }
.pk-fig-pupils { transform: translate(var(--lx, 0px), var(--ly, 0px)); transition: transform .12s ease-out; }
.pk-fig-tassel { transform-box: view-box; transform-origin: 61px 26.5px; animation: pk-fig-tassel 3.2s ease-in-out infinite; }
.pk-fig-arm, .pk-fig-leg { transform-box: fill-box; transform-origin: 50% 12%; transition: transform .3s ease; }
.pk-fig-eyes-happy, .pk-fig-eyes-closed, .pk-fig-mouth, .pk-fig-dots, .pk-fig-sparkles, .pk-fig-zzz { opacity: 0; transition: opacity .2s; }
.pk-fig-mouth { transform-box: fill-box; transform-origin: center; }
.pk-fig-sparkles { transform-box: view-box; transform-origin: 40px 40px; }
.pk-fig-zzz { font: 700 11px/1 system-ui, sans-serif; fill: var(--pka-z); }
@keyframes pk-fig-bob { 50% { transform: translateY(-2.5px) scaleY(1.015); } }
@keyframes pk-fig-blink { 0%, 92%, 97%, 100% { transform: scaleY(1); } 94.5% { transform: scaleY(.1); } }
@keyframes pk-fig-tassel { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(8deg); } }

/* Flying: leaning into the trip, legs kicking, arms out. Dragging: held up, legs dangling, mouth open */
.pk-ast[data-face="left"] { --pka-tilt: -9deg; }
.pk-ast[data-face="right"] { --pka-tilt: 9deg; }
.pk-ast[data-mode="flying"] .pk-fig { transform: rotate(var(--pka-tilt)); }
.pk-ast[data-mode="flying"] .pk-fig-leg-l { animation: pk-fig-kick .28s ease-in-out infinite alternate; }
.pk-ast[data-mode="flying"] .pk-fig-leg-r { animation: pk-fig-kick .28s ease-in-out infinite alternate-reverse; }
.pk-ast[data-mode="flying"] .pk-fig-arm-l { transform: rotate(55deg); }
.pk-ast[data-mode="flying"] .pk-fig-arm-r { transform: rotate(-55deg); }
.pk-ast[data-mode="dragging"] .pk-fig { transform: scale(1.1) rotate(-5deg); filter: drop-shadow(0 16px 14px var(--pka-cast)); }
.pk-ast[data-mode="dragging"] .pk-fig-leg { animation: pk-fig-dangle .45s ease-in-out infinite alternate; }
.pk-ast[data-mode="dragging"] .pk-fig-arm-l { transform: rotate(130deg); }
.pk-ast[data-mode="dragging"] .pk-fig-arm-r { transform: rotate(-130deg); }
.pk-ast[data-mode="dragging"] .pk-fig-eyes-open { transform: scale(1.2); animation: none; }
.pk-ast[data-mode="dragging"] .pk-fig-mouth { opacity: 1; }
@keyframes pk-fig-kick { from { transform: rotate(-20deg); } to { transform: rotate(20deg); } }
@keyframes pk-fig-dangle { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }

/* Moods */
.pk-ast:is([data-mood="happy"], [data-mood="excited"], [data-mood="celebrate"], [data-mood="wave"]) .pk-fig-eyes-open { opacity: 0; }
.pk-ast:is([data-mood="happy"], [data-mood="excited"], [data-mood="celebrate"], [data-mood="wave"]) .pk-fig-eyes-happy { opacity: 1; }
.pk-ast[data-mood="happy"] .pk-fig { animation: pk-fig-bounce .55s ease-out; }
.pk-ast[data-mood="excited"] .pk-fig { animation: pk-fig-bounce .5s ease-out 2; }
.pk-ast:is([data-mood="excited"], [data-mood="celebrate"]) .pk-fig-sparkles { opacity: 1; animation: pk-fig-twinkle .7s ease-in-out infinite alternate; }
.pk-ast[data-mood="celebrate"] .pk-fig { animation: pk-fig-jump .7s cubic-bezier(.3, 1.6, .5, 1) 2; }
.pk-ast[data-mood="celebrate"] .pk-fig-arm-l { transform: rotate(150deg); }
.pk-ast[data-mood="celebrate"] .pk-fig-arm-r { transform: rotate(-150deg); }
.pk-ast[data-mood="wave"] .pk-fig-arm-r { animation: pk-fig-wave .32s ease-in-out 5 alternate; }
.pk-ast[data-mood="thinking"] .pk-fig-pupils { transform: translate(1.6px, -1.9px); }
.pk-ast[data-mood="thinking"] .pk-fig-dots { opacity: 1; }
.pk-ast[data-mood="thinking"] .pk-fig-dots circle { animation: pk-fig-dot 1.2s ease-in-out infinite; }
.pk-ast[data-mood="thinking"] .pk-fig-dots circle:nth-child(2) { animation-delay: .2s; }
.pk-ast[data-mood="thinking"] .pk-fig-dots circle:nth-child(3) { animation-delay: .4s; }
.pk-ast[data-mood="thinking"] .pk-fig-arm-r { transform: rotate(-150deg) translateY(2px); }
.pk-ast[data-mood="talking"] .pk-fig-mouth { opacity: 1; animation: pk-fig-talk .22s ease-in-out infinite alternate; }
.pk-ast[data-mood="sleepy"] .pk-fig-eyes-open { opacity: 0; }
.pk-ast[data-mood="sleepy"] .pk-fig-eyes-closed { opacity: 1; }
.pk-ast[data-mood="sleepy"] .pk-fig-zzz { opacity: 1; animation: pk-fig-zzz 2.4s ease-in-out infinite; }
.pk-ast[data-mood="sleepy"] .pk-fig-body { animation-duration: 4.5s; }
.pk-ast[data-mood="surprised"] .pk-fig-eyes-open { transform: scale(1.28); animation: none; }
.pk-ast[data-mood="surprised"] .pk-fig-mouth { opacity: 1; }
.pk-ast[data-mood="surprised"] .pk-fig { animation: pk-fig-jump .45s ease-out; }
.pk-ast[data-mood="landed"] .pk-fig { animation: pk-fig-squash .45s ease-out; }
.pk-ast:is([data-mood="pointing"], [data-mood="tap"])[data-face="left"] .pk-fig-arm-l { transform: rotate(95deg); }
.pk-ast:is([data-mood="pointing"], [data-mood="tap"])[data-face="right"] .pk-fig-arm-r { transform: rotate(-95deg); }
.pk-ast[data-mood="tap"][data-face="left"] .pk-fig { animation: pk-fig-poke-l .45s ease-in-out; }
.pk-ast[data-mood="tap"][data-face="right"] .pk-fig { animation: pk-fig-poke-r .45s ease-in-out; }
@keyframes pk-fig-bounce { 30% { transform: translateY(-7px) scale(1.04, .97); } 60% { transform: translateY(0) scale(1.04, .94); } 80% { transform: scale(.98, 1.02); } }
@keyframes pk-fig-jump { 40% { transform: translateY(-16px) rotate(-6deg); } 70% { transform: translateY(0) scale(1.06, .92); } }
@keyframes pk-fig-squash { 0% { transform: scale(1.12, .84); } 45% { transform: scale(.94, 1.08); } 100% { transform: none; } }
@keyframes pk-fig-wave { from { transform: rotate(-120deg); } to { transform: rotate(-165deg); } }
@keyframes pk-fig-dot { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes pk-fig-talk { from { transform: scaleY(.35); } to { transform: scaleY(1.1); } }
@keyframes pk-fig-twinkle { from { opacity: .35; transform: scale(.9); } to { opacity: 1; transform: scale(1.08); } }
@keyframes pk-fig-zzz { 0% { transform: translate(0, 0); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(8px, -12px); opacity: 0; } }
@keyframes pk-fig-poke-l { 50% { transform: translateX(-6px) rotate(-4deg); } }
@keyframes pk-fig-poke-r { 50% { transform: translateX(6px) rotate(4deg); } }

/* Speech bubble, and the ring around what it points at */
.pk-ast-bubble { position: absolute; bottom: calc(100% + 4px); width: max-content; max-width: min(260px, calc(100vw - 40px)); padding: 9px 12px; background: var(--pkc-surface); color: var(--pkc-text); border: 1px solid var(--pkc-edge); border-radius: 14px; box-shadow: var(--pkc-shadow); font-size: 14px; line-height: 1.4; transform: translateX(var(--pka-bx, 0px)); overflow-wrap: anywhere; }
.pk-ast-bubble.is-right { left: 0; }
.pk-ast-bubble.is-left { right: 0; }
.pk-ast-bubble.is-below { bottom: auto; top: calc(100% + 4px); }
.pk-ast-bubble-btn { display: block; padding: 0; border: 0; background: none; text-align: left; line-height: inherit; }
.pk-ast-bubble-btn::after { color: var(--pkc-link); font-weight: 600; }
.pk-ast-bubble-btn--ask::after { content: " Ask →"; }
.pk-ast-bubble-btn--go::after { content: " Show me →"; }
.pk-ast-spot { position: fixed; top: 0; left: 0; z-index: 58; border: 3px solid var(--pka-spot); border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 4px rgb(123 145 245 / .18); animation: pk-ast-ring 1.2s ease-in-out infinite; }
@keyframes pk-ast-ring { 50% { box-shadow: 0 0 0 9px rgb(123 145 245 / .06); } }

.pk-chat-panel { position: fixed; z-index: 60; bottom: max(16px, env(safe-area-inset-bottom)); width: 380px; max-width: calc(100vw - 32px); height: min(600px, calc(100dvh - 40px - var(--pka-h))); display: flex; flex-direction: column; background: var(--pkc-bg); color: var(--pkc-text); border: 1px solid var(--pkc-line); border-radius: 18px; box-shadow: var(--pkc-shadow); }
.pk-chat-panel.is-right { right: max(16px, env(safe-area-inset-right)); }
.pk-chat-panel.is-left { left: max(16px, env(safe-area-inset-left)); }
.pk-chat-panel:not([hidden]) { animation: pk-chat-in .18s ease-out; }
@keyframes pk-chat-in { from { opacity: 0; } }
.pk-chat-head { position: relative; display: flex; align-items: center; gap: 8px; padding: 10px 8px 8px calc(16px + var(--pka-w) + 8px); border-bottom: 1px solid var(--pkc-line); flex: none; }
.pk-chat-title { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.2; color: var(--pkc-text); }
.pk-chat-badge { padding: 1px 6px; border: 1px solid var(--pkc-edge); border-radius: 6px; color: var(--pkc-link); font-size: 11px; font-weight: 600; }
.pk-chat-tools { display: flex; flex: 1; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0; }
.pk-chat-left { margin-right: 4px; color: var(--pkc-muted); font-size: 12px; line-height: 1.25; text-align: right; }
.pk-chat-iconbtn { display: grid; place-items: center; flex: none; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--pkc-muted); }
.pk-chat-iconbtn:hover { background: var(--pkc-surface); color: var(--pkc-text); }
.pk-chat-ico { display: block; width: 18px; height: 18px; flex: none; }
.pk-chat-menu { position: absolute; top: calc(100% - 4px); right: 8px; z-index: 2; display: grid; min-width: 180px; padding: 4px; background: var(--pkc-surface); border: 1px solid var(--pkc-line); border-radius: 12px; box-shadow: var(--pkc-shadow); }
.pk-chat-menuitem { padding: 10px 12px; border: 0; border-radius: 8px; background: none; font-size: 14px; text-align: left; }
.pk-chat-menuitem:hover { background: var(--pkc-bg); }

.pk-chat-log { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; }
.pk-chat-log:focus-visible { outline-offset: -2px; }
.pk-chat-msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.pk-chat-msg--user { align-self: flex-end; background: var(--pkc-user-bg); color: var(--pkc-user-text); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.pk-chat-msg--bot { align-self: flex-start; display: grid; gap: 8px; background: var(--pkc-surface); border: 1px solid var(--pkc-line); border-bottom-left-radius: 5px; }
.pk-chat-msg--bot p { margin: 0; }
.pk-chat-part > * + * { margin-top: 8px; }
.pk-chat-msg--bot ul { margin: 0; padding: 0 0 0 20px; list-style: disc; }
.pk-chat-msg--bot li + li { margin-top: 3px; }
.pk-chat-msg a, .pk-chat-note a, .pk-chat-gate a { color: var(--pkc-link); text-decoration: underline; text-underline-offset: 3px; }
.pk-chat-action { display: flex; align-items: flex-start; gap: 8px; color: var(--pkc-muted); font-size: 13.5px; line-height: 1.4; }
.pk-chat-action .pk-chat-ico { width: 15px; height: 15px; margin-top: 2px; }
.pk-chat-action.is-done .pk-chat-ico { color: var(--pkc-link); }
.pk-chat-action.is-failed { color: var(--pkc-error); }
.pk-chat-pulse { flex: none; width: 8px; height: 8px; margin: 6px 3.5px 0; border-radius: 50%; background: var(--pkc-link); animation: pk-chat-pulse 1.1s ease-in-out infinite; }
@keyframes pk-chat-pulse { 50% { opacity: .3; transform: scale(.7); } }
.pk-chat-status { margin: 0; color: var(--pkc-muted); font-size: 13.5px; font-style: italic; }
.pk-chat-undo { display: inline-flex; align-items: center; gap: 6px; justify-self: start; padding: 6px 2px; border: 0; background: none; color: var(--pkc-link); font-size: 13.5px; text-decoration: underline; text-underline-offset: 3px; }
.pk-chat-note { align-self: stretch; margin: 0; padding: 10px 12px; border: 1px solid var(--pkc-line); border-radius: 12px; background: var(--pkc-surface); font-size: 14px; }
.pk-chat-note--error { border-color: var(--pkc-error); color: var(--pkc-error); background: transparent; }
.pk-chat-empty { display: grid; gap: 10px; align-content: start; }
.pk-chat-empty p { margin: 0; color: var(--pkc-muted); font-size: 14px; }
.pk-chat-chip { padding: 10px 14px; border: 1px solid var(--pkc-line); border-radius: 12px; background: var(--pkc-surface); font-size: 14px; line-height: 1.35; text-align: left; }
.pk-chat-chip:hover { border-color: var(--pkc-edge); }

.pk-chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--pkc-line); flex: none; }
.pk-chat-input { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; padding: 10px 12px; resize: none; overflow-y: auto; background: var(--pkc-surface); border: 1px solid var(--pkc-line); border-radius: 12px; font-size: 16px; line-height: 1.35; }
.pk-chat-input::placeholder { color: var(--pkc-muted); opacity: 1; }
.pk-chat-input:focus-visible { outline-offset: 1px; border-color: transparent; }
.pk-chat-send { flex: none; min-width: 64px; min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--pkc-user-bg); color: var(--pkc-user-text); font-size: 15px; font-weight: 600; }
.pk-chat-send:hover:not(:disabled) { filter: brightness(1.1); }
.pk-chat-send:disabled { opacity: .45; cursor: not-allowed; }
.pk-chat-send--stop { background: transparent; color: var(--pkc-text); border: 1px solid var(--pkc-edge); }
.pk-chat-gate { display: grid; gap: 6px; padding: 12px 16px; border-top: 1px solid var(--pkc-line); font-size: 14px; flex: none; }
.pk-chat-gate p { margin: 0; }
.pk-chat-gate-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.pk-chat-gate-links a { padding: 6px 0; }
.pk-chat-fine { padding: 0 16px 12px; color: var(--pkc-muted); font-size: 12px; line-height: 1.5; flex: none; }
.pk-chat-fine p { margin: 0 0 4px; }
.pk-chat-fine form { display: inline; margin: 0; }
.pk-chat-fine .pk-chat-note { margin-top: 2px; }
.pk-chat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.pk-chat-linkbtn { padding: 6px 2px; margin: -6px 0; border: 0; background: none; color: var(--pkc-link); font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }

/* Phones: a bottom sheet, so the page stays visible while it points at something */
@media (max-width: 559.98px) {
  .pk-chat-panel, .pk-chat-panel.is-left, .pk-chat-panel.is-right { left: 8px; right: 8px; width: auto; max-width: none; bottom: calc(8px + var(--pkc-kb, 0px) + env(safe-area-inset-bottom)); height: min(62dvh, 520px, calc(var(--pkc-vvh, 100dvh) - 24px - var(--pka-h))); }
  .pk-chat-chip { min-height: 44px; }
  .pk-chat-iconbtn { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) { .pk-chat *, .pk-chat *::before, .pk-chat *::after { animation: none !important; transition: none !important; } }
@media (forced-colors: active) {
  .pk-chat-panel, .pk-chat-msg--bot, .pk-chat-chip, .pk-chat-input, .pk-ast-bubble, .pk-chat-menu { border: 1px solid CanvasText; }
  .pk-fig { forced-color-adjust: none; }
  .pk-ast-btn:focus-visible { outline-color: CanvasText; }
}
@media screen { html.pk-chat-on body > footer { padding-bottom: calc(96px + env(safe-area-inset-bottom)); } }
@media print { .pk-chat { display: none !important; } }
