:root {
  /* Sidebar — dark warm */
  --sb-bg: #1a1612;
  --sb-surface: #222018;
  --sb-border: rgba(255, 255, 255, 0.07);
  --sb-text: #e8d9c4;
  --sb-muted: #8a7a6a;
  --sb-accent: #c96f2d;

  /* Topbar */
  --tb-bg: #131110;

  /* Main area */
  --main-bg-from: #f7f0e3;
  --main-bg-to: #ece2d2;
  --surface: #ffffff;
  --surface-dim: rgba(255, 253, 248, 0.9);
  --ink: #1d1a16;
  --muted: #685f55;
  --line: rgba(29, 26, 22, 0.09);

  --accent: #0f766e;
  --accent-strong: #115e59;
  --warm: #c96f2d;

  --success: #166534;
  --danger: #991b1b;

  --shadow-sm: 0 2px 6px rgba(29, 26, 22, 0.07);
  --shadow-md: 0 8px 24px rgba(29, 26, 22, 0.1);

  --topbar-h: 58px;
  --sidebar-w: 288px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background: var(--sb-bg);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
p { margin: 0; }
h1, h2, h3 {
  margin: 0;
  font-family: "Fraunces", serif;
  line-height: 1.1;
  letter-spacing: -0.02em;
}


/* ─────────────────────────────────────────
   TOP BAR
───────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--tb-bg);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 20px 0 0;
  z-index: 200;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 20px;
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  height: 100%;
}

.brand-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #c96f2d, #0f766e);
  color: #fff;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.brand-eyebrow {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 800;
  color: var(--sb-accent);
  margin-bottom: 1px !important;
}

.brand-name {
  font-size: 0.95rem;
  font-family: "Fraunces", serif;
  color: #fff;
  letter-spacing: -0.01em;
}

/* Course selector */
.course-selector {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  flex: 1;
  min-width: 0;
  height: 100%;
  align-items: center;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.course-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.83rem;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}

.course-tab.active {
  background: rgba(201, 111, 45, 0.14);
  border-color: rgba(201, 111, 45, 0.28);
  color: #e8a96b;
}

.course-tab:not(.active):hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-left: 20px;
  flex-shrink: 0;
}

.topbar-stats {
  display: flex;
  gap: 16px;
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stat-chip-label {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.35);
}

.stat-chip strong {
  font-size: 1rem;
  color: #fff;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, #c96f2d, #0f766e);
  color: #fff;
  font-weight: 800;
  font-size: 0.83rem;
  transition: opacity 0.15s, transform 0.15s;
}
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-ghost {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 600;
  font-size: 0.83rem;
  transition: all 0.15s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.btn-icon:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }


/* ─────────────────────────────────────────
   BODY LAYOUT
───────────────────────────────────────── */
.body-layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}


/* ─────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sb-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Progress block */
.sidebar-progress {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sidebar-section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 800;
  color: var(--sb-muted);
}

.completion-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--sb-accent);
}

.progress-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #c96f2d, #0f766e);
  border-radius: inherit;
  transition: width 0.4s ease;
}

/* Sidebar nav tabs */
.sidebar-nav {
  display: flex;
  padding: 10px 12px 8px;
  gap: 6px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--sb-muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  transition: all 0.15s;
}

.sidebar-tab.active {
  background: rgba(201, 111, 45, 0.14);
  border-color: rgba(201, 111, 45, 0.24);
  color: #e8a96b;
}

.sidebar-tab:not(.active):hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
}

/* Sidebar panels */
.sidebar-panel { display: none; flex-direction: column; flex: 1; }
.sidebar-panel.active { display: flex; }

.sidebar-note {
  padding: 10px 16px;
  font-size: 0.75rem;
  color: var(--sb-muted);
  line-height: 1.55;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

/* Lesson list */
.lesson-list { display: flex; flex-direction: column; flex: 1; }

/* Group by bucket */
.lesson-group { border-bottom: 1px solid var(--sb-border); }

.lesson-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 7px;
  user-select: none;
}

.group-color-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.85;
}

.group-name {
  flex: 1;
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sb-muted);
}

.group-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.18);
}

.group-count.done { color: #4ade80; }

/* Individual lesson row */
.lesson-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px 8px 24px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.lesson-card:hover { background: rgba(255, 255, 255, 0.04); }

.lesson-card.active {
  background: rgba(201, 111, 45, 0.11);
  border-left-color: var(--sb-accent);
}

.lesson-card.complete { opacity: 0.65; }
.lesson-card.complete:hover { opacity: 1; }

.lesson-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.18);
  width: 16px;
  flex-shrink: 0;
  text-align: right;
}

.lesson-card.active .lesson-num { color: var(--sb-accent); }
.lesson-card.complete .lesson-num { color: #4ade80; }

.lesson-name {
  flex: 1;
  font-size: 0.83rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.3;
}

.lesson-card.active .lesson-name { color: #f5e6d0; }
.lesson-card.complete .lesson-name { color: rgba(255, 255, 255, 0.45); }

.lesson-status-icon {
  font-size: 0.68rem;
  flex-shrink: 0;
  line-height: 1;
}

/* Metric map */
.bucket-list { display: flex; flex-direction: column; }

.bucket-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--sb-border);
}

.bucket-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.bucket-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.85;
}

.bucket-name {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--sb-text);
}

.bucket-desc {
  font-size: 0.77rem;
  color: var(--sb-muted);
  line-height: 1.5;
  margin-bottom: 8px !important;
}

.bucket-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.bucket-tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.38);
}


/* ─────────────────────────────────────────
   MAIN CONTENT
───────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, var(--main-bg-from) 0%, var(--main-bg-to) 100%);
  min-height: calc(100vh - var(--topbar-h));
}

/* Lesson context bar */
.lesson-context-bar {
  padding: 14px 24px 12px;
  border-bottom: 1px solid rgba(29, 26, 22, 0.08);
  background: rgba(255, 252, 245, 0.75);
  backdrop-filter: blur(8px);
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
}

.context-pills {
  display: flex;
  gap: 6px;
  margin-bottom: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.pill-bucket {
  background: rgba(15, 118, 110, 0.1);
  color: #115e59;
  border: 1px solid rgba(15, 118, 110, 0.15);
}

.pill-difficulty {
  background: rgba(29, 26, 22, 0.07);
  color: var(--muted);
  border: 1px solid rgba(29, 26, 22, 0.1);
}

.lesson-title {
  font-size: 1.18rem;
  font-family: "Fraunces", serif;
  color: var(--ink);
  line-height: 1.2;
}

/* Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 272px;
  gap: 20px;
  padding: 20px 24px 28px;
  align-items: start;
}


/* ─────────────────────────────────────────
   CHAT PANEL
───────────────────────────────────────── */
.chat-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-window {
  min-height: 460px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 20px;
  background: #fafaf8;
}

.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: rgba(29, 26, 22, 0.1); border-radius: 2px; }

/* Messages */
.message {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  animation: rise 0.24s ease;
}

.message.tutor { justify-content: flex-start; align-items: flex-start; }
.message.user  { justify-content: flex-end; }
.message.system { justify-content: center; margin: 2px 0 14px; }

.tutor-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(201,111,45,0.2), rgba(15,118,110,0.2));
  border: 1px solid rgba(15, 118, 110, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #0f766e;
  flex-shrink: 0;
  margin-top: 3px;
}

.bubble {
  max-width: min(84%, 640px);
  padding: 12px 15px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 0.9rem;
  white-space: pre-line;
}

.message.tutor .bubble {
  background: #fff;
  border: 1px solid rgba(29, 26, 22, 0.09);
  border-top-left-radius: 4px;
  color: var(--ink);
}

.message.user .bubble {
  background: linear-gradient(135deg, rgba(15,118,110,0.1), rgba(201,111,45,0.1));
  border: 1px solid rgba(15, 118, 110, 0.14);
  border-top-right-radius: 4px;
  color: var(--ink);
}

.message.system .bubble {
  background: rgba(29, 26, 22, 0.06);
  border-radius: var(--radius-sm);
  padding: 5px 14px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  max-width: none;
  border: none;
}

/* Options panel */
.options-panel {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.options-label {
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
  margin-bottom: 10px;
}

.options-grid { display: grid; gap: 7px; }

.option-btn {
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(29, 26, 22, 0.09);
  background: #fafaf8;
  color: var(--ink);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.13s, border-color 0.13s, transform 0.13s;
}

.option-btn:hover:not(:disabled) {
  background: rgba(15, 118, 110, 0.05);
  border-color: rgba(15, 118, 110, 0.2);
  transform: translateX(2px);
}

.option-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.option-key {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.1);
  color: #0f766e;
  font-weight: 800;
  font-size: 0.78rem;
  flex-shrink: 0;
}


/* ─────────────────────────────────────────
   GUIDE PANEL
───────────────────────────────────────── */
.guide-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}

.guide-card--concept {
  border-left: 3px solid var(--accent);
}

.guide-eyebrow {
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 800;
  color: var(--accent-strong);
  margin-bottom: 7px !important;
}

.guide-card h3 {
  font-size: 0.95rem;
  margin-bottom: 6px !important;
  color: var(--ink);
}

.guide-card p:not(.guide-eyebrow) {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.62;
}

.formula-chain {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.formula-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(201, 111, 45, 0.1);
  color: #8f4b17;
  font-size: 0.76rem;
  font-weight: 700;
}

.checklist {
  margin: 6px 0 0;
  padding-left: 16px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.85;
}


/* ─────────────────────────────────────────
   RESULT STATES
───────────────────────────────────────── */
.highlight-correct {
  color: var(--success);
  font-weight: 700;
}

.highlight-wrong {
  color: var(--danger);
  font-weight: 700;
}


/* ─────────────────────────────────────────
   ANIMATIONS
───────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ─────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────── */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .guide-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 860px) {
  .course-selector { display: none; }
  .topbar-stats { display: none; }
  :root { --sidebar-w: 256px; }
}

@media (max-width: 660px) {
  .body-layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 280px;
    position: static;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }

  .main-content {
    min-height: auto;
  }

  .workspace {
    padding: 14px 14px 20px;
    gap: 14px;
  }

  .lesson-context-bar {
    padding: 12px 14px 10px;
    position: static;
  }

  .guide-panel {
    grid-template-columns: 1fr;
  }

  .btn-ghost { display: none; }

  .topbar { padding: 0 14px 0 0; }
  .topbar-brand { padding: 0 14px; }
}
