/* ── Base CSS — Tawfik AI Tutoring Framework (Cheerful Light Theme) ────── */
:root {
  /* Backgrounds: warm off-white */
  --bg:          #f8f7f4;
  --bg2:         #ffffff;
  --bg3:         #f0eee9;

  /* Borders & Shadows */
  --border:      #e2dfd8;
  --shadow:      0 2px 12px rgba(120,100,80,.07);
  --shadow-md:   0 6px 24px rgba(120,100,80,.10);
  --shadow-lg:   0 12px 40px rgba(120,100,80,.14);

  /* Primary: vibrant purple */
  --primary:     #7c3aed;
  --primary-h:   #6d28d9;
  --primary-light: rgba(124,58,237,.08);
  --primary-glow:  rgba(124,58,237,.18);

  /* Accent: warm orange (gamification) */
  --gold:        #ff9500;
  --gold-dim:    #e08600;
  --gold-glow:   rgba(255,149,0,.15);

  /* Text */
  --text:        #2d2a26;
  --muted:       #8c857a;
  --text-inv:    #ffffff;

  /* Semantic */
  --danger:      #ef4444;
  --success:     #10b981;
  --warn:        #f59e0b;
  --info:        #06b6d4;

  /* Knowledge levels */
  --level-course:  #7c3aed;
  --level-module:  #ec4899;
  --level-topic:   #3b82f6;
  --level-lesson:  #10b981;

  /* Gamification */
  --xp-gradient: linear-gradient(90deg, #ff9500, #ff6b00);

  /* Layout */
  --radius:      16px;
  --radius-sm:   10px;
  --radius-lg:   24px;

  /* Animation easings */
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Keyframe Animations ─────────────────────────────────────────────── */
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes popupBounce {
  0%   { transform: translateY(30px) scale(.8); opacity: 0; }
  60%  { transform: translateY(-5px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}
@keyframes modalEnter {
  from { transform: scale(.92) translateY(12px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}
@keyframes bubbleIn {
  from { transform: translateY(8px) scale(.96); opacity: 0; }
  to   { transform: translateY(0) scale(1);     opacity: 1; }
}
@keyframes fadeSlideIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes xpShimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(0,0,0,.04);
  position: sticky; top: 0; z-index: 100;
}
.topbar-brand { display: flex; align-items: baseline; gap: .5rem; }
.brand-name   {
  font-size: 1.2rem; font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-sub    { font-size: .75rem; color: var(--muted); }
.topbar-nav   { display: flex; align-items: center; gap: .75rem; }
.nav-user     { font-size: .82rem; color: var(--muted); font-weight: 600; }
.nav-link     { color: var(--text); text-decoration: none; font-size: .84rem;
                padding: .3rem .7rem; border-radius: var(--radius-sm);
                font-weight: 600; transition: all .15s; }
.nav-link:hover   { background: var(--primary-light); color: var(--primary); }
.nav-logout       { color: var(--danger); }
.nav-logout:hover { background: rgba(239,68,68,.08); color: var(--danger); }
.role-pill        { display:inline-block; padding: 2px 8px; border-radius:999px;
                    font-size:.7rem; font-weight:700; text-transform:uppercase;
                    letter-spacing: .03em; }
.role-pill.student   { color: var(--primary); background: var(--primary-light);
                       border: 1px solid rgba(124,58,237,.2); }
.role-pill.professor { color: var(--gold); background: var(--gold-glow);
                       border: 1px solid rgba(255,149,0,.25); }

/* ── Flash messages ──────────────────────────────────────────────────── */
.flash-container { padding: .5rem 1.25rem; }
.flash-msg {
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3);
  border-radius: var(--radius-sm); padding: .65rem 1rem;
  color: #92400e; margin-bottom: .4rem; font-weight: 600;
}

/* ── Main content ────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow: hidden; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem 1.1rem; border-radius: var(--radius-sm);
  font-size: .84rem; font-weight: 700; cursor: pointer;
  border: none; text-decoration: none;
  transition: all .2s var(--ease-smooth);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary   { background: linear-gradient(135deg, var(--primary), #a855f7);
                 color: var(--text-inv);
                 box-shadow: 0 2px 8px rgba(124,58,237,.25); }
.btn-primary:hover { box-shadow: 0 4px 14px rgba(124,58,237,.35); }
.btn-secondary { background: var(--bg2); color: var(--text);
                 border: 2px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary);
                       background: var(--primary-light); }
.btn-ghost     { background: transparent; color: var(--muted);
                 border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--primary); background: var(--primary-light);
                   border-color: rgba(124,58,237,.2); }
.btn-gold      { background: linear-gradient(135deg, var(--gold), #ff6b00);
                 color: var(--text-inv); font-weight: 700;
                 box-shadow: 0 2px 8px rgba(255,149,0,.25); }
.btn-gold:hover { box-shadow: 0 4px 14px rgba(255,149,0,.35); }
.btn-sm        { padding: .3rem .7rem; font-size: .78rem; }
.btn-success   { background: linear-gradient(135deg, var(--success), #059669);
                 color: var(--text-inv);
                 box-shadow: 0 2px 8px rgba(16,185,129,.25); }
.btn-success:hover { box-shadow: 0 4px 14px rgba(16,185,129,.35); }
.btn-danger-outline { background: transparent; color: var(--danger);
                      border: 1px solid rgba(239,68,68,.3); }
.btn-danger-outline:hover { background: rgba(239,68,68,.06);
                            border-color: var(--danger); }
.btn-warn-outline { background: transparent; color: #d97706;
                    border: 1px solid rgba(217,119,6,.3); }
.btn-warn-outline:hover { background: rgba(217,119,6,.06);
                          border-color: #d97706; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow);
  transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: var(--shadow-md); }
.section-title { font-size: .92rem; font-weight: 700; margin-bottom: .75rem;
                 display: flex; align-items: center; gap: .5rem;
                 color: var(--text); }
.section-icon  { font-size: 1.05rem; }
.count-pill    { background: var(--primary-light); border: 1px solid rgba(124,58,237,.15);
                 border-radius: 999px; padding: 1px 8px; font-size: .72rem;
                 color: var(--primary); font-weight: 700; }

/* ── Course list items ───────────────────────────────────────────────── */
.course-list { display: flex; flex-direction: column; gap: .5rem; }
.course-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .9rem;
  transition: all .2s var(--ease-smooth);
}
.course-item:hover { border-color: var(--primary); transform: translateX(3px);
                     box-shadow: 0 2px 8px rgba(124,58,237,.08); }
.course-name  { font-weight: 700; font-size: .88rem; }
.course-path  { font-size: .72rem; color: var(--muted); word-break: break-all; }
.course-info  { flex: 1; min-width: 0; }

/* ── Dashboard page ──────────────────────────────────────────────────── */
.dashboard-page   { padding: 1.25rem; max-height: calc(100vh - 56px); overflow-y: auto;
                    animation: fadeSlideIn .35s var(--ease-smooth); }
.dashboard-header { display: flex; align-items: flex-start; justify-content: space-between;
                    margin-bottom: 1.25rem; }
.dashboard-actions { display: flex; gap: .5rem; }
.courses-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .courses-grid { grid-template-columns: 1fr; } }

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert       { padding: .65rem .95rem; border-radius: var(--radius-sm); font-size: .84rem;
               font-weight: 600; }
.alert-warn  { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3);
               color: #92400e; }

/* ── Empty states ────────────────────────────────────────────────────── */
.empty-state { color: var(--muted); font-size: .85rem; padding: .75rem 0;
               text-align: center; }

/* ── Illustrated empty state ─────────────────────────────────────────── */
.empty-illustrated {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .75rem; padding: 2rem 1rem; text-align: center;
}
.empty-illustrated svg { width: 160px; height: auto; opacity: .9; }
.empty-illustrated .empty-title {
  font-size: 1rem; font-weight: 700; color: var(--text);
}
.empty-illustrated .empty-desc {
  font-size: .84rem; color: var(--muted); max-width: 280px;
}

/* ── Utility ─────────────────────────────────────────────────────────── */
.gold     { color: var(--gold); }
.muted    { color: var(--muted); }
.hidden   { display: none !important; }

/* ── Auth page ───────────────────────────────────────────────────────── */
.auth-page   { padding: 2rem 1.25rem; max-width: 1000px; margin: 0 auto;
               animation: fadeSlideIn .4s var(--ease-smooth); }
.auth-hero   { text-align: center; margin-bottom: 2rem; }
.auth-hero svg { max-width: 320px; height: auto; margin-bottom: 1rem; }
.auth-title  { font-size: 2rem; font-weight: 800; color: var(--text); }
.auth-title .gold {
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-sub    { color: var(--muted); margin-top: .5rem; font-size: .95rem; }
.auth-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 680px) { .auth-grid { grid-template-columns: 1fr; } }

.auth-card   { background: var(--bg2); border: 1px solid var(--border);
               border-radius: var(--radius); padding: 1.75rem;
               box-shadow: var(--shadow);
               transition: box-shadow .25s, transform .25s; }
.auth-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-badge  { display: inline-block; padding: 3px 10px; border-radius: 999px;
               font-size: .72rem; font-weight: 700; text-transform: uppercase;
               letter-spacing: .04em; margin-bottom: .75rem; }
.student-badge   { background: var(--primary-light); color: var(--primary);
                   border: 1px solid rgba(124,58,237,.2); }
.professor-badge { background: var(--gold-glow); color: var(--gold-dim);
                   border: 1px solid rgba(255,149,0,.25); }

.auth-form   { display: flex; flex-direction: column; gap: .25rem; margin-top: .75rem; }
.auth-form label { font-size: .8rem; font-weight: 700; color: var(--muted);
                   margin-top: .5rem; }
.auth-form input {
  background: var(--bg); border: 2px solid var(--border); border-radius: var(--radius-sm);
  padding: .55rem .8rem; color: var(--text); font-size: .88rem;
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus { outline: none; border-color: var(--primary);
                         box-shadow: 0 0 0 3px var(--primary-glow); }
.auth-form .btn { margin-top: .75rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Info table (verify page) ────────────────────────────────────────── */
.info-table  { width: 100%; border-collapse: collapse; }
.info-table th, .info-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border);
                                  text-align: left; font-size: .85rem; }
.info-table th { color: var(--muted); font-weight: 700; width: 35%; }
.code-pill { background: var(--primary-light); border: 1px solid rgba(124,58,237,.2);
             color: var(--primary); font-family: monospace; font-size: 1.1rem;
             letter-spacing: 4px; padding: 2px 10px; border-radius: var(--radius-sm); }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal::backdrop { background: rgba(0,0,0,.3); backdrop-filter: blur(4px); }
.modal { background: transparent; border: none; padding: 0; }
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.75rem; min-width: 320px; max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: modalEnter .25s var(--ease-smooth);
}
.modal-box h2 { margin-bottom: 1rem; }
.modal-box label { display: block; font-size: .8rem; color: var(--muted);
                   font-weight: 700; margin-top: .75rem; }
.modal-box input, .modal-textarea {
  width: 100%; background: var(--bg); border: 2px solid var(--border);
  border-radius: var(--radius-sm); padding: .55rem .8rem; color: var(--text);
  font-size: .85rem; font-family: inherit; resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
.modal-box input:focus, .modal-textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.modal-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }
.modal-box select {
  width: 100%; background: var(--bg); border: 2px solid var(--border);
  border-radius: var(--radius-sm); padding: .55rem .8rem; color: var(--text);
  font-size: .85rem; font-family: inherit;
}

/* ── Course actions & sharing ────────────────────────────────────────── */
.course-actions { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.permission-pill {
  font-size: .68rem; padding: .15rem .5rem; border-radius: 10px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.permission-pill.owner { background: rgba(16,185,129,.1); color: #059669; }
.permission-pill.write { background: var(--primary-light); color: var(--primary); }
.permission-pill.read  { background: var(--gold-glow); color: var(--gold-dim); }
.share-list { display: flex; flex-direction: column; gap: .4rem; }
.share-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .4rem .65rem; font-size: .84rem;
}

/* ── Publish/status pills ────────────────────────────────────────────── */
.pill-published {
  font-size: .68rem; padding: .15rem .5rem; border-radius: 10px;
  font-weight: 700; text-transform: uppercase;
  background: rgba(16,185,129,.1); color: #059669; border: 1px solid rgba(16,185,129,.25);
}
.pill-unpublished {
  font-size: .68rem; padding: .15rem .5rem; border-radius: 10px;
  font-weight: 700; text-transform: uppercase;
  background: rgba(245,158,11,.1); color: #92400e; border: 1px solid rgba(245,158,11,.3);
}

/* ── Console shared ──────────────────────────────────────────────────── */
.console-layout {
  display: flex;
  height: calc(100vh - 104px);
  overflow: hidden;
}
.pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden; position: relative;
  background: var(--bg2);
  min-width: 120px;
}
.pane:last-child { border-right: none; }
.pane.collapsed  { min-width: 0 !important; width: 0 !important; flex: none !important; overflow: hidden; }

/* ── Resize handles ─────────────────────────────────────────────────── */
.pane-resize-handle {
  width: 5px; cursor: col-resize; background: transparent;
  flex-shrink: 0; position: relative; z-index: 10;
  transition: background .15s;
}
.pane-resize-handle:hover,
.pane-resize-handle.active {
  background: var(--primary);
}
.pane-resize-handle::after {
  content: ''; position: absolute; top: 0; bottom: 0;
  left: -3px; right: -3px;
}
body.resizing-panes { cursor: col-resize !important; user-select: none; }
body.resizing-panes * { cursor: col-resize !important; user-select: none; }
body.resizing-panes iframe { pointer-events: none; }
.pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .8rem; background: var(--bg2);
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: .84rem;
  flex-shrink: 0; gap: .5rem;
}
.pane-body    { flex: 1; overflow-y: auto; overflow-x: hidden; }
.pane-toggle  { background: none; border: none; cursor: pointer; color: var(--muted);
                font-size: .75rem; padding: 2px 4px; transition: color .15s; }
.pane-toggle:hover { color: var(--primary); }

/* ── Tree ────────────────────────────────────────────────────────────── */
.tree-scroll  { padding: .5rem; }
.course-tree, .tree-children { list-style: none; padding: 0; margin: 0; }
.tree-children { padding-left: 1rem; }
.tree-children.hidden { display: none; }
.tree-node    { margin: 1px 0; }
.tree-label {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .4rem; border-radius: var(--radius-sm); cursor: pointer;
  font-size: .84rem; width: 100%; font-weight: 600;
  transition: all .15s;
}
.tree-label:hover { background: var(--primary-light); }
.tree-label.selected { background: var(--primary-light); color: var(--primary); }
.tree-lesson  { color: var(--text); }
.tree-expand  { cursor: pointer; color: var(--muted); font-size: .65rem;
                width: 14px; flex-shrink: 0;
                transition: transform .2s var(--ease-bounce); }
.tree-expand.expanded { transform: rotate(90deg); }
.leaf-spacer  { display: inline-block; width: 14px; }
.node-icon    { font-size: .85rem; }
.lesson-stars { font-size: .75rem; color: var(--gold); margin-left: auto; }

/* ── Tabs ────────────────────────────────────────────────────────────── */
.center-tabs  { display: flex; gap: 4px; }
.tab-btn {
  background: none; border: none; cursor: pointer; padding: .35rem .7rem;
  font-size: .82rem; font-weight: 700; color: var(--muted); border-radius: var(--radius-sm);
  transition: all .15s; position: relative;
}
.tab-btn.active { color: var(--primary); background: var(--primary-light); }
.tab-btn:hover:not(.active) { color: var(--text); background: var(--bg3); }
.tab-content  { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.tab-content.hidden { display: none !important; }
.pane-center  { display: flex; flex-direction: column; }

/* ── Media ───────────────────────────────────────────────────────────── */
.media-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; height: 100%; color: var(--muted); gap: .75rem;
}
.media-placeholder svg { width: 140px; height: auto; opacity: .85; }
.placeholder-icon { font-size: 2.5rem; }
.media-toggle-bar {
  display: flex; gap: .4rem; padding: .45rem .65rem;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toggle-btn {
  padding: .3rem .85rem; border-radius: var(--radius-sm); font-size: .82rem;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer; transition: all .15s; font-weight: 600;
}
.toggle-btn.active {
  background: linear-gradient(135deg, var(--primary), #a855f7);
  color: var(--text-inv); border-color: transparent; font-weight: 700;
}
.toggle-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }
.toggle-btn.hidden { display: none; }
.toggle-extras {
  display: flex; gap: .3rem; margin-left: auto; flex-wrap: wrap;
}
.toggle-extra-btn {
  font-size: .74rem; padding: .2rem .6rem;
  border-color: var(--border); color: var(--muted);
}
.toggle-extra-btn:hover { border-color: var(--primary); color: var(--primary); }
.toggle-summary-btn { border-color: rgba(124,58,237,.2); color: var(--primary); }
.toggle-summary-btn:hover { background: var(--primary-light); }
.context-close {
  position: absolute; top: .3rem; right: .5rem; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: .9rem;
}
.context-close:hover { color: var(--text); }
.media-pane   { flex: 1; display: flex; flex-direction: column; }
.context-panel {
  flex: 1; overflow-y: auto; background: var(--bg2);
  padding: 1rem 1.25rem; position: relative;
}
.context-panel .context-close {
  position: absolute; top: .5rem; right: .75rem; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 1rem;
}
.context-panel .context-close:hover { color: var(--text); }
.context-section h4 {
  font-size: .8rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .04em; color: var(--primary); margin: 0 0 .4rem;
}
.context-section p { font-size: .85rem; color: var(--text); margin: 0 0 .75rem; line-height: 1.6; }
.context-section ul {
  list-style: none; display: flex; flex-direction: column; gap: .3rem;
  margin: 0 0 .75rem; padding: 0;
}
.context-section ul li {
  font-size: .84rem; color: var(--text); padding-left: 1.1rem; position: relative; line-height: 1.5;
}
.context-section ul li::before {
  content: ''; position: absolute; left: 0; top: .55rem;
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.video-player { width: 100%; height: 100%; max-height: calc(100vh - 200px);
                background: #000; border-radius: var(--radius-sm); }
.yt-frame, .pdf-frame { width: 100%; flex: 1; border: none;
                         min-height: calc(100vh - 200px); }
.img-viewer   { max-width: 100%; max-height: calc(100vh - 200px);
                object-fit: contain; margin: auto; display: block;
                border-radius: var(--radius-sm); }

/* ── AI Chat ─────────────────────────────────────────────────────────── */
.chat-history {
  flex: 1; overflow-y: auto; padding: .75rem;
  display: flex; flex-direction: column; gap: .65rem;
  background: var(--bg);
}
.chat-bubble {
  padding: .65rem .9rem; border-radius: var(--radius); font-size: .84rem;
  line-height: 1.6; max-width: 90%;
  animation: bubbleIn .2s var(--ease-smooth);
}
.chat-bubble.user {
  background: linear-gradient(135deg, var(--primary), #a855f7);
  color: var(--text-inv); align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(124,58,237,.2);
}
.chat-bubble.ai {
  background: var(--bg2); border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.chat-bubble.ai p { margin: .3rem 0; }
.chat-bubble.ai code { background: var(--primary-light); color: var(--primary);
                        padding: 1px 5px; border-radius: 5px; font-size: .8em; }
.chat-bubble.ai pre { background: var(--bg); padding: .5rem; border-radius: var(--radius-sm);
                       overflow-x: auto; margin: .4rem 0; border: 1px solid var(--border); }
.bubble-meta  { font-size: .7rem; color: var(--muted); margin-top: .3rem; }
.chat-bubble.user .bubble-meta { color: rgba(255,255,255,.7); }
.bloom-tag    { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .7rem;
                background: var(--primary-light); color: var(--primary);
                border: 1px solid rgba(124,58,237,.15); font-weight: 700; }
.score-tag    { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .7rem;
                background: rgba(16,185,129,.1); color: var(--success); font-weight: 700; }

.chat-input-area {
  padding: .5rem; background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .35rem;
}
.chat-textarea {
  width: 100%; background: var(--bg); border: 2px solid var(--border);
  border-radius: var(--radius-sm); padding: .55rem .7rem; color: var(--text);
  font-size: .84rem; font-family: inherit; resize: none;
  transition: border-color .15s, box-shadow .15s;
}
.chat-textarea:focus { outline: none; border-color: var(--primary);
                       box-shadow: 0 0 0 3px var(--primary-glow); }
.send-btn     { width: 100%; }
.tts-bar      { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.voice-select { background: var(--bg); border: 2px solid var(--border);
                color: var(--text); border-radius: var(--radius-sm); padding: .2rem .4rem;
                font-size: .75rem; flex: 1; max-width: 140px; }
.lesson-name-label { font-size: .8rem; color: var(--muted); white-space: nowrap;
                     overflow: hidden; text-overflow: ellipsis; max-width: 200px;
                     font-weight: 600; }

/* ── Mode toggle ─────────────────────────────────────────────────────── */
.mode-toggle { display: flex; gap: 4px; }
.mode-btn {
  background: none; border: 2px solid var(--border); cursor: pointer;
  padding: .28rem .7rem; font-size: .8rem; font-weight: 700; color: var(--muted);
  border-radius: var(--radius-sm); transition: all .15s;
}
.mode-btn.active { background: linear-gradient(135deg, var(--primary), #a855f7);
                   color: var(--text-inv); border-color: transparent; }
.mode-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* ── XP / Badge popups ──────────────────────────────────────────────── */
.xp-popup, .badge-popup {
  position: fixed; bottom: 2rem; right: 1.5rem; z-index: 999;
  padding: .7rem 1.2rem; border-radius: var(--radius); font-weight: 800;
  animation: popupBounce .4s var(--ease-bounce); box-shadow: var(--shadow-lg);
}
.xp-popup    { background: linear-gradient(135deg, var(--gold), #ff6b00);
               color: var(--text-inv); }
.badge-popup { background: var(--bg2); border: 2px solid var(--gold);
               color: var(--gold); }

/* ── Report bar ──────────────────────────────────────────────────────── */
.report-bar  { padding: .4rem .5rem; background: var(--bg2); border-top: 1px solid var(--border); }

/* ── Streak warning ──────────────────────────────────────────────────── */
.streak-warning {
  background: rgba(245,158,11,.08); border-bottom: 1px solid rgba(245,158,11,.3);
  color: #92400e; padding: .5rem 1.25rem; font-size: .84rem; font-weight: 600;
}

/* ── HUD bar ─────────────────────────────────────────────────────────── */
.hud-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .4rem 1rem; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: .75rem; height: 48px;
  box-shadow: 0 1px 4px rgba(0,0,0,.03);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: .5rem; }
.hud-center { display: flex; align-items: center; gap: .5rem; flex: 1; justify-content: center; }
.hud-course  { font-weight: 800; font-size: .9rem; max-width: 200px;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
               background: linear-gradient(135deg, var(--primary), #a855f7);
               -webkit-background-clip: text; -webkit-text-fill-color: transparent;
               background-clip: text; }
.hud-streak  { font-size: .82rem; font-weight: 700; }
.hud-level   { font-weight: 800; font-size: .82rem; color: var(--primary);
               background: var(--primary-light); padding: 1px 8px;
               border-radius: 999px; }
.hud-title-text { font-size: .76rem; color: var(--muted); font-weight: 600; }
.hud-xp      { font-size: .74rem; color: var(--muted); white-space: nowrap; font-weight: 600; }
.xp-bar-wrap { width: 110px; height: 8px; background: var(--bg3);
               border-radius: 999px; overflow: hidden; position: relative; }
.xp-bar      { height: 100%; background: var(--xp-gradient); border-radius: 999px;
               transition: width .5s ease; position: relative; overflow: hidden; }
.xp-bar::after {
  content: ''; position: absolute; top: 0; left: 0;
  width: 40%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.4), transparent);
  animation: xpShimmer 2s infinite;
}

/* ── Pomodoro ────────────────────────────────────────────────────────── */
.pomo-select  { background: var(--bg); border: 2px solid var(--border); color: var(--text);
                border-radius: var(--radius-sm); padding: 2px 5px; font-size: .75rem;
                font-weight: 600; }
.pomo-display { font-family: 'Nunito', monospace; font-size: .92rem; font-weight: 800;
                color: var(--primary); min-width: 42px; }

/* ── Loading Overlay ─────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(248,247,244,.88);
  backdrop-filter: blur(6px);
}
.loading-overlay[hidden] { display: none; }
.loading-box {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-text {
  color: var(--muted); font-size: 1rem; font-weight: 600;
}

/* ── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Mobile tab bar: hidden on desktop by default ───────────────────── */
.mobile-tab-bar { display: none; }

/* ══════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS — max-width: 768px
   All rules below only activate on mobile. Desktop is unaffected.
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── Console layout: single-pane, full-width ───────────────────── */
  .console-layout {
    flex-direction: column;
    position: relative;
    /* Height: viewport minus topbar(56px) + HUD(approx 88px 2-row)
       + bottom nav(52px). The HUD calc is approximate; overflow:hidden
       on the pane handles any residual pixel difference. */
    height: calc(100vh - 196px);
  }

  /* Each pane takes full width and height; hidden by default on mobile */
  .pane {
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
    height: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: none;
  }

  /* Only the pane marked mobile-active is shown */
  .pane.mobile-active {
    display: flex;
  }

  /* Override the collapsed class on mobile — use mobile-active instead */
  .pane.collapsed {
    width: 100% !important;
    display: none;
  }

  /* Hide resize handles — meaningless on touch */
  .pane-resize-handle { display: none; }

  /* Hide pane collapse/expand toggle buttons on mobile */
  .pane-toggle { display: none; }

  /* ── Mobile bottom tab bar ─────────────────────────────────────── */
  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 52px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 200;
    box-shadow: 0 -2px 8px rgba(0,0,0,.06);
  }
  .mobile-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: .65rem;
    font-weight: 700;
    color: var(--muted);
    transition: color .15s, background .15s;
    line-height: 1.2;
  }
  .mobile-tab-btn .tab-icon { font-size: 1.25rem; }
  .mobile-tab-btn.active {
    color: var(--primary);
    background: var(--primary-light);
  }

  /* ── HUD bar: compact two-row layout on mobile ─────────────────── */
  .hud-bar {
    flex-wrap: wrap;
    height: auto;
    padding: .35rem .65rem;
    gap: .3rem;
  }
  .hud-left {
    order: 1;
    flex: 1;
  }
  .hud-center {
    order: 2;
    width: 100%;
    justify-content: flex-start;
    gap: .4rem;
  }
  /* Hide Pomodoro and feedback on mobile — not essential for students */
  .hud-right { display: none; }
  /* Hide verbose title text — saves space */
  .hud-title-text { display: none; }
  /* Shrink XP bar */
  .xp-bar-wrap { width: 70px; }
  /* Hide XP number labels — the bar is enough */
  .hud-xp { display: none; }

  /* ── Dashboard header: stack vertically ─────────────────────────── */
  .dashboard-header {
    flex-direction: column;
    gap: .5rem;
  }
  .dashboard-actions { align-self: flex-end; }

  /* ── Topbar: tighten spacing on small screens ────────────────────── */
  .topbar { padding: 0 .75rem; }
  .topbar-nav { gap: .4rem; }
  .nav-link { padding: .3rem .5rem; }
  /* Hide brand sub-title on very small screens to save space */
  .brand-sub { display: none; }

}
