/* ========== MathTalking Theme ========== */
/* Adapted from terreflow/lyncius/assets/mvp-theme.css */

/* ── Variables ── */
:root {
  --text-main: #111;
  --text-sec: #444;
  --text-ter: #999;
  --border: #e5e7eb;
  --radius: 16px;
  --font-sans: 'Inter', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --color-primary: #1d4ed8;
  --color-primary-hover: #1e40af;
  --color-success: #059669;
  --color-error: #dc2626;
  --nav-height: 56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  background: #f8fafc;
  padding-top: var(--nav-height);
  -webkit-font-smoothing: antialiased;
}

/* ── Global Nav ── */
.global-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: #fff;
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
}

.nav-inner {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-slogan {
  font-size: 13px;
  color: var(--text-ter);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-hamburger { display: none; } /* hidden on desktop */
.nav-mobile-menu { display: none; } /* hidden on desktop, shown on mobile via .open */

.lang-select {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-sec);
  cursor: pointer;
  outline: none;
}

.lang-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
}

/* ── Buttons ── */
.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  min-width: 64px;
  text-align: center;
}

.btn-nav {
  background: #fff;
  color: var(--text-main);
  border: 1px solid var(--border);
  text-decoration: none;
}
.btn-nav:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.btn-nav-active {
  background: #eff6ff;
  color: #2563eb;
  border-color: #93c5fd;
}

.btn-login {
  background: var(--color-primary);
  color: #fff;
}
.btn-login:hover {
  background: var(--color-primary-hover);
}

/* ── Login Modal ── */
.login-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.login-modal {
  background: #fff; border-radius: 16px; padding: 32px;
  max-width: 380px; width: 90%; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 24px; color: #666; cursor: pointer;
}
.login-title { font-size: 20px; font-weight: 600; margin: 0 0 8px; text-align: center; }
.login-subtitle { font-size: 14px; color: #666; margin: 0 0 24px; text-align: center; }
.login-buttons { display: flex; flex-direction: column; gap: 12px; }
.login-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px; border-radius: 8px; border: 1px solid #ddd;
  font-size: 15px; font-weight: 500; cursor: pointer; transition: background 0.15s;
}
.login-btn-google { background: #fff; color: #333; }
.login-btn-google:hover { background: #f5f5f5; }
.login-btn-apple { background: #000; color: #fff; border-color: #000; }
.login-btn-apple:hover { background: #222; }

/* ── Nav User Avatar ── */
.nav-user { position: relative; }
.nav-avatar {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--color-primary);
  cursor: pointer; background: var(--color-primary); padding: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.nav-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.nav-avatar-letter { color: #fff; font-size: 14px; font-weight: 600; }
.nav-user-dropdown {
  position: absolute; top: 40px; right: 0; background: #fff;
  border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  min-width: 180px; padding: 12px 0; z-index: 100;
}
.nav-user-info { padding: 4px 16px; font-weight: 500; font-size: 14px; }
.nav-user-tier { padding: 2px 16px; font-size: 12px; color: #888; }
.nav-user-dropdown hr { border: none; border-top: 1px solid #eee; margin: 8px 0; }
.nav-user-action {
  display: block; width: 100%; text-align: left; padding: 8px 16px;
  background: none; border: none; font-size: 14px; cursor: pointer; color: #333;
}
.nav-user-action:hover { background: #f5f5f5; }

/* Function input row */
.func-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.func-add-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--color-primary);
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.func-add-btn:hover { background: var(--color-primary-hover); }

.func-empty {
  font-size: 12px;
  color: var(--text-ter);
  text-align: center;
  padding: 16px 8px;
}

.func-item {
  padding-bottom: 4px;
  border-bottom: 1px solid #f3f4f6;
}
.func-item:last-of-type { border-bottom: none; }

.func-label {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Layout ── */
.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
}

.grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}

.left-panels {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Height driven by grid row = graph card height. No viewport calc. */
}

.right-col {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: start;
}

/* Info / description card above graph */
.info-card {
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-sec);
}

.seo-content {
  grid-column: 1 / -1;
  grid-row: 2;
}

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #aaa;
  margin-bottom: 12px;
}

/* ── Function Card ── */
.func-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.func-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

/* Function row */
.func-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.func-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.func-color-dot:hover { transform: scale(1.2); }

.func-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #fafafa;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.func-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
  background: #fff;
}
.func-input.has-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.1);
}

.func-preview {
  font-size: 12px;
  padding: 2px 0 0 22px;
  color: var(--text-sec);
  min-height: 20px;
}

.func-error {
  font-size: 11px;
  color: var(--color-error);
  padding: 2px 0 0 22px;
}

.param-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 22px;
  font-size: 13px;
}
.param-play-btn {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border: none;
  border-radius: 50%;
  background: #f3f4f6;
  color: var(--text-sec);
  font-size: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  letter-spacing: -2px;
  padding-left: 2px;
}
.param-play-btn:hover { background: #e5e7eb; }
.param-play-btn.playing {
  background: #eff6ff;
  color: var(--color-primary);
  font-size: 7px;
  letter-spacing: -1px;
  padding-left: 0;
}
.param-label {
  min-width: 16px;
  font-weight: 500;
  color: var(--text-sec);
  font-family: 'KaTeX_Math', serif;
  font-style: italic;
  font-size: 13px;
}
.param-slider {
  flex: 1;
  max-width: 180px;
  height: 4px;
  accent-color: var(--color-primary, #2563eb);
  cursor: pointer;
}
.param-value {
  min-width: 32px;
  text-align: right;
  font-size: 11px;
  color: var(--text-ter);
  font-variant-numeric: tabular-nums;
}

.func-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-ter);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.func-btn:hover {
  background: #f3f4f6;
  color: var(--text-sec);
}
.func-btn.hidden-state {
  opacity: 0.4;
}

/* ── Chat Card ── */
.chat-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-thread {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding-right: 4px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.6;
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 88%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chat-msg.user {
  background: #f3f4f6;
  color: var(--text-main);
  align-self: flex-end;
  border-radius: 10px 10px 2px 10px;
}

.chat-msg.assistant {
  background: #f0f2ff;
  color: #333;
  align-self: flex-start;
  border: 1px solid #e0e4f8;
  border-radius: 10px 10px 10px 2px;
}

/* Thinking indicator — shown before first text arrives */
.thinking-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-ter);
  font-size: 13px;
  padding: 8px 12px;
}
.thinking-bubble .thinking-dots {
  display: inline-flex;
  gap: 3px;
}
.thinking-bubble .thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-ter);
  animation: thinking-bounce 1.2s ease-in-out infinite;
}
.thinking-bubble .thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-bubble .thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Hide the old empty streaming dots */
.chat-msg.streaming:empty::after { content: none; }

/* Tool status bubble: ephemeral "Plotting graph..." indicator in chat */
.tool-status-bubble {
  font-size: 13px;
  color: #6b7280;
  padding: 6px 14px;
  animation: pulse-text 1.5s ease-in-out infinite;
}
@keyframes pulse-text {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Tool-active: graph container border glow while AI is updating */
.graph-container.tool-active {
  box-shadow: inset 0 0 0 2px var(--color-primary);
  animation: pulse-border 1.5s ease-in-out infinite;
}
@keyframes pulse-border {
  0%, 100% { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--color-primary) 30%, transparent); }
  50% { box-shadow: inset 0 0 0 2px var(--color-primary); }
}

/* KaTeX in chat */
.chat-msg .katex { font-size: 1em; }
.chat-msg .katex-display { margin: 8px 0; overflow-x: auto; }

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: #f9fafb;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
  background: #fff;
}

.chat-send-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 100px;
  border: none;
  background: #1f2937;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.chat-send-btn:hover { background: #111827; }
.chat-send-btn:disabled { opacity: 0.4; pointer-events: none; }
.chat-input:disabled { opacity: 0.6; }

/* ── Graph Card ── */
.graph-card {
  padding: 0;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.graph-header-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-ter);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* Function pills in graph header */
.graph-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.graph-pills::-webkit-scrollbar { display: none; }

.graph-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 6px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: #fff;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-main);
  white-space: nowrap;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}
.graph-pill:hover { background: #f9fafb; }
.graph-pill.pill-hidden { opacity: 0.35; }

.pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.graph-container {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  background: #fff;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Floating toolbar */
.graph-toolbar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  color: var(--text-main);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.92);
}

/* ── SEO Content ── */
.seo-content {
  padding: 16px 4px;
}
.seo-content h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}
.seo-content p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-sec);
  margin-bottom: 16px;
}

/* ── Ad Slots ── */
.ad-slot {
  min-height: 90px;
  background: #fafafa;
  border: 1px dashed #ddd;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Color Picker Popover ── */
.color-picker {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(4, 24px);
  gap: 4px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 20;
}
.color-picker-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.color-picker-swatch:hover { transform: scale(1.15); }
.color-picker-swatch.active { border-color: var(--text-main); }

/* ========== Responsive ========== */

/* Tablet: single column */
@media (max-width: 1100px) {
  .grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .left-panels {
    display: contents;
  }
  .right-col {
    display: contents;
  }

  /* Reorder: info first, then graph, then func list, then chat, then SEO */
  .info-card    { order: 0; }
  .graph-card   { order: 1; }
  .func-card    { order: 2; }
  .chat-card    { order: 3; min-height: 300px; max-height: 400px; }
  .seo-content  { order: 4; }

  .chat-thread { min-height: 200px; }
}

/* Small tablet */
@media (max-width: 768px) {
  .nav-slogan { display: none; }
  .btn-nav { display: none; }
  .wrap { padding: 16px; }
  .card { padding: 16px; }
  .nav-inner { padding: 0 16px; }
  .chat-card { max-height: 360px; }
  .chat-thread { min-height: 180px; max-height: 220px; }
}

/* Mobile */
@media (max-width: 480px) {
  :root { --nav-height: 48px; }
  .wrap { padding: 12px; }
  .card { padding: 14px; }
  .grid { gap: 12px; }
  .graph-container { aspect-ratio: 4 / 5; }
  .nav-logo { font-size: 16px; }

  .btn-nav, .nav-slogan { display: none; }
  .btn-login { font-size: 12px; padding: 4px 12px; }

  /* Hamburger toggle */
  .nav-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: none; border: none; cursor: pointer;
    flex-direction: column; gap: 5px;
  }
  .nav-hamburger span {
    display: block; width: 20px; height: 2px;
    background: var(--text-main); border-radius: 1px;
    transition: transform 0.2s, opacity 0.2s;
  }
  .nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-hamburger.open span:nth-child(2) { opacity: 0; }
  .nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* Mobile menu dropdown */
  .nav-mobile-menu {
    display: none;
    position: absolute; top: var(--nav-height); left: 0; right: 0;
    background: #fff; border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding: 8px 16px; z-index: 90;
    flex-direction: column; gap: 4px;
  }
  .nav-mobile-menu.open { display: flex; }
  .nav-mobile-menu a {
    display: block; padding: 10px 12px; border-radius: 8px;
    color: var(--text-main); text-decoration: none; font-size: 15px; font-weight: 500;
  }
  .nav-mobile-menu a:hover { background: #f1f5f9; }
  .nav-mobile-menu a.mobile-active { color: var(--color-primary); background: #eff6ff; }

  .toolbar-btn { width: 28px; height: 28px; font-size: 14px; }

  .func-input { font-size: 12px; padding: 5px 8px; }
  .chat-input { font-size: 12px; padding: 7px 12px; }
  .chat-msg { font-size: 12px; padding: 6px 10px; }

  .seo-content h2 { font-size: 16px; }
  .seo-content p { font-size: 13px; }
}

/* ── Voice Controls ── */
.mic-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 100px;
  border: none;
  background: #f3f4f6;
  color: var(--text-sec);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  position: relative;
}
.mic-btn:hover { background: #e5e7eb; }

.mic-btn.recording {
  background: #fef2f2;
  color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.1); }
}

.mic-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Voice mode active (not recording, waiting for turn) */
.mic-btn.voice-mode {
  background: #eff6ff;
  color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
}
.mic-btn.voice-mode:hover {
  background: #dbeafe;
}

/* ── Lesson Content (inside info-card) ── */
.lesson-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.lesson-subheading {
  font-size: 13px;
  color: var(--text-ter);
  margin-bottom: 12px;
}

.lesson-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-sec);
}

.lesson-body p {
  margin-bottom: 8px;
}
.lesson-body p:last-child {
  margin-bottom: 0;
}

.katex-static {
  font-family: 'KaTeX_Math', serif;
  font-style: italic;
  white-space: nowrap;
}

/* FAQ (inside seo-content) */
.faq-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: #fff;
  overflow: hidden;
}

.faq-item summary {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.faq-item summary::before {
  content: '▸';
  font-size: 12px;
  color: var(--text-ter);
  transition: transform 0.15s;
}

.faq-item[open] summary::before {
  transform: rotate(90deg);
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-answer {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-sec);
  padding: 0 18px 16px;
}

.faq-answer .katex-static {
  font-size: 14px;
}

/* Related lessons */
.lesson-related {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.lesson-related h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 12px;
}

.lesson-related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lesson-link {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px;
  color: var(--color-primary);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.lesson-link:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
}

/* ── Scrollbar ── */
.func-list::-webkit-scrollbar,
.chat-thread::-webkit-scrollbar {
  width: 4px;
}
.func-list::-webkit-scrollbar-thumb,
.chat-thread::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

/* ── Stat page data card ── */
.stat-data-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.stat-data-textarea {
  width: 100%;
  min-height: 120px;
  max-height: 200px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
  background: #fafbfc;
  box-sizing: border-box;
}
.stat-data-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.stat-run-btn {
  align-self: flex-end;
  padding: 6px 20px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.stat-run-btn:hover { background: #1d4ed8; }
.stat-summary {
  font-size: 12px;
  color: var(--text-sec);
  line-height: 1.6;
}
.stat-summary table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}
.stat-summary td {
  padding: 2px 8px;
  border-bottom: 1px solid var(--border);
}
.stat-summary td:first-child {
  font-weight: 500;
  color: var(--text-main);
}

/* ── Classes page layout ── */
.classes-grid {
  grid-template-columns: 280px 1fr;
  grid-template-rows: 1fr;
  min-height: calc(100vh - var(--nav-height) - 32px); /* match math page viewport height */
}
.classes-grid .left-panels {
  align-self: stretch;
  position: sticky;
  top: calc(var(--nav-height) + 16px);
  max-height: calc(100vh - var(--nav-height) - 32px);
  overflow-y: auto;
}
.classes-toc-card {
  padding: 16px;
}
.classes-toc {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* Category buttons in ToC */
.toc-cat-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.toc-cat-btn:hover { background: #f0f4ff; }
.toc-cat-btn.toc-active { background: #eff6ff; color: #2563eb; }
.toc-cat-btn.toc-disabled { color: #bbb; cursor: default; font-weight: 500; }
.toc-cat-btn.toc-disabled:hover { background: transparent; }
.toc-soon { font-size: 10px; color: #ccc; margin-left: 4px; font-weight: 400; }

/* Lesson links within a category */
.toc-lessons {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: 8px;
  overflow: hidden;
  max-height: 500px;
  transition: max-height 0.3s ease;
}
.toc-lessons.toc-collapsed { max-height: 0; padding: 0 0 0 8px; }
.toc-lesson {
  display: block;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-sec);
  font-size: 13px;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
}
.toc-lesson:hover { background: #eff6ff; color: #2563eb; }

/* Category heading in right panel */
.class-cat-heading {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin: 12px 0 4px;
}
.classes-grid .right-col {
  align-self: stretch;
}
.classes-grid .info-card {
  min-height: auto;
  flex-grow: 1;
  justify-content: flex-start;
}
.classes-grid .classes-toc-card {
  height: 100%;
  box-sizing: border-box;
}
@media (max-width: 768px) {
  .classes-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .classes-grid .left-panels {
    position: static;
    max-height: none;
  }
}

/* ── Classes page cards ── */
.class-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
@media (max-width: 600px) {
  .class-list { grid-template-columns: 1fr; }
}

.class-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #f8f9fa;
  border: 1px solid #e5e7eb;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.class-card:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.class-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 40px;
  text-align: center;
}

.class-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.class-title {
  font-weight: 600;
  font-size: 15px;
  color: #1d1d1f;
}

.class-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.3;
}

.class-level {
  font-size: 11px;
  color: #2563eb;
  font-weight: 500;
  margin-top: 2px;
}

.class-coming-soon {
  text-align: center;
  color: #999;
  font-size: 13px;
  margin-top: 16px;
  font-style: italic;
}
