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

:root {
  /* ── Light theme (default) ── */
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-muted: #8888a8;
  --border: #e2e4e9;
  --accent: #6c5ce7;
  --accent-hover: #5a4bd1;
  --accent-light: rgba(108, 92, 231, 0.08);
  --success: #00b894;
  --success-bg: rgba(0, 184, 148, 0.1);
  --danger: #e17055;
  --danger-bg: rgba(225, 112, 85, 0.1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #1e1e32;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0c0;
  --text-muted: #6a6a8a;
  --border: #2a2a40;
  --accent: #a29bfe;
  --accent-hover: #6c5ce7;
  --accent-light: rgba(162, 155, 254, 0.1);
  --success: #55efc4;
  --success-bg: rgba(85, 239, 196, 0.12);
  --danger: #fab1a0;
  --danger-bg: rgba(250, 177, 160, 0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-title span {
  color: var(--accent);
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 1.15rem;
  color: var(--text-primary);
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.theme-toggle:active {
  transform: scale(0.92);
}

/* ── Container ───────────────────────────────── */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ── Sections (SPA pages) ────────────────────── */
.page {
  display: none;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

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

/* ── Home ─────────────────────────────────────── */
.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 160px);
  gap: 16px;
}

.home-hero h1 {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.home-hero p {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 12px;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.btn-main {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.btn-main:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  background: var(--accent-light);
}

.btn-main:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-main .icon {
  font-size: 1.3rem;
}

.home-footer {
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.home-footer a {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.home-footer a:hover {
  color: var(--primary);
}

/* ── Back button ─────────────────────────────── */
.back-row {
  margin-bottom: 20px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

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

/* ── Page Headers ────────────────────────────── */
.page h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  overflow: hidden;
}

.summary-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.summary-card .summary-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--transition);
}

.summary-card .summary-header::-webkit-details-marker {
  display: none;
}

.summary-card .summary-header:hover {
  background: var(--accent-light);
}

.summary-card .summary-header .week-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.summary-card .summary-header .chevron {
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: transform 0.25s ease;
}

.summary-card[open] .summary-header .chevron {
  transform: rotate(90deg);
}

.summary-card .summary-body {
  padding: 0 18px 18px;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.summary-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 10px;
}

.summary-card p:last-child {
  margin-bottom: 0;
}

.summary-card p strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Code Blocks ─────────────────────────────── */
.code-block {
  background: #1e1e2e;
  border-radius: 10px;
  padding: 16px 18px;
  margin: 12px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(255,255,255,0.06);
}

.code-block code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  color: #cdd6f4;
  white-space: pre;
  tab-size: 4;
}

.code-keyword {
  color: #cba6f7;
  font-weight: 600;
}

.code-string {
  color: #a6e3a1;
}

.code-comment {
  color: #6c7086;
  font-style: italic;
}

.code-type {
  color: #89b4fa;
}

[data-theme="light"] .code-block {
  background: #1e1e2e;
  border: 1px solid #e2e4e9;
}

/* Quiz question code blocks */
.question-text .code-block {
  margin-top: 12px;
  font-size: 0.82rem;
}

/* ── Test Selection ──────────────────────────── */
.test-select-page h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.test-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-week {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.btn-week:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-week:active {
  transform: translateY(0);
}

.btn-week .week-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.test-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.btn-special {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.btn-special:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-special:active {
  transform: translateY(0);
}

.btn-special .icon {
  font-size: 1.2rem;
}

.btn-special.wrong-btn {
  border-color: var(--danger);
}

.btn-special.wrong-btn .icon {
  color: var(--danger);
}

/* ── Quiz ────────────────────────────────────── */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.quiz-progress {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 24px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.35s ease;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  line-height: 1.5;
  width: 100%;
}

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

.option-btn .option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
  transition: all var(--transition);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
}

.option-btn.correct .option-letter {
  background: var(--success);
  color: #fff;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.option-btn.wrong .option-letter {
  background: var(--danger);
  color: #fff;
}

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

.option-btn.disabled.correct,
.option-btn.disabled.wrong {
  opacity: 1;
}

.explanation {
  display: none;
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  animation: fadeIn 0.25s ease;
}

.explanation.visible {
  display: block;
}

.quiz-nav {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-nav {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-nav:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.btn-nav:active {
  transform: scale(0.98);
}

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

.btn-nav:disabled:hover {
  border-color: var(--border);
  background: var(--bg-card);
}

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

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

/* ── Stats ───────────────────────────────────── */
.stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
  animation: fadeIn 0.3s ease;
}

.stats-card h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
}

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

.stat-value {
  font-size: 2rem;
  font-weight: 800;
}

.stat-value.correct-val {
  color: var(--success);
}

.stat-value.wrong-val {
  color: var(--danger);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-percent {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 20px;
}

.stats-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Quit Button ─────────────────────────────── */
.btn-quit {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: transparent;
  color: var(--danger);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.btn-quit:hover {
  background: var(--danger-bg);
}

.btn-quit:active {
  transform: scale(0.98);
}

/* ── Resume Modal ────────────────────────────── */
.resume-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.resume-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.25s ease;
}

.resume-modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.resume-modal p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.resume-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Utilities ───────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Responsive ──────────────────────────────── */
@media (min-width: 768px) {
  .container {
    padding: 32px 24px 60px;
  }

  .home-hero h1 {
    font-size: 1.8rem;
  }

  .home-buttons {
    flex-direction: row;
    max-width: 440px;
  }

  .home-buttons .btn-main {
    flex: 1;
  }

  .question-card {
    padding: 28px 24px;
  }

  .stats-row {
    gap: 40px;
  }
}

/* ── Footer ──────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: auto;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.site-footer a:hover {
  color: var(--primary);
}

/* ── Auth Modal ──────────────────────────────── */
.auth-group {
  margin-bottom: 15px;
  text-align: left;
}

.auth-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.auth-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
}

.auth-group input:focus {
  border-color: var(--accent);
}

/* ── Lectures (PDF) ──────────────────────────── */
.lectures-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lecture-card[open] .summary-header {
  border-bottom: 1px solid var(--border);
}

.pdf-wrapper {
  width: 100%;
  height: 60vh;
  min-height: 400px;
  background: var(--bg-primary);
}

.pdf-embed {
  width: 100%;
  height: 100%;
  border: none;
}
