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

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2e3250;
  --text:       #e2e8f0;
  --text-muted: #8892b0;
  --accent:     #4f8ef7;
  --accent-dim: #1e3a6e;
  --green:      #22c55e;
  --green-dim:  #14532d;
  --red:        #ef4444;
  --red-dim:    #7f1d1d;
  --yellow:     #f59e0b;
  --radius:     10px;
  --shadow:     0 4px 24px rgba(0,0,0,.45);
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono:       'Cascadia Code', 'Fira Code', monospace;
}

html { font-size: 16px; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

header .logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  white-space: nowrap;
}

nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }

nav a {
  padding: .4rem .85rem;
  border-radius: 6px;
  font-size: .85rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
nav a:hover, nav a.active {
  background: var(--accent-dim);
  color: var(--accent);
  text-decoration: none;
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.main-content { flex: 1; padding: 1rem 1.25rem; width: 100%; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-family: var(--font);
  font-weight: 500;
  transition: filter .15s, transform .1s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.15); text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-success   { background: var(--green);   color: #fff; }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-ghost     { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm        { padding: .3rem .7rem; font-size: .8rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .3rem; }
.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .55rem .85rem;
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ===== Quiz Layout ===== */
.quiz-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

/* ===== Quiz Panel ===== */
.quiz-panel { display: flex; flex-direction: column; gap: 1rem; }

.category-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}

.category-pill {
  padding: .35rem .9rem;
  border-radius: 20px;
  font-size: .8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.category-pill:hover { border-color: var(--accent); color: var(--accent); }
.category-pill.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .4s;
}

.question-counter { font-size: .85rem; color: var(--text-muted); text-align: right; }

/* Question Card */
.question-card {}

.question-status-badge {
  display: inline-block;
  font-size: .72rem;
  padding: .15rem .5rem;
  border-radius: 4px;
  margin-bottom: .6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-new      { background: var(--surface2); color: var(--text-muted); }
.status-learning { background: #1e3a6e; color: #93c5fd; }
.status-review   { background: #451a03; color: #fed7aa; }
.status-mastered { background: var(--green-dim); color: var(--green); }

.question-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  line-height: 1.55;
}

.answer-options { display: flex; flex-direction: column; gap: .65rem; }

.answer-option {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface2);
  position: relative;
}
.answer-option:hover:not(.disabled) { border-color: var(--accent); background: var(--accent-dim); }
.answer-option.selected { border-color: var(--accent); background: var(--accent-dim); }
.answer-option.correct  { border-color: var(--green);  background: var(--green-dim); }
.answer-option.wrong    { border-color: var(--red);    background: var(--red-dim); }
.answer-option.disabled { cursor: default; }

.answer-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
  margin-top: .05rem;
}
.answer-option.correct .answer-letter { background: var(--green); color: #fff; }
.answer-option.wrong   .answer-letter { background: var(--red);   color: #fff; }
.answer-option.selected:not(.correct):not(.wrong) .answer-letter { background: var(--accent); color: #fff; }

.answer-text { font-size: .95rem; line-height: 1.5; }

.submit-row { display: flex; gap: .75rem; align-items: center; margin-top: .25rem; }

/* Result area */
.result-box {
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-top: .25rem;
  display: none;
}
.result-box.show { display: block; }
.result-box.correct { background: var(--green-dim); border: 1px solid var(--green); }
.result-box.wrong   { background: var(--red-dim);   border: 1px solid var(--red); }

.result-verdict {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: .4rem;
}
.result-box.correct .result-verdict { color: var(--green); }
.result-box.wrong   .result-verdict { color: var(--red); }

.result-explanation { font-size: .9rem; color: var(--text); line-height: 1.6; }
.result-explanation strong { color: var(--text); }

/* ===== AI Chat Panel ===== */
.chat-panel {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 90px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
/* placeholder fills remaining space between header and input bar */
#chat-placeholder { flex: 1; }

.chat-header {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface2);
}
.chat-header .ai-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.chat-context-tag {
  font-size: .72rem;
  padding: .1rem .5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
  margin-left: auto;
}

/* Question context strip inside chat panel */
.chat-question-ctx {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: none;
}
.chat-question-ctx .ctx-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: .2rem;
}
.chat-question-ctx .ctx-text {
  color: var(--text);
  font-size: .82rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  flex-direction: column;
  gap: .75rem;
  /* display toggled by JS between none and flex */
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg {
  padding: .65rem .9rem;
  border-radius: 10px;
  font-size: .875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-user {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text);
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.msg-ai {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.msg-ai code {
  background: var(--bg);
  padding: .1em .35em;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: .85em;
}
.msg-typing { color: var(--text-muted); font-style: italic; }

.chat-placeholder {
  color: var(--text-muted);
  font-size: .85rem;
  text-align: center;
  margin: auto;
  padding: 2rem;
  line-height: 1.8;
}

.chat-input-area {
  padding: .75rem;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.chat-input-row { display: flex; gap: .5rem; }
.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .75rem;
  color: var(--text);
  font-family: var(--font);
  font-size: .875rem;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

/* ===== Stats bar ===== */
.stats-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.stat-pill {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .75rem;
  border-radius: 6px;
  font-size: .8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.stat-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-new      { background: var(--text-muted); }
.dot-learning { background: #60a5fa; }
.dot-review   { background: var(--yellow); }
.dot-mastered { background: var(--green); }

/* ===== Labs Layout ===== */
.labs-grid { display: grid; grid-template-columns: 260px 1fr; gap: 1.25rem; align-items: start; }
.labs-list { display: flex; flex-direction: column; gap: .5rem; }
.lab-item {
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s;
}
.lab-item:hover { border-color: var(--accent); }
.lab-item.active { border-color: var(--accent); background: var(--accent-dim); }
.lab-item h4 { font-size: .9rem; margin-bottom: .2rem; }
.lab-item .lab-meta { font-size: .75rem; color: var(--text-muted); }
.difficulty-easy   { color: var(--green); }
.difficulty-medium { color: var(--yellow); }
.difficulty-hard   { color: var(--red); }

.lab-steps { display: flex; flex-direction: column; gap: 1rem; }
.lab-step {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.step-number {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step-content h4 { font-size: .95rem; margin-bottom: .4rem; }
.step-content p  { font-size: .875rem; color: var(--text-muted); line-height: 1.6; }
.expected-result {
  margin-top: .6rem;
  padding: .6rem .85rem;
  background: var(--green-dim);
  border-left: 3px solid var(--green);
  border-radius: 4px;
  font-size: .82rem;
  color: var(--text);
}

/* ===== Videos Layout ===== */
.videos-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1.25rem; }
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s;
}
.video-card:hover { border-color: var(--accent); }
.video-thumb { position: relative; padding-top: 56.25%; background: #000; }
.video-thumb iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.video-info { padding: .75rem; }
.video-info h4 { font-size: .9rem; margin-bottom: .3rem; }
.video-info p  { font-size: .8rem; color: var(--text-muted); }
.video-actions { margin-top: .5rem; }

.add-video-form {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.add-video-form h3 { font-size: .95rem; margin-bottom: .75rem; }

/* ===== Dashboard ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
}
.dash-stat .number { font-size: 2rem; font-weight: 700; color: var(--accent); }
.dash-stat .label  { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }

.category-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  transition: border-color .15s, transform .15s;
  cursor: pointer;
  text-decoration: none;
  display: block;
  color: var(--text);
}
.cat-card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; color: var(--text); }
.cat-card h3 { font-size: .95rem; margin-bottom: .5rem; }
.cat-card .cat-meta { font-size: .8rem; color: var(--text-muted); }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.4rem; margin-bottom: .3rem; }
.login-card p  { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.alert {
  padding: .7rem 1rem;
  border-radius: 6px;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.alert-error { background: var(--red-dim); border: 1px solid var(--red); color: #fca5a5; }

/* ===== Category Progress Table ===== */
.cat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.cat-table th {
  padding: .4rem .75rem;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.cat-table td {
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.cat-table tbody tr:last-child td { border-bottom: none; }
.cat-table tbody tr:hover { background: var(--surface2); }
.cat-table .tc { text-align: center; font-weight: 600; }

/* ===== Quiz session score ===== */
.session-score {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: .6rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  flex-wrap: wrap;
}
.session-score .score-item { display: flex; align-items: center; gap: .4rem; }
.score-val { font-weight: 700; font-size: 1rem; }

/* ===== Forms ===== */
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .4rem;
}

/* ===== Mock Exam ===== */
.exam-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem 1.25rem;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.exam-topbar-left  { display: flex; align-items: center; gap: 1rem; }
.exam-topbar-right { display: flex; align-items: center; gap: .75rem; }

.exam-timer {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .05em;
}

.exam-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.exam-nav-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 1rem;
}

#q-nav-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .35rem;
  margin-bottom: .75rem;
}

.q-nav-dot {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: .7rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s;
}
.q-nav-dot:hover       { transform: scale(1.15); }
.q-nav-dot.current     { outline: 2px solid var(--accent); outline-offset: 1px; }
.q-nav-dot.nav-unanswered { background: var(--surface2); color: var(--text-muted); }
.q-nav-dot.nav-answered   { background: var(--accent-dim); color: var(--accent); }
.q-nav-dot.nav-flagged    { background: rgba(245,158,11,.2); color: var(--yellow); }

.exam-nav-legend {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .72rem;
  color: var(--text-muted);
}
.nav-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: .3rem;
  vertical-align: middle;
}
.nav-dot.nav-answered   { background: var(--accent-dim); }
.nav-dot.nav-flagged    { background: rgba(245,158,11,.35); }
.nav-dot.nav-unanswered { background: var(--surface2); }

.exam-question-area { min-width: 0; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow);
}

/* Results page */
.q-review-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: .5rem;
  overflow: hidden;
}
.q-review-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem .9rem;
  cursor: pointer;
  user-select: none;
}
.q-review-header:hover { background: var(--surface2); }
.q-review-num  { font-weight:700;color:var(--text-muted);font-size:.8rem;min-width:24px }
.q-review-icon { font-weight:800;font-size:.9rem; }
.q-review-card[data-correct="1"] .q-review-icon { color: var(--green); }
.q-review-card[data-correct="0"] .q-review-icon { color: var(--red); }
.q-review-card[data-correct="1"] { border-left: 3px solid var(--green); }
.q-review-card[data-correct="0"] { border-left: 3px solid var(--red); }
.q-review-text { flex:1;font-size:.85rem;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
.q-review-arrow { color:var(--text-muted);transition:transform .2s; }
.q-review-card.expanded .q-review-arrow { transform: rotate(180deg); }
.q-review-body {
  display: none;
  padding: .75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.q-review-card.expanded .q-review-body { display: block; }

@media (max-width: 900px) {
  .exam-layout { grid-template-columns: 1fr; }
  .exam-nav-panel { position: static; }
  #q-nav-grid { grid-template-columns: repeat(8, 1fr); }
}

/* ===== Lab step list ===== */
.step-list-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  transition: background .15s;
}
.step-list-item:last-child { border-bottom: none; }
.step-list-item:hover  { background: var(--surface2); }
.step-list-item.active { background: var(--accent-dim); color: var(--accent); }
.step-list-item.done   { opacity: .65; }
.step-list-item.done .step-list-title { text-decoration: line-through; }
.overview-item { font-weight: 600; font-size: .85rem; color: var(--text-muted); }
.overview-item.active { color: var(--accent); }

.step-list-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
}
.step-list-item.active .step-list-num { background: var(--accent); color: #fff; }
.step-list-item.done .step-list-num   { background: var(--green-dim); color: var(--green); }

.step-list-title { flex: 1; }

.step-done-check {
  color: var(--green);
  font-size: .85rem;
  font-weight: 700;
}

/* ===== Lab success button ===== */
.btn-success {
  background: var(--green);
  color: #fff;
  border: none;
}
.btn-success:hover { background: #16a34a; }

/* ===== Mastery breakdown bar in session score ===== */
.sc-breakdown-wrap {
  width: 120px;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.sc-breakdown {
  display: flex;
  height: 100%;
}
.bd-seg { height: 100%; transition: width .4s; }
.bd-mastered { background: var(--green); }
.bd-review   { background: var(--yellow); }
.bd-learning { background: #60a5fa; }
.bd-new      { background: var(--border); }

/* ===== Utilities ===== */
.text-muted    { color: var(--text-muted); }
.text-accent   { color: var(--accent); }
.text-green    { color: var(--green); }
.text-red      { color: var(--red); }
.text-yellow   { color: var(--yellow); }
.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; }
.gap-1         { gap: .5rem; }
.gap-2         { gap: 1rem; }
.mt-1          { margin-top: .5rem; }
.mt-2          { margin-top: 1rem; }
.mb-1          { margin-bottom: .5rem; }
.mb-2          { margin-bottom: 1rem; }
.page-title    { font-size: 1.3rem; font-weight: 700; margin-bottom: 1rem; }
.hidden        { display: none !important; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .quiz-layout { grid-template-columns: 1fr; }
  .chat-panel { position: static; height: 550px; }
  .labs-grid { grid-template-columns: 1fr; }
  .videos-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .main-content { padding: .75rem; }
  header { padding: .6rem 1rem; }
  header .logo { font-size: 1rem; }
  nav a { padding: .35rem .6rem; font-size: .8rem; }
  .question-text { font-size: 1rem; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== Study Plan ===== */
.sp-wrap { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }

/* Hero */
.sp-hero { background: linear-gradient(135deg, var(--surface1) 0%, var(--surface2) 100%); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem 2rem; display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; }
.sp-hero-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.sp-hero-sub { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }
.sp-hero-right { display: flex; align-items: center; gap: 2rem; }
.sp-countdown { text-align: center; background: var(--accent-dim); border: 1px solid var(--accent); border-radius: 12px; padding: .75rem 1.25rem; }
.sp-cd-num { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.sp-cd-lbl { font-size: .72rem; color: var(--accent); opacity: .8; margin-top: .2rem; }
.sp-hero-stats { display: flex; gap: 1.5rem; }
.sp-hs { text-align: center; }
.sp-hs-val { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.sp-hs-lbl { font-size: .72rem; color: var(--text-muted); margin-top: .15rem; }

/* Progress bar */
.sp-prog-wrap { background: var(--surface1); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.5rem; }
.sp-prog-bar { background: var(--surface2); border-radius: 99px; height: 12px; overflow: hidden; margin-bottom: .5rem; }
.sp-prog-fill { height: 100%; background: linear-gradient(90deg,#4a9eff,#a78bfa,#f59e0b,#10b981,#f43f5e,#ff6b35); border-radius: 99px; transition: width .8s cubic-bezier(.4,0,.2,1); }
.sp-prog-labels { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-muted); }

/* Phase legend */
.sp-legend { display: flex; flex-wrap: wrap; gap: .5rem; }
.sp-leg { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; padding: .3rem .75rem; border-radius: 20px; background: var(--surface1); border: 1px solid var(--border); color: var(--text-muted); }
.sp-leg::before { content:''; width: 8px; height: 8px; border-radius: 50%; background: var(--lc); flex-shrink: 0; }

/* Main layout */
.sp-main { display: grid; grid-template-columns: 1fr 420px; gap: 1.25rem; align-items: start; }

/* Calendar */
.sp-cal-wrap { display: flex; flex-direction: column; gap: 1.25rem; }
.sp-cal-month { background: var(--surface1); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.sp-cal-hdr { padding: .9rem 1.25rem; font-weight: 700; font-size: 1rem; border-bottom: 1px solid var(--border); background: var(--surface2); }
.sp-cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 3px; padding: .6rem; }
.sp-cal-dname { text-align: center; font-size: .7rem; font-weight: 600; color: var(--text-muted); padding: .3rem 0; }
.sp-cal-empty,.sp-cal-noplan { background: transparent; border-radius: 8px; aspect-ratio: 1; }
.sp-cal-noplan { display: flex; align-items: center; justify-content: center; }
.sp-cal-noplan .sp-cal-num { font-size: .78rem; color: var(--text-muted); opacity: .4; }

.sp-cal-cell { border-radius: 8px; padding: .35rem .4rem; cursor: pointer; position: relative; display: flex; flex-direction: column; gap: 1px; border: 2px solid transparent; transition: all .15s; min-height: 70px; background: var(--surface2); }
.sp-cal-cell:hover:not(.sp-cal-locked) { border-color: var(--pc, var(--accent)); background: color-mix(in srgb, var(--pc,var(--accent)) 10%, var(--surface2)); }
.sp-cal-locked { opacity: .4; cursor: default; background: var(--surface2); }
.sp-cal-done { background: color-mix(in srgb, #10b981 8%, var(--surface2)); }
.sp-cal-today { border-color: var(--pc, var(--accent)) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc,var(--accent)) 20%, transparent); }
.sp-cal-selected { border-color: var(--pc, var(--accent)) !important; background: color-mix(in srgb, var(--pc,var(--accent)) 15%, var(--surface2)) !important; }

.sp-cal-num { font-size: .85rem; font-weight: 700; color: var(--text); line-height: 1; }
.sp-cal-daynum { font-size: .6rem; color: var(--text-muted); }
.sp-cal-badge { font-size: .6rem; font-weight: 700; border-radius: 4px; padding: 1px 4px; align-self: flex-start; margin-top: 2px; }
.sp-cal-badge--done { background: #10b981; color: #fff; }
.sp-cal-badge--today { background: var(--pc, var(--accent)); color: #fff; }
.sp-cal-badge--pct { background: var(--surface1); color: var(--text-muted); border: 1px solid var(--border); }
.sp-cal-badge--lock { font-size: .65rem; }
.sp-cal-bar { position: absolute; bottom: 4px; left: 4px; right: 4px; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.sp-cal-bar-fill { height: 100%; border-radius: 2px; transition: width .4s; }

/* Goals panel */
.sp-panel { background: var(--surface1); border: 1px solid var(--border); border-radius: 14px; overflow-y: auto; max-height: 85vh; position: sticky; top: 1rem; }
.sp-panel-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 4rem 2rem; text-align: center; color: var(--text-muted); }
.sp-panel-empty-icon { font-size: 3rem; }
.sp-panel-empty-txt { font-size: .9rem; line-height: 1.5; }
.sp-panel-loading { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 3rem; color: var(--text-muted); }

.sp-panel-head { padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); }
.sp-panel-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.sp-panel-phase { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.sp-panel-date { font-size: .75rem; color: var(--text-muted); }
.sp-panel-daynum { font-size: .78rem; color: var(--text-muted); font-weight: 600; margin-bottom: .2rem; }
.sp-panel-title { font-size: 1.1rem; font-weight: 700; line-height: 1.3; margin-bottom: .75rem; }
.sp-panel-done-badge { display: inline-block; background: color-mix(in srgb,#10b981 12%,var(--surface2)); border: 1px solid #10b981; color: #10b981; border-radius: 8px; padding: .4rem .9rem; font-size: .82rem; font-weight: 600; margin-bottom: .5rem; }
.sp-panel-locked-msg { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; font-size: .82rem; color: var(--text-muted); }
.sp-panel-prog { margin-top: .5rem; }
.sp-panel-prog-bar { background: var(--surface2); border-radius: 99px; height: 6px; overflow: hidden; margin-bottom: .35rem; }
.sp-panel-prog-fill { height: 100%; border-radius: 99px; transition: width .4s; }
.sp-panel-prog-txt { font-size: .75rem; color: var(--text-muted); }

/* Goals */
.sp-goals { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.sp-goal { background: var(--surface2); border: 1.5px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; transition: border-color .2s,background .2s; }
.sp-goal--done { border-color: #10b981; background: color-mix(in srgb,#10b981 6%,var(--surface2)); }
.sp-goal--done .sp-goal-desc { text-decoration: line-through; opacity: .55; }
.sp-goal--locked { opacity: .45; pointer-events: none; }
.sp-goal-row { display: flex; gap: .75rem; align-items: flex-start; }
.sp-goal-check { width: 24px; height: 24px; min-width: 24px; border-radius: 50%; border: 2px solid var(--border); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: .8rem; color: #fff; transition: all .2s; margin-top: 2px; }
.sp-goal-check:hover { border-color: #10b981; background: color-mix(in srgb,#10b981 15%,transparent); }
.sp-goal-check.checked { background: #10b981; border-color: #10b981; }
.sp-goal-check-ph { width: 24px; min-width: 24px; height: 24px; }
.sp-goal-body { flex: 1; min-width: 0; }
.sp-goal-top-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; flex-wrap: wrap; }
.sp-goal-type-badge { font-size: .72rem; font-weight: 700; padding: .2rem .55rem; border-radius: 6px; background: color-mix(in srgb,var(--tc,var(--accent)) 15%,var(--surface1)); color: var(--tc, var(--accent)); border: 1px solid color-mix(in srgb,var(--tc,var(--accent)) 30%,transparent); }
.sp-goal-target { font-size: .72rem; color: var(--accent); font-weight: 700; background: var(--accent-dim); border-radius: 6px; padding: .2rem .5rem; }
.sp-goal-desc { font-size: .88rem; font-weight: 600; line-height: 1.4; margin-bottom: .3rem; }
.sp-goal-detail { font-size: .78rem; color: var(--text-muted); line-height: 1.7; margin-top: .4rem; padding: .5rem .75rem; background: var(--surface1); border-radius: 8px; border-left: 3px solid var(--border); }
.sp-goal-go { display: inline-block; margin-top: .5rem; font-size: .78rem; color: var(--accent); font-weight: 700; text-decoration: none; padding: .25rem .65rem; border: 1px solid var(--accent); border-radius: 6px; transition: background .15s; }
.sp-goal-go:hover { background: var(--accent-dim); }

/* Toast */
.sp-toast { position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(3rem); background: var(--surface1); border: 1.5px solid #10b981; border-radius: 12px; padding: .75rem 1.5rem; font-size: .9rem; font-weight: 600; color: #10b981; opacity: 0; transition: all .35s cubic-bezier(.4,0,.2,1); z-index: 9999; pointer-events: none; box-shadow: 0 8px 32px rgba(0,0,0,.3); }
.sp-toast--in { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1100px) { .sp-main { grid-template-columns: 1fr; } .sp-panel { position: static; max-height: none; } }
@media (max-width: 600px) { .sp-hero { flex-direction: column; align-items: flex-start; } .sp-hero-right { flex-wrap: wrap; } }

/* Study Plan — Resource Modal */
.sp-modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.7); z-index:10000; display:none; align-items:center; justify-content:center; padding:1rem; backdrop-filter:blur(4px); }
.sp-modal-overlay.sp-modal-open { display:flex; }
.sp-modal { background:var(--surface1); border:1px solid var(--border); border-radius:16px; width:100%; max-width:1100px; height:85vh; display:flex; flex-direction:column; overflow:hidden; box-shadow:0 24px 80px rgba(0,0,0,.5); }
.sp-modal-head { display:flex; align-items:center; justify-content:space-between; padding:.85rem 1.25rem; border-bottom:1px solid var(--border); gap:1rem; flex-shrink:0; }
.sp-modal-title { font-size:.9rem; font-weight:600; flex:1; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sp-modal-actions { display:flex; align-items:center; gap:.75rem; flex-shrink:0; }
.sp-modal-open { font-size:.78rem; color:var(--accent); text-decoration:none; border:1px solid var(--accent); border-radius:6px; padding:.25rem .65rem; white-space:nowrap; }
.sp-modal-open:hover { background:var(--accent-dim); }
.sp-modal-close { background:var(--surface2); border:1px solid var(--border); border-radius:8px; color:var(--text); cursor:pointer; padding:.3rem .7rem; font-size:.9rem; line-height:1; }
.sp-modal-close:hover { background:var(--border); }
.sp-modal-frame { flex:1; border:none; width:100%; }

/* Goal resource buttons */
.sp-goal-actions { display:flex; flex-wrap:wrap; gap:.5rem; margin-top:.6rem; }
.sp-goal-res { border:none; border-radius:8px; padding:.35rem .85rem; font-size:.8rem; font-weight:600; cursor:pointer; transition:all .15s; }
.sp-goal-res--doc { background:color-mix(in srgb,#4a9eff 15%,var(--surface1)); color:#4a9eff; border:1px solid color-mix(in srgb,#4a9eff 35%,transparent); }
.sp-goal-res--doc:hover { background:color-mix(in srgb,#4a9eff 25%,var(--surface1)); }
.sp-goal-res--vid { background:color-mix(in srgb,#f43f5e 15%,var(--surface1)); color:#f43f5e; border:1px solid color-mix(in srgb,#f43f5e 35%,transparent); }
.sp-goal-res--vid:hover { background:color-mix(in srgb,#f43f5e 25%,var(--surface1)); }
