/* ═══════════════════════════════════════════
   PyTrainer – Premium Dark Learning Platform
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── Design Tokens ─── */
:root {
  --bg-deepest: #0a0a0f;
  --bg-deep: #10101a;
  --bg-card: #161625;
  --bg-card-hover: #1c1c30;
  --bg-elevated: #1e1e32;
  --bg-input: #12121e;

  --border-subtle: rgba(255,255,255,0.06);
  --border-accent: rgba(139,92,246,0.3);

  --text-primary: #e8e6f0;
  --text-secondary: #9896a8;
  --text-muted: #5c5a6e;

  --accent-violet: #8b5cf6;
  --accent-violet-light: #a78bfa;
  --accent-violet-dim: rgba(139,92,246,0.15);
  --accent-emerald: #10b981;
  --accent-emerald-dim: rgba(16,185,129,0.15);
  --accent-rose: #f43f5e;
  --accent-rose-dim: rgba(244,63,94,0.15);
  --accent-amber: #f59e0b;
  --accent-amber-dim: rgba(245,158,11,0.15);
  --accent-cyan: #06b6d4;
  --accent-cyan-dim: rgba(6,182,212,0.15);

  --gradient-hero: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 50%, #10b981 100%);
  --gradient-card: linear-gradient(145deg, rgba(139,92,246,0.08), rgba(6,182,212,0.04));

  --shadow-glow: 0 0 40px rgba(139,92,246,0.15);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.4);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deepest);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Subtle Background Pattern ─── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 20% 10%, rgba(139,92,246,0.06), transparent),
    radial-gradient(ellipse 500px 500px at 80% 80%, rgba(6,182,212,0.04), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ─── Main Layout ─── */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* ─── Header ─── */
.app-header {
  padding: 32px 0 24px;
  text-align: center;
}

.app-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.app-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 6px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
}

.auth-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-section span {
  font-size: 0.9rem;
  color: var(--accent-emerald);
  font-weight: 600;
}

.hidden {
  display: none !important;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 90%;
  max-width: 400px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: fadeSlideUp 0.3s ease;
}

.modal-content h2 { margin-bottom: 12px; font-size: 1.5rem; text-align: center; }
.modal-content p { color: var(--text-secondary); margin-bottom: 24px; text-align: center; font-size: 0.9rem; }

.auth-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  margin-bottom: 12px;
  outline: none;
}
.auth-input:focus { border-color: var(--accent-violet); }

.auth-error {
  color: var(--accent-rose);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 12px;
  background: var(--accent-rose-dim);
  padding: 8px;
  border-radius: 4px;
}

.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer;
}
.modal-close:hover { color: var(--text-primary); }

/* ─── Exercise Selector ─── */
.exercise-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 16px 0 24px;
}

.exercise-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.exercise-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.exercise-btn.active {
  background: var(--accent-violet);
  border-color: var(--accent-violet);
  color: #fff;
  box-shadow: 0 0 20px rgba(139,92,246,0.4);
}

.exercise-btn.completed::after {
  content: '✓';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  background: var(--accent-emerald);
  border-radius: 50%;
  font-size: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* ─── Exercise Card ─── */
.exercise-card {
  background: var(--gradient-card);
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  animation: fadeSlideUp 0.4s ease;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.exercise-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.exercise-description {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.7;
  margin-bottom: 20px;
}

/* ─── Stage Tabs ─── */
.stage-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-deep);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.stage-tab {
  flex: 1;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-smooth);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.stage-tab:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}

.stage-tab.active {
  background: var(--accent-violet-dim);
  color: var(--accent-violet-light);
}

.stage-tab .tab-icon {
  font-size: 1rem;
}

.stage-tab .tab-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  font-size: 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stage-tab.active .tab-num {
  background: var(--accent-violet);
  color: #fff;
}

/* ─── Stage Content Panels ─── */
.stage-panel {
  display: none;
  animation: fadeIn 0.3s ease;
}
.stage-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── Stage 1: Theory ─── */
.theory-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.theory-section h3 {
  font-size: 1.05rem;
  color: var(--accent-cyan);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theory-section p,
.theory-section li {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.8;
}

.theory-section ul {
  padding-left: 20px;
  margin: 10px 0;
}

.theory-section li {
  margin-bottom: 6px;
}

.concept-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  margin: 2px;
}

.concept-tag.loop { background: var(--accent-violet-dim); color: var(--accent-violet-light); }
.concept-tag.condition { background: var(--accent-amber-dim); color: var(--accent-amber); }
.concept-tag.input { background: var(--accent-cyan-dim); color: var(--accent-cyan); }
.concept-tag.math { background: var(--accent-emerald-dim); color: var(--accent-emerald); }
.concept-tag.string { background: var(--accent-rose-dim); color: var(--accent-rose); }

.code-hint {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent-emerald);
  overflow-x: auto;
}

/* ─── Stage 2: Parsons Problem ─── */
.parsons-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.parsons-instruction {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.parsons-blocks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 100px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-smooth);
}

.parsons-blocks.drag-over {
  border-color: var(--accent-violet);
  background: rgba(139,92,246,0.03);
}

.parsons-block {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
  cursor: grab;
  transition: all var(--transition-smooth);
  user-select: none;
  position: relative;
}

.parsons-block:active { cursor: grabbing; }

.parsons-block:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
  transform: translateX(4px);
}

.parsons-block.correct {
  border-color: var(--accent-emerald);
  background: var(--accent-emerald-dim);
}

.parsons-block.incorrect {
  border-color: var(--accent-rose);
  background: var(--accent-rose-dim);
  animation: shake 0.4s ease;
}

.parsons-block.indent-1 { margin-left: 30px; }
.parsons-block.indent-2 { margin-left: 60px; }

/* drag ghost */
.parsons-block.sortable-ghost {
  opacity: 0.4;
  background: var(--accent-violet-dim);
  border-color: var(--accent-violet);
}

.parsons-block.sortable-chosen {
  box-shadow: 0 8px 30px rgba(139,92,246,0.3);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ─── Stage 3: Code Editor ─── */
.editor-wrapper {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-input);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-subtle);
}

.editor-toolbar .lang-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-amber);
  background: var(--accent-amber-dim);
  padding: 3px 10px;
  border-radius: 99px;
  font-weight: 600;
}

#code-editor {
  width: 100%;
  min-height: 240px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 16px;
  resize: vertical;
  outline: none;
  tab-size: 4;
}

#code-editor::placeholder {
  color: var(--text-muted);
}

.output-panel {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-top: 12px;
  overflow: hidden;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#output-content {
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent-emerald);
  min-height: 60px;
  white-space: pre-wrap;
  word-break: break-all;
}

#output-content.error {
  color: var(--accent-rose);
}

/* Input prompt area */
.input-prompt-area {
  display: none;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  align-items: center;
  gap: 8px;
}

.input-prompt-area.visible {
  display: flex;
}

.input-prompt-area label {
  color: var(--accent-amber);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: nowrap;
}

.input-prompt-area input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  outline: none;
}

.input-prompt-area input:focus {
  border-color: var(--accent-violet);
}

/* ─── Stage 4: Paper Mode ─── */
.paper-mode {
  background: #fefdf8;
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  color: #1a1a1a;
  font-family: 'Georgia', serif;
  position: relative;
  box-shadow: 0 2px 20px rgba(0,0,0,0.3);
}

.paper-mode::before {
  content: '';
  position: absolute;
  left: 60px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(244, 63, 94, 0.15);
}

.paper-mode h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: #333;
}

.paper-mode .task-text {
  font-size: 0.95rem;
  line-height: 2;
  color: #444;
}

.paper-mode .paper-lines {
  margin-top: 24px;
  min-height: 200px;
  background-image: repeating-linear-gradient(
    transparent,
    transparent 31px,
    rgba(6,182,212,0.12) 31px,
    rgba(6,182,212,0.12) 32px
  );
  background-size: 100% 32px;
  padding-top: 8px;
}

.paper-mode textarea {
  width: 100%;
  min-height: 200px;
  background: transparent;
  border: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 32px;
  color: #222;
  resize: vertical;
  outline: none;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.btn-primary {
  background: var(--accent-violet);
  color: #fff;
  box-shadow: 0 2px 12px rgba(139,92,246,0.3);
}
.btn-primary:hover {
  background: var(--accent-violet-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(139,92,246,0.4);
}

.btn-success {
  background: var(--accent-emerald);
  color: #fff;
  box-shadow: 0 2px 12px rgba(16,185,129,0.3);
}
.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(16,185,129,0.4);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.btn-outline:hover {
  border-color: var(--border-accent);
  color: var(--text-primary);
  background: rgba(255,255,255,0.03);
}

.btn-danger {
  background: var(--accent-rose);
  color: #fff;
}

.btn-group {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ─── Progress Bar ─── */
.progress-bar-wrapper {
  margin: 8px 0 16px;
}

.progress-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-bar-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--gradient-hero);
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Toast Notifications ─── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  z-index: 999;
  opacity: 0;
  transform: translateY(20px);
  transition: all var(--transition-smooth);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { background: var(--accent-emerald); box-shadow: 0 4px 20px rgba(16,185,129,0.4); }
.toast.error { background: var(--accent-rose); box-shadow: 0 4px 20px rgba(244,63,94,0.4); }
.toast.info { background: var(--accent-violet); box-shadow: 0 4px 20px rgba(139,92,246,0.4); }

/* ─── Loading Spinner ─── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Pyodide loading overlay ─── */
.pyodide-loading {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pyodide-loading .spinner {
  width: 32px;
  height: 32px;
  border-color: var(--border-subtle);
  border-top-color: var(--accent-violet);
  margin: 0 auto 12px;
}

/* ─── AI Chat Toggle Button ─── */
.ai-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  border: none;
  border-radius: 99px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(139,92,246,0.4);
  transition: all var(--transition-smooth);
}

.ai-chat-toggle:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 32px rgba(139,92,246,0.5);
}

.ai-chat-toggle.hidden { display: none; }

.ai-chat-icon { font-size: 1.2rem; }

/* ─── AI Chat Panel ─── */
.ai-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  max-height: 520px;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-xl);
  box-shadow: 0 12px 48px rgba(0,0,0,0.5), 0 0 40px rgba(139,92,246,0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp 0.3s ease;
}

.ai-chat-panel.open {
  display: flex;
}

@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-subtle);
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
}

.ai-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-emerald);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ai-model-badge {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--accent-violet-dim);
  color: var(--accent-violet-light);
  font-weight: 600;
}

.ai-chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.ai-chat-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

/* Messages */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 380px;
}

.ai-msg {
  display: flex;
  gap: 10px;
  animation: fadeIn 0.3s ease;
}

.ai-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.ai-msg-content {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  line-height: 1.6;
  max-width: 85%;
}

.ai-msg-bot .ai-msg-content {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.ai-msg-user {
  flex-direction: row-reverse;
}

.ai-msg-user .ai-msg-content {
  background: var(--accent-violet);
  color: #fff;
  border-radius: var(--radius-md);
}

.ai-msg-user .ai-msg-avatar {
  background: var(--accent-violet-dim);
}

.ai-typing .ai-msg-content::after {
  content: '●●●';
  animation: typingDots 1.2s infinite;
  letter-spacing: 3px;
  color: var(--text-muted);
}

@keyframes typingDots {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Input area */
.ai-chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-deep);
}

.ai-chat-input input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.ai-chat-input input:focus {
  border-color: var(--accent-violet);
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .app-container { padding: 0 12px 40px; }
  .app-header h1 { font-size: 1.6rem; }
  .exercise-card { padding: 20px; }
  .stage-tabs { gap: 2px; }
  .stage-tab { padding: 8px 8px; font-size: 0.75rem; }
  .paper-mode { padding: 24px 20px; }
  .paper-mode::before { left: 30px; }
  .exercise-btn { width: 36px; height: 36px; font-size: 0.72rem; }
  .ai-chat-panel { width: calc(100vw - 24px); right: 12px; bottom: 12px; }
  .ai-chat-toggle { bottom: 16px; right: 16px; }
}
