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

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --surface-alt: #f0f2f7;
  --border: #e2e6ef;
  --text: #1a1d26;
  --text-dim: #6b7280;
  --text-light: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --primary-bg: #eff6ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --error: #ef4444;
  --error-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --accent: #8b5cf6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --topbar-h: 56px;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  padding-top: var(--topbar-h);
  -webkit-font-smoothing: antialiased;
}

/* ===== Top Bar ===== */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.logo { font-size: 1.5rem; }
.brand { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-alt); padding: 4px 10px;
  border-radius: 20px; font-size: 0.8rem; font-weight: 600;
  color: var(--text-dim);
}
.eli5-btn {
  cursor: pointer; border: 2px solid transparent;
  transition: all 0.2s; user-select: none;
}
.eli5-btn.active {
  background: #fef3c7; color: #92400e;
  border-color: #f59e0b;
}
.eli5-btn:hover { opacity: 0.8; }

/* ELI5 mode styles */
body.eli5-mode .eli5-box {
  background: linear-gradient(135deg, #fef9c3, #fef3c7);
  border-radius: var(--radius-sm); padding: 16px; margin-bottom: 16px;
  border-left: 4px solid #f59e0b; font-size: 1rem; line-height: 1.8;
}
body.eli5-mode .eli5-box .eli5-label {
  font-weight: 700; color: #92400e; margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
body:not(.eli5-mode) .eli5-box { display: none; }

/* ===== Main Content ===== */
#app { max-width: 900px; margin: 0 auto; padding: 20px 16px 100px; }

/* ===== Welcome Page ===== */
.welcome-hero {
  text-align: center; padding: 40px 20px;
  background: linear-gradient(135deg, var(--primary-bg), #f0e7ff);
  border-radius: var(--radius); margin-bottom: 24px;
}
.welcome-hero h1 { font-size: 2rem; margin-bottom: 8px; }
.welcome-hero .tagline { color: var(--text-dim); font-size: 1.1rem; margin-bottom: 24px; }
.start-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff;
  padding: 14px 32px; border-radius: 50px;
  font-size: 1.1rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.start-btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-lg); }

.welcome-section { background: var(--surface); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; box-shadow: var(--shadow); }
.welcome-section h2 { font-size: 1.3rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.welcome-section p, .welcome-section li { color: var(--text-dim); line-height: 1.7; }
.welcome-section ul { list-style: none; padding: 0; }
.welcome-section li { padding: 6px 0; padding-left: 24px; position: relative; }
.welcome-section li::before { content: ""; position: absolute; left: 0; top: 14px; width: 8px; height: 8px; background: var(--primary); border-radius: 50%; }

.example-box {
  background: #1e1e2e; border-radius: var(--radius-sm); padding: 16px; margin: 12px 0;
  font-family: var(--font-mono); font-size: 0.9rem; color: #cdd6f4;
  overflow-x: auto;
}
.example-box .comment { color: #6c7086; }
.example-box .output { color: var(--success); border-top: 1px solid #313244; margin-top: 8px; padding-top: 8px; }

/* ===== Dashboard ===== */
.dashboard-header { margin-bottom: 24px; }
.dashboard-header h1 { font-size: 1.5rem; margin-bottom: 4px; }
.dashboard-header p { color: var(--text-dim); }

.topic-grid { display: grid; gap: 12px; }
.topic-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  cursor: pointer; transition: all 0.2s;
  border: 2px solid transparent;
  display: flex; gap: 16px; align-items: center;
}
.topic-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.topic-card .icon { font-size: 2rem; min-width: 48px; text-align: center; }
.topic-card .info { flex: 1; min-width: 0; }
.topic-card .info h3 { font-size: 1rem; margin-bottom: 2px; }
.topic-card .info p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; }
.progress-bar { height: 6px; background: var(--surface-alt); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--success); border-radius: 3px; transition: width 0.5s ease; }
.progress-text { font-size: 0.75rem; color: var(--text-light); margin-top: 4px; }

/* ===== Topic / Lesson Page ===== */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--primary); font-weight: 600; font-size: 0.9rem;
  cursor: pointer; padding: 8px 0; margin-bottom: 12px;
  background: none; border: none;
}
.back-btn:hover { text-decoration: underline; }

.topic-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.topic-header .icon { font-size: 2.5rem; }
.topic-header h1 { font-size: 1.5rem; }
.topic-header p { color: var(--text-dim); font-size: 0.9rem; }

.tab-bar {
  display: flex; gap: 0; margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.tab {
  padding: 10px 20px; font-weight: 600; font-size: 0.9rem;
  color: var(--text-dim); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all 0.2s;
  background: none; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.lesson-content { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.lesson-section { margin-bottom: 32px; }
.lesson-section:last-child { margin-bottom: 0; }
.lesson-section h3 { font-size: 1.15rem; margin-bottom: 12px; color: var(--text); }
.lesson-section p { margin-bottom: 10px; color: var(--text); line-height: 1.7; }
.lesson-section code { background: var(--surface-alt); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.9em; }
.lesson-section ul, .lesson-section ol { margin: 8px 0; padding-left: 24px; }
.lesson-section li { margin-bottom: 6px; line-height: 1.6; }
.lesson-section strong { color: var(--text); }

.lesson-example {
  background: #1e1e2e; border-radius: var(--radius-sm); margin: 16px 0;
  overflow: hidden;
}
.lesson-example-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; background: #181825; font-size: 0.8rem; color: #a6adc8;
}
.lesson-example pre {
  padding: 16px; font-family: var(--font-mono); font-size: 0.88rem;
  color: #cdd6f4; overflow-x: auto; margin: 0;
}
.lesson-example .output-line {
  color: var(--success); display: block;
  border-top: 1px solid #313244; padding-top: 8px; margin-top: 8px;
}
.lesson-example-explain {
  padding: 12px 16px; background: var(--primary-bg);
  font-size: 0.85rem; color: var(--text-dim); line-height: 1.6;
  border-top: 1px solid var(--border);
}
.try-btn {
  background: var(--primary); color: #fff; border: none;
  padding: 4px 12px; border-radius: 4px; cursor: pointer;
  font-size: 0.8rem; font-weight: 600;
}
.try-btn:hover { background: var(--primary-hover); }

.tips-box, .mistakes-box {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; margin-top: 16px; box-shadow: var(--shadow);
}
.tips-box h3, .mistakes-box h3 { margin-bottom: 12px; }
.tip-item { padding: 8px 0 8px 20px; position: relative; color: var(--text-dim); }
.tip-item::before { content: "💡"; position: absolute; left: 0; }
.mistake-item { padding: 10px; background: var(--error-light); border-radius: var(--radius-sm); margin-bottom: 8px; }
.mistake-item .wrong { color: var(--error); font-family: var(--font-mono); font-size: 0.85rem; }
.mistake-item .right { color: var(--success); font-family: var(--font-mono); font-size: 0.85rem; }
.mistake-fix { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }

/* ===== Exercise List ===== */
.exercise-list { display: grid; gap: 8px; }
.exercise-item {
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: all 0.15s; border: 1px solid var(--border);
}
.exercise-item:hover { border-color: var(--primary); background: var(--primary-bg); }
.exercise-item.completed { border-left: 3px solid var(--success); }
.exercise-num {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  background: var(--surface-alt); color: var(--text-dim);
  flex-shrink: 0;
}
.exercise-item.completed .exercise-num { background: var(--success-light); color: var(--success); }
.exercise-item .info { flex: 1; min-width: 0; }
.exercise-item .info h4 { font-size: 0.9rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exercise-item .diff-dots { display: flex; gap: 3px; }
.diff-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.diff-dot.active { background: var(--warning); }
.exercise-item .check-icon { font-size: 1.2rem; color: var(--success); }

/* ===== Exercise Page ===== */
.exercise-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.exercise-header h2 { font-size: 1.2rem; }
.exercise-meta { display: flex; gap: 8px; align-items: center; }
.diff-badge {
  padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.diff-1 { background: var(--success-light); color: #047857; }
.diff-2 { background: #dbeafe; color: #1d4ed8; }
.diff-3 { background: var(--warning-light); color: #92400e; }
.diff-4 { background: #fce7f3; color: #9d174d; }
.diff-5 { background: var(--error-light); color: #991b1b; }

.exercise-description {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
  line-height: 1.7;
}
.exercise-description code { background: var(--surface-alt); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.9em; }
.exercise-concepts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.concept-tag { background: var(--primary-light); color: var(--primary); padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }

.editor-wrapper {
  background: #1e1e2e; border-radius: var(--radius);
  overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow);
}
.editor-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: #181825;
}
.editor-toolbar span { font-size: 0.8rem; color: #a6adc8; font-family: var(--font-mono); }
.run-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--success); color: #fff;
  padding: 8px 20px; border-radius: 8px;
  font-size: 0.9rem; font-weight: 600;
  border: none; cursor: pointer; transition: all 0.2s;
}
.run-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.output-panel {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow);
  min-height: 60px;
}
.output-header {
  padding: 8px 16px; background: var(--surface-alt);
  font-size: 0.8rem; font-weight: 600; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.output-body { padding: 12px 16px; font-family: var(--font-mono); font-size: 0.85rem; white-space: pre-wrap; }
.output-body.pass { background: var(--success-light); color: #047857; }
.output-body.fail { background: var(--error-light); color: #991b1b; }
.output-body.idle { color: var(--text-light); font-style: italic; font-family: var(--font); }

.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  font-size: 0.85rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--text-dim); transition: all 0.15s;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

.hint-box {
  background: var(--warning-light); border-radius: var(--radius-sm);
  padding: 14px 16px; margin-bottom: 12px;
  font-size: 0.9rem; color: #92400e; line-height: 1.6;
}
.solution-box {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow);
}
.solution-box .editor-toolbar { background: #047857; }
.solution-box .editor-toolbar span { color: #d1fae5; }
.solution-box pre {
  padding: 16px; background: #1e1e2e;
  font-family: var(--font-mono); font-size: 0.85rem; color: #cdd6f4;
  overflow-x: auto; margin: 0;
}

.exercise-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0; border-top: 1px solid var(--border); margin-top: 16px;
}
.nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px;
  font-weight: 600; font-size: 0.9rem;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--text); transition: all 0.15s;
}
.nav-btn:hover { border-color: var(--primary); color: var(--primary); }
.nav-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.nav-btn.primary:hover { background: var(--primary-hover); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== Loading Overlay ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.overlay.hidden { display: none; }
.loader { text-align: center; background: var(--surface); padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.loader p { margin-top: 12px; font-weight: 600; }
.loader .subtle { font-weight: 400; color: var(--text-dim); font-size: 0.85rem; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto;
  border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== CodeMirror Overrides ===== */
.CodeMirror {
  height: auto; min-height: 120px; max-height: 400px;
  font-family: var(--font-mono) !important; font-size: 0.9rem !important;
  line-height: 1.5 !important; padding: 8px 0;
}
.CodeMirror-scroll { min-height: 120px; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  :root { --topbar-h: 48px; }
  #app { padding: 12px 10px 80px; }
  .welcome-hero h1 { font-size: 1.5rem; }
  .welcome-hero { padding: 24px 16px; }
  .topic-card { padding: 14px; }
  .tab { padding: 8px 12px; font-size: 0.8rem; }
  .exercise-header { flex-direction: column; }
  .exercise-nav { flex-direction: column; gap: 8px; }
  .nav-btn { width: 100%; justify-content: center; }
  .lesson-content { padding: 16px; }
  .CodeMirror { font-size: 0.82rem !important; }
}

/* ===== Celebration Toast ===== */
.celebration-toast {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.4);
  animation: fadeIn 0.3s ease;
  backdrop-filter: blur(4px);
}
.celebration-content {
  background: var(--surface); border-radius: 20px;
  padding: 32px 40px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-width: 420px; width: 90%;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.celebration-emoji { font-size: 3rem; margin-bottom: 8px; }
.celebration-msg { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.celebration-milestone {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  padding: 8px 16px; border-radius: 8px; margin-bottom: 12px;
  font-weight: 600; color: #92400e; font-size: 0.9rem;
}
.celebration-stats { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 20px; }
.celebration-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.celebration-actions .start-btn { font-size: 0.95rem; padding: 10px 24px; }
.celebration-actions .action-btn { font-size: 0.85rem; }

/* ===== Shake animation (wrong answer) ===== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.fade-in { animation: fadeIn 0.3s ease; }

/* ===== Pytor Tutor Sidebar ===== */
.tutor-toggle-btn {
  cursor: pointer; border: 2px solid transparent;
  transition: all 0.2s; user-select: none;
  padding: 4px 10px 4px 4px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tutor-toggle-btn.active {
  background: #ede9fe; color: #6d28d9;
  border-color: var(--accent);
}
.tutor-toggle-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  object-fit: cover; display: block;
  background: #e0e7ff;
}

/* Floating Pytor mascot (bottom-right, always-visible invitation) */
.pytor-mascot {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 72px; height: 72px;
  border: none; padding: 0; margin: 0;
  background: radial-gradient(circle at 30% 30%, #fef3c7 0%, #ede9fe 70%);
  border-radius: 50%;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.25), 0 2px 6px rgba(0,0,0,0.08);
  cursor: pointer;
  z-index: 150;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  animation: pytorIdle 4s ease-in-out infinite;
}
.pytor-mascot:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 10px 28px rgba(139, 92, 246, 0.35), 0 4px 10px rgba(0,0,0,0.1);
  animation-play-state: paused;
}
.pytor-mascot:active { transform: translateY(-2px) scale(1.02); }
.pytor-mascot img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  pointer-events: none;
}
@keyframes pytorIdle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.pytor-mascot-bubble {
  position: absolute;
  right: calc(100% + 12px);
  bottom: 10px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px 14px 2px 14px;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  opacity: 0; transform: translateX(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.pytor-mascot.greet .pytor-mascot-bubble {
  opacity: 1; transform: translateX(0);
}
@media (max-width: 768px) {
  .pytor-mascot { width: 60px; height: 60px; right: 14px; bottom: 14px; }
  .pytor-mascot-bubble { display: none; }
}

#tutor-sidebar {
  position: fixed;
  right: 0; top: var(--topbar-h); bottom: 0;
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 90;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -2px 0 12px rgba(0,0,0,0.06);
}
#tutor-sidebar.open { transform: translateX(0); }

#app.tutor-shifted {
  transition: margin-right 0.3s ease;
  margin-right: 340px;
}

.tutor-header {
  display: flex; align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #ede9fe, #fef3c7);
}
.tutor-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  flex-shrink: 0;
}
.tutor-header-title { flex: 1; min-width: 0; }
.tutor-header h3 {
  font-size: 1rem; margin: 0; line-height: 1.2;
  color: #4c1d95;
}
.tutor-header-sub {
  font-size: 0.72rem; color: var(--text-dim);
  display: block; margin-top: 2px;
}
.lesson-modal-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 8px;
  background: #fff;
}
.tutor-close {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text-dim); padding: 4px;
  border-radius: 4px;
}
.tutor-close:hover { background: var(--surface-alt); }

.tutor-chat-area {
  flex: 1; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}

.tutor-empty {
  color: var(--text-light); font-size: 0.85rem;
  text-align: center; padding: 32px 16px;
  line-height: 1.6;
}

.tutor-msg {
  padding: 10px 14px; border-radius: 12px;
  font-size: 0.88rem; line-height: 1.55;
  max-width: 88%; word-wrap: break-word;
  white-space: pre-wrap;
}
.tutor-msg.user {
  align-self: flex-end;
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.tutor-msg.assistant {
  align-self: flex-start;
  background: var(--surface-alt); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.tutor-loading {
  display: flex; gap: 4px; padding: 8px 14px; align-self: flex-start;
}
.tutor-loading span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-light);
  animation: tutorBounce 1.2s infinite;
}
.tutor-loading span:nth-child(2) { animation-delay: 0.2s; }
.tutor-loading span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tutorBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

.tutor-input-area {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.tutor-input-area textarea {
  flex: 1; resize: none; min-height: 38px; max-height: 80px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--font);
  font-size: 0.88rem; line-height: 1.4;
  outline: none;
}
.tutor-input-area textarea:focus { border-color: var(--accent); }

.tutor-send-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 14px; border-radius: 8px;
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.tutor-send-btn:hover { filter: brightness(1.1); }
.tutor-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tutor-controls {
  padding: 8px 12px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.8rem;
}
.tutor-controls label { display: flex; gap: 6px; align-items: center; cursor: pointer; color: var(--text-dim); }
.tutor-clear-btn {
  background: none; border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 6px; font-size: 0.75rem;
  cursor: pointer; color: var(--text-dim);
}
.tutor-clear-btn:hover { border-color: var(--error); color: var(--error); }

/* Tutor button variant in exercise action bar */
.action-btn.tutor-ask {
  background: #ede9fe; color: #6d28d9;
  border-color: #c4b5fd;
}
.action-btn.tutor-ask:hover { background: #ddd6fe; border-color: var(--accent); }

/* ===== Lesson Modal ===== */
.lesson-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 200; backdrop-filter: blur(4px);
}
.lesson-modal.open { display: flex; }

.lesson-modal-content {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; width: 90%; max-width: 800px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.lesson-modal-content h2 { font-size: 1.2rem; margin-bottom: 16px; }

.lesson-input-row {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.lesson-input-row input {
  flex: 1; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 0.95rem; font-family: var(--font);
  outline: none;
}
.lesson-input-row input:focus { border-color: var(--accent); }

.lesson-status {
  font-size: 0.85rem; color: var(--text-dim); padding: 8px 0;
}

#lesson-iframe {
  width: 100%; height: 500px;
  border: 1px solid var(--border); border-radius: 8px;
  margin-top: 12px;
}

/* ===== Tutor Responsive ===== */
@media (max-width: 768px) {
  #tutor-sidebar { width: 100%; }
  #app.tutor-shifted { margin-right: 0; }
}

/* ===== Playground ===== */
.pg-nav-btn { cursor: pointer; border: 1px solid var(--border); background: var(--surface); }
.pg-nav-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

.pg-toolbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.pg-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.pg-tab {
  font-family: var(--font-mono); font-size: 0.8rem;
  padding: 6px 12px; border-radius: 8px 8px 0 0;
  border: 1px solid var(--border); border-bottom: none;
  background: var(--surface-alt); color: var(--text-dim); cursor: pointer;
}
.pg-tab.active { background: #1e1e2e; color: #cdd6f4; border-color: #1e1e2e; }
.pg-tab-add { background: var(--surface); }
.pg-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pg-tools .action-btn { padding: 6px 12px; }
.pg-select {
  padding: 6px 10px; border-radius: 8px; font-size: 0.85rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
}
.pg-run-group { display: inline-flex; gap: 8px; align-items: center; }
.pg-run-group .action-btn { background: #313244; color: #cdd6f4; border-color: #45475a; }
.pg-run-group .action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pg-io { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-bottom: 12px; }
.pg-io-col {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.pg-stdin {
  border: none; resize: vertical; min-height: 160px; padding: 12px 16px;
  font-family: var(--font-mono); font-size: 0.85rem;
  background: var(--surface); color: var(--text); outline: none; width: 100%;
}
.pg-output {
  min-height: 160px; max-height: 420px; overflow: auto;
  background: #1e1e2e; color: #cdd6f4; margin: 0;
  font-style: normal; font-family: var(--font-mono);
}
.pg-output.idle { color: #7f849c; font-style: italic; font-family: var(--font); }
.pg-output .pg-err { color: #f38ba8; }
.pg-status { float: right; font-weight: 400; font-style: italic; color: var(--text-light); }

@media (max-width: 720px) {
  .pg-io { grid-template-columns: 1fr; }
  .pg-stdin { min-height: 90px; }
}
