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

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --card-hover: #f0f4f8;
  --accent: #1a73e8;
  --accent-light: #4a9af5;
  --vec-a: #e17055;
  --vec-b: #00b894;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --border: #dde1e8;
  --success: #00b894;
  --error: #e17055;
  --warning: #fdcb6e;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 280px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

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

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 4px;
}

.sidebar-header .badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.sidebar-header .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Progress bar */
.progress-wrap {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

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

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 3px;
  transition: width 0.5s ease;
  width: 0%;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.nav-section {
  padding: 8px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(26, 115, 232, 0.08);
  color: var(--text);
}

.nav-item.active {
  background: rgba(26, 115, 232, 0.12);
  color: var(--accent-light);
  border-left-color: var(--accent);
}

.nav-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-item .check {
  margin-left: auto;
  font-size: 14px;
  color: var(--success);
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-item.done .check {
  opacity: 1;
}

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-w);
  padding: 40px 48px 80px;
  max-width: 960px;
}

/* ===== MOBILE MENU ===== */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 44px;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  font-size: 20px;
  align-items: center;
  justify-content: center;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 90;
}

/* ===== SECTIONS ===== */
.section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

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

/* ===== TYPOGRAPHY ===== */
.section-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #0a0a1a;
}

.section-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

h3 {
  font-size: 20px;
  font-weight: 600;
  margin: 32px 0 12px;
  color: #0a0a1a;
}

h4 {
  font-size: 16px;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--accent-light);
}

p, li {
  font-size: 15px;
  margin-bottom: 10px;
}

ul, ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.card-accent {
  border-left: 4px solid var(--accent);
}

.card-success {
  border-left: 4px solid var(--success);
}

.card-warning {
  border-left: 4px solid var(--warning);
}

.card-error {
  border-left: 4px solid var(--error);
}

.card h4:first-child {
  margin-top: 0;
}

/* ===== FORMULA BLOCKS ===== */
.formula-block {
  background: rgba(26, 115, 232, 0.08);
  border: 1px solid rgba(26, 115, 232, 0.2);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin: 16px 0;
  text-align: center;
  font-size: 18px;
}

.formula-block .katex {
  font-size: 1.3em;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.formula-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.formula-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ===== CANVAS CONTAINERS ===== */
.canvas-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}

.canvas-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.info-chip {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
}

.info-chip .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.info-chip .value {
  font-weight: 600;
  font-size: 15px;
}

.info-chip.vec-a .value { color: var(--vec-a); }
.info-chip.vec-b .value { color: var(--vec-b); }

/* ===== OPERATION BUTTONS ===== */
.op-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.op-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.op-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.op-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== CALCULATOR ===== */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.calc-input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.calc-input-row {
  display: flex;
  gap: 8px;
}

.calc-input-row input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.calc-input-row input:focus {
  border-color: var(--accent);
}

.calc-results {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
}

.calc-results .row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.calc-results .row:last-child {
  border-bottom: none;
}

.calc-results .row .val {
  font-weight: 600;
  color: var(--accent-light);
}

/* ===== TASK CARDS ===== */
.task-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.task-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: background 0.2s;
}

.task-header:hover {
  background: var(--card-hover);
}

.task-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  border-radius: 50%;
  flex-shrink: 0;
}

.task-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.task-tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(26, 115, 232, 0.15);
  color: var(--accent-light);
  white-space: nowrap;
}

.task-toggle {
  font-size: 18px;
  color: var(--text-muted);
  transition: transform 0.3s;
}

.task-card.open .task-toggle {
  transform: rotate(180deg);
}

.task-body {
  display: none;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}

.task-card.open .task-body {
  display: block;
}

.task-body .condition {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 12px 0;
  font-size: 15px;
}

.task-body .answer-line {
  margin: 12px 0;
  font-weight: 600;
  color: var(--success);
  font-size: 15px;
}

.step {
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.8;
}

.step-num {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  margin-right: 8px;
  vertical-align: middle;
}

/* ===== TRAINER ===== */
.trainer-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
}

.trainer-problem {
  font-size: 17px;
  margin-bottom: 20px;
  line-height: 1.7;
}

.trainer-input-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.trainer-input-row label {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

.trainer-input-row input {
  width: 140px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.trainer-input-row input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: #1557b0;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-sm {
  padding: 7px 16px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.feedback {
  margin-top: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  display: none;
  transition: all 0.3s ease;
}

.feedback.correct {
  display: block;
  background: rgba(0, 184, 148, 0.18);
  border: 2px solid rgba(0, 184, 148, 0.5);
  color: #00b894;
  box-shadow: 0 0 15px rgba(0, 184, 148, 0.2);
  animation: correctPulse 0.5s ease;
}

.feedback.wrong {
  display: block;
  background: rgba(225, 112, 85, 0.18);
  border: 2px solid rgba(225, 112, 85, 0.5);
  color: #e17055;
  box-shadow: 0 0 15px rgba(225, 112, 85, 0.2);
  animation: wrongShake 0.4s ease;
}

@keyframes correctPulse {
  0% { transform: scale(0.95); opacity: 0; }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ===== EXAM MODE ===== */
.exam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.exam-timer {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
}

.exam-timer.warning {
  color: var(--warning);
}

.exam-timer.danger {
  color: var(--error);
  animation: pulse 1s infinite;
}

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

.exam-score {
  font-size: 14px;
  color: var(--text-muted);
}

.exam-score span {
  font-weight: 700;
  color: var(--accent-light);
  font-size: 18px;
}

/* ===== CHEATSHEET ===== */
.cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.cheat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.cheat-card h4 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--accent-light);
}

.cheat-card .formula-block {
  margin: 8px 0;
  padding: 12px 16px;
  font-size: 15px;
}

/* ===== STATS BAR ===== */
.stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.stat-card {
  flex: 1;
  min-width: 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.stat-card .num {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-light);
}

.stat-card .lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Canvas for task illustrations */
.task-canvas-wrap {
  margin: 12px 0;
  text-align: center;
}

.task-canvas-wrap canvas {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    z-index: 200;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .overlay.open {
    display: block;
  }

  .menu-toggle {
    display: flex;
  }

  .main {
    margin-left: 0;
    padding: 70px 20px 60px;
  }

  .calc-grid {
    grid-template-columns: 1fr;
  }

  .cheatsheet-grid {
    grid-template-columns: 1fr;
  }

  .formula-grid {
    grid-template-columns: 1fr;
  }

  /* Tables: horizontal scroll */
  .styled-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 500px) {
  .section-title {
    font-size: 22px;
  }

  .trainer-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .trainer-input-row input {
    width: 100%;
  }

  .stats-row {
    flex-direction: column;
  }

  /* Touch targets */
  .btn, .nav-link, button {
    min-height: 44px;
  }

  .nav-link {
    padding: 12px 14px;
  }

  /* Formula blocks: prevent overflow */
  .formula-box {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* iOS input zoom prevention */
@media (max-width: 860px) {
  input, select, textarea {
    font-size: 16px;
  }
}

/* ===== TASK SOLVED STATE ===== */
.task-card.solved .task-header {
  border-left: 3px solid var(--success);
}

.task-card.solved .task-num {
  background: var(--success);
}

.task-solved-mark {
  color: var(--success);
  font-size: 18px;
  font-weight: 700;
  margin-left: -4px;
  flex-shrink: 0;
}

/* ===== TASK ANSWER ROW ===== */
.task-answer-row {
  margin: 12px 0;
}

.task-answer-row .trainer-input-row {
  margin-bottom: 8px;
}

.task-feedback {
  margin-top: 8px;
}

/* ===== HINTS ===== */
.task-hints {
  margin: 8px 0;
}

.hint-level {
  background: rgba(253, 203, 110, 0.12);
  border: 1px solid rgba(253, 203, 110, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text);
  animation: fadeIn 0.3s ease;
}

.hint-badge {
  display: inline-block;
  background: var(--warning);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 6px;
}

/* ===== TASK SOLUTION TOGGLE ===== */
.task-solution-toggle {
  margin: 12px 0 8px;
}

.task-solution {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 8px;
}

/* ===== SIDEBAR STATISTICS ===== */
.sidebar-stats {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
}

.sidebar-stat-row span:last-child {
  font-weight: 600;
  color: var(--accent-light);
}

/* KaTeX overrides for dark theme */
.katex { color: var(--text); }
.katex .mord { color: var(--text); }
