/* Chat answer extras: the Thinking capsule and callout blockquotes.
 * Uses the shared theme tokens, so light and dark themes follow automatically.
 * The Thinking capsule is a small night-sky scene in both themes (original OWEN artwork). */

/* ---- Thinking capsule (public/chat-thinking.mjs, symbols in public/chat-thinking-symbols.mjs) ---- */
.bubble > .thinking-panel {
  max-width: 100%;
  margin: 0 0 10px;
  font-size: 0.9em;
  color: var(--color-muted);
}
/* The capsule replaces chat.js's separate status pill while the answer is being prepared; its text and
 * stop button live in the capsule. (Browsers without :has keep both, as before.) */
.bubble.thinking:has(> .thinking-panel.is-thinking) .bubble-status { display: none; }

.thinking-panel__capsule {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-height: 44px;
  padding: 5px 6px 5px 5px;
  border-radius: 999px;
  color: #eef1ff;
  background: radial-gradient(130% 180% at 0% 0%, #3a3496 0%, #1d2259 46%, #0f1538 100%);
  border: 1px solid #ffffff1f;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, min-height 0.25s ease, padding 0.25s ease;
  vertical-align: top;
}
.thinking-panel__capsule:hover { box-shadow: var(--shadow-sm); }
/* The expand control: the activity label, timer, trail and arrow. */
.thinking-panel__summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  padding: 4px 10px 4px 0;
  border: 0;
  border-radius: 999px;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
  user-select: none;
}
.thinking-panel__summary:focus-visible { outline: 3px solid var(--owen-focus, var(--color-accent)); outline-offset: 3px; box-shadow: none; }
.thinking-panel__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #eef1ff;
}
.thinking-panel__elapsed { flex: none; font-variant-numeric: tabular-nums; color: #aab4dc; white-space: nowrap; }
.thinking-panel__elapsed:not(:empty)::before { content: "· "; }
.thinking-panel__chevron {
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 2px 2px;
  border-inline-end: 1.5px solid #c9d0f0;
  border-block-end: 1.5px solid #c9d0f0;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.thinking-panel.is-open .thinking-panel__chevron { transform: rotate(225deg); margin-block: 4px 0; }
/* No reasoning text yet: a label, not an expandable control. */
.thinking-panel--empty .thinking-panel__summary { cursor: default; }
.thinking-panel--empty .thinking-panel__chevron { display: none; }
.thinking-panel__stop {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: 1px solid #ffffff26;
  border-radius: 50%;
  color: #eef1ff;
  background: #ffffff14;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.thinking-panel__stop:hover { background: #ff7c8740; border-color: #ff7c87aa; }
.thinking-panel__stop:focus-visible { outline: 3px solid var(--owen-focus, var(--color-accent)); outline-offset: 2px; box-shadow: none; }

/* Starfield behind the capsule, clipped to its shape; a second layer twinkles while thinking. */
.cosmic-stars {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 18% 28%, #ffffffcc 0 0.7px, transparent 1.3px),
    radial-gradient(circle at 46% 78%, #ffffff99 0 0.6px, transparent 1.2px),
    radial-gradient(circle at 63% 22%, #bfe9f7cc 0 0.8px, transparent 1.4px),
    radial-gradient(circle at 81% 64%, #ffffffaa 0 0.6px, transparent 1.2px),
    radial-gradient(circle at 92% 30%, #ffd166aa 0 0.7px, transparent 1.3px),
    radial-gradient(circle at 34% 50%, #ffffff66 0 0.5px, transparent 1px);
}
.cosmic-stars::before,
.cosmic-stars::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
}
.cosmic-stars::before {
  background-image:
    radial-gradient(circle at 26% 70%, #ffffff 0 0.9px, transparent 1.6px),
    radial-gradient(circle at 55% 40%, #ff8fc7 0 0.8px, transparent 1.5px),
    radial-gradient(circle at 74% 82%, #42c9e8 0 0.9px, transparent 1.6px),
    radial-gradient(circle at 88% 16%, #ffffff 0 0.8px, transparent 1.5px);
}
/* A faint nebula wash drifting across the capsule. */
.cosmic-stars::after {
  background: radial-gradient(60% 120% at 70% 50%, #ff5fa21f, transparent 70%), radial-gradient(50% 120% at 30% 60%, #42c9e81a, transparent 70%);
}
.thinking-panel.is-thinking .cosmic-stars::before { animation: cosmic-twinkle 2.6s ease-in-out infinite; }
.thinking-panel.is-thinking .cosmic-stars::after { opacity: 1; animation: cosmic-nebula 7s ease-in-out infinite alternate; }

/* The orb: a small planet with a dashed orbit and a satellite; symbols pop in and spin out here. */
.cosmic-orb {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #5650c8 0%, #2a2c78 58%, #191d52 100%);
  box-shadow: var(--shadow-sm);
  transition: width 0.25s ease, height 0.25s ease;
}
.cosmic-orb::before,
.cosmic-orb::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  pointer-events: none;
}
.cosmic-orb::before { border: 1px dashed #8f7bff8c; }
.cosmic-orb::after { background: radial-gradient(circle at 50% 0, #42c9e8 0 2.2px, #42c9e855 2.8px, transparent 3.6px); }
.thinking-panel.is-thinking .cosmic-orb::before { animation: cosmic-orbit 9s linear infinite; }
.thinking-panel.is-thinking .cosmic-orb::after { animation: cosmic-orbit 3.4s linear infinite; }
.cosmic-orb.is-flash { animation: cosmic-flash 0.7s ease-out; }

.cosmic-symbol { display: inline-flex; pointer-events: none; }
.cosmic-symbol > svg { display: block; width: 100%; height: 100%; overflow: visible; }
.cosmic-symbol--hero {
  position: absolute;
  inset: 5px;
  filter: drop-shadow(0 0 3px #ffffff40);
  animation: cosmic-pop-in 0.56s cubic-bezier(0.18, 1.5, 0.4, 1) both;
}
.thinking-panel.is-thinking .cosmic-symbol--hero:not(.is-leaving) {
  animation: cosmic-pop-in 0.56s cubic-bezier(0.18, 1.5, 0.4, 1) both, cosmic-bob 2.6s ease-in-out 0.56s infinite alternate;
}
.cosmic-symbol--hero.is-leaving { animation: cosmic-spin-out 0.52s cubic-bezier(0.5, 0, 0.75, 0) forwards; }
.cosmic-symbol--burst {
  position: absolute;
  z-index: 2;
  top: 9px;
  left: 9px;
  width: 16px;
  height: 16px;
  filter: drop-shadow(0 0 4px #ffffff59);
  animation: cosmic-burst 1.4s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
/* The trail: every topic visited so far, kept on the collapsed label as a recap. */
.cosmic-trail { display: inline-flex; align-items: center; gap: 4px; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.cosmic-trail:empty { display: none; }
.cosmic-symbol--trail { width: 16px; height: 16px; flex: none; animation: cosmic-trail-in 0.45s cubic-bezier(0.18, 1.5, 0.4, 1) both; }
.cosmic-symbol--trail.is-ping { animation: cosmic-ping 0.5s ease-out; }

/* Shimmer on the activity while the answer is being prepared. */
.thinking-panel.is-thinking .thinking-panel__label {
  background: linear-gradient(90deg, #c9d0f0 0%, #ffffff 38%, #7fe3ff 52%, #ffd1ea 62%, #c9d0f0 90%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: owen-thinking-shimmer 1.8s linear infinite;
}

/* The faded live preview: the shown reasoning section, revealed at reading pace, rising out of a fade under
   the capsule. Three lines, so the sentence being read keeps its context. The text sits about 2 mm lower
   (padding-top), so the fade dims much less of the top line. The fade is fully clear over that padding, so the
   clipped bottom of an older line never shows there, and then reaches full strength by 1.15em. */
.thinking-panel__preview {
  display: none;
  position: relative;
  max-width: min(100%, 64ch);
  max-height: 5.35em;
  margin: 7px 0 0 22px;
  padding-top: 0.55em;
  padding-inline-start: 16px;
  overflow: hidden;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 0.94em;
  font-style: italic;
  line-height: 1.6;
  color: var(--color-muted);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0.55em, #000 1.15em);
  mask-image: linear-gradient(to bottom, transparent 0.55em, #000 1.15em);
}
/* A thin glowing thread from the capsule's orb down to the preview, like a thought trailing off. */
.thinking-panel__preview::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(to bottom, #7864e8, #42c9e8 60%, #42c9e800);
  opacity: 0.7;
}
.thinking-panel.is-thinking.has-preview:not(.is-open) > .thinking-panel__preview { display: flex; animation: cosmic-preview-in 0.4s ease-out both; }
.thinking-panel__preview-text { opacity: 0.88; }
/* Each new section fades in (chat-thinking.mjs replays this class when the next section starts). */
.thinking-panel__preview-text.is-turning { animation: cosmic-section-in 0.45s ease-out both; }
.thinking-panel__preview-text::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-inline-start: 6px;
  border-radius: 50%;
  vertical-align: 0.1em;
  background: #42c9e8;
  box-shadow: var(--shadow-sm);
  animation: cosmic-caret 1.1s ease-in-out infinite;
}

/* Collapsed after thinking: a compact chip that keeps the symbol trail. */
.thinking-panel:not(.is-thinking) > .thinking-panel__capsule { min-height: 34px; gap: 8px; padding: 3px 4px 3px 3px; }
.thinking-panel:not(.is-thinking) .thinking-panel__summary { gap: 8px; padding-inline-end: 10px; }
.thinking-panel:not(.is-thinking) .cosmic-orb { width: 26px; height: 26px; }
.thinking-panel:not(.is-thinking) .cosmic-orb::before { inset: -3px; opacity: 0.55; }
.thinking-panel:not(.is-thinking) .cosmic-orb::after { display: none; }
.thinking-panel:not(.is-thinking) .cosmic-symbol--hero { inset: 4px; }
.thinking-panel:not(.is-thinking) .thinking-panel__label { font-weight: 500; color: #dfe4f5; }
.thinking-panel:not(.is-thinking) .cosmic-symbol--trail { width: 15px; height: 15px; }

.thinking-panel__body {
  margin: 8px 0 2px;
  padding: 10px 14px 6px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--owen-violet, #7864e8) 22%, var(--color-border));
  background:
    var(--owen-surface);
  max-height: 18rem;
  overflow-y: auto;
  line-height: 1.55;
}
.thinking-panel__body[hidden] { display: none; }
.thinking-panel__body p { margin: 0 0 8px; padding-inline-start: 32px; }
.thinking-panel__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding-inline-start: 0 !important;
  color: var(--color-text);
}
.thinking-panel__title:first-child { margin-top: 2px; }
/* What was read (slides, retrieved sources, the student's files), above the reasoning. */
.thinking-panel__body .thinking-panel__reads-title {
  margin: 2px 0 4px;
  padding-inline-start: 0;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted, #9aa3c0);
}
.thinking-panel__reads {
  margin: 0 0 10px;
  padding-inline-start: 32px;
  font-size: 0.92em;
  color: var(--color-muted, #9aa3c0);
}
.thinking-panel__reads li { margin: 0 0 3px; overflow-wrap: anywhere; }
.thinking-panel__reads li::marker { color: color-mix(in srgb, var(--owen-violet, #7864e8) 70%, transparent); }
.cosmic-symbol--title {
  flex: none;
  width: 22px;
  height: 22px;
  padding: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #5650c8, #1d2259);
  box-shadow: var(--shadow-sm);
}

/* Phones: the activity keeps the room. The trail waits for the collapsed chip, where it is the recap. */
@media (max-width: 480px) {
  .thinking-panel__capsule { gap: 8px; }
  .thinking-panel__summary { gap: 8px; }
  .thinking-panel.is-thinking .cosmic-trail { display: none; }
  .thinking-panel__preview { margin-left: 18px; }
}

@keyframes owen-thinking-shimmer {
  from { background-position: 110% 0; }
  to { background-position: -110% 0; }
}
@keyframes cosmic-orbit { to { transform: rotate(360deg); } }
@keyframes cosmic-twinkle { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }
@keyframes cosmic-nebula { from { transform: translateX(-12%); } to { transform: translateX(12%); } }
@keyframes cosmic-caret { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }
@keyframes cosmic-preview-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes cosmic-section-in { from { opacity: 0; } to { opacity: 0.88; } }
@keyframes cosmic-flash {
  0% { box-shadow: var(--shadow-sm); }
  40% { box-shadow: var(--shadow-sm); }
  100% { box-shadow: var(--shadow-sm); }
}
@keyframes cosmic-pop-in {
  0% { opacity: 0; transform: scale(0.1) rotate(-170deg); filter: brightness(2.4) drop-shadow(0 0 6px #ffffff); }
  60% { opacity: 1; transform: scale(1.2) rotate(14deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); filter: drop-shadow(0 0 3px #ffffff40); }
}
@keyframes cosmic-spin-out {
  to { opacity: 0; transform: translate(16px, -14px) scale(0.2) rotate(220deg); }
}
@keyframes cosmic-bob {
  from { transform: translateY(1px) rotate(-6deg); }
  to { transform: translateY(-1.5px) rotate(6deg); }
}
@keyframes cosmic-burst {
  0% { opacity: 0; transform: translate(0, 0) scale(0.3) rotate(0deg); }
  18% { opacity: 1; transform: translate(calc(var(--burst-dx, 30px) * 0.25), calc(var(--burst-dy, -30px) * 0.25)) scale(1.15) rotate(calc(var(--burst-spin, 200deg) * 0.2)); }
  100% { opacity: 0; transform: translate(var(--burst-dx, 30px), var(--burst-dy, -30px)) scale(0.6) rotate(var(--burst-spin, 200deg)); }
}
@keyframes cosmic-trail-in {
  0% { opacity: 0; transform: translateX(-10px) scale(0.2) rotate(-120deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes cosmic-ping {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); filter: drop-shadow(0 0 4px #ffd166); }
  100% { transform: scale(1); }
}

/* Reduced motion: the same symbols and preview, standing still. (These selectors outrank the global reset.) */
@media (prefers-reduced-motion: reduce) {
  .thinking-panel .cosmic-symbol,
  .thinking-panel .cosmic-orb,
  .thinking-panel .cosmic-orb::before,
  .thinking-panel .cosmic-orb::after,
  .thinking-panel .cosmic-stars::before,
  .thinking-panel .cosmic-stars::after,
  .thinking-panel .thinking-panel__preview,
  .thinking-panel .thinking-panel__preview-text,
  .thinking-panel .thinking-panel__preview-text::after,
  .thinking-panel.is-thinking .thinking-panel__label { animation: none !important; }
  .thinking-panel .cosmic-symbol--burst { display: none; }
  .thinking-panel .cosmic-symbol--hero.is-leaving { display: none; }
  .thinking-panel.is-thinking .thinking-panel__label { color: #ffffff; background: none; }
}

/* ---- Callouts (public/markdown_runtime.js decorateCallouts) ---- */
blockquote.owen-callout {
  --callout-tint: var(--color-accent);
  position: relative;
  margin: 14px 0;
  padding: 12px 14px 12px 50px;
  border: 1px solid color-mix(in srgb, var(--callout-tint) 32%, var(--color-border));
  border-inline-start: 4px solid var(--callout-tint);
  border-radius: 14px;
  background:
    color-mix(in srgb,var(--callout-tint) 6%,var(--owen-surface));
  color: var(--color-text);
  /* Answer bubbles inherit pre-wrap; inside a callout the parser's newline text nodes would render as blank lines. */
  white-space: normal;
}
blockquote.owen-callout > p:last-child { margin-bottom: 0; }
blockquote.owen-callout > p:first-of-type { margin-top: 0; }
blockquote.owen-callout > p:first-of-type > strong:first-child { color: color-mix(in srgb, var(--callout-tint) 72%, var(--color-text)); }
/* The icon sits in a solid round badge, like a flat illustrated sticker. */
.owen-callout__icon {
  position: absolute;
  inset-inline-start: 12px;
  top: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--callout-badge, var(--callout-tint));
  box-shadow: 0 3px 0 color-mix(in srgb, var(--callout-badge, var(--callout-tint)) 60%, #111936), 0 0 0 3px color-mix(in srgb, var(--callout-tint) 18%, transparent);
}
.owen-callout__icon svg { width: 15px; height: 15px; }
blockquote.owen-callout[data-callout="high-yield"] { --callout-tint: var(--color-accent); --callout-badge: #7864e8; }
blockquote.owen-callout[data-callout="exam-trap"] { --callout-tint: var(--color-warning); --callout-badge: #ff9f43; }
blockquote.owen-callout[data-callout="mnemonic"] { --callout-tint: var(--color-success); --callout-badge: #2bb79e; }
blockquote.owen-callout[data-callout="clinical-pearl"] { --callout-tint: var(--color-accent-strong, var(--color-accent)); --callout-badge: #ff5fa2; }
blockquote.owen-callout[data-callout="key-point"] { --callout-tint: var(--color-accent); --callout-badge: #42a5e8; }
