/* FAHAD — application shell: page background, header, sidebar, 3D stage, chat, composer, tutor bar.
   Uses the tokens from base.css only. Layout (docs/ARCHITECTURE.md §5.6):
     ≥ 1100 px            [sidebar 280] [stage] [chat ≤ 820]        (RTL mirrors automatically)
     768–1099 landscape   [stage] [chat], sidebar as off-canvas drawer
     portrait / < 768     stage on top (collapsible to a 72 px strip), chat below, composer pinned to the bottom */

/* Registered so the emotion accent can cross-fade instead of jumping. */
@property --emotion-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #7dd3fc;
}

:root {
  --header-h: 60px;
  --sidebar-w: 280px;
  --gutter: 12px;
  --stage-radius: 28px;
  --chat-max: 820px;
  --emotion-soft: color-mix(in oklab, var(--emotion-color) 18%, transparent);
  --emotion-glow: color-mix(in oklab, var(--emotion-color) 40%, transparent);
  --brand-pink: #f0abfc;
  transition: --emotion-color 700ms var(--ease);
}

/* ================================================================= page background */

html, body { overflow: hidden; }
body {
  overscroll-behavior: none;
  background:
    radial-gradient(1200px 700px at 85% -10%, color-mix(in oklab, var(--accent-2) 16%, transparent), transparent 65%),
    radial-gradient(1000px 700px at -10% 110%, color-mix(in oklab, var(--accent) 12%, transparent), transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 70%);
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
}

/* Static on purpose: glass panels blur what lies beneath them, so a moving layer here would force a re-blur of
   every panel on every frame. */
.aurora { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.aurora span { position: absolute; border-radius: 50%; }
.aurora span:nth-child(1) {
  width: 70vmax; height: 70vmax; top: -38vmax; inset-inline-end: -22vmax;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--accent-2) 26%, transparent), transparent);
}
.aurora span:nth-child(2) {
  width: 64vmax; height: 64vmax; bottom: -40vmax; inset-inline-start: -24vmax;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--accent) 20%, transparent), transparent);
}
.aurora span:nth-child(3) {
  width: 46vmax; height: 46vmax; top: 18%; left: 30%;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--emotion-color) 12%, transparent), transparent);
}

/* ================================================================= boot, noscript, skip link */

.boot-splash {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 360ms var(--ease), visibility 0s 360ms;
}
.boot-splash img { filter: drop-shadow(0 12px 40px rgba(111, 123, 255, 0.45)); animation: splash-pulse 1.6s var(--ease) infinite; }
.boot-splash-name { font-weight: 700; letter-spacing: 0.24em; color: var(--text-2); font-size: 14px; }
.is-booting .boot-splash { opacity: 1; visibility: visible; transition: none; }
.app { transition: opacity 420ms var(--ease); }
.is-booting .app { opacity: 0; }
@keyframes splash-pulse { 50% { transform: scale(1.06); } }

.noscript {
  position: fixed; inset-inline: 16px; top: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 4px; padding: 14px 18px;
  border-radius: var(--radius); background: var(--warn-soft); border: 1px solid var(--warn); color: var(--text);
}

.skip-link {
  position: fixed; top: 8px; inset-inline-start: 8px; z-index: 300;
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-solid); color: var(--text);
  box-shadow: var(--shadow-2); transform: translateY(-160%); transition: transform var(--dur) var(--ease);
}
.skip-link:focus-visible { transform: none; text-decoration: none; }

/* ================================================================= shell grid */

.app {
  position: relative; z-index: 1; top: var(--app-top, 0px);
  display: flex; flex-direction: column; gap: var(--gutter);
  height: 100vh; height: var(--app-height, 100dvh); /* the visual viewport (main.js): stays above the on-screen keyboard */
  padding: calc(var(--gutter) + var(--safe-top)) calc(var(--gutter) + env(safe-area-inset-right, 0px)) 0 calc(var(--gutter) + env(safe-area-inset-left, 0px));
}

.app-body {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: calc(var(--sidebar-w) + var(--gutter)) minmax(0, 1fr);
  padding-bottom: calc(var(--gutter) + var(--safe-bottom));
  transition: grid-template-columns var(--dur-slow) var(--ease);
}
:root[data-sidebar='closed'] .app-body { grid-template-columns: 0px minmax(0, 1fr); }

.main { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 5fr); }

/* ================================================================= header */

.app-header {
  flex: none; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 10px; border-radius: 20px;
  position: relative; z-index: 20;
}
.header-start { display: flex; align-items: center; gap: 6px; min-width: 0; }
.header-actions { display: flex; align-items: center; gap: 2px; }
.hdr-btn { border-radius: 12px; color: var(--text-2); }
.hdr-btn:hover:not(:disabled) { color: var(--text); }
.hdr-btn[aria-pressed='true'] { background: transparent; color: var(--accent); }
.hdr-btn[aria-pressed='true']:hover { background: var(--surface-hover); }
.lang-glyph { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }

.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); padding: 4px 6px; border-radius: 12px; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 36px; height: 36px; flex: none; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)); }
.brand-tagline { font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes gradient-flow { to { background-position: 300% 0; } }

/* ================================================================= sidebar */

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  width: var(--sidebar-w); border-radius: 22px; overflow: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s;
}
:root[data-sidebar='closed'] .sidebar { opacity: 0; visibility: hidden; transition: opacity var(--dur-fast) var(--ease), visibility 0s var(--dur); }

.sidebar-head { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.sidebar-row { display: flex; gap: 8px; align-items: center; }
.new-chat-btn { flex: 1; height: 44px; border-radius: 14px; font-size: 14px; }
.sidebar-close { display: none; }

/* "My quizzes" (quiz-library.js). */
.side-link { justify-content: flex-start; gap: 10px; height: 40px; padding: 0 12px; border-radius: 12px; font-size: 13.5px; color: var(--text-2); }
.side-link:hover { color: var(--text); }
.side-count { margin-inline-start: auto; min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }

.search-field { position: relative; display: block; }
.search-icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); display: inline-flex; pointer-events: none; }
.search-icon .icon { width: 17px; height: 17px; }
.search-input { height: 40px; min-height: 40px; border-radius: 12px; padding-inline-start: 38px; font-size: 13.5px; background: var(--surface); }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

.conv-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 8px; }
.conv-group { margin-bottom: 4px; }
.conv-group-title { font-size: 11.5px; font-weight: 600; color: var(--text-3); padding: 12px 10px 6px; margin: 0; letter-spacing: 0.02em; }
.conv-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-item { position: relative; border-radius: 12px; transition: background var(--dur-fast) var(--ease); }
.conv-item:hover, .conv-item:focus-within { background: var(--surface-hover); }
.conv-item.is-active { background: var(--accent-soft); }
.conv-item.is-active::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px;
  background: var(--gradient-accent);
}
.conv-open {
  display: flex; flex-direction: column; gap: 1px; width: 100%; min-width: 0;
  padding: 9px 12px; background: none; border: 0; border-radius: 12px; text-align: start; color: var(--text-2);
}
.conv-title { font-size: 13.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-actions {
  position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 2px; padding-inline-start: 18px;
  background: linear-gradient(to var(--fade-dir, left), var(--surface-solid) 62%, transparent);
  border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease);
}
[dir='rtl'] .conv-actions { --fade-dir: right; }
.conv-item:hover .conv-actions, .conv-item:focus-within .conv-actions { opacity: 1; pointer-events: auto; }
.conv-item.is-active .conv-actions { background: linear-gradient(to var(--fade-dir, left), color-mix(in oklab, var(--surface-solid) 86%, var(--accent)) 62%, transparent); }
.conv-action {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2);
}
.conv-action:hover { background: var(--surface-active); color: var(--text); }
.conv-action.is-danger:hover { color: var(--danger); background: var(--danger-soft); }
.conv-rename { display: flex; padding: 4px; }
.conv-rename .input { height: 36px; min-height: 36px; font-size: 13.5px; padding: 6px 10px; }
.conv-empty { padding: 28px 16px; text-align: center; color: var(--text-3); font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.conv-empty .icon { opacity: 0.6; }

.sidebar-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border);
}
.clear-all-btn { color: var(--text-3); }
.clear-all-btn:hover:not(:disabled) { color: var(--danger); }
.sidebar-credit { width: 100%; margin: 2px 0 0; font-size: 11px; color: var(--text-2); text-align: center; }
.sidebar-scrim { display: none; }

/* ================================================================= stage */

.stage {
  position: relative; min-height: 0; min-width: 0; overflow: hidden;
  margin-inline-end: var(--gutter);
  border-radius: var(--stage-radius); border: 1px solid var(--border);
  background:
    radial-gradient(80% 55% at 50% 34%, color-mix(in oklab, var(--emotion-color) 17%, transparent), transparent 72%),
    radial-gradient(120% 70% at 50% 115%, color-mix(in oklab, var(--accent-2) 18%, transparent), transparent 62%),
    linear-gradient(180deg, color-mix(in oklab, var(--surface-2) 70%, transparent), color-mix(in oklab, var(--bg) 55%, transparent));
  box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  isolation: isolate;
}
/* Graphite: no colored aurora behind the panels. */
:root[data-theme='gray'] .aurora span:nth-child(1),
:root[data-theme='gray'] .aurora span:nth-child(2) { display: none; }
:root[data-theme='gray'] .stage {
  /* Graphite keeps a deep, almost black backdrop behind FAHAD so the figure and the emotion glow stand out. */
  background:
    radial-gradient(80% 55% at 50% 34%, color-mix(in oklab, var(--emotion-color) 13%, transparent), transparent 72%),
    radial-gradient(120% 70% at 50% 115%, color-mix(in oklab, var(--accent-2) 12%, transparent), transparent 62%),
    linear-gradient(180deg, #0a0a0c 0%, #050506 60%, #000000 100%);
}
.stage::before {
  /* halo ring behind the head */
  content: ''; position: absolute; z-index: 0; left: 50%; top: 44%;
  width: min(78%, 62vh); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid color-mix(in oklab, var(--emotion-color) 22%, transparent);
  box-shadow: inset 0 0 80px color-mix(in oklab, var(--emotion-color) 10%, transparent), 0 0 60px color-mix(in oklab, var(--emotion-color) 8%, transparent);
  pointer-events: none;
}
.stage-floor {
  position: absolute; z-index: 0; left: 8%; right: 8%; bottom: -14%; height: 40%;
  background: radial-gradient(closest-side, var(--emotion-glow), transparent);
  opacity: 0.75; pointer-events: none;
}
.avatar-stage { position: absolute; inset: 0; z-index: 1; }
.avatar-stage canvas, .avatar-stage svg { width: 100% !important; height: 100% !important; }

.stage-fallback {
  position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease);
}
.stage-fallback img { width: 96px; height: 96px; opacity: 0.9; filter: drop-shadow(0 16px 40px rgba(111, 123, 255, 0.5)); animation: splash-pulse 1.8s var(--ease) infinite; }
.stage[data-avatar='ready'] .stage-fallback { opacity: 0; }
.stage[data-avatar='failed'] .stage-fallback img { animation: none; }

.stage-top {
  position: absolute; z-index: 3; top: 14px; inset-inline: 14px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; pointer-events: none;
}
.stage-top > * { pointer-events: auto; }
.emotion-badge {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px 0 10px;
  border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text);
  background: color-mix(in oklab, var(--emotion-color) 14%, var(--surface-solid));
  border: 1px solid color-mix(in oklab, var(--emotion-color) 45%, transparent);
  box-shadow: 0 0 26px color-mix(in oklab, var(--emotion-color) 26%, transparent);
  transition: background var(--dur-slow) var(--ease), border-color var(--dur-slow), box-shadow var(--dur-slow);
}
.emotion-icon { display: inline-flex; color: var(--emotion-color); }
.emotion-icon .icon { width: 18px; height: 18px; }
.emotion-badge.is-changing .emotion-icon { animation: icon-pop 520ms var(--ease-spring); }
@keyframes icon-pop { 0% { transform: scale(0.4) rotate(-20deg); } 60% { transform: scale(1.25) rotate(6deg); } 100% { transform: none; } }

.stage-toggle {
  display: none; width: 36px; height: 36px; border-radius: 12px;
  background: color-mix(in oklab, var(--surface-solid) 88%, transparent);
}
.stage-toggle .icon { transition: transform var(--dur) var(--ease); }
:root[data-stage='collapsed'] .stage-toggle .icon { transform: rotate(180deg); }

.nameplate {
  position: absolute; z-index: 3; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 12px; padding: 8px 16px 8px 18px; max-width: calc(100% - 24px);
  border-radius: 999px; white-space: nowrap;
  background: color-mix(in oklab, var(--surface-solid) 86%, transparent);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-1);
}
.nameplate-name {
  font-weight: 700; letter-spacing: 0.2em; font-size: 14px; direction: ltr;
  background: var(--gradient-accent); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.nameplate-state { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); padding-inline-start: 12px; border-inline-start: 1px solid var(--border-strong); }
.nameplate-stop {
  flex: none; width: 30px; height: 30px; margin-inline: -4px -8px; display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--text); color: var(--bg);
  animation: pop-in 200ms var(--ease);
}
.nameplate-stop:hover { filter: brightness(0.9); }
.nameplate-stop .icon { fill: currentColor; }
/* The other teacher, reading a sentence in his language (main.js showGuest): his picture beside the stage, its ring
   following his voice (--open, 0–1). */
.stage-guest {
  position: absolute; z-index: 3; inset-inline-end: 14px; bottom: 74px; display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px; max-width: calc(100% - 28px); border-radius: 999px;
  background: color-mix(in oklab, var(--surface-solid) 90%, transparent); border: 1px solid var(--border-strong); box-shadow: var(--shadow-1);
  opacity: 0; transform: translateY(8px) scale(0.96); transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  pointer-events: none;
}
.stage-guest.is-in { opacity: 1; transform: none; }
.stage-guest-photo {
  flex: none; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; background: var(--surface-3);
  box-shadow: 0 0 0 calc(2px + var(--open, 0) * 6px) color-mix(in oklab, var(--accent) 70%, transparent);
  transition: box-shadow 90ms linear;
}
.stage-guest-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; display: block; }
.stage-guest-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.stage-guest-name { font-size: 14px; color: var(--text); }
.stage-guest-note { font-size: 12px; color: var(--text-2); white-space: nowrap; }
:root[data-stage='collapsed'] .stage-guest { display: none; }
:root[data-reduced-motion='true'] .stage-guest, :root[data-reduced-motion='true'] .stage-guest-photo { transition: none; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 currentColor; flex: none; }
.nameplate-state[data-state='listening'] .state-dot { background: var(--accent); animation: state-pulse 1.2s ease-out infinite; color: var(--accent); }
.nameplate-state[data-state='thinking'] .state-dot { background: var(--accent-2); animation: state-pulse 1s ease-out infinite; color: var(--accent-2); }
.nameplate-state[data-state='talking'] .state-dot { background: var(--emotion-color); animation: state-pulse 0.7s ease-out infinite; color: var(--emotion-color); }
@keyframes state-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in oklab, currentColor 60%, transparent); }
  100% { box-shadow: 0 0 0 8px transparent; }
}

.avatar-quip {
  position: absolute; z-index: 4; top: 64px; inset-inline-end: 16px; max-width: min(240px, 70%);
  padding: 10px 14px; border-radius: 16px; border-start-end-radius: 4px;
  background: var(--surface-solid); border: 1px solid color-mix(in oklab, var(--emotion-color) 45%, var(--border));
  box-shadow: var(--shadow-2), 0 0 30px var(--emotion-soft);
  font-size: 13.5px; font-weight: 500; line-height: 1.5; color: var(--text);
  transform-origin: top right; animation: quip-in 380ms var(--ease-spring);
}
[dir='rtl'] .avatar-quip { transform-origin: top left; }
.avatar-quip.is-leaving { opacity: 0; transform: scale(0.9); transition: opacity 220ms, transform 220ms; }
@keyframes quip-in { from { opacity: 0; transform: scale(0.7) translateY(-6px); } to { opacity: 1; transform: none; } }

/* ================================================================= chat column */

.chat {
  position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-radius: var(--stage-radius);
  background: color-mix(in oklab, var(--surface-solid) 72%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.setup-banner {
  flex: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: 'icon text close' 'icon actions close';
  align-items: start; column-gap: 12px; row-gap: 10px; margin: 12px 12px 0; padding: 12px 10px 12px 14px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  animation: fade-up 360ms var(--ease);
}
.setup-icon { grid-area: icon; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); color: var(--text); }
.setup-text { grid-area: text; min-width: 0; display: flex; flex-direction: column; font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.setup-text strong { font-size: 14px; color: var(--text); }
.setup-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 6px; }
.setup-dismiss { grid-area: close; color: var(--text-3); }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 20px 20px 12px; scroll-padding-bottom: 24px; }
.chat-inner { max-width: var(--chat-max); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; }

/* ---------- welcome */

.welcome { margin: auto 0; padding: 20px 4px 12px; display: flex; flex-direction: column; align-items: center; text-align: center; animation: fade-up 520ms var(--ease); }
.welcome-date {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; margin-bottom: 14px;
  border-radius: 999px; font-size: 12px; font-weight: 500; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
}
.welcome-title { font-size: clamp(22px, 1.4vw + 14px, 32px); font-weight: 700; line-height: 1.35; margin: 0 0 8px; letter-spacing: -0.005em; text-wrap: balance; }
.grad-text { color: var(--text); direction: ltr; unicode-bidi: isolate; letter-spacing: 0.04em; } /* the name, plain (no color-shifting gradient) */
.welcome-sub { max-width: 520px; margin: 0 auto 18px; color: var(--text-2); font-size: 14.5px; text-wrap: balance; }
/* The teacher chosen for the student, under the greeting (chat.js renderWelcomeTeacher). */
.welcome-teacher {
  display: flex; width: fit-content; max-width: 100%; align-items: center; gap: 10px; margin: -2px auto 12px; padding: 4px 6px;
  border-radius: 999px; border: 1px solid var(--border); background: color-mix(in oklab, var(--surface-2) 80%, transparent);
  color: var(--text-2); font-size: 14px;
}
.welcome-teacher-photo { flex: none; width: 30px; height: 30px; border-radius: 50%; overflow: hidden; background: var(--surface-3); }
.welcome-teacher-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; display: block; }
.welcome-teacher-text strong { color: var(--text); }
.welcome-teacher-change {
  height: 28px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: transparent;
  color: var(--accent); font: inherit; font-size: 13px; cursor: pointer;
}
.welcome-teacher-change:hover { background: var(--surface-hover); }

.welcome-modes { width: 100%; margin: 0 0 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.welcome-modes-title { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
/* Centred chips that wrap; "More" opens every mode in place. */
.mode-picks { max-width: 640px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 2px 8px; }
.mode-pick {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px 0 11px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast) var(--ease);
}
.mode-pick:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); }
.mode-pick[aria-pressed='true'] { background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 45%, transparent); color: var(--accent); font-weight: 600; }
.mode-pick-icon { display: inline-flex; }
.mode-pick-icon .icon { width: 16px; height: 16px; }
.mode-more { border-style: dashed; color: var(--text-3); }
.mode-more[aria-expanded='true'] { border-style: solid; }
.mode-picks .mode-pick { animation: mode-in var(--dur) var(--ease) both; }
@keyframes mode-in { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .mode-picks .mode-pick { animation: none; } }

.suggestions { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; text-align: start; }
.suggestion {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px; min-height: 76px;
  border-radius: 18px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  text-align: start; line-height: 1.45;
  transition: transform var(--dur) var(--ease), border-color var(--dur), box-shadow var(--dur), background var(--dur);
  animation: fade-up 480ms var(--ease) backwards;
}
.suggestion:nth-child(2) { animation-delay: 50ms; }
.suggestion:nth-child(3) { animation-delay: 100ms; }
.suggestion:nth-child(4) { animation-delay: 150ms; }
.suggestion:nth-child(5) { animation-delay: 200ms; }
.suggestion:nth-child(6) { animation-delay: 250ms; }
.suggestion:hover { transform: translateY(-2px); border-color: color-mix(in oklab, var(--sugg-color, var(--accent)) 50%, transparent); box-shadow: 0 10px 30px color-mix(in oklab, var(--sugg-color, var(--accent)) 16%, transparent); background: var(--surface-3); }
.suggestion:active { transform: translateY(0) scale(0.99); }
.ltr-run { white-space: nowrap; }
.sugg-icon {
  flex: none; width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  color: var(--sugg-color, var(--accent));
  background: color-mix(in oklab, var(--sugg-color, var(--accent)) 16%, transparent);
  border: 1px solid color-mix(in oklab, var(--sugg-color, var(--accent)) 28%, transparent);
}
.sugg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sugg-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.sugg-tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--sugg-color, var(--accent)); flex: none; }
.sugg-title { font-size: 14px; font-weight: 600; }
.sugg-text { font-size: 12.5px; color: var(--text-3); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- messages */

.earlier-btn {
  align-self: center; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px 0 10px; margin: 0 0 18px;
  border-radius: 999px; border: 1px dashed var(--border-strong); background: transparent; color: var(--text-2);
  font-size: 12.5px; font-weight: 600;
}
.earlier-btn:hover { color: var(--text); border-style: solid; border-color: var(--accent); }

.messages { display: flex; flex-direction: column; gap: 18px; padding-bottom: 4px; }
.messages:empty { display: none; }
.msg { position: relative; display: flex; flex-direction: column; min-width: 0; animation: fade-up 320ms var(--ease); }

.msg-user { align-self: flex-end; align-items: flex-end; max-width: min(86%, 640px); }
.msg-bubble {
  padding: 10px 16px; border-radius: 20px; border-end-end-radius: 6px;
  background: var(--gradient-user); color: var(--user-text);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.7;
  unicode-bidi: plaintext; text-align: start; /* each line takes the direction of its own text (see chat.js bidiText) */
}
.msg-user .msg-meta { display: flex; align-items: center; gap: 4px; margin-top: 4px; min-height: 30px; }

.msg-assistant {
  align-self: stretch; padding: 12px 16px 8px;
  border-radius: 22px; border-start-start-radius: 8px;
  background: color-mix(in oklab, var(--surface-2) 82%, transparent);
  border: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-height: 26px; }
.msg-avatar {
  width: 26px; height: 26px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: var(--gradient-accent); box-shadow: 0 0 0 2px color-mix(in oklab, var(--msg-emotion, var(--accent)) 50%, transparent);
}
.msg-avatar img { width: 26px; height: 26px; border-radius: 9px; }
.msg-name { font-size: 13px; font-weight: 700; letter-spacing: 0.12em; direction: ltr; color: var(--text); }
.msg-emotion {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  color: var(--text-2);
  background: color-mix(in oklab, var(--msg-emotion, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in oklab, var(--msg-emotion, var(--accent)) 30%, transparent);
}
.msg-emotion-icon { display: inline-flex; color: var(--msg-emotion, var(--accent)); }
.msg-emotion-icon .icon { width: 13px; height: 13px; }
.msg-time { font-size: 11.5px; color: var(--text-3); opacity: 0; transition: opacity var(--dur-fast) var(--ease); white-space: nowrap; }
.msg-assistant .msg-time { margin-inline-start: auto; }
.msg:hover .msg-time, .msg:focus-within .msg-time { opacity: 1; }

.msg-body { font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; min-width: 0; text-wrap: pretty; }
.msg-body:empty { display: none; }

.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: 4px; min-height: 32px; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.is-last .msg-actions { opacity: 1; }
.msg-user .msg-actions { margin-top: 0; }
.msg-action {
  height: 30px; min-width: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 9px; background: transparent; color: var(--text-3); font-size: 12.5px; font-weight: 500;
}
.msg-action:hover { background: var(--surface-hover); color: var(--text); }
.msg-action[aria-pressed='true'] { color: var(--accent); background: var(--accent-soft); }
.msg-action.is-done { color: var(--success); }
.msg-note { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; font-size: 12px; color: var(--text-3); }
.msg-note .icon { fill: currentColor; opacity: 0.8; }

/* web search: the list of sources under a reply (sources.js), and the source numbers in its text */
.msg-sources {
  margin: 10px 0 2px; border: 1px solid var(--border); border-radius: 12px;
  background: color-mix(in oklab, var(--surface-2) 70%, transparent); font-size: 13px;
}
.msg-sources > summary {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none; color: var(--text-2);
  border-radius: 12px; user-select: none;
}
.msg-sources > summary::-webkit-details-marker { display: none; }
.msg-sources > summary:hover { background: var(--surface-hover); color: var(--text); }
.msg-sources > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg-sources .src-icon { display: inline-flex; color: var(--accent); }
.msg-sources .src-title { font-weight: 600; color: var(--text); }
.msg-sources .src-count { color: var(--text-3); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-sources .src-chevron { display: inline-flex; margin-inline-start: auto; color: var(--text-3); transition: transform var(--dur-fast) var(--ease); }
.msg-sources[open] .src-chevron { transform: rotate(180deg); }
.msg-sources-list { list-style: none; margin: 0; padding: 2px 8px 4px; display: grid; gap: 2px; }
.msg-sources-list li { display: flex; align-items: flex-start; gap: 10px; padding: 6px 6px; border-radius: 9px; scroll-margin: 80px; }
.msg-sources-list li.is-flash { animation: src-flash 1.6s var(--ease); }
@keyframes src-flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
.msg-sources .src-n {
  flex: none; min-width: 22px; height: 22px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700;
}
.msg-sources .src-main { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.msg-sources .src-main a { color: var(--text); text-decoration: none; line-height: 1.45; overflow-wrap: anywhere; }
.msg-sources .src-main a:hover { color: var(--accent); text-decoration: underline; }
.msg-sources .src-host { color: var(--text-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-sources .src-note { margin: 0; padding: 4px 14px 10px; color: var(--text-3); font-size: 11.5px; line-height: 1.5; }
.msg-sources-note { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 12.5px; color: var(--text-3); }
.msg-sources-note > span { display: inline-flex; color: var(--accent); }
.md sup.cite-wrap { line-height: 0; vertical-align: super; font-size: 0.72em; margin-inline: 1px; }
.md a.cite {
  display: inline-block; min-width: 1.5em; padding: 0 0.32em; border-radius: 0.6em; text-align: center; text-decoration: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; line-height: 1.5;
}
.md a.cite:hover, .md a.cite:focus-visible { background: var(--accent); color: var(--accent-contrast); }
.msg-thinking.is-searching .thinking-dots i { animation-duration: 0.9s; }

/* thinking indicator + caret */
.msg-thinking { display: flex; align-items: center; gap: 10px; padding: 6px 0 4px; font-size: 14px; }
/* The connection was lost while the reply was being written: it goes on on the server and appears when it is done. */
.msg-reconnect {
  display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 8px 12px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.5; color: var(--text-2);
  background: color-mix(in oklab, var(--accent) 9%, transparent);
  border: 1px solid color-mix(in oklab, var(--accent) 22%, transparent);
}
.msg-reconnect .thinking-dots { flex: none; }
/* Waiting for the connection: nothing is moving, so neither do the dots. */
.msg-reconnect.is-waiting .thinking-dots i { animation-play-state: paused; opacity: 0.4; }
.thinking-dots { display: inline-flex; gap: 4px; }
.thinking-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dot-bounce 1.2s var(--ease) infinite; }
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; background: color-mix(in oklab, var(--accent) 50%, var(--accent-2)); }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; background: var(--accent-2); }
.thinking-text {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 45%, var(--text-3) 90%);
  background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.8s linear infinite;
}
@keyframes dot-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.55; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes shimmer { from { background-position: 110% 0; } to { background-position: -110% 0; } }

.caret {
  display: inline-block; width: 0.5em; height: 1.05em; margin-inline-start: 3px; vertical-align: -0.16em;
  border-radius: 2px; background: var(--gradient-accent); animation: caret-blink 1s steps(2, start) infinite;
}
@keyframes caret-blink { to { visibility: hidden; } }

/* error card */
.msg-error {
  display: flex; align-items: flex-start; gap: 10px; margin: 8px 0 4px; padding: 12px;
  border-radius: 14px; background: var(--danger-soft); border: 1px solid color-mix(in oklab, var(--danger) 35%, transparent);
}
.msg-error-icon { color: var(--danger); display: inline-flex; margin-top: 1px; }
.msg-error-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.msg-error-text { font-size: 13.5px; color: var(--text); line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; }
.msg-error-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- markdown */

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.75em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.1em 0 0.5em; font-weight: 700; line-height: 1.4; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.22em; }
.md h3 { font-size: 1.1em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.8em; padding-inline-start: 1.5em; }
.md li { margin: 0.25em 0; }
.md li > p { margin-bottom: 0.35em; }
.md li::marker { color: var(--accent); font-weight: 600; }
.md strong { font-weight: 700; color: var(--text); }
.md blockquote {
  margin: 0.8em 0; padding: 0.6em 1em; border-radius: 12px;
  border-inline-start: 3px solid var(--accent); background: var(--accent-soft); color: var(--text);
}
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; height: 1px; background: var(--border-strong); margin: 1.2em 0; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--accent); }
.md :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.86em; padding: 0.12em 0.42em; border-radius: 6px;
  background: var(--surface-3); border: 1px solid var(--border); direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere;
}
.md .math-fallback { font-family: var(--font-mono); font-size: 0.9em; }

.code-block { margin: 0.8em 0; border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255, 255, 255, 0.08); text-align: left; }
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; padding: 0 6px 0 14px;
  background: rgba(255, 255, 255, 0.04); border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.code-head > .lang-icon { flex: none; margin-inline-end: -2px; }
.code-lang { font-family: var(--font-mono); font-size: 12px; color: #8b95b5; }
.code-file { font-family: var(--font-mono); font-size: 12px; color: #d7deef; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-head > .code-lang { margin-inline-end: auto; }
.code-head > .code-file { margin-inline-end: auto; margin-inline-start: -2px; }
.code-head > .code-lang:has(+ .code-file) { margin-inline-end: 0; }
.code-actions { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.code-copy, .code-action {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 9px; border: 0; border-radius: 8px;
  background: transparent; color: #aab3cf; font-size: 12px; font-family: var(--font);
}
.code-copy:hover, .code-action:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.code-run { color: #7ee2b8; }
.code-run:hover { color: #a8f0d0; }
/* Narrow message columns: icons only (the label stays as the accessible name). */
@media (max-width: 560px) { .code-action span, .code-copy span { display: none; } }
.code-bundle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 10px 0 2px; padding: 8px 10px;
  border-radius: 12px; border: 1px dashed var(--border-strong); background: var(--surface-2); direction: ltr;
}
.code-bundle-text { display: inline-flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-2); font-size: 13px; direction: rtl; }
:root[lang='en'] .code-bundle-text { direction: ltr; }
.code-bundle-name { font-family: var(--font-mono); font-weight: 700; color: var(--text); max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-bundle-count { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.code-bundle-count::before { content: ''; width: 1px; height: 14px; background: var(--border-strong); }
.code-bundle .code-action { color: var(--text-2); }
.code-bundle .code-action:hover { background: var(--surface-hover); color: var(--text); }
.code-bundle .code-run { color: var(--accent); }
.code-copy.is-copied { color: #34d399; }
.code-check { margin: 8px 0 2px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.code-check-head { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.code-check.is-ok .code-check-head .icon { color: #34d399; }
.code-check.is-bad { border-color: rgba(251, 191, 36, 0.45); }
.code-check.is-bad .code-check-head { color: var(--text); font-weight: 600; }
.code-check.is-bad .code-check-head .icon { color: #fbbf24; }
.code-check-list { margin: 6px 0 8px; padding-inline-start: 22px; color: var(--text-2); line-height: 1.7; }
.code-check-list li { overflow-wrap: anywhere; }
.code-check-notes { color: var(--text-3, var(--text-2)); font-size: 12.5px; }
.code-check .code-action { color: var(--accent); border: 1px solid var(--border-strong); }
.code-check .code-action span { display: inline; }
.msg-auto { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-bottom: 4px; font-size: 12px; color: var(--text-3, var(--text-2)); }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.65; direction: ltr; }
/* An edit to a file (markdown.js editView): what is removed and added, per file, and whether it was applied. */
.code-edit { margin: 0.8em 0; text-align: left; }
.code-edit-raw { margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--code-bg); overflow-x: auto; font-size: 13px; line-height: 1.6; }
.code-edit-raw code { font-family: var(--font-mono); color: #e6edf3; white-space: pre; }
.code-edit-file { border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255, 255, 255, 0.08); }
.code-edit-file + .code-edit-file { margin-top: 8px; }
/* The head holds the path, the result and four buttons: the buttons show icons only (their names stay as labels). */
.code-edit-file .code-head { height: auto; min-height: 36px; flex-wrap: wrap; row-gap: 0; padding-block: 3px; justify-content: flex-start; }
.code-edit-file .code-head > .code-lang { flex: none; margin-inline-end: 0; white-space: nowrap; font-family: var(--font); }
.code-edit-file .code-head > .code-file { flex: 0 1 auto; margin-inline-end: 0; }
.code-edit-file .code-actions { margin-inline-start: auto; }
.code-edit-file .code-action span { display: none; }
.code-edit-file .code-action { padding: 0 7px; }
.code-edit-status { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-family: var(--font); white-space: nowrap; }
.code-edit-status.is-ok { color: #34d399; background: rgba(52, 211, 153, 0.12); }
.code-edit-status.is-bad { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.code-diff { padding: 8px 0; overflow-x: auto; font-family: var(--font-mono); font-size: 13px; line-height: 1.6; color: #e6edf3; }
.code-diff:focus-visible { outline-offset: -2px; }
.diff-line { display: block; width: max-content; min-width: 100%; padding: 0 14px 0 0; white-space: pre; }
.diff-sign { display: inline-block; width: 26px; text-align: center; color: #8b95b5; user-select: none; }
.diff-line.is-del { background: rgba(255, 93, 115, 0.13); color: #ffc2cb; }
.diff-line.is-del .diff-sign { color: #ff8a9b; }
.diff-line.is-add { background: rgba(52, 211, 153, 0.13); color: #c9f7e3; }
.diff-line.is-add .diff-sign { color: #6ee7b7; }
.diff-line.is-failed { opacity: 0.6; }
.diff-gap { height: 1px; margin: 6px 14px; background: rgba(255, 255, 255, 0.08); }
.diff-note { margin: 6px 14px 2px; padding: 6px 10px; border-radius: 8px; background: rgba(251, 191, 36, 0.12); color: #fde7a7; font-family: var(--font); font-size: 12.5px; white-space: normal; overflow-wrap: anywhere; text-align: start; }
.code-edit-note { margin: 6px 0 0; color: var(--text-2); font-size: 13px; }
/* <pre> is the only horizontal scroller (highlight.js' theme would otherwise make <code> scroll too). */
.code-block code.hljs { display: block; overflow: visible; font-family: var(--font-mono); background: transparent; padding: 0; color: #e6edf3; white-space: pre; }

.table-wrap { margin: 0.8em 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.md table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md th, .md td { padding: 9px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
/* Cells keep their words whole (the table scrolls inside .table-wrap) instead of breaking them letter by letter. */
.md td { overflow-wrap: break-word; }
.md th { background: var(--surface-3); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md tbody tr:nth-child(even) td { background: var(--surface-hover); }

.md .math-block, .md .math-display { display: block; margin: 0.6em 0; padding: 2px 4px; overflow-x: auto; overflow-y: hidden; text-align: center; }
.code-block pre:focus-visible, .table-wrap:focus-visible, .md .math-block:focus-visible, .md .math-display:focus-visible { outline-offset: -2px; }
.md .katex-display { margin: 0; }
.md .katex { font-size: 1.08em; direction: ltr; unicode-bidi: isolate; }
/* KaTeX draws arrows/accents (\vec, \overrightarrow…) as absolutely positioned SVGs sized in em; the global
   `svg { max-width: 100% }` reset would clamp them to their zero-width box and hide them. */
.katex svg { max-width: none; }

/* ---------- jump to latest */

.jump-latest {
  position: absolute; z-index: 5; left: 50%; bottom: calc(var(--composer-h, 150px) + 10px); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-solid); color: var(--text);
  font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow-2);
  animation: fade-up 240ms var(--ease);
}
.jump-latest:hover { border-color: var(--accent); color: var(--accent); }
.jump-latest.has-new::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

/* ================================================================= composer + tutor bar */

.composer-area { flex: none; width: 100%; max-width: calc(var(--chat-max) + 40px); margin: 0 auto; padding: 6px 20px 12px; }

.tutor-bar {
  display: flex; align-items: center; gap: 6px; padding: 2px 2px 8px; overflow-x: auto; scrollbar-width: none;
  mask-image: linear-gradient(to var(--mask-dir, right), #000 calc(100% - 24px), transparent);
  -webkit-mask-image: linear-gradient(to var(--mask-dir, right), #000 calc(100% - 24px), transparent);
}
[dir='rtl'] .tutor-bar { --mask-dir: left; }
.tutor-bar::-webkit-scrollbar { display: none; }
.tutor-bar:empty { display: none; }
.pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 9px;
  border-radius: 999px; border: 1px solid var(--border); background: color-mix(in oklab, var(--surface-2) 90%, transparent);
  color: var(--text-2); font-size: 12.5px; font-weight: 500; white-space: nowrap;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.pill:hover { border-color: var(--border-strong); color: var(--text); }
.pill[aria-expanded='true'] { border-color: var(--accent); color: var(--text); box-shadow: var(--ring); }
.pill[aria-pressed='true'] { background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 40%, transparent); color: var(--accent); }
.pill-icon { display: inline-flex; }
.pill-icon .icon { width: 15px; height: 15px; }
.pill-value { color: var(--text-2); }
.pill.is-set { border-color: color-mix(in oklab, var(--accent-2) 45%, transparent); background: color-mix(in oklab, var(--accent-2) 12%, var(--surface-2)); }
.pill.is-set .pill-value { color: var(--text); font-weight: 600; }
.pill[aria-pressed='true'] .pill-value { color: var(--accent); }
.pill .icon-chevron-down { opacity: 0.6; }
.pill-sep { width: 1px; height: 18px; background: var(--border-strong); flex: none; margin: 0 2px; }

.composer {
  position: relative;
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 6px; padding: 6px; padding-inline-start: 16px;
  border-radius: 26px; border: 1px solid var(--border-strong);
  background: color-mix(in oklab, var(--surface-2) 92%, transparent);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

/* ---------- attachments: the chips above the input, the paperclip, and drag-and-drop (attachments.js) */
.att-file-input { display: none !important; }
/* Its own full row above the text box (the composer wraps): exactly 100%, so nothing else fits beside it. */
.att-strip {
  order: -1; flex: 0 0 100%; display: flex; flex-wrap: wrap; gap: 8px; min-width: 0;
  padding: 6px 0 2px;
}
.att-strip[hidden] { display: none; }
.att-chip {
  display: flex; align-items: center; gap: 8px; max-width: 260px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-solid); font-size: 12.5px;
}
.att-chip.att-reading { opacity: 0.8; }
.att-chip.att-error { border-color: var(--danger); color: var(--danger); }
.att-chip.att-danger { border-color: color-mix(in oklab, var(--danger) 55%, var(--border)); }
.att-chip.att-warn { border-color: color-mix(in oklab, var(--warn, #e0a33a) 55%, var(--border)); }
.att-chip .att-icon { display: inline-flex; color: var(--text-2); flex: none; }
.att-chip.att-danger .att-icon, .att-chip.att-danger .att-flag { color: var(--danger); }
.att-chip.att-warn .att-icon, .att-chip.att-warn .att-flag { color: var(--warn, #e0a33a); }
.att-thumb { width: 34px; height: 34px; flex: none; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.att-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.att-name { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { color: var(--text-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-flag { display: inline-flex; flex: none; }
.att-remove {
  flex: none; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-3);
}
.att-remove:hover { background: var(--surface-hover); color: var(--text); }
.att-spin {
  flex: none; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: att-spin 0.7s linear infinite;
}
@keyframes att-spin { to { transform: rotate(360deg); } }
.att-drop {
  position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 26px; background: color-mix(in oklab, var(--accent) 16%, var(--surface-solid));
  border: 2px dashed var(--accent); color: var(--accent); font-weight: 600; font-size: 14px; pointer-events: none;
}
.att-drop[hidden] { display: none; }
/* attachment chips shown inside a sent user message */
.msg-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.msg-user .msg-atts { justify-content: flex-end; }
.msg-att {
  display: flex; align-items: center; gap: 6px; max-width: 220px; padding: 5px 9px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 12px;
}
.msg-att .att-icon { display: inline-flex; color: var(--text-2); flex: none; }
.msg-att .att-thumb { width: 28px; height: 28px; border-radius: 6px; }
.msg-att .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.msg-att.att-danger { border-color: color-mix(in oklab, var(--danger) 55%, var(--border)); }
.msg-att.att-danger .att-icon, .msg-att.att-danger .att-flag { color: var(--danger); }
.msg-att.att-warn .att-icon, .msg-att.att-warn .att-flag { color: var(--warn, #e0a33a); }
.composer:focus-within { border-color: color-mix(in oklab, var(--accent) 70%, transparent); box-shadow: var(--glow); }
.composer.is-listening { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger), 0 0 28px var(--danger-soft); }
.composer-input {
  flex: 1; min-width: 0; min-height: 44px; max-height: 40vh; padding: 10px 2px; margin: 0;
  border: 0; outline: none; background: transparent; resize: none; color: var(--text);
  font-size: 15.5px; line-height: 1.6; overflow-y: auto;
}
.composer-input::placeholder { color: var(--text-3); }
.composer-input:focus-visible { outline: none; }
.composer-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.composer-btn {
  width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 0; background: transparent; color: var(--text-2);
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast) var(--ease), box-shadow var(--dur);
}
.composer-btn:hover:not(:disabled):not([aria-disabled='true']) { background: var(--surface-hover); color: var(--text); }
.composer-btn:active:not(:disabled) { transform: scale(0.94); }
.mic-btn[aria-disabled='true'] { opacity: 0.4; cursor: not-allowed; }
.live-btn[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent); }

/* ---------- live conversation: replaces the composer while FAHAD listens, thinks and speaks */
.composer-area.is-live .composer,
.composer-area.is-live .tutor-bar,
.composer-area.is-live .composer-foot { display: none; }
.live-panel {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 22px; background: var(--surface-2); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-1); animation: fade-up 300ms var(--ease);
}
.live-panel[hidden] { display: none; }
.live-orb { position: relative; width: 46px; height: 46px; display: grid; place-items: center; }
.live-orb span, .live-orb::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--live-color, var(--accent));
}
.live-orb span { inset: 9px; }
.live-orb::before { opacity: 0.25; animation: live-pulse 1.6s ease-out infinite; }
.live-panel[data-phase='listening'] { --live-color: var(--accent); }
.live-panel[data-phase='thinking'] { --live-color: var(--text-3); }
.live-panel[data-phase='thinking'] .live-orb::before { animation-duration: 0.9s; }
.live-panel[data-phase='speaking'] { --live-color: var(--emotion-color); }
@keyframes live-pulse { 0% { transform: scale(0.7); opacity: 0.45; } 100% { transform: scale(1.35); opacity: 0; } }
.live-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.live-status { font-size: 14.5px; color: var(--text); }
.live-transcript { font-size: 13px; color: var(--text-2); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.live-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.live-end { color: var(--danger); }
@media (max-width: 767px) {
  .live-panel { grid-template-columns: auto minmax(0, 1fr); padding: 12px; gap: 10px 12px; }
  .live-actions { grid-column: 1 / -1; }
  .live-actions .btn { flex: 1; height: 40px; }
}
.mic-btn.is-listening { background: var(--danger); color: #fff; animation: mic-ring 1.4s ease-out infinite; }
.mic-btn.is-listening:hover { background: var(--danger) !important; color: #fff !important; }
@keyframes mic-ring { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--danger) 55%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
.send-btn { background: var(--gradient-accent); color: var(--on-primary, #fff); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); }
.send-btn:hover:not(:disabled) { background: var(--gradient-accent) !important; color: var(--on-primary, #fff) !important; filter: brightness(1.1); }
.send-btn:disabled { background: var(--surface-3); color: var(--text-3); box-shadow: none; }
[dir='rtl'] .send-btn .icon { transform: scaleX(-1); }
.stop-btn { background: var(--text); color: var(--bg); }
.stop-btn:hover { background: var(--text) !important; color: var(--bg) !important; filter: brightness(0.9); }
.stop-btn .icon { fill: currentColor; }

.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; padding: 6px 12px 0; font-size: 11.5px; color: var(--text-3); }
.composer-hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-hint kbd {
  display: inline-block; min-width: 18px; padding: 0 5px; margin: 0 1px; border-radius: 5px; text-align: center;
  font-family: var(--font-mono); font-size: 10.5px; line-height: 17px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  direction: ltr; unicode-bidi: isolate;
}
.char-counter { font-variant-numeric: tabular-nums; margin-inline-start: auto; direction: ltr; }
/* Replies left today (plans with a daily limit, plan.js). */
.plan-usage { margin-inline-start: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.plan-usage[data-level='low'] { color: var(--warn); }
.plan-usage[data-level='out'] { color: var(--danger); font-weight: 600; white-space: normal; }
.plan-usage + .char-counter { margin-inline-start: 10px; }
.char-counter.is-near { color: var(--warn); }
.char-counter.is-over { color: var(--danger); font-weight: 700; }

/* ---------- popovers (tutor pickers, student profile) */

.popover {
  position: fixed; z-index: 90; min-width: 250px; max-width: min(360px, calc(100vw - 16px)); max-height: 60vh; overflow-y: auto;
  padding: 6px; border-radius: 18px; background: var(--surface-solid); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2); animation: pop-in 160ms var(--ease);
  overscroll-behavior: contain;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
.popover-title { padding: 8px 10px 6px; margin: 0; font-size: 12px; font-weight: 600; color: var(--text-3); }
.opt {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text); text-align: start;
}
.opt:hover, .opt:focus-visible { background: var(--surface-hover); outline: none; }
.opt:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.opt[aria-selected='true'], .opt[aria-checked='true'] { background: var(--accent-soft); }
.opt-icon { flex: none; width: 24px; height: 21px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); }
.opt-icon .icon { width: 18px; height: 18px; }
.opt[aria-selected='true'] .opt-icon, .opt[aria-checked='true'] .opt-icon { color: var(--accent); }
.opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.opt-label { font-size: 14px; font-weight: 600; line-height: 1.5; }
.opt-badge {
  display: inline-block; margin-inline-start: 8px; padding: 0 8px; border-radius: 999px; vertical-align: 1px;
  font-size: 11.5px; font-weight: 600; line-height: 1.6; color: var(--text-2); background: var(--surface-3); border: 1px solid var(--border);
}
.opt-hint { font-size: 12px; color: var(--text-2); line-height: 1.45; }
.opt-check { flex: none; color: var(--accent); margin-top: 3px; visibility: hidden; }
.opt[aria-selected='true'] .opt-check, .opt[aria-checked='true'] .opt-check { visibility: visible; }
.opt:disabled { opacity: 0.5; cursor: not-allowed; }

.profile-pop { width: min(340px, calc(100vw - 16px)); padding: 14px; }

/* ---------- voice menu (chat bar): engine, live download progress, speaking speed */
.pill-voice { position: relative; overflow: hidden; }
.pill-voice.is-loading { border-color: color-mix(in oklab, var(--accent) 45%, transparent); color: var(--text); }
.pill-voice.is-loading::after {
  content: ''; position: absolute; inset-inline-start: 0; bottom: 0; height: 3px; width: var(--progress, 0%);
  background: var(--accent); transition: width var(--dur) var(--ease);
}
.voice-pop { width: min(360px, calc(100vw - 16px)); padding: 12px; }
.voice-pop .profile-pop-head { margin-bottom: 4px; }
.voice-pop .popover-title { padding-inline: 2px; }
.voice-progress { display: block; height: 6px; margin-top: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.voice-progress-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width var(--dur) var(--ease); }
.voice-speeds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin: 2px 0 12px; }
.voice-people { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 2px 0 4px; }
.voice-speed, .voice-person {
  height: 34px; padding: 0 2px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 12px; font-weight: 600; white-space: nowrap; transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.voice-speed:hover, .voice-person:hover { border-color: var(--border-strong); color: var(--text); }
.voice-speed[aria-pressed='true'], .voice-person[aria-checked='true'] { background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 45%, transparent); color: var(--accent); }
.voice-who-hint { margin: 0 2px 12px; font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.voice-auto-read { padding: 2px 2px 4px; }
.profile-pop .field { margin-bottom: 12px; }
.profile-pop .textarea { min-height: 84px; font-size: 14px; }
.profile-pop-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.profile-pop-head .icon { color: var(--accent); }
.profile-pop-head h3 { margin: 0; font-size: 15px; }
.profile-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.profile-pop-note { margin: -4px 0 12px; }

/* ================================================================= shared bits */

@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }
.show-xs { display: none !important; }

/* ================================================================= responsive */

/* Drawer sidebar (tablet + mobile). */
@media (max-width: 1099px) {
  .app-body, :root[data-sidebar='closed'] .app-body { grid-template-columns: minmax(0, 1fr); }
  .main { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  .sidebar, :root[data-sidebar='closed'] .sidebar {
    position: fixed; z-index: 70; top: 0; bottom: 0; inset-inline-start: 0;
    width: min(330px, 88vw); border-radius: 0; border-start-end-radius: 24px; border-end-end-radius: 24px;
    padding-top: var(--safe-top); background: var(--surface-solid);
    opacity: 1; visibility: hidden; transform: translateX(-104%);
    transition: transform var(--dur-slow) var(--ease), visibility 0s var(--dur-slow);
    box-shadow: var(--shadow-2);
  }
  [dir='rtl'] .sidebar { transform: translateX(104%); }
  :root[data-drawer='open'] .sidebar { transform: none; visibility: visible; transition: transform var(--dur-slow) var(--ease), visibility 0s; }
  .sidebar-close { display: inline-flex; }
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(0, 0, 0, 0.6);
    animation: fade-in var(--dur) var(--ease);
  }
  .sidebar-scrim[hidden] { display: none; }
  .conv-actions { opacity: 1; pointer-events: auto; background: none; position: static; transform: none; padding: 0; }
  .conv-item { display: flex; align-items: center; }
  .conv-open { flex: 1; }
  .stage { margin-inline-end: var(--gutter); }
}
@keyframes fade-in { from { opacity: 0; } }

/* Stacked layout: phones and portrait tablets. */
@media (max-width: 767px), (max-width: 1099px) and (orientation: portrait) {
  :root { --gutter: 10px; }
  .main { display: flex; flex-direction: column; gap: var(--gutter); }
  .stage {
    flex: none; margin: 0; height: clamp(200px, 34dvh, 380px);
    transition: height var(--dur-slow) var(--ease), border-radius var(--dur-slow);
  }
  .stage-toggle { display: inline-flex; }
  .chat { flex: 1; min-height: 0; }
  .stage::before { width: min(70%, 30dvh); top: 46%; }

  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage { height: 72px; border-radius: 22px; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage::before,
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage-floor { display: none; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .avatar-stage { inset: 0 auto 0 0; width: 76px; }
  [dir='rtl']:root:is([data-stage='collapsed'], [data-keyboard='open']) .avatar-stage { inset: 0 0 0 auto; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage-fallback { width: 76px; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage-fallback img { width: 44px; height: 44px; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .stage-top { top: 50%; transform: translateY(-50%); inset-inline-start: auto; inset-inline-end: 12px; align-items: center; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .nameplate {
    left: auto; right: auto; inset-inline-start: 82px; bottom: auto; top: 50%; transform: translateY(-50%);
    background: none; border: 0; box-shadow: none; padding: 0;
    display: grid; grid-template-columns: auto auto; align-items: center; justify-items: start; column-gap: 14px;
  }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .nameplate-state { border: 0; padding: 0; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .nameplate > :not(.nameplate-stop) { grid-column: 1; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .nameplate-stop { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .avatar-quip { display: none; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .emotion-label { display: none; }
  :root:is([data-stage='collapsed'], [data-keyboard='open']) .emotion-badge { padding: 0 10px; }
  /* Typing with the on-screen keyboard up folds the stage without touching the saved preference (main.js). */
  :root[data-keyboard='open'] .stage-toggle { display: none; }
}
@media (min-width: 768px) and (max-width: 1099px) and (orientation: portrait) {
  .stage { height: clamp(260px, 36dvh, 440px); }
}

/* Phones. */
@media (max-width: 767px) {
  :root { --header-h: 56px; --stage-radius: 22px; }
  .app { gap: 8px; }
  .app-header { border-radius: 18px; padding: 0 4px; }
  .brand { gap: 8px; padding: 4px; }
  .brand-logo { width: 32px; height: 32px; }
  .brand-tagline { display: none; }
  .hdr-btn { width: 44px; height: 44px; }
  .chat-scroll { padding: 14px 12px 8px; }
  .composer-area { padding: 4px 10px 10px; }
  .composer { padding: 4px; padding-inline-start: 14px; border-radius: 24px; }
  .composer-input { font-size: 16px; } /* ≥ 16px prevents iOS zoom on focus */
  .composer-hint { display: none; }
  .composer-foot { min-height: 0; padding-top: 2px; }
  .composer-foot:has(.char-counter[hidden]):has(.plan-usage[hidden]) { display: none; }
  .suggestions { grid-template-columns: 1fr 1fr; gap: 8px; }
  .suggestion { flex-direction: column; gap: 8px; padding: 12px; min-height: 0; }
  .sugg-icon { width: 34px; height: 34px; border-radius: 11px; }
  .sugg-icon .icon { width: 18px; height: 18px; }
  .sugg-text { display: none; }
  .welcome { padding-top: 8px; }
  .welcome-sub { font-size: 13.5px; margin-bottom: 16px; }
  .msg-assistant { padding: 10px 12px 6px; border-radius: 18px; border-start-start-radius: 6px; }
  .msg-user { max-width: 90%; }
  .msg-actions { opacity: 1; }
  .msg-time { opacity: 1; }
  .msg-action { height: 40px; min-width: 40px; }
  .pill { height: 38px; padding: 0 12px 0 10px; }
  .setup-banner { grid-template-areas: 'icon text close' 'actions actions actions'; align-items: center; margin: 10px 10px 0; padding: 10px 10px 10px 12px; row-gap: 8px; }
  .setup-icon { width: 32px; height: 32px; border-radius: 10px; }
  .setup-text span { display: none; } /* phones: title + actions only, the chat needs the room */
  .setup-actions .btn { flex: 1; height: 40px; }
  .nameplate { bottom: 12px; padding: 6px 14px; }
  .emotion-badge { height: 32px; font-size: 12.5px; }
  .avatar-quip { top: 56px; font-size: 13px; }
  .stage-toggle { width: 44px; height: 44px; }
}

/* Very narrow phones: the theme toggle moves from the header into the sidebar footer. */
@media (max-width: 400px) {
  :root { --gutter: 8px; }
  .hide-xs { display: none !important; }
  .show-xs { display: inline-flex !important; }
  .header-start { gap: 0; }
  .header-actions { gap: 0; }
  .brand { gap: 6px; padding: 2px; }
  .brand-logo { width: 28px; height: 28px; }
  .suggestion { padding: 10px; }
  .sugg-title { font-size: 13px; }
}

/* Touch devices: always show row actions. */
@media (hover: none) {
  .msg-actions, .msg-time, .conv-actions { opacity: 1; pointer-events: auto; }
}
/* Touch screens: every control is at least 44 × 44 px. */
@media (pointer: coarse) {
  .btn, .hdr-btn, .stage-toggle, .msg-action, .conv-action, .toast-close, .code-copy, .code-action { min-width: 44px; min-height: 44px; }
  .code-copy, .code-action { justify-content: center; }
  .brand, .input, .select, .pill, .mode-pick, .earlier-btn, .jump-latest, .code-copy, .code-action, .search-input, .conv-rename .input { min-height: 44px; }
  .brand { min-width: 44px; justify-content: center; } /* the logo alone on phones: keep a full-size tap target */
  .code-head { height: auto; }
  .toast-close { align-items: center; justify-content: center; }
  .nameplate-stop { position: relative; }
  .nameplate-stop::after { content: ''; position: absolute; inset: -7px; }
}

/* ================================================================= reduced motion */

:root[data-reduced-motion='true'] .grad-text { animation: none; }
:root[data-reduced-motion='true'] .live-orb::before { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .grad-text { animation: none; }
}

/* ------------------------------------------------------------------------------------------- first visit (onboarding) */
.onboard {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px;
  background: color-mix(in oklab, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.1); backdrop-filter: blur(14px) saturate(1.1);
  opacity: 0; transition: opacity 240ms var(--ease);
}
.onboard.is-open { opacity: 1; }
.onboard.is-closing { opacity: 0; pointer-events: none; }
.onboard-card {
  width: min(640px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: 22px 22px 18px;
  border-radius: var(--radius-xl); border: 1px solid var(--border-strong); background: var(--surface-solid);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55); text-align: center;
  transform: translateY(10px) scale(0.98); transition: transform 280ms var(--ease);
  animation: onboard-in 280ms var(--ease) both;
}
.onboard.is-open .onboard-card { transform: none; }
@keyframes onboard-in { from { opacity: 0; transform: translateY(8px); } }
.onboard-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.onboard-label { font-size: 12px; font-weight: 700; letter-spacing: 0.02em; color: var(--text-3); }
.onboard-dots { display: inline-flex; gap: 6px; }
.onboard-dot { width: 22px; height: 5px; border-radius: 999px; background: var(--surface-3); transition: background var(--dur); }
.onboard-dot.is-on { background: var(--accent); }
.onboard-title { margin: 4px 0 6px; font-size: clamp(20px, 3.4vw, 26px); font-weight: 800; color: var(--text); }
.onboard-sub { margin: 0 auto 16px; max-width: 440px; font-size: 13.5px; line-height: 1.6; color: var(--text-2); }
.onboard-choices { display: grid; gap: 12px; margin-bottom: 16px; }
.onboard-teachers { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 600px; margin-inline: auto; }
.onboard-modes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.onboard-choice {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 8px 10px;
  border-radius: var(--radius-lg); border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text);
  text-align: center; transition: border-color var(--dur-fast), transform var(--dur-fast) var(--ease), background var(--dur-fast);
}
.onboard-choice:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.onboard-choice[aria-checked='true'] { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 10%, var(--surface-2)); }
.onboard-choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.onboard-portrait {
  display: flex; align-items: flex-end; justify-content: center; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 14px;
  background: radial-gradient(circle at 50% 78%, var(--accent-soft), transparent 70%), var(--surface-3);
}
.onboard-portrait img { width: 92%; height: auto; display: block; }
.onboard-choice-text { display: flex; flex-direction: column; gap: 2px; padding: 0 4px; }
.onboard-choice-name { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px; font-size: 14.5px; font-weight: 700; }
.onboard-choice-desc { font-size: 12px; color: var(--text-3); }
.onboard-check {
  position: absolute; top: 12px; inset-inline-end: 12px; display: grid; place-items: center; width: 24px; height: 24px;
  border-radius: 50%; background: var(--accent); color: var(--on-primary, #fff); opacity: 0; transform: scale(0.6);
  transition: opacity var(--dur-fast), transform var(--dur-fast) var(--ease);
}
.onboard-choice[aria-checked='true'] .onboard-check { opacity: 1; transform: none; }
.onboard-mode-art {
  --ta-bg: #060913; --ta-side: #0f1630; --ta-bubble: #1a2242; --ta-line: #26305a; --ta-user: #1d2750;
  display: flex; height: 92px; overflow: hidden; border-radius: 12px; border: 1px solid var(--border); background: var(--ta-bg);
}
.onboard-mode-art[data-preview='gray'] { --ta-bg: #121316; --ta-side: #1b1c20; --ta-bubble: #2c2f35; --ta-line: #3c4048; --ta-user: #2c2f35; }
.onboard-mode-art[data-preview='black'] { --ta-bg: #000000; --ta-side: #0d0d10; --ta-bubble: #1c1c21; --ta-line: #2a2a31; --ta-user: #1e1e23; }
.oma-side { width: 26%; background: var(--ta-side); }
.oma-main { flex: 1; display: flex; flex-direction: column; gap: 7px; padding: 12px 10px; }
.oma-line { width: 45%; height: 6px; border-radius: 4px; background: var(--ta-line); }
.oma-bubble { width: 72%; height: 16px; border-radius: 8px; background: var(--ta-bubble); }
.oma-user { align-self: flex-end; width: 46%; background: var(--ta-user); }
.onboard-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.onboard-next { min-width: 132px; gap: 6px; }
html.is-onboarding { overflow: hidden; }
@media (max-width: 520px) {
  .onboard-card { padding: 18px 14px 14px; }
  .onboard-choices { gap: 8px; }
  .onboard-mode-art { height: 70px; }
  .onboard-choice { padding: 6px 6px 8px; }
  .onboard-choice-name { font-size: 13px; }
  .onboard-choice-desc { font-size: 11px; }
  .onboard-check { top: 9px; inset-inline-end: 9px; width: 22px; height: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .onboard, .onboard-card, .onboard-choice, .onboard-check { transition: none; animation: none; }
}

/* ------------------------------------------------------------------------------------------- code studio */
.studio {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--bg); opacity: 0; transition: opacity 200ms var(--ease);
}
.studio.is-open { opacity: 1; }
html.is-studio { overflow: hidden; }
.studio-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.studio-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); }
.studio-brand h2 { margin: 0; font-size: 17px; color: var(--text); white-space: nowrap; }
.studio-name { flex: 1 1 180px; max-width: 360px; height: 38px; }
.studio-head-actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.studio-steps { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
.studio-steps::-webkit-scrollbar { display: none; }
.studio-step {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px 0 6px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: 12.5px;
}
.studio-step:hover { border-color: var(--border-strong); color: var(--text); }
.studio-step-n { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 11px; }
.studio-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 10px; }
.studio-side {
  display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow: auto; padding: 10px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface-solid);
}
.studio-side-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--text-3); }
.studio-files, .studio-projects { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.studio-file, .studio-project { display: flex; align-items: center; gap: 2px; border-radius: 10px; }
.studio-file.is-active, .studio-project.is-active { background: var(--accent-soft); }
.studio-file-open, .studio-project-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font-size: 13px; text-align: start;
}
.studio-file-open:hover, .studio-project-open:hover { background: var(--surface-hover); }
.studio-file-name, .studio-project-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-file-name { font-family: var(--font-mono); font-size: 12.5px; }
.studio-mini { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: var(--text-3); flex: none; }
.studio-mini:hover { background: var(--surface-hover); color: var(--text); }
.studio-new { height: 30px; font-size: 12px; max-width: 150px; }
.studio-main { position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.studio-generate { display: flex; gap: 8px; }
.studio-idea { flex: 1; min-width: 0; height: 38px; }
/* An empty box follows the page's direction (dir="auto" reads it as left-to-right), so a long Arabic hint is cut at its end. */
[dir='rtl'] .studio-idea:placeholder-shown { direction: rtl; text-align: right; }
.studio-filebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.studio-lang-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600;
}
.studio-lang-btn:hover { border-color: var(--border-strong); }
.studio-status { min-width: 0; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-code {
  flex: 1; min-height: 0; display: flex; overflow: hidden; border-radius: 16px; border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--code-bg); direction: ltr;
}
.studio-gutter {
  flex: none; min-width: 44px; padding: 14px 8px; overflow: hidden; white-space: pre; text-align: right; user-select: none;
  font: 13px/1.65 var(--font-mono); color: #4b5675; background: rgba(255, 255, 255, 0.02); border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.studio-editor {
  flex: 1; min-width: 0; padding: 14px 16px; border: 0; outline: none; resize: none; tab-size: 2;
  font: 13px/1.65 var(--font-mono); color: #e6edf3; background: transparent; white-space: pre; overflow: auto;
}
.studio-editor:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent) 50%, transparent); }
.studio-languages {
  position: absolute; inset-inline: 0; top: 92px; bottom: 0; z-index: 2; overflow: auto; padding: 14px; border-radius: 16px;
  border: 1px solid var(--border-strong); background: var(--surface-solid); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.studio-lang-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; margin-bottom: 8px; }
.studio-lang-count { padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-variant-numeric: tabular-nums; }
.studio-lang-search { width: 100%; margin-bottom: 4px; }
.studio-lang-empty { color: var(--text-3); font-size: 13px; margin: 10px 0; }
.studio-lang-group[hidden], .studio-lang[hidden] { display: none !important; }
.studio-lang-group h3 { margin: 10px 0 6px; font-size: 12px; color: var(--text-3); }
.studio-lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.studio-lang {
  position: relative; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600; text-align: start;
}
.studio-lang:hover { border-color: var(--border-strong); }
.studio-lang[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); }
.studio-lang-run { margin-inline-start: auto; color: var(--accent); display: inline-flex; }
@media (max-width: 760px) {
  .studio { padding: 8px; gap: 8px; }
  /* minmax(0, …): a long status line or file name must not widen the column past the screen. */
  .studio-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .studio-side { max-height: 30vh; }
  .studio-btn-label { display: none; }
  .studio-name { order: 3; flex-basis: 100%; max-width: none; }
  .studio-languages { top: 84px; }
}
@media (prefers-reduced-motion: reduce) { .studio { transition: none; } }

/* ================================================================================================ quizzes (quiz.js) */
.quiz-block { margin: 12px 0; }
.quiz-src { display: none !important; }
.quiz-pending { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2); color: var(--text-2); font-size: 14px; }
.quiz-pending .icon { color: var(--accent); flex: none; }
.quiz-block[data-complete='0'] .quiz-pending span:last-child::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-inline-start: 8px; border-radius: 50%; background: var(--accent); animation: quiz-pulse 1s var(--ease) infinite alternate; vertical-align: middle; }
.quiz-block.is-invalid .quiz-pending { border-color: var(--danger-soft); color: var(--danger); }
@keyframes quiz-pulse { from { opacity: 0.25; } to { opacity: 1; } }

.quiz { border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; }
.quiz-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.quiz-badge { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.quiz-heading { flex: 1; min-width: 0; }
.quiz-title { margin: 0; font-size: 15.5px; line-height: 1.4; }
.quiz-meta { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.quiz-save { flex: none; gap: 6px; }
.quiz-save[aria-pressed='true'] { color: var(--success); opacity: 1; }
.quiz-note { margin: 0; padding: 8px 16px; font-size: 12.5px; color: var(--warn); background: var(--warn-soft); }

.md .quiz-list, .quiz-list { list-style: none; margin: 0; padding: 6px 12px 4px; counter-reset: none; }
.quiz-q { padding: 14px 4px; border-bottom: 1px solid var(--border); }
.quiz-q:last-child { border-bottom: 0; }
.quiz-q-text { display: flex; gap: 10px; align-items: baseline; font-weight: 600; line-height: 1.7; margin-bottom: 10px; }
.quiz-num { flex: none; display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--surface-3); color: var(--text-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.quiz-rich { min-width: 0; overflow-wrap: anywhere; }
.quiz-rich p { margin: 0; }
.quiz-options { display: grid; gap: 8px; }
.quiz-options-tf { grid-template-columns: 1fr 1fr; }
.quiz-option {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; line-height: 1.6;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
/* The real radio covers the whole option: one big target, native keyboard and screen-reader behaviour. */
.quiz-option input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; }
.quiz-option:hover { border-color: var(--accent); }
.quiz-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.quiz-option:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
.quiz-options-tf .quiz-option { justify-content: center; font-weight: 600; }
.quiz-letter { flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: 12.5px; font-weight: 700; }
.quiz-option:has(input:checked) .quiz-letter { background: var(--accent); color: var(--accent-contrast); }
.quiz-input { width: 100%; max-width: 420px; }
.quiz-q[data-result] .quiz-option { cursor: default; }
.quiz-q[data-result] .quiz-option:hover { border-color: var(--border-strong); }
/* Marked: these win over the "selected" look (the rules below are more specific than .quiz-option:has(input:checked)). */
.quiz-q[data-result] .quiz-option.is-right { border-color: var(--success); background: var(--success-soft); }
.quiz-q[data-result] .quiz-option.is-right .quiz-letter { background: var(--success); color: #fff; }
.quiz-q[data-result] .quiz-option.is-wrong { border-color: var(--danger); background: var(--danger-soft); }
.quiz-q[data-result] .quiz-option.is-wrong .quiz-letter { background: var(--danger); color: #fff; }
.quiz-q[data-result='correct'] .quiz-input { border-color: var(--success); }
.quiz-q[data-result='wrong'] .quiz-input { border-color: var(--danger); }
.quiz-feedback { display: grid; gap: 4px; margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border-inline-start: 3px solid var(--border-strong); font-size: 13.5px; line-height: 1.7; }
.quiz-q[data-result='correct'] .quiz-feedback { border-inline-start-color: var(--success); }
.quiz-q[data-result='wrong'] .quiz-feedback, .quiz-q[data-result='skipped'] .quiz-feedback { border-inline-start-color: var(--danger); }
.quiz-verdict { display: inline-flex; align-items: center; gap: 6px; }
.quiz-q[data-result='correct'] .quiz-verdict { color: var(--success); }
.quiz-q[data-result='wrong'] .quiz-verdict, .quiz-q[data-result='skipped'] .quiz-verdict { color: var(--danger); }
.quiz-right { font-weight: 600; }
.quiz-explain { color: var(--text-2); }

.quiz-result { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; margin: 0 16px; padding: 14px 16px; border-radius: 14px; background: var(--accent-soft); }
.quiz-score { display: inline-flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quiz[data-graded='great'] .quiz-result { background: var(--success-soft); }
.quiz[data-graded='great'] .quiz-score { color: var(--success); }
.quiz[data-graded='keep'] .quiz-result { background: var(--warn-soft); }
.quiz-cheer { color: var(--text-2); font-size: 13.5px; }
.quiz-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px 14px; }
.quiz-progress { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.quiz-foot .btn { gap: 6px; }
.quiz-check { min-width: 150px; }

/* My quizzes */
.quiz-library { width: min(720px, calc(100vw - 24px)); max-height: min(88vh, 900px); }
.quiz-library[open] { display: flex; flex-direction: column; background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); overflow: hidden; }
.ql-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.ql-title { flex: 1; display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 17px; }
.ql-title .icon { color: var(--accent); }
.ql-back { gap: 6px; }
:root[dir='ltr'] .ql-back-icon { transform: scaleX(-1); display: inline-flex; }
.ql-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px; }
.ql-empty { display: grid; justify-items: center; gap: 10px; padding: 36px 16px; text-align: center; color: var(--text-2); }
.ql-empty .icon { color: var(--accent); }
.ql-empty p { max-width: 420px; margin: 0; line-height: 1.8; }
.ql-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ql-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.ql-info { flex: 1; min-width: 0; display: grid; gap: 2px; }
.ql-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ql-meta { color: var(--text-3); font-size: 12.5px; }
.ql-score { color: var(--success); font-size: 12.5px; font-weight: 600; }
.ql-score.is-new { color: var(--text-3); font-weight: 500; }
.ql-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.ql-open { gap: 6px; }
@media (max-width: 560px) {
  .quiz-head { flex-wrap: wrap; }
  .quiz-options-tf { grid-template-columns: 1fr; }
  .ql-item { flex-wrap: wrap; }
  .ql-actions { width: 100%; justify-content: flex-end; }
}
@media (pointer: coarse) {
  .side-link, .quiz-save, .quiz-foot .btn, .ql-actions .btn, .ql-head .btn { min-height: 44px; min-width: 44px; }
}

/* ================================================================================================ documents and slides (docs.js) */
.doc-block { margin: 12px 0; }
.doc-src { display: none !important; }
.doc-pending { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2); color: var(--text-2); font-size: 14px; }
.doc-pending .icon { color: var(--accent); flex: none; }
.doc-block[data-complete='0'] .doc-pending span:last-child::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-inline-start: 8px; border-radius: 50%; background: var(--accent); animation: quiz-pulse 1s var(--ease) infinite alternate; vertical-align: middle; }
.doc-block.is-invalid .doc-pending { color: var(--danger); }
.doc-card { border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; }
.doc-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.doc-badge { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.doc-heading { min-width: 0; }
.doc-title { margin: 0; font-size: 15.5px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.doc-frame-wrap { background: #dfe5ee; }
.doc-frame { display: block; width: 100%; height: 320px; border: 0; background: #dfe5ee; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.doc-action { gap: 6px; }
.doc-present, .doc-open { color: var(--accent); }
.doc-print-frame { position: fixed; inset-inline-end: 0; bottom: 0; width: 800px; height: 600px; border: 0; opacity: 0; pointer-events: none; z-index: -1; }

.doc-viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #050914; color: #e8ecf8; }
.doc-viewer[open] { display: flex; flex-direction: column; }
.doc-viewer::backdrop { background: #050914; }
.doc-viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(8px + var(--safe-top)); background: rgba(255, 255, 255, 0.04); border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.doc-viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.doc-vbtn { color: #e8ecf8; }
.doc-vbtn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); color: #fff; }
.doc-vbtn:disabled { opacity: 0.35; }
.doc-nav { display: inline-flex; align-items: center; gap: 4px; }
.doc-counter { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; direction: ltr; }
.doc-viewer-stage { flex: 1; min-height: 0; display: flex; }
.doc-viewer-stage .doc-frame { flex: 1; height: auto; background: #dfe5ee; }
.doc-viewer.is-slides .doc-viewer-stage .doc-frame { background: #050914; }
@media (max-width: 560px) {
  .doc-action span:last-child { display: none; }
  .doc-action { min-width: 44px; justify-content: center; }
  .doc-counter { min-width: 48px; }
}
@media (pointer: coarse) {
  .doc-action, .doc-vbtn { min-height: 44px; min-width: 44px; }
}
.plan-usage[data-level='own'] { color: var(--success); }
