/* Nederlandse Lerares — typographic tuning for language-learning content.
   The default Chainlit markdown renderer italicizes blockquotes and gives
   horizontal rules very low contrast. Neither works for a tutor where the
   Dutch block IS the primary content students must read carefully. */

/* Spoken Dutch block: restyle blockquotes that appear inside assistant
   messages so the Dutch text reads as body copy, not a citation.
   Left border in the Chainlit primary tone makes the block unmistakable. */
.message-content blockquote,
[class*="message"] blockquote,
[data-slot="message"] blockquote,
.prose blockquote {
  font-style: normal;
  font-weight: 400;
  font-size: 1.05rem;
  line-height: 1.6;
  color: inherit;
  margin: 0.35rem 0 0.6rem 0;
  padding: 0.1rem 0 0.1rem 14px;
  border-left: 3px solid hsl(var(--primary) / 1);
  background: transparent;
  quotes: none;
}

/* Remove the auto-generated curly-quote pseudo-element that some
   Chainlit builds add before/after blockquotes. */
.message-content blockquote::before,
.message-content blockquote::after,
[class*="message"] blockquote::before,
[class*="message"] blockquote::after,
.prose blockquote::before,
.prose blockquote::after {
  content: none !important;
}

/* Nested paragraphs inside a blockquote should not inherit italic either. */
.message-content blockquote p,
[class*="message"] blockquote p,
.prose blockquote p {
  font-style: normal;
  margin: 0.15rem 0;
}

/* Horizontal rule used as the spoken/correction separator — make it
   actually visible against the dark chat background. */
.message-content hr,
[class*="message"] hr,
.prose hr {
  border: none;
  border-top: 1px solid hsl(var(--muted-foreground) / 0.35);
  margin: 0.9rem 0 0.6rem 0;
}

/* Correction heading spacing — tighten so the heading sits close to the
   paragraph it labels. */
.message-content h1 + p,
.message-content h2 + p,
.message-content h3 + p,
.message-content h4 + p,
[class*="message"] h1 + p,
[class*="message"] h2 + p,
[class*="message"] h3 + p,
[class*="message"] h4 + p {
  margin-top: 0.3rem;
}

/* Native audio player — reduce the visual tear in dark mode.
   We can't deeply style <audio controls>, but we can tame the container. */
.message-content audio,
[class*="message"] audio {
  width: 100%;
  max-width: 360px;
  margin: 0.6rem 0;
  border-radius: 999px;
  background: hsl(var(--muted) / 0.5);
}

/* Inline images in assistant replies — exam photos for Parts 2/3/4.
   Chainlit's default inline preview is small; we want large, always-visible
   photos that students can describe without clicking. */
.message-content img:not([class*="avatar"]):not([alt*="avatar"]),
[class*="message"] [class*="image"] img,
.prose img {
  max-width: min(520px, 100%);
  max-height: 400px;
  width: auto;
  height: auto;
  border-radius: 12px;
  object-fit: cover;
  margin: 0.4rem 0;
  cursor: zoom-in;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: block;
}

/* Image card wrapper. Chainlit wraps each cl.Image in a rounded 'bg-accent'
   card that is wider than the image itself — leaking a gray halo to the
   right of landscape/square photos. Shrink the wrapper to its content and
   neutralise the background. Selector targets the exact wrapper seen in
   Chainlit 2.11 (class: rounded-sm bg-accent overflow-hidden). */
div.rounded-sm.bg-accent.overflow-hidden:has(> img),
div.rounded-sm.bg-accent.overflow-hidden:has(img) {
  width: fit-content;
  max-width: min(520px, 100%);
  background: transparent;
}

/* The wrapper one level up also has max-w-[600px]; it's a flex child so
   letting it sit inline-block-ish is fine. */
div[class*="max-w-[600px]"]:has(img:not([class*="avatar"])) {
  max-width: 520px;
  width: fit-content;
}

/* When the user clicks an inline image Chainlit typically opens a sidebar
   drawer or overlay. Ensure that doesn't render broken on dark theme. */
[class*="ElementSideView"],
[class*="side-view"] {
  background: hsl(var(--background));
}

/* Student avatar on user messages.
   Chainlit 2.x does not wire public/avatars/user.svg to user bubbles.
   We inject it via ::after on the row that contains the bubble. The user
   bubble is uniquely identifiable by its wrapper classes
   (.bg-accent .rounded-3xl .max-w-[70%]), and its row is the flex-row that
   is NOT an .ai-message. */
.flex.flex-row.items-center.gap-1.w-full.group:has(.bg-accent.rounded-3xl.max-w-\[70\%\]) {
  justify-content: flex-end;
  align-items: flex-end;
}
.flex.flex-row.items-center.gap-1.w-full.group:has(.bg-accent.rounded-3xl.max-w-\[70\%\])::after {
  content: "";
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff url("/public/avatars/user.svg") center/cover;
  flex-shrink: 0;
  margin-left: 12px;
  align-self: flex-end;
  order: 10;
}

/* 60-second exam timer pill — fixed at bottom-right of viewport above the
   composer. Counts down from 60 to 0 then shows a 10s grace window. */
#dutch-exam-timer {
  position: fixed;
  bottom: 120px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: background 0.3s, color 0.3s;
}
#dutch-exam-timer.warning {
  background: hsl(30 95% 55%);
  color: white;
}
#dutch-exam-timer.grace {
  background: hsl(0 85% 55%);
  color: white;
  animation: dutch-timer-pulse 1s ease-in-out infinite;
}
@keyframes dutch-timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
#dutch-exam-timer[hidden] { display: none; }

/* Light theme overrides. Chainlit writes [data-theme="light"] on <html>
   when the user flips to light mode via its built-in toggle. Our custom
   rules need explicit light variants. */
@media (prefers-color-scheme: light) {
  .message-content blockquote,
  [class*="message"] blockquote,
  .prose blockquote {
    border-left-color: #ff4b4b;
  }
}

html[data-theme="light"] .message-content blockquote,
html[data-theme="light"] [class*="message"] blockquote,
html[data-theme="light"] .prose blockquote {
  border-left-color: #ff4b4b;
  background: rgba(0, 0, 0, 0.02);
}

html[data-theme="light"] .message-content hr,
html[data-theme="light"] [class*="message"] hr,
html[data-theme="light"] .prose hr {
  border-top-color: rgba(0, 0, 0, 0.2);
}

html[data-theme="light"] .message-content audio,
html[data-theme="light"] [class*="message"] audio {
  background: rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] #dutch-exam-timer {
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

html[data-theme="light"] div.rounded-sm.bg-accent.overflow-hidden:has(img) {
  background: transparent;
}
