/* === MIT Missing Semester Quiz App === */
:root {
  --bg: #1a1b26;
  --bg-card: #24283b;
  --bg-hover: #2f334d;
  --bg-input: #1f2335;
  --text: #c0caf5;
  --text-dim: #565f89;
  --text-bright: #e0e0e0;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --green: #9ece6a;
  --red: #f7768e;
  --yellow: #e0af68;
  --orange: #ff9e64;
  --border: #3b4261;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

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

body {
  font-family: 'Segoe UI', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Light Mode === */
body.light {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-hover: #f0f0f0;
  --bg-input: #e8e8e8;
  --text: #333333;
  --text-dim: #888888;
  --text-bright: #111111;
  --accent: #4a6cf7;
  --accent-hover: #3b5de7;
  --green: #2d8a4e;
  --red: #d63031;
  --yellow: #c57d10;
  --orange: #d35400;
  --border: #d0d0d0;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

/* === Theme Toggle === */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.theme-toggle:hover {
  border-color: var(--accent);
  transform: scale(1.1);
}

/* === Layout === */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  padding: 30px 0 20px;
}

header h1 {
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 4px;
}

header p {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* === Navigation / Lesson Grid === */
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.lesson-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.lesson-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.lesson-card .lesson-id {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lesson-card .lesson-title {
  font-size: 1rem;
  color: var(--text-bright);
  margin: 6px 0;
}

.lesson-card .lesson-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.lesson-card .progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}

.lesson-card .progress-bar .fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s;
}

/* === Top Bar (quiz mode) === */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

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

.quiz-title {
  font-size: 1.1rem;
  color: var(--text-bright);
  flex: 1;
}

.quiz-counter {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* === Mode Buttons === */
.mode-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.btn-mode {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.btn-mode:hover { border-color: var(--accent); }
.btn-mode.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* === Quiz Card === */
.quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

.question-tags {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.tag.easy { color: var(--green); border-color: var(--green); }
.tag.medium { color: var(--yellow); border-color: var(--yellow); }
.tag.hard { color: var(--red); border-color: var(--red); }

.question-text {
  font-size: 1.05rem;
  color: var(--text-bright);
  margin-bottom: 20px;
  flex: 1;
}

.question-text code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.9em;
  color: var(--orange);
}

.question-text pre {
  background: var(--bg-input);
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
}

.question-text pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

/* === Multiple Choice === */
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.choice-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.choice-btn:hover:not(.disabled) {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.choice-btn.correct {
  border-color: var(--green);
  background: rgba(158, 206, 106, 0.15);
  color: var(--green);
}

.choice-btn.wrong {
  border-color: var(--red);
  background: rgba(247, 118, 142, 0.15);
  color: var(--red);
}

.choice-btn.disabled { cursor: default; opacity: 0.7; }

/* === True/False === */
.tf-buttons {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.tf-btn {
  flex: 1;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.tf-btn:hover:not(.disabled) {
  border-color: var(--accent);
}

.tf-btn.correct {
  border-color: var(--green);
  background: rgba(158, 206, 106, 0.15);
  color: var(--green);
}

.tf-btn.wrong {
  border-color: var(--red);
  background: rgba(247, 118, 142, 0.15);
  color: var(--red);
}

/* === Flashcard === */
.flashcard-answer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  display: none;
}

.flashcard-answer.show { display: block; }

.flashcard-answer h4 {
  color: var(--green);
  font-size: 0.8rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.flashcard-answer p {
  color: var(--text);
  white-space: pre-wrap;
}

.btn-reveal {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  align-self: center;
}

.btn-reveal:hover { background: var(--accent-hover); }

/* === Self Assessment === */
.self-assess {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.assess-btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.assess-btn:hover { transform: translateY(-1px); }
.assess-btn.know { border-color: var(--green); color: var(--green); }
.assess-btn.know:hover { background: rgba(158, 206, 106, 0.15); }
.assess-btn.maybe { border-color: var(--yellow); color: var(--yellow); }
.assess-btn.maybe:hover { background: rgba(224, 175, 104, 0.15); }
.assess-btn.dunno { border-color: var(--red); color: var(--red); }
.assess-btn.dunno:hover { background: rgba(247, 118, 142, 0.15); }

.assess-btn.active {
  font-weight: 700;
  transform: scale(1.05);
}
.assess-btn.know.active { background: rgba(158, 206, 106, 0.25); }
.assess-btn.maybe.active { background: rgba(224, 175, 104, 0.25); }
.assess-btn.dunno.active { background: rgba(247, 118, 142, 0.25); }

/* === Explanation === */
.explanation {
  background: var(--bg-input);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: none;
}

.explanation.show { display: block; }

/* === Navigation Buttons === */
.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 12px;
}

.btn-nav {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

/* === Stats Bar === */
.stats-bar {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 16px 0;
  font-size: 0.8rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.stat .dot.green { background: var(--green); }
.stat .dot.yellow { background: var(--yellow); }
.stat .dot.red { background: var(--red); }
.stat .dot.gray { background: var(--text-dim); }

/* === Results Screen === */
.results {
  text-align: center;
  padding: 40px 20px;
}

.results h2 {
  font-size: 1.4rem;
  color: var(--accent);
  margin-bottom: 20px;
}

.results .score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-bright);
  margin: 20px 0;
}

.results .score-label {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin: 8px;
  transition: all 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }

/* === Progress dots === */
.progress-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 12px 0;
  flex-wrap: wrap;
}

.progress-dots .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.2s;
}

.progress-dots .dot.current {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.progress-dots .dot.correct { background: var(--green); }
.progress-dots .dot.wrong { background: var(--red); }
.progress-dots .dot.skipped { background: var(--yellow); }

/* === Overall Stats on Home === */
.overall-stats {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
  text-align: center;
}

.overall-stats h3 {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.overall-stats .big-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
}

.overall-stats .sub {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.reset-link {
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  margin-top: 8px;
  display: inline-block;
  text-decoration: underline;
}

.reset-link:hover { color: var(--red); }

/* === Responsive === */
@media (max-width: 600px) {
  .container { padding: 12px; }
  header h1 { font-size: 1.3rem; }
  .lesson-grid { grid-template-columns: 1fr; }
  .quiz-card { padding: 20px; }
  .tf-buttons { flex-direction: column; }
  .self-assess { flex-direction: column; }
  .nav-buttons { flex-direction: column; }
  .btn-nav { text-align: center; }
  .mode-bar { justify-content: center; }
}

/* === Code Sandbox === */
.sandbox-textarea {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-bright);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.sandbox-textarea:focus {
  border-color: var(--accent);
}

.sandbox-result {
  margin-top: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

/* === Utility === */
.hidden { display: none !important; }

/* Markdown-like rendering in questions */
.question-text strong { color: var(--accent); }
.question-text em { color: var(--yellow); font-style: italic; }
