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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3347;
  --text: #e4e6f0;
  --text2: #9ca0b4;
  --accent: #6c63ff;
  --accent2: #8b83ff;
  --green: #4ade80;
  --red: #f87171;
  --orange: #fb923c;
  --blue: #60a5fa;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
}

#app { display: flex; min-height: 100vh; }

#sidebar {
  width: 270px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  overflow-y: auto;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
}

.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.logo-icon { font-size: 30px; color: var(--accent); }
.logo h1 { font-size: 19px; font-weight: 700; }

.nav-section { margin-bottom: 22px; }
.nav-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text2); margin-bottom: 10px;
}

.nav-btn, .topic-btn {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--text2); padding: 10px 14px; border-radius: 8px; cursor: pointer;
  font-size: 15px; transition: all 0.15s;
}
.nav-btn:hover, .topic-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active, .topic-btn.active { background: var(--accent); color: #fff; }
.topic-btn { font-size: 14px; padding: 8px 14px; }

#content {
  margin-left: 270px;
  flex: 1;
  padding: 36px 44px;
  max-width: 1060px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  margin-bottom: 22px;
}
.card h2 { font-size: 24px; margin-bottom: 14px; color: var(--accent2); }
.card h3 { font-size: 19px; margin: 18px 0 10px; color: var(--blue); }
.card p, .card li { color: var(--text2); margin-bottom: 10px; font-size: 16px; }
.card ul, .card ol { padding-left: 24px; }

.math-block {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding: 18px 24px;
  margin: 14px 0;
  border-radius: 0 10px 10px 0;
  overflow-x: auto;
  font-size: 17px;
}

.step {
  background: var(--surface2);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 12px 0;
  border-left: 3px solid var(--accent);
  font-size: 16px;
}
.step-num {
  display: inline-block; background: var(--accent); color: #fff;
  width: 26px; height: 26px; border-radius: 50%; text-align: center;
  line-height: 26px; font-size: 14px; font-weight: 700; margin-right: 10px;
}

.problem-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px;
  margin-bottom: 20px;
}
.problem-card p { font-size: 16px; }

.difficulty {
  display: inline-block; padding: 3px 12px; border-radius: 12px;
  font-size: 13px; font-weight: 600; margin-bottom: 12px;
}
.difficulty.easy { background: rgba(74,222,128,0.15); color: var(--green); }
.difficulty.medium { background: rgba(251,146,60,0.15); color: var(--orange); }
.difficulty.hard { background: rgba(248,113,113,0.15); color: var(--red); }

.hint-box, .solution-box {
  background: var(--surface2); border-radius: 10px; padding: 18px 22px;
  margin-top: 12px; display: none; font-size: 16px; line-height: 1.7;
}
.hint-box.show, .solution-box.show { display: block; }
.hint-box { border-left: 3px solid var(--orange); }
.solution-box { border-left: 3px solid var(--green); }

.btn {
  display: inline-block; padding: 10px 20px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  cursor: pointer; font-size: 14px; transition: all 0.15s; margin-right: 6px; margin-top: 10px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent2); }

.topic-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px; margin-top: 18px;
}
.topic-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 26px; cursor: pointer; transition: all 0.2s;
}
.topic-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.topic-card .emoji { font-size: 34px; margin-bottom: 10px; }
.topic-card h3 { font-size: 18px; margin-bottom: 6px; }
.topic-card p { font-size: 14px; color: var(--text2); }

.progress-bar {
  height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin: 10px 0;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s;
}
.score-display {
  font-size: 52px; font-weight: 800; text-align: center; color: var(--accent); margin: 24px 0;
}

.quiz-option {
  display: block; width: 100%; text-align: left; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text); padding: 14px 20px;
  border-radius: 10px; cursor: pointer; font-size: 16px; margin-bottom: 10px; transition: all 0.15s;
}
.quiz-option:hover { border-color: var(--accent); }
.quiz-option.correct { border-color: var(--green); background: rgba(74,222,128,0.1); }
.quiz-option.wrong { border-color: var(--red); background: rgba(248,113,113,0.1); }
.quiz-option:disabled { cursor: default; }

.eng-note {
  background: rgba(96,165,250,0.08); border: 1px solid rgba(96,165,250,0.25);
  border-radius: 10px; padding: 18px 22px; margin: 14px 0; font-size: 16px;
}
.eng-note::before { content: "🔧 Engineering Application: "; font-weight: 700; color: var(--blue); }

.tip-box {
  background: rgba(74,222,128,0.08); border: 1px solid rgba(74,222,128,0.25);
  border-radius: 10px; padding: 18px 22px; margin: 14px 0; font-size: 16px;
}
.tip-box::before { content: "💡 Exam Tip: "; font-weight: 700; color: var(--green); }

.warn-box {
  background: rgba(251,146,60,0.08); border: 1px solid rgba(251,146,60,0.25);
  border-radius: 10px; padding: 18px 22px; margin: 14px 0; font-size: 16px;
}
.warn-box::before { content: "⚠️ Common Mistake: "; font-weight: 700; color: var(--orange); }

/* Chat panel */
#chat-toggle {
  position: fixed; bottom: 28px; right: 28px; z-index: 1000;
  padding: 12px 22px; border-radius: 50px; border: none;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; box-shadow: 0 4px 24px rgba(108,99,255,0.4);
  transition: transform 0.2s; white-space: nowrap;
}
#chat-toggle:hover { transform: scale(1.05); }

#chat-panel {
  position: fixed; top: 0; right: -440px; width: 440px; height: 100vh;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 999;
  transition: right 0.3s ease; box-shadow: -4px 0 30px rgba(0,0,0,0.3);
}
#chat-panel.open { right: 0; }

#chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 700;
}

#chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}

.chat-msg {
  padding: 14px 18px; border-radius: 14px; font-size: 15px;
  line-height: 1.7; max-width: 92%; word-wrap: break-word;
}
.chat-msg.user {
  background: var(--accent); color: #fff; align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  background: var(--surface2); color: var(--text); align-self: flex-start;
  border-bottom-left-radius: 4px;
}

#chat-input-area {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
#chat-mode-bar { width: 100%; }
.chat-mode-btn {
  padding: 5px 12px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text2); font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.chat-mode-btn.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.chat-mode-btn:hover:not(.active) { border-color: var(--accent); }
#chat-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px; color: var(--text);
  font-size: 15px; font-family: inherit; resize: none; outline: none;
}
#chat-input:focus { border-color: var(--accent); }
#chat-send { margin-top: 0; flex-shrink: 0; }

/* Responsive */
@media (max-width: 768px) {
  #sidebar {
    width: 100%; position: relative; flex-direction: row; flex-wrap: wrap;
    padding: 12px;
  }
  .nav-section h3 { display: none; }
  #topic-list { display: flex; flex-wrap: wrap; gap: 4px; }
  #content { margin-left: 0; padding: 20px; }
  #app { flex-direction: column; }
  .topic-grid { grid-template-columns: 1fr; }
}
