/* ==========================================================================
   THE CLARA SAT - CAPI MASCOT DESIGN SYSTEM
   Tokens come from The_Clara_SAT_Capi_Brand_Kit/08_Documentation/tokens.css.
   ========================================================================== */

:root {
  --capi-primary: #5B5CE6;
  --capi-primary-bright: #6D59E8;
  --capi-primary-soft: #B7B5FF;
  --capi-ink: #22205A;
  --capi-ink-outline: #241640;
  --capi-mint: #A7F3E1;
  --capi-gold: #FFD166;
  --capi-cream: #FFF7ED;
  --capi-fur: #D9A87C;
  --capi-fur-shadow: #9C6B4F;
  --capi-white: #FFFFFF;
  --capi-surface: #F3F4FF;

  --capi-radius: 20px;
  --capi-shadow: 0 18px 40px -18px rgba(34, 32, 90, 0.55);
  --capi-shadow-soft: 0 8px 24px -12px rgba(34, 32, 90, 0.35);
  --capi-frame-bg: rgba(91, 92, 230, 0.10);
}

/* ---------- Mascot element ---------- */

.capi-mascot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  line-height: 0;
  /* Reserved intrinsic box prevents CLS while the WebP decodes. */
  aspect-ratio: 1 / 1;
  width: var(--capi-size, 96px);
  height: var(--capi-size, 96px);
  max-width: 100%;
  contain: layout paint style;
}

.capi-mascot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(34, 32, 90, 0.18));
  user-select: none;
  -webkit-user-drag: none;
}

.capi-mascot--xs   { --capi-size: 28px; }
.capi-mascot--sm   { --capi-size: 44px; }
.capi-mascot--md   { --capi-size: 72px; }
.capi-mascot--lg   { --capi-size: 112px; }
.capi-mascot--xl   { --capi-size: 168px; }
.capi-mascot--hero { --capi-size: clamp(180px, 26vw, 320px); }

.capi-mascot--xs img { filter: none; }

/* ---------- Frames / containers ---------- */

.capi-frame {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--capi-radius);
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(183, 181, 255, 0.28) 0%, rgba(183, 181, 255, 0) 55%),
    var(--capi-frame-bg);
  padding: 8%;
  overflow: hidden;
  flex: 0 0 auto;
}

.capi-frame--plain { background: transparent; padding: 0; }

.capi-hero {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-radius: var(--capi-radius);
  padding: clamp(1rem, 2.4vw, 1.75rem);
  background:
    radial-gradient(90% 140% at 100% 0%, rgba(183, 181, 255, 0.32) 0%, rgba(183, 181, 255, 0) 60%),
    linear-gradient(140deg, rgba(91, 92, 230, 0.22) 0%, rgba(34, 32, 90, 0.08) 100%);
  border: 1px solid rgba(183, 181, 255, 0.28);
  overflow: hidden;
}

.capi-hero__text { position: relative; z-index: 1; min-width: 0; }
.capi-hero__art { position: relative; z-index: 1; flex: 0 0 auto; }

.capi-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  vertical-align: middle;
}

/* ---------- Branding marks ---------- */

#site-logo {
  background: transparent !important;
  border: 0 !important;
  border-radius: 0;
  overflow: visible;
}

/* Cropped Capi portrait and live wordmark share a baseline across placements. */
.brand-logo-slot,
#global-footer .site-footer-brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
}

img.capi-wordmark {
  height: 22px;
  width: auto;
  max-width: 180px;
  display: block;
}

img[data-brand-portrait] {
  display: block;
  flex: none;
  object-fit: contain;
}

#site-logo img, #mnav-brand-header img { width: 36px; height: 37px; }
#auth-modal-logo-badge img { width: 46px; height: 47px; }
.site-footer-brand img { width: 23px; height: 24px; }
#site-logo .tenant-logo, #mnav-brand-header .tenant-logo {
  width: auto;
  max-width: min(84px, 16vw);
}

.clara-wordmark {
  font-family: Georgia, Cambria, serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

#auth-modal-title.clara-wordmark { font-size: clamp(21px, 4vw, 27px); }
.site-footer-brand .clara-wordmark { font-size: 15px; }
.tenant-lockup .clara-wordmark, .org-sat-drills .clara-wordmark {
  font-family: inherit;
  letter-spacing: normal;
}

/* The utility buttons occupy most of the 380–479px header. The drawer
   carries the full name there. Below 380px the shell hides those buttons. */
@media (min-width: 380px) and (max-width: 479.98px) {
  #global-navbar #site-org-name { display: none !important; }
}
@media (max-width: 379.98px) {
  #global-navbar #site-org-name { display: block !important; font-size: 16px; }
  #global-navbar > .group:has(#site-logo) { gap: 5px !important; }
  #global-navbar #site-logo, #global-navbar #site-logo img {
    width: 32px !important;
    height: 33px !important;
  }
}

.capi-favicon-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: block;
}

/* ---------- Subtle motion ----------
   The mascot deliberately does NOT float or bounce: vertical motion on a
   static illustration reads as jitter and distracts from the content.
   Only a slow opacity breath is allowed while an AI request is in flight. */

/* Hard guard: no utility or future rule may translate, scale, rotate or
   animate the mascot itself. The opacity breath below re-enables animation
   explicitly for the aiThinking mood at higher specificity. */
.capi-mascot,
.capi-mascot img {
  transform: none;
  animation-name: none;
}

.capi-mascot--animated img {
  transform: none;
}

.capi-mascot--animated.capi-mascot--celebrating img,
.capi-mascot--animated.capi-mascot--questComplete img,
.capi-mascot--animated.capi-mascot--rankUp img {
  transform: none;
}

.capi-mascot--animated.capi-mascot--aiThinking img {
  animation: capi-think-breathe 2.8s ease-in-out infinite;
}

@keyframes capi-think-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.78; }
}

/* ---------- Exam-mode safety ---------- */

#view-question-solver:not(.hidden) .capi-mascot img,
#view-question-solver:not(.hidden) .capi-frame,
#view-question-solver:not(.hidden) .capi-mascot,
#rush-gameplay-arena .capi-mascot img,
#rush-gameplay-arena .capi-frame,
#rush-gameplay-arena .capi-mascot,
#battle-screen-quiz .capi-mascot img,
#battle-screen-quiz .capi-frame,
#battle-screen-quiz .capi-mascot,
#exam-result-printable-card .capi-mascot img,
#exam-result-printable-card .capi-frame,
#exam-result-printable-card .capi-mascot {
  animation: none !important;
  transform: none !important;
}

.capi-exam-hidden { display: none !important; }

body.exam-window-blurred .capi-mascot img,
body.exam-screenshot-active .capi-mascot img {
  animation: none !important;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .capi-mascot,
  .capi-mascot img,
  .capi-mascot--animated img {
    animation: none !important;
    transform: none !important;
  }
}

/* ---------- Light theme ---------- */

html.light .capi-hero {
  background:
    radial-gradient(90% 140% at 100% 0%, rgba(183, 181, 255, 0.5) 0%, rgba(183, 181, 255, 0) 60%),
    linear-gradient(140deg, rgba(91, 92, 230, 0.12) 0%, rgba(243, 244, 255, 0.9) 100%);
  border-color: rgba(91, 92, 230, 0.22);
}

html.light .capi-frame {
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(183, 181, 255, 0.45) 0%, rgba(183, 181, 255, 0) 55%),
    rgba(91, 92, 230, 0.07);
}

html.light .capi-mascot img {
  filter: drop-shadow(0 8px 16px rgba(34, 32, 90, 0.14));
}

/* ---------- Dashboard companion ---------- */

.capi-companion {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-width: 0;
}

.capi-companion__art { flex: 0 0 auto; }
.capi-companion__body { min-width: 0; }

.capi-nudge {
  font-size: 0.75rem;
  line-height: 1.5;
  color: #cbd5e1;
}

html.light .capi-nudge { color: #475569; }

/* ---------- Empty / loading states ---------- */

.capi-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem;
}

.capi-state__title {
  font-size: 0.875rem;
  font-weight: 800;
  color: #e2e8f0;
}

.capi-state__desc {
  font-size: 0.75rem;
  line-height: 1.55;
  color: #94a3b8;
  max-width: 34ch;
}

html.light .capi-state__title { color: #1e293b; }
html.light .capi-state__desc  { color: #64748b; }

/* ---------- Skeleton / empty / inline-error primitives ---------- */
/* Shared async-state primitives. Panels assemble their own copy through these
   classes so loading, empty, error and offline states stay visually coherent. */

.capi-skeleton {
  display: block;
  width: var(--skel-w, 100%);
  height: var(--skel-h, 0.875rem);
  border-radius: 0.5rem;
  background: rgba(148, 163, 184, 0.16);
  position: relative;
  overflow: hidden;
  pointer-events: none;
}

.capi-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, 0) 0%,
    rgba(148, 163, 184, 0.22) 50%,
    rgba(148, 163, 184, 0) 100%
  );
  animation: capi-skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes capi-skeleton-shimmer {
  100% { transform: translateX(100%); }
}

.capi-skeleton--circle {
  width: var(--skel-w, 2rem);
  height: var(--skel-h, 2rem);
  border-radius: 9999px;
}

.capi-skeleton--title {
  height: var(--skel-h, 1.125rem);
  width: var(--skel-w, 60%);
  border-radius: 0.375rem;
}

@media (prefers-reduced-motion: reduce) {
  .capi-skeleton::after { animation: none; }
}

.capi-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.375rem;
  padding: 1.25rem 1rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.5);
  box-shadow: inset 0 0 0 1px rgba(51, 65, 85, 0.45);
}

.capi-empty__art {
  color: #818cf8;
  margin-bottom: 0.125rem;
}

.capi-empty__title {
  font-size: 0.8125rem;
  font-weight: 800;
  color: #e2e8f0;
}

.capi-empty__desc {
  font-size: 0.75rem;
  line-height: 1.55;
  color: #94a3b8;
  max-width: 38ch;
}

.capi-empty__cta {
  margin-top: 0.375rem;
}

html.light .capi-empty {
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px #e2e8f0;
}
html.light .capi-empty__title { color: #1e293b; }
html.light .capi-empty__desc  { color: #64748b; }

/* Inline error / offline banner with retry slot. `data-tone="offline"` swaps
   the palette so a lost connection is distinct from a server failure. */
.capi-inline-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
  padding: 0.875rem 1rem;
  border-radius: 1rem;
  background: rgba(244, 63, 94, 0.10);
  box-shadow: inset 0 0 0 1px rgba(244, 63, 94, 0.35);
}

.capi-inline-error__msg {
  font-size: 0.75rem;
  line-height: 1.55;
  color: #fda4af;
  max-width: 44ch;
}

.capi-inline-error__retry {
  margin-top: 0.375rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.6875rem;
  font-weight: 800;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.25);
  transition: background 0.15s ease;
}

.capi-inline-error__retry:hover {
  background: rgba(51, 65, 85, 0.95);
}

.capi-inline-error--offline {
  background: rgba(56, 189, 248, 0.10);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.capi-inline-error--offline .capi-inline-error__msg {
  color: #7dd3fc;
}

html.light .capi-inline-error {
  background: #fff1f2;
  box-shadow: inset 0 0 0 1px #fecdd3;
}
html.light .capi-inline-error__msg { color: #9f1239; }
html.light .capi-inline-error__retry {
  background: #ffffff;
  color: #334155;
  border-color: #cbd5e1;
}
html.light .capi-inline-error--offline {
  background: #f0f9ff;
  box-shadow: inset 0 0 0 1px #bae6fd;
}
html.light .capi-inline-error--offline .capi-inline-error__msg { color: #0369a1; }

/* ---------- Celebration toast avatar ---------- */

.capi-toast-avatar {
  width: 32px;
  height: 32px;
  border-radius: 12px;
  background: var(--capi-frame-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.capi-toast-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Global toast notifications render a compact 20px mascot avatar. */
#global-toast-notification .capi-toast-avatar {
  width: 20px;
  height: 20px;
  border-radius: 7px;
}

/* ---------- Responsive tuning ---------- */

@media (max-width: 639px) {
  .capi-mascot--xl   { --capi-size: 132px; }
  .capi-mascot--hero { --capi-size: clamp(140px, 42vw, 220px); }
  .capi-hero { padding: 1rem; gap: 0.75rem; }
  img.capi-wordmark { height: 18px; max-width: 140px; }
}

/* ==========================================================================
   CAPI DESIGN SYSTEM — COMPONENT LANGUAGE
   Applies the mascot's soft, rounded, high-contrast look to shared surfaces.
   All colours derive from the tokens above; no component invents its own hue.
   ========================================================================== */

:root {
  --capi-radius-sm: 12px;
  --capi-radius-md: 16px;
  --capi-radius-lg: 24px;
  --capi-radius-xl: 32px;

  --capi-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --capi-duration: 220ms;

  --capi-surface-1: rgba(255, 255, 255, 0.04);
  --capi-surface-2: rgba(255, 255, 255, 0.07);
  --capi-hairline: rgba(183, 181, 255, 0.18);
  --capi-hairline-strong: rgba(183, 181, 255, 0.34);
  --capi-glow: 0 0 0 1px rgba(91, 92, 230, 0.28), 0 18px 40px -18px rgba(34, 32, 90, 0.65);
}

html.light {
  --capi-surface-1: #FFFFFF;
  --capi-surface-2: #F3F4FF;
  --capi-hairline: rgba(34, 32, 90, 0.10);
  --capi-hairline-strong: rgba(91, 92, 230, 0.28);
  --capi-glow: 0 0 0 1px rgba(91, 92, 230, 0.14), 0 16px 36px -20px rgba(34, 32, 90, 0.35);
}

/* ---------- Surface primitives ---------- */

.capi-surface {
  background: var(--capi-surface-1);
  border: 1px solid var(--capi-hairline);
  border-radius: var(--capi-radius-lg);
}

.capi-surface--raised {
  box-shadow: var(--capi-shadow-soft);
}

.capi-surface--interactive {
  transition: transform var(--capi-duration) var(--capi-ease),
              border-color var(--capi-duration) var(--capi-ease),
              box-shadow var(--capi-duration) var(--capi-ease);
}

.capi-surface--interactive:hover {
  transform: translateY(-2px);
  border-color: var(--capi-hairline-strong);
  box-shadow: var(--capi-glow);
}

.capi-hairline {
  border-color: var(--capi-hairline);
}

/* ---------- Typographic accents ---------- */

.capi-eyebrow {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--capi-primary-soft);
}

html.light .capi-eyebrow {
  color: var(--capi-primary);
}

.capi-display {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--capi-white);
}

html.light .capi-display {
  color: var(--capi-ink);
}

.capi-mark-underline {
  position: relative;
  display: inline-block;
}

.capi-mark-underline::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.08em;
  height: 0.32em;
  background: var(--capi-gold);
  opacity: 0.42;
  border-radius: 999px;
  z-index: -1;
}

/* ---------- Buttons ---------- */

.capi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--control-min-size, 44px);
  padding: 0.625rem 1.125rem;
  border-radius: var(--capi-radius-md);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color var(--capi-duration) var(--capi-ease),
              border-color var(--capi-duration) var(--capi-ease),
              transform var(--capi-duration) var(--capi-ease),
              box-shadow var(--capi-duration) var(--capi-ease);
}

.capi-btn:active {
  transform: translateY(1px);
}

/* Compact icon-only button (close, refresh, row actions). Keeps the shared
   surface/colour primitives without the large default padding. Declared with
   raised specificity so it wins over `.capi-btn`. */
.capi-btn.capi-btn--icon {
  padding: 0.5rem;
  min-height: 0;
}

.capi-btn--primary {
  background: linear-gradient(135deg, var(--capi-primary) 0%, var(--capi-primary-bright) 100%);
  color: var(--capi-white);
  box-shadow: 0 10px 24px -14px rgba(91, 92, 230, 0.9);
}

.capi-btn--primary:hover {
  box-shadow: 0 14px 30px -12px rgba(91, 92, 230, 0.95);
  transform: translateY(-1px);
}

.capi-btn--secondary {
  background: var(--capi-surface-2);
  border-color: var(--capi-hairline);
  color: var(--capi-white);
}

html.light .capi-btn--secondary {
  color: var(--capi-ink);
}

.capi-btn--secondary:hover {
  border-color: var(--capi-hairline-strong);
}

.capi-btn--gold {
  background: var(--capi-gold);
  color: var(--capi-ink-outline);
}

.capi-btn--ghost {
  background: transparent;
  border-color: var(--capi-hairline);
  color: inherit;
}

.capi-btn:focus-visible,
.capi-chip:focus-visible {
  outline: 2px solid var(--capi-primary-soft);
  outline-offset: 2px;
}

/* primary-soft (#B7B5FF) is only 1.9:1 on white/light surfaces, so light mode
   switches to the primary token (5.1:1 on white) to keep the ring visible. */
html.light .capi-btn:focus-visible,
html.light .capi-chip:focus-visible {
  outline-color: var(--capi-primary);
}

/* Visually-hidden checkbox peers (custom toggles) cannot show the global
   focus ring on their 1px input, so mirror it onto the visible track. */
.sr-only.peer:focus-visible + div,
.sr-only.peer:focus-visible + span {
  outline: 2px solid var(--capi-primary-soft);
  outline-offset: 2px;
}

html.light .sr-only.peer:focus-visible + div,
html.light .sr-only.peer:focus-visible + span {
  outline-color: var(--capi-primary);
}

/* ---------- Chips / badges ---------- */

.capi-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--capi-hairline);
  background: var(--capi-surface-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* Status badges (roadmap stages, quests, level pills). Aliased to the same
   visual language as .capi-chip so components that emit `capi-badge` share
   one implementation; tone variants mirror the chip ramp. */
.capi-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--capi-hairline);
  background: var(--capi-surface-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.capi-badge--success {
  background: rgba(23, 178, 150, 0.16);
  border-color: rgba(167, 243, 225, 0.4);
  color: var(--capi-mint);
}

.capi-badge--info {
  background: rgba(91, 92, 230, 0.18);
  border-color: rgba(129, 140, 248, 0.45);
  color: var(--capi-primary-soft);
}

.capi-badge--warn {
  background: rgba(255, 209, 102, 0.16);
  border-color: rgba(255, 209, 102, 0.36);
  color: var(--capi-gold);
}

.capi-badge--neutral {
  background: var(--capi-surface-2);
  border-color: var(--capi-hairline);
  color: var(--capi-primary-soft);
}

html.light .capi-badge--success {
  background: #F0FDFA;
  border-color: rgba(11, 122, 102, 0.4);
  color: #0B7A66;
}

html.light .capi-badge--info {
  background: var(--capi-primary-50, #F1F0FF);
  border-color: rgba(91, 92, 230, 0.4);
  color: var(--capi-primary-700, #2627D7);
}

html.light .capi-badge--warn {
  background: #FFFBF0;
  border-color: rgba(174, 124, 19, 0.4);
  /* #AE7C13 was 3.57:1 on the cream chip; #7A530B is 6.62:1. */
  color: #7A530B;
}

html.light .capi-badge--neutral {
  background: #F3F4FF;
  border-color: rgba(34, 32, 90, 0.14);
  color: #4648E3;
}

.capi-chip--primary {
  background: rgba(91, 92, 230, 0.16);
  border-color: rgba(91, 92, 230, 0.32);
  color: var(--capi-primary-soft);
}

html.light .capi-chip--primary {
  background: var(--capi-primary-50, #F1F0FF);
  color: var(--capi-primary-700, #2627D7);
}

.capi-chip--gold {
  background: rgba(255, 209, 102, 0.16);
  border-color: rgba(255, 209, 102, 0.36);
  color: var(--capi-gold);
}

html.light .capi-chip--gold {
  background: #FFFBF0;
  /* #AE7C13 was 3.57:1 on the cream chip; #7A530B is 6.62:1. */
  color: #7A530B;
}

.capi-chip--mint {
  background: rgba(167, 243, 225, 0.14);
  border-color: rgba(167, 243, 225, 0.32);
  color: var(--capi-mint);
}

html.light .capi-chip--mint {
  background: #F0FDFA;
  /* #0F9179 was 3.77:1 on the mint chip; #0B7A66 is 5.05:1. */
  color: #0B7A66;
}

.capi-chip--red {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.34);
  color: #FCA5A5;
}

html.light .capi-chip--red {
  background: #FEF2F2;
  color: #B91C1C;
}

/* ---------- Progress ---------- */

.capi-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--capi-surface-2);
  overflow: hidden;
}

.capi-progress__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--capi-primary) 0%, var(--capi-primary-bright) 55%, var(--capi-gold) 100%);
  transition: width 420ms var(--capi-ease);
}

/* Auth inputs use the brand primary for their focus ring. Declared here
   because `primary` is not part of the compiled Tailwind palette. */
.focus\:ring-primary\/50:focus {
  --tw-ring-color: rgba(91, 92, 230, 0.5);
  --tw-ring-opacity: 0.5;
}

/* Literal mint-400 token alias (the palette is exposed as `emerald`). */
.text-mint-400 {
  color: rgb(var(--org-mint-400-rgb, 63, 208, 178));
}

html.light .text-mint-400 {
  color: #0F9179;
}

/* 375px safety: the auth dialog never scrolls horizontally. */
#modal-auth {
  overflow-x: hidden;
}

#modal-auth > div {
  max-width: min(28rem, 100%);
  min-width: 0;
}

#modal-auth form,
#modal-auth .auth-tab-btn {
  min-width: 0;
}

/* ---------- Decorative brand motif ---------- */

.capi-spark-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--capi-primary-soft);
}

.capi-spark-divider::before,
.capi-spark-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--capi-hairline-strong), transparent);
}

.capi-brand-mark {
  display: block;
  max-width: 100%;
  height: auto;
}

.capi-favicon-mark {
  border-radius: 10px;
  flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
  .capi-surface--interactive,
  .capi-btn,
  .capi-progress__fill {
    transition: none !important;
  }
  .capi-surface--interactive:hover,
  .capi-btn--primary:hover {
    transform: none;
  }
}

/* ==========================================================================
   CAPI QUIET LAYER — calmer scale, fewer competing treatments
   One spacing scale, one radius scale, three soft elevations, five type
   roles. Views should compose these primitives instead of stacking Tailwind
   ring/shadow utilities. `.capi-card` owns its border AND its shadow.
   ========================================================================== */

:root {
  /* Spacing — 4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 */
  --capi-space-1: 4px;
  --capi-space-2: 8px;
  --capi-space-3: 12px;
  --capi-space-4: 16px;
  --capi-space-5: 24px;
  --capi-space-6: 32px;
  --capi-space-7: 48px;
  --capi-space-8: 64px;

  /* Radius */
  --capi-radius-card: 20px;
  --capi-radius-tile: 16px;
  --capi-radius-pill: 999px;
  --capi-radius-field: 12px;

  /* Elevation — three soft indigo levels, never heavy black */
  --capi-elev-1: 0 1px 2px rgba(34, 32, 90, 0.05), 0 6px 16px -10px rgba(34, 32, 90, 0.22);
  --capi-elev-2: 0 1px 3px rgba(34, 32, 90, 0.06), 0 14px 30px -18px rgba(34, 32, 90, 0.30);
  --capi-elev-3: 0 2px 6px rgba(34, 32, 90, 0.07), 0 24px 52px -24px rgba(34, 32, 90, 0.36);

  /* Typography roles: size / weight / tracking */
  --capi-fs-eyebrow: 11px;
  --capi-fw-eyebrow: 700;
  --capi-tracking-eyebrow: 0.12em;

  --capi-fs-title: 18px;
  --capi-fw-title: 800;

  --capi-fs-h1: 24px;
  --capi-fw-h1: 800;

  --capi-fs-body: 13.5px;
  --capi-fw-body: 400;

  --capi-fs-meta: 11.5px;
  --capi-fw-meta: 500;
}

html.light {
  --capi-elev-1: 0 1px 2px rgba(34, 32, 90, 0.04), 0 6px 16px -12px rgba(34, 32, 90, 0.16);
  --capi-elev-2: 0 1px 3px rgba(34, 32, 90, 0.05), 0 14px 30px -18px rgba(34, 32, 90, 0.20);
  --capi-elev-3: 0 2px 6px rgba(34, 32, 90, 0.05), 0 24px 52px -26px rgba(34, 32, 90, 0.24);
}

/* ---------- Card primitives ---------- */

.capi-card {
  position: relative;
  background: var(--capi-surface-1);
  border: 1px solid var(--capi-hairline);
  border-radius: var(--capi-radius-card);
  box-shadow: var(--capi-elev-1);
  transition: background-color var(--capi-duration) var(--capi-ease),
              border-color var(--capi-duration) var(--capi-ease),
              box-shadow var(--capi-duration) var(--capi-ease);
}

.capi-card--flat {
  box-shadow: none;
}

.capi-card--focus {
  border-color: var(--capi-hairline-strong);
  box-shadow: var(--capi-elev-2);
}

/* Noise guard: a `.capi-card` already owns its hairline and elevation.
   When a view also adds Tailwind `ring-1`/`shadow-xl`, drop the duplicate so
   the card never double-outlines or stacks two shadows. Views should pick
   ONE: `.capi-card` OR the utilities, not both. */
.capi-card.ring-1,
.capi-card.ring-2,
.capi-card.shadow-sm,
.capi-card.shadow,
.capi-card.shadow-md,
.capi-card.shadow-lg,
.capi-card.shadow-xl,
.capi-card.shadow-2xl {
  box-shadow: var(--capi-elev-1) !important;
}

.capi-card--flat.ring-1,
.capi-card--flat.ring-2,
.capi-card--flat.shadow-sm,
.capi-card--flat.shadow,
.capi-card--flat.shadow-md,
.capi-card--flat.shadow-lg,
.capi-card--flat.shadow-xl,
.capi-card--flat.shadow-2xl {
  box-shadow: none !important;
}

.capi-card--focus.ring-1,
.capi-card--focus.ring-2,
.capi-card--focus.shadow-sm,
.capi-card--focus.shadow,
.capi-card--focus.shadow-md,
.capi-card--focus.shadow-lg,
.capi-card--focus.shadow-xl,
.capi-card--focus.shadow-2xl {
  box-shadow: var(--capi-elev-2) !important;
}

/* ---------- Vertical rhythm ---------- */

.capi-section {
  display: flex;
  flex-direction: column;
  gap: var(--capi-space-5);
  min-width: 0;
}

.capi-section > :first-child { margin-top: 0; }
.capi-section > :last-child { margin-bottom: 0; }

.capi-stack-sm {
  display: flex;
  flex-direction: column;
  gap: var(--capi-space-2);
  min-width: 0;
}

.capi-stack-md {
  display: flex;
  flex-direction: column;
  gap: var(--capi-space-4);
  min-width: 0;
}

/* ---------- Quiet mode for dense lists ---------- */

/* Only a bottom hairline: no per-row card, no ring, no shadow. Use for dense
   tables, feeds and rosters where boxed rows read as visual noise. */
.capi-list-row {
  display: flex;
  align-items: center;
  gap: var(--capi-space-3);
  padding: var(--capi-space-3) var(--capi-space-1);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--capi-hairline);
  border-radius: 0;
  box-shadow: none;
  transition: background-color var(--capi-duration) var(--capi-ease);
}

.capi-list-row:hover {
  background: var(--capi-surface-2);
}

.capi-list-row:last-child {
  border-bottom-color: transparent;
}

/* ---------- Section head ---------- */

/* One eyebrow + one title on the left, an optional tertiary action on the
   right. Keeps every "Tiến Độ / Tín hiệu / Lộ trình" card on the same rhythm
   and lets long CJK/Arabic titles truncate instead of nudging the action. */
.capi-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--capi-space-3);
  min-width: 0;
}

.capi-section-head__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.capi-section-head__eyebrow {
  font-size: var(--type-eyebrow-size, 11px);
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--capi-primary-soft);
}

.capi-section-head__title {
  margin: 0;
  font-size: var(--type-h2-size, 18px);
  line-height: 1.3;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--capi-white);
}

.capi-section-head__action {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

html.light .capi-section-head__eyebrow {
  color: var(--capi-primary);
}

html.light .capi-section-head__title {
  color: var(--capi-ink);
}

/* ---------- Stat ---------- */

/* Compact metric cell: quiet uppercase label, one strong figure, one meta
   line. Views compose the grid; the cell only owns the vertical rhythm. */
.capi-stat {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2px;
  min-width: 0;
}

.capi-stat__label {
  font-size: 10px;
  line-height: 1.4;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--capi-primary-soft);
}

.capi-stat__value {
  font-size: 1rem;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--capi-white);
}

.capi-stat--sm .capi-stat__value {
  font-size: 0.95rem;
}

.capi-stat__delta {
  font-size: 11px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--capi-text-muted);
}

html.light .capi-stat__label {
  color: var(--capi-primary);
}

html.light .capi-stat__value {
  color: var(--capi-ink);
}

html.light .capi-stat__delta {
  color: #524C68;
}

/* ---------- Focus-visible ---------- */

.capi-card:focus-visible,
.capi-section:focus-visible,
.capi-list-row:focus-visible {
  outline: 2px solid var(--capi-primary-soft);
  outline-offset: 2px;
}

html.light .capi-card:focus-visible,
html.light .capi-section:focus-visible,
html.light .capi-list-row:focus-visible {
  outline-color: var(--capi-primary);
}

/* ---------- Light theme counterparts ---------- */

html.light .capi-card {
  background: var(--capi-surface-1);
  border-color: var(--capi-hairline);
  box-shadow: var(--capi-elev-1);
}

html.light .capi-card--flat {
  box-shadow: none;
}

html.light .capi-card--focus {
  border-color: var(--capi-hairline-strong);
  box-shadow: var(--capi-elev-2);
}

html.light .capi-section {
  background: transparent;
}

html.light .capi-stack-sm,
html.light .capi-stack-md {
  background: transparent;
}

html.light .capi-list-row {
  background: transparent;
  border-bottom-color: var(--capi-hairline);
  box-shadow: none;
}

html.light .capi-list-row:hover {
  background: var(--capi-surface-2);
}

html.light .capi-list-row:last-child {
  border-bottom-color: transparent;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .capi-card,
  .capi-card--flat,
  .capi-card--focus,
  .capi-section,
  .capi-stack-sm,
  .capi-stack-md,
  .capi-list-row {
    transition: none !important;
  }
}

/* ---------- RTL (Arabic) ---------- */

html[dir="rtl"] #global-navbar,
html[dir="rtl"] #view-landing,
html[dir="rtl"] .capi-surface,
html[dir="rtl"] .capi-btn {
  text-align: right;
}

html[dir="rtl"] #desktop-main-nav,
html[dir="rtl"] #nav-drills-group,
html[dir="rtl"] #nav-knowledge-group,
html[dir="rtl"] #nav-progress-group,
html[dir="rtl"] #nav-role-dropdown,
html[dir="rtl"] #lang-picker-menu .lang-picker-row {
  flex-direction: row-reverse;
}

html[dir="rtl"] #lang-picker-menu .lang-picker-row {
  text-align: right;
}

html[dir="rtl"] .mr-1 { margin-right: 0; margin-left: 0.25rem; }
html[dir="rtl"] .mr-1\.5 { margin-right: 0; margin-left: 0.375rem; }
html[dir="rtl"] .mr-2 { margin-right: 0; margin-left: 0.5rem; }
html[dir="rtl"] .ml-1 { margin-left: 0; margin-right: 0.25rem; }
html[dir="rtl"] .ml-1\.5 { margin-left: 0; margin-right: 0.375rem; }
html[dir="rtl"] .ml-2 { margin-left: 0; margin-right: 0.5rem; }

/* ---------- Language picker polish (8-language UX) ---------- */

#lang-picker-menu .lang-picker-row {
  min-height: 40px;
  scroll-margin: 6px;
}

#lang-picker-menu .lang-picker-row:active {
  transform: scale(0.99);
}

#lang-picker-menu .lang-picker-check {
  transition: opacity .15s ease, transform .15s ease;
}

#lang-picker-menu .lang-picker-row[aria-checked="true"] .lang-picker-check {
  animation: lang-check-pop .18s ease-out;
}

@keyframes lang-check-pop {
  from { opacity: 0; transform: scale(.6); }
  to   { opacity: 1; transform: scale(1); }
}

/* Mobile drawer language chips */
.mnav-lang-chip .mnav-lang-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 24px;
  height: 20px;
  padding: 0 4px;
  border-radius: 5px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #a5b4fc;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .04em;
}

.mnav-lang-chip .mnav-lang-check {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #4f46e5;
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.mnav-lang-chip.mnav-lang-active {
  background: rgba(99, 102, 241, .18) !important;
  border-color: rgba(99, 102, 241, .55) !important;
  color: #e0e7ff !important;
}

.mnav-lang-chip.mnav-lang-active .mnav-lang-flag {
  background: #4f46e5;
  border-color: #6366f1;
  color: #fff;
}

.mnav-lang-chip.mnav-lang-active .mnav-lang-check {
  display: inline-flex;
}

.mnav-lang-chip:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 1px;
}

/* RTL: keep picker and mobile chips readable when Arabic is selected */
html[dir="rtl"] #lang-picker-menu .lang-picker-header {
  text-align: right;
  letter-spacing: 0;
}

html[dir="rtl"] #lang-picker-menu .lang-picker-flag,
html[dir="rtl"] #lang-picker-menu .lang-picker-check,
html[dir="rtl"] .mnav-lang-chip .mnav-lang-flag,
html[dir="rtl"] .mnav-lang-chip .mnav-lang-check {
  direction: ltr;
}

html[dir="rtl"] #lang-picker-menu .lang-picker-row .lang-picker-label,
html[dir="rtl"] .mnav-lang-chip > span:nth-child(2) {
  text-align: right;
}

/* ==========================================================================
   CAPI TEXT CONTRAST
   Secondary slate copy authored for the dark ink canvas drops below WCAG AA
   (slate-500 ≈ 3.1:1, slate-600 ≈ 2.1:1, slate-700 ≈ 1.6:1). Remap it to the
   ink-on-dark neutral ramp, scoped to the content views so decorative slate
   usages elsewhere keep their authored palette.
   ========================================================================== */
html:not(.light) #view-landing .text-slate-500,
html:not(.light) #view-admin .text-slate-500,
html:not(.light) #view-analytics .text-slate-500,
html:not(.light) #view-profile .text-slate-500,
html:not(.light) #view-error_log .text-slate-500 {
  color: #A9A3BF !important;
}

html:not(.light) #view-landing .text-slate-600,
html:not(.light) #view-admin .text-slate-600,
html:not(.light) #view-analytics .text-slate-600,
html:not(.light) #view-profile .text-slate-600,
html:not(.light) #view-error_log .text-slate-600 {
  color: #B9B5CE !important;
}

html:not(.light) #view-landing .text-slate-700,
html:not(.light) #view-admin .text-slate-700,
html:not(.light) #view-analytics .text-slate-700,
html:not(.light) #view-profile .text-slate-700,
html:not(.light) #view-error_log .text-slate-700 {
  color: #C9C5DC !important;
}

/* ==========================================================================
   CAPI STRICT TYPOGRAPHY SCALE
   --------------------------------------------------------------------------
   Seven sanctioned roles. Views must compose headings and body copy from
   these classes instead of adding ad-hoc text-* / font-* sizes.

     Role          Size / Line-height / Weight / Tracking
     .type-h1      24px / 32px / 800 / -0.02em
     .type-h2      18px / 26px / 800
     .type-h3      15px / 22px / 700
     .type-body    13.5px / 21px / 400
     .type-meta    11.5px / 16px / 500
     .type-eyebrow 11px / 16px / 700 / 0.12em, uppercase
     .type-number  inherits size / 700, tabular numerals

   Every role resolves to one of these sizes; no new font sizes are sanctioned
   inside view markup. Line-heights are all >= 1.3 so stacked Vietnamese
   diacritics (ắ, ộ, ữ, ễ) render without clipping when combined with
   `leading-tight`/`truncate` leftovers.
   ========================================================================== */

:root {
  --type-h1-size: 24px;
  --type-h1-line: 32px;
  --type-h2-size: 18px;
  --type-h2-line: 26px;
  --type-h3-size: 15px;
  --type-h3-line: 22px;
  --type-body-size: 13.5px;
  --type-body-line: 21px;
  --type-meta-size: 11.5px;
  --type-meta-line: 16px;
  --type-eyebrow-size: 11px;
  --type-eyebrow-line: 16px;
}

.type-h1,
.type-h2,
.type-h3 {
  text-wrap: balance;
}

.type-h1 {
  font-size: var(--type-h1-size);
  line-height: var(--type-h1-line);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.type-h2 {
  font-size: var(--type-h2-size);
  line-height: var(--type-h2-line);
  font-weight: 800;
}

.type-h3 {
  font-size: var(--type-h3-size);
  line-height: var(--type-h3-line);
  font-weight: 700;
}

.type-body {
  font-size: var(--type-body-size);
  line-height: var(--type-body-line);
  font-weight: 400;
}

.type-meta {
  font-size: var(--type-meta-size);
  line-height: var(--type-meta-line);
  font-weight: 500;
}

.type-eyebrow {
  font-size: var(--type-eyebrow-size);
  line-height: var(--type-eyebrow-line);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.type-number {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-weight: 700;
}

/* Light-mode defaults apply only when the view has not chosen an explicit
   text colour. `:not([class*="text-"])` keeps `.text-slate-*`, `.text-white`
   and gradient text utilities authoritative. */
html.light .type-h1:not([class*="text-"]),
html.light .type-h2:not([class*="text-"]),
html.light .type-h3:not([class*="text-"]) {
  color: var(--capi-ink);
}

html.light .type-body:not([class*="text-"]) {
  color: #3D3752;
}

html.light .type-meta:not([class*="text-"]) {
  color: #524C68;
}

html.light .type-eyebrow:not([class*="text-"]) {
  color: var(--capi-primary);
}

/* ---------- Per-language font fallbacks ----------
   Inter + Be Vietnam Pro cover Latin and Vietnamese. The premium Latin stack
   ("Plus Jakarta Sans", "Be Vietnam Pro", "Inter") leads every list so digits,
   punctuation, English words and Vietnamese diacritics keep the web font, and
   the matching Noto Sans script family is only reached for CJK/Arabic glyphs
   (so text never falls back to an arbitrary system face, or tofu). They also
   cover body/form controls because base.css sets font-family on those
   elements explicitly. KaTeX is deliberately excluded: its own `font`
   shorthand and internal KaTeX_* families stay authoritative. */
html[lang="zh"],
html[lang="zh"] body,
html[lang="zh"] button,
html[lang="zh"] input,
html[lang="zh"] select,
html[lang="zh"] textarea {
  font-family: "Plus Jakarta Sans", "Be Vietnam Pro", "Inter", "Noto Sans SC", system-ui, sans-serif;
}

html[lang="ja"],
html[lang="ja"] body,
html[lang="ja"] button,
html[lang="ja"] input,
html[lang="ja"] select,
html[lang="ja"] textarea {
  font-family: "Plus Jakarta Sans", "Be Vietnam Pro", "Inter", "Noto Sans JP", system-ui, sans-serif;
}

html[lang="ko"],
html[lang="ko"] body,
html[lang="ko"] button,
html[lang="ko"] input,
html[lang="ko"] select,
html[lang="ko"] textarea {
  font-family: "Plus Jakarta Sans", "Be Vietnam Pro", "Inter", "Noto Sans KR", system-ui, sans-serif;
}

html[lang="ar"],
html[lang="ar"] body,
html[lang="ar"] button,
html[lang="ar"] input,
html[lang="ar"] select,
html[lang="ar"] textarea {
  font-family: "Plus Jakarta Sans", "Be Vietnam Pro", "Inter", "Noto Sans Arabic", system-ui, sans-serif;
}

/* Arabic is a connected script: letter-spacing on tracked uppercase labels
   visibly breaks the joins between glyphs. Keep the natural Arabic shape for
   every eyebrow / stat / stage label role. */
html[lang="ar"] :is(
  .capi-section-head__eyebrow,
  .capi-eyebrow,
  .capi-stat__label,
  .type-eyebrow,
  .ai-roadmap-stage-label,
  .ai-roadmap-live-chip,
  .landing-explore-tile__arrow
) {
  letter-spacing: 0 !important;
  text-transform: none !important;
}

/* ==========================================================================
   MULTILINGUAL USER / ORG NAMES
   Long CJK strings (no spaces) and RTL Arabic names must never stretch the
   navbar, avatar chip, or mobile drawer. Truncate with an ellipsis and keep
   the full value available via the `title` attribute set in JS.
   ========================================================================== */
#site-org-name,
#user-display-name,
#mnav-user-name,
.user-display-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
}

html[dir="rtl"] #site-org-name,
html[dir="rtl"] #user-display-name,
html[dir="rtl"] #mnav-user-name,
html[dir="rtl"] .user-display-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

/* Avatar badges must stay square when a wide/combining grapheme is used. */
#user-avatar-badge,
#mnav-avatar-badge,
#prof-avatar,
#dash-avatar-letter {
  overflow: hidden;
  line-height: 1;
}


/* ==========================================================================
   WCAG 2.1 AA ACCESSIBILITY LAYER (contrast, focus, motion, high contrast)
   Appended in isolation so existing theme rules stay untouched.
   ========================================================================== */

/* ---------- 1. Contrast: muted copy that failed 4.5:1 on dark surfaces ----------
   Dark theme muted ramps:
     slate-500 (#6A6482) measured 3.10:1 on #1B1730 and 2.64:1 on #2A2440.
     slate-600 (#524C68) measured 2.14:1 on #1B1730.
   Raised to #9A95B2 (6.04:1 on #1B1730, 5.13:1 on #2A2440, 6.67:1 on #100D1C)
   and #8F8AA8 (5.26:1 / 4.47:1 / 5.81:1) respectively. Light mode already
   remaps these ramps in base.css, so the overrides stay scoped to dark. */
html:not(.light) .text-slate-500,
html:not(.light) [class~="text-slate-500"] {
  color: #9A95B2 !important;
}
html:not(.light) .text-slate-600,
html:not(.light) [class~="text-slate-600"] {
  color: #9A95B2 !important;
}
html:not(.light) .placeholder-slate-500::placeholder {
  color: #9A95B2 !important;
  opacity: 1 !important;
}

/* Muted icons are non-text UI (3:1). Keep them at #8F8AA8 on raised surfaces
   and lighten them if a rule lowered them to slate-600. */
html:not(.light) [data-lucide].text-slate-600,
html:not(.light) i.text-slate-600 {
  color: #8F8AA8 !important;
}

/* Disabled controls: WCAG exempts them, but keep the label readable. */
button:disabled,
[aria-disabled="true"] {
  opacity: 0.7;
}

/* ---------- 2. Focus visibility: 3:1 minimum against every surface ----------
   fixes.css already paints a 2px ring. These rules add a contrasting outer
   halo so the ring stays visible on same-colour cards and image backgrounds,
   and they explicitly re-enable a ring on controls that used outline:none. */
:where(a, button, input, select, textarea, summary,
  [role="button"], [role="tab"], [role="radio"], [role="option"],
  [role="menuitem"], [role="menuitemradio"], [role="switch"],
  [role="checkbox"], [role="combobox"], [role="slider"], [role="link"],
  [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 3px solid #B7B5FF !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 5px rgba(16, 13, 28, 0.85) !important;
}
html.light :where(a, button, input, select, textarea, summary,
  [role="button"], [role="tab"], [role="radio"], [role="option"],
  [role="menuitem"], [role="menuitemradio"], [role="switch"],
  [role="checkbox"], [role="combobox"], [role="slider"], [role="link"],
  [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 3px solid #3D24DA !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.95) !important;
}
/* Exam surfaces keep their own focus treatment but must never lose the ring. */
#view-question-solver :where([role="radio"], .option-item, button, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus-visible,
#options-container .option-item:focus-visible,
#grid-in-container :where(button, input):focus-visible {
  outline: 3px solid #B7B5FF !important;
  outline-offset: 2px !important;
}
html.light #view-question-solver :where([role="radio"], .option-item, button, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus-visible,
html.light #options-container .option-item:focus-visible,
html.light #grid-in-container :where(button, input):focus-visible {
  outline: 3px solid #3D24DA !important;
  outline-offset: 2px !important;
}

/* Skip links must outrank the global ring halo. */
.skip-to-content:focus-visible {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55) !important;
}

/* ---------- 3. prefers-contrast: more ----------
   Users who ask the OS for more contrast get near-solid ink, stronger borders
   and fully opaque surfaces. Scoped to text and borders, never to layout. */
@media (prefers-contrast: more) {
  html:not(.light) body,
  html:not(.light) #main-content {
    background-color: #05040A !important;
  }
  html:not(.light) {
    --capi-text: #FFFFFF;
    --capi-text-muted: #E5E2F0;
    --capi-border: #9A95B2;
  }
  html:not(.light) :where(.text-slate-300, .text-slate-400, .text-slate-500, .text-slate-600,
    [class~="text-slate-300"], [class~="text-slate-400"], [class~="text-slate-500"], [class~="text-slate-600"]) {
    color: #E5E2F0 !important;
  }
  html:not(.light) :where(.text-slate-200, .text-slate-100, .text-slate-50, .text-white) {
    color: #FFFFFF !important;
  }
  html:not(.light) :where(.border-slate-700, .border-slate-800, .border-slate-900,
    [class~="border-slate-700"], [class~="border-slate-800"], [class~="border-slate-900"]) {
    border-color: #9A95B2 !important;
  }
  html:not(.light) :where(.bg-slate-900, .bg-slate-800, .bg-slate-950) {
    background-color: #0B0A12 !important;
  }
  html.light body,
  html.light #main-content {
    background-color: #FFFFFF !important;
  }
  html.light :where(.text-slate-300, .text-slate-400, .text-slate-500, .text-slate-600,
    [class~="text-slate-300"], [class~="text-slate-400"], [class~="text-slate-500"], [class~="text-slate-600"]) {
    color: #2A2440 !important;
  }
  html.light :where(.border-slate-700, .border-slate-800, .border-slate-900) {
    border-color: #3D3752 !important;
  }
  :where(a, button, input, select, textarea, summary,
    [role="button"], [role="tab"], [role="radio"], [role="option"],
    [tabindex]:not([tabindex="-1"])):focus-visible {
    outline-width: 4px !important;
  }
}

/* ---------- 4. Explicit "High contrast" toggle (html.high-contrast) ----------
   Mirrors prefers-contrast: more and is persisted in localStorage by
   initHighContrast() in theme.js. */
html.high-contrast:not(.light) body,
html.high-contrast:not(.light) #main-content {
  background-color: #05040A !important;
  background-image: none !important;
  color: #FFFFFF !important;
}
html.high-contrast:not(.light) :where(.text-slate-300, .text-slate-400, .text-slate-500, .text-slate-600,
  [class~="text-slate-300"], [class~="text-slate-400"], [class~="text-slate-500"], [class~="text-slate-600"]) {
  color: #E5E2F0 !important;
}
html.high-contrast:not(.light) :where(.text-slate-200, .text-slate-100, .text-slate-50, .text-white) {
  color: #FFFFFF !important;
}
html.high-contrast:not(.light) :where(.border-slate-700, .border-slate-800, .border-slate-900,
  [class~="border-slate-700"], [class~="border-slate-800"], [class~="border-slate-900"]) {
  border-color: #9A95B2 !important;
}
html.high-contrast:not(.light) :where(.bg-slate-900, .bg-slate-800, .bg-slate-950,
  [class~="bg-slate-900"], [class~="bg-slate-800"], [class~="bg-slate-950"]) {
  background-color: #0B0A12 !important;
}
html.high-contrast:not(.light) a,
html.high-contrast:not(.light) .text-blue-300,
html.high-contrast:not(.light) .text-blue-400 {
  color: #C9C6FF !important;
}
html.high-contrast:not(.light) :where(a, button, input, select, textarea, summary,
  [role="button"], [role="tab"], [role="radio"], [role="option"], [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 4px solid #FFD166 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px #05040A !important;
}

html.high-contrast.light body,
html.high-contrast.light #main-content {
  background-color: #FFFFFF !important;
  background-image: none !important;
  color: #100D1C !important;
}
html.high-contrast.light :where(.text-slate-300, .text-slate-400, .text-slate-500, .text-slate-600,
  [class~="text-slate-300"], [class~="text-slate-400"], [class~="text-slate-500"], [class~="text-slate-600"]) {
  color: #2A2440 !important;
}
html.high-contrast.light :where(.bg-slate-900, .bg-slate-950, .bg-slate-800) {
  background-color: #FFFFFF !important;
}
html.high-contrast.light :where(.border-slate-700, .border-slate-800, .border-slate-900) {
  border-color: #3D3752 !important;
}
html.high-contrast.light :where(a, button, input, select, textarea, summary,
  [role="button"], [role="tab"], [role="radio"], [role="option"], [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 4px solid #3D24DA !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px #FFFFFF !important;
}

/* ---------- 5. Live-region helpers used by the solver ---------- */
.a11y-live {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Grid-in error state is reinforced by colour + border + icon in markup. */
#grid-in-input[aria-invalid="true"] {
  border-color: #F43F5E !important;
  box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.28) !important;
}

/* Respect reduced motion for the new focus halo transitions. */
@media (prefers-reduced-motion: reduce) {
  :where(a, button, input, select, textarea):focus-visible {
    transition: none !important;
  }
}

/* ==========================================================================
   CAPI CONTRAST FIX — WCAG AA residual failures (Nov 2026 audit)
   Palette stays Capi: gold-800 #7F5A0F, mint-800 #0A5A4D, primary-700
   #2627D7 on light surfaces. Measured with the WCAG 2.x relative-luminance
   formula against the *effective* (blended) backgrounds.
   ========================================================================== */

/* ---------- 1. Flashcards / SRS grade buttons (light mode) ----------
   The 1-4 grade buttons keep pastel text (red-200 #FECACA, amber-200
   #FFE7AD, emerald-200 #A7F3E1, blue-200 #BFDBFE) on 15%-tint backgrounds.
   In light mode every pair measured 1.0-1.2:1 — invisible on #F6F5FB.
   Remapped to the dark end of the Capi ramps:
     red    #991B1B  -> 6.33:1 on red-500/15,  kbd 4.81:1 on red-500/25
     amber  #523A0B  -> 8.86:1 on amber-500/15, kbd 7.66:1 on amber-500/25
     emerald #0A5A4D -> 6.57:1 on emerald-500/15, kbd 5.43:1 on /25
     blue   #2627D7  -> 6.99:1 on blue-500/15,  kbd 5.48:1 on blue-500/25
   Dark theme is untouched (those pairs measure 7-11:1 already). */
html.light .flashcard-grade-btn.text-red-200,
html.light .srs-grade-btn.text-red-200,
html.light #view-flashcards .bg-red-500\/15.text-red-200 {
  color: #991B1B !important;
}
html.light .flashcard-grade-btn .text-red-100,
html.light .srs-grade-btn .text-red-100,
html.light #view-flashcards .bg-red-500\/15 .text-red-100 {
  color: #991B1B !important;
}
html.light .srs-grade-btn .text-red-300,
html.light #view-flashcards .bg-red-500\/15 .text-red-300 {
  color: #7F1D1D !important;
}
html.light .flashcard-grade-btn.text-amber-200,
html.light .srs-grade-btn.text-amber-200,
html.light #view-flashcards .bg-amber-500\/15.text-amber-200 {
  color: #523A0B !important;
}
html.light .flashcard-grade-btn .text-amber-100,
html.light .srs-grade-btn .text-amber-100,
html.light #view-flashcards .bg-amber-500\/15 .text-amber-100 {
  color: #523A0B !important;
}
html.light .flashcard-grade-btn.text-emerald-200,
html.light .srs-grade-btn.text-emerald-200,
html.light #view-flashcards .bg-emerald-500\/15.text-emerald-200 {
  color: #0A5A4D !important;
}
html.light .flashcard-grade-btn .text-emerald-100,
html.light .srs-grade-btn .text-emerald-100,
html.light #view-flashcards .bg-emerald-500\/15 .text-emerald-100 {
  color: #0A5A4D !important;
}
html.light .flashcard-grade-btn.text-blue-200,
html.light .srs-grade-btn.text-blue-200,
html.light #view-flashcards .bg-blue-500\/15.text-blue-200 {
  color: #2627D7 !important;
}
html.light .flashcard-grade-btn .text-blue-100,
html.light .srs-grade-btn .text-blue-100,
html.light #view-flashcards .bg-blue-500\/15 .text-blue-100 {
  color: #2627D7 !important;
}
/* Grade-button kbd chips and interval labels inherit the 800/900 shades so
   the keyboard hints stay readable inside the darker text colour. */
html.light .flashcard-grade-btn kbd,
html.light .srs-grade-btn kbd {
  color: inherit !important;
}
html.light .srs-interval-label.text-red-300 {
  color: #7F1D1D !important;
}
html.light .srs-interval-label.group-hover\:text-red-200 {
  color: #991B1B !important;
}

/* ---------- 2. Exam result: pace metric + section pills (light mode) ----------
   #res-pace-total renders 24-30px bold gold text as #DB9F1B (2.34:1 on the
   white card; AA large requires 3.0). Use gold-800.
   #res-accuracy-pct used #0F9179 (3.93:1; passes large but sits next to the
   11px tier caption) -> mint-800 for uniform AA on both.
   The amber-950/40 "unanswered" pill used #AE7C13 (3.35:1 on #FFF3D6). */
html.light #view-exam-result #res-pace-total,
html.light #view-exam-result #res-pace-total.text-amber-400 {
  color: #7F5A0F !important;
}
html.light #view-exam-result #res-accuracy-pct,
html.light #view-exam-result #res-accuracy-pct.text-emerald-400 {
  color: #0A5A4D !important;
}
html.light #view-exam-result .bg-amber-950\/40 {
  color: #7F5A0F !important;
}

/* ---------- 3. Exam result filter chips (light mode) ----------
   Incorrect/unanswered/correct/flagged pills render #ECEAF4 buttons with
   20%-tint badges; rose text #dc2626 measured 3.19:1 on the blended badge.
   Switch to #B91C1C (4.98:1 over white, 4.27:1 over the deepest tint used)
   and keep amber/emerald chips on the 800 shades (4.62/5.79:1). */
html.light #view-exam-result .bg-rose-500\/20.text-rose-300,
html.light #view-exam-result .bg-amber-500\/20.text-amber-300,
html.light #view-exam-result .bg-emerald-500\/20.text-emerald-300 {
  color: inherit;
}
html.light #view-exam-result #res-badge-incorrect,
html.light #view-exam-result #res-badge-unanswered,
html.light #view-exam-result #res-badge-correct,
html.light #view-exam-result #res-badge-flagged {
  color: #3D3752 !important;
}

/* ---------- 4. Gold icons & small gold accents (light mode) ----------
   fixes.css paints light-mode amber icons #DB9F1B (2.34:1). Icons are
   non-text UI components (AA 3:1) and several carry 10-12px labels.
   #AE7C13 keeps the gold hue and clears 3:1 (3.69:1 on white, 3.10:1 on the
   #ECEAF4 theme-toggle chip). Profile's 11px `text-amber-400/80` caption
   blends to 3.99:1 -> force full-opacity gold-800. */
html.light i.text-amber-300,
html.light i.text-amber-400,
html.light svg.text-amber-300,
html.light svg.text-amber-400,
html.light [data-lucide].text-amber-300,
html.light [data-lucide].text-amber-400 {
  color: #AE7C13 !important;
}
html.light #view-profile .text-amber-400\/80 {
  color: #7F5A0F !important;
}

/* ---------- 5. High-contrast & prefers-contrast reinforcement ----------
   Inside the OS-level / toggle high-contrast modes the fixed shades above
   must not weaken: push grade buttons to near-ink and thicken their borders
   so state never depends on colour alone. */
@media (prefers-contrast: more) {
  html.light .flashcard-grade-btn,
  html.light .srs-grade-btn {
    border-width: 2px !important;
    font-weight: 800;
  }
  html.light .flashcard-grade-btn.text-red-200,
  html.light .srs-grade-btn.text-red-200,
  html.light .flashcard-grade-btn .text-red-100,
  html.light .srs-grade-btn .text-red-100,
  html.light .srs-grade-btn .text-red-300 {
    color: #7F1D1D !important;
  }
  html.light .flashcard-grade-btn.text-amber-200,
  html.light .srs-grade-btn.text-amber-200,
  html.light .flashcard-grade-btn .text-amber-100,
  html.light .srs-grade-btn .text-amber-100 {
    color: #523A0B !important;
  }
  html.light .flashcard-grade-btn.text-emerald-200,
  html.light .srs-grade-btn.text-emerald-200,
  html.light .flashcard-grade-btn .text-emerald-100,
  html.light .srs-grade-btn .text-emerald-100 {
    color: #08443A !important;
  }
  html.light .flashcard-grade-btn.text-blue-200,
  html.light .srs-grade-btn.text-blue-200,
  html.light .flashcard-grade-btn .text-blue-100,
  html.light .srs-grade-btn .text-blue-100 {
    color: #2627D7 !important;
  }
  html.light #view-exam-result #res-pace-total,
  html.light #view-exam-result #res-accuracy-pct {
    text-decoration: underline;
    text-underline-offset: 4px;
  }
}

/* Mirrors the block above for the explicit in-app high-contrast toggle. */
html.high-contrast.light .flashcard-grade-btn,
html.high-contrast.light .srs-grade-btn {
  border-width: 2px !important;
  font-weight: 800;
}
html.high-contrast.light .flashcard-grade-btn.text-red-200,
html.high-contrast.light .srs-grade-btn.text-red-200,
html.high-contrast.light .flashcard-grade-btn .text-red-100,
html.high-contrast.light .srs-grade-btn .text-red-100,
html.high-contrast.light .srs-grade-btn .text-red-300 {
  color: #7F1D1D !important;
}
html.high-contrast.light .flashcard-grade-btn.text-amber-200,
html.high-contrast.light .srs-grade-btn.text-amber-200,
html.high-contrast.light .flashcard-grade-btn .text-amber-100,
html.high-contrast.light .srs-grade-btn .text-amber-100 {
  color: #523A0B !important;
}
html.high-contrast.light .flashcard-grade-btn.text-emerald-200,
html.high-contrast.light .srs-grade-btn.text-emerald-200,
html.high-contrast.light .flashcard-grade-btn .text-emerald-100,
html.high-contrast.light .srs-grade-btn .text-emerald-100 {
  color: #08443A !important;
}
html.high-contrast.light .flashcard-grade-btn.text-blue-200,
html.high-contrast.light .srs-grade-btn.text-blue-200,
html.high-contrast.light .flashcard-grade-btn .text-blue-100,
html.high-contrast.light .srs-grade-btn .text-blue-100 {
  color: #2627D7 !important;
}
html.high-contrast.light #view-exam-result #res-pace-total,
html.high-contrast.light #view-exam-result #res-accuracy-pct {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Learner navigation and disclosures share the shell's theme and tenant tokens. */
.study-disclosure, .study-link-list > button {
  border-block-start: 1px solid var(--capi-hairline);
}
.study-disclosure > summary, .study-link-list > button {
  display: flex;
  align-items: center;
  gap: .85rem;
  min-height: 48px;
  padding: .65rem .25rem;
  cursor: pointer;
  font-weight: 600;
  text-align: start;
}
.study-disclosure > summary::marker { content: ""; }
.study-disclosure > summary::-webkit-details-marker { display: none; }
.study-disclosure > summary::after {
  content: "";
  width: .5rem;
  height: .5rem;
  margin-inline: auto .5rem;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.study-disclosure[open] > summary::after { transform: rotate(225deg); }
.study-disclosure-body { padding: .5rem 0 1rem; }
.study-disclosure-body > * + * { margin-block-start: .75rem; }
.week-disclosure:has(#dash-7day-stepper:empty) { display: none; }
.study-link-list { display: grid; gap: 0 2rem; }
.study-link-list > button { min-height: 56px; }
.study-link-list > button > :last-child { margin-inline-start: auto; font-size: 1.3rem; }
[dir="rtl"] .study-link-list > button > :last-child { transform: rotate(180deg); }
.study-destinations h2 { margin-block-end: .65rem; }
.study-disclosure summary:focus-visible, .study-link-list button:focus-visible {
  outline: 2px solid var(--org-primary, var(--capi-primary));
  outline-offset: 2px;
}
.study-link-list button:hover, .study-disclosure summary:hover { background: var(--capi-frame-bg); }
@media (min-width: 640px) { .study-link-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
:is(#view-subscription, #view-taxonomy_drills, #view-difficulty_drills, #view-test_suites) .capi-card {
  border-radius: .85rem;
  box-shadow: none;
  background-image: none;
}
:is(#view-subscription, #view-taxonomy_drills, #view-difficulty_drills, #view-test_suites) h1 {
  letter-spacing: -.025em;
  line-height: 1.2;
}
#view-landing #dash-ai-plan-title { white-space: normal; }
#view-landing #dash-7day-stepper > button { min-height: 44px; }
#view-landing #dash-7day-stepper > button > span { display: block; }
#view-landing #dash-7day-stepper > button > span:nth-child(2) { display: grid; place-items: center; }

#ai-study-tools {
  display: flex;
  flex: none;
  gap: .375rem;
}
#ai-tutor-quick-prompts[hidden], #ai-open-hint-ladder[hidden] { display: none !important; }
#ai-study-tools button {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 2.5rem;
  padding: .35rem .75rem;
  border: 1px solid currentColor;
  border-radius: .75rem;
  font: inherit;
  font-weight: 600;
}
#ai-study-tools button[aria-pressed="true"] {
  color: white;
  background: #4338ca;
  border-color: #4338ca;
}
#ai-study-tools button:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
#ai-study-tools button:disabled { opacity: .65; }
