/* === Topic Theme Variables === */
:root {
  --accent: #38bdf8;
  --accent-soft: #7dd3fc;
  --accent-bg: rgba(56, 189, 248, 0.1);
  --accent-bg-strong: rgba(56, 189, 248, 0.12);
  --accent-border: rgba(56, 189, 248, 0.3);
  --accent-border-hover: rgba(56, 189, 248, 0.4);
  --accent-glow: rgba(56, 189, 248, 0.08);
  --accent-glow-subtle: rgba(56, 189, 248, 0.05);
  --tab-color: #60a5fa;
  --tab-bg: rgba(37, 99, 235, 0.18);
  --tab-border: rgba(37, 99, 235, 0.35);
  --tab-hover: #93c5fd;
}

[data-theme="Diffusion"] {
  --accent: #a78bfa;
  --accent-soft: #c4b5fd;
  --accent-bg: rgba(139, 92, 246, 0.1);
  --accent-bg-strong: rgba(139, 92, 246, 0.14);
  --accent-border: rgba(139, 92, 246, 0.3);
  --accent-border-hover: rgba(139, 92, 246, 0.45);
  --accent-glow: rgba(139, 92, 246, 0.08);
  --accent-glow-subtle: rgba(139, 92, 246, 0.05);
  --tab-color: #8b5cf6;
  --tab-bg: rgba(109, 40, 217, 0.18);
  --tab-border: rgba(109, 40, 217, 0.35);
  --tab-hover: #a78bfa;
}

[data-theme="ReinforcementLearning"] {
  --accent: #34d399;
  --accent-soft: #6ee7b7;
  --accent-bg: rgba(52, 211, 153, 0.1);
  --accent-bg-strong: rgba(52, 211, 153, 0.14);
  --accent-border: rgba(52, 211, 153, 0.3);
  --accent-border-hover: rgba(52, 211, 153, 0.45);
  --accent-glow: rgba(52, 211, 153, 0.08);
  --accent-glow-subtle: rgba(52, 211, 153, 0.05);
  --tab-color: #10b981;
  --tab-bg: rgba(5, 150, 105, 0.18);
  --tab-border: rgba(5, 150, 105, 0.35);
  --tab-hover: #34d399;
}

/* === Base Layout === */
body {
  background: radial-gradient(circle at 20% 20%, #111827, #030712);
  color: #cbd5e1;
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* === Top Bar === */
.top-bar {
  width: 100%;
  max-width: 1100px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
}

/* === Breadcrumb === */
.breadcrumb {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0;
}

.breadcrumb-item {
  color: #64748b;
  text-decoration: none;
  transition: color 0.2s;
}

a.breadcrumb-item:hover {
  color: var(--accent);
}

.breadcrumb-item.active {
  color: #e2e8f0;
  font-weight: 600;
}

.breadcrumb-sep {
  color: #475569;
  user-select: none;
}

/* === Home View === */
#home-view {
  width: 100%;
  max-width: 1100px;
}

#home-view h1 {
  text-align: center;
  font-family: "Outfit", sans-serif;
  font-size: 2.6rem;
  color: #f1f5f9;
  margin-bottom: 0.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.home-subtitle {
  text-align: center;
  color: #64748b;
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
}

/* === Topic Cards Grid === */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.topic-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  height: 340px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.topic-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: #1e293b;
  transition: transform 0.4s ease;
}

.topic-card:hover .card-bg {
  transform: scale(1.05);
}

.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(2, 6, 23, 0.95) 0%,
    rgba(2, 6, 23, 0.5) 50%,
    rgba(2, 6, 23, 0.2) 100%
  );
}

.card-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.8rem;
  z-index: 1;
}

.card-content h2 {
  font-family: "Outfit", sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: #f1f5f9;
  margin: 0 0 0.5rem 0;
}

.card-content p {
  color: #94a3b8;
  font-size: 0.95rem;
  margin: 0 0 0.8rem 0;
  line-height: 1.5;
}

.card-count {
  font-size: 0.85rem;
  color: #38bdf8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

[data-subject="Diffusion"] .card-count { color: #a78bfa; }
[data-subject="ReinforcementLearning"] .card-count { color: #34d399; }

/* === Topic View === */
#topic-view {
  width: 100%;
  max-width: 900px;
}

#topic-view h1 {
  text-align: center;
  font-family: "Outfit", sans-serif;
  font-size: 2.2rem;
  color: #f1f5f9;
  margin-bottom: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* === Mode Buttons === */
.mode-switch {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.mode-switch button {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.55rem 1.3rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-switch button:hover {
  color: #f1f5f9;
  background: #334155;
  border-color: #475569;
}

.mode-switch button.active {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
}

/* === Topic Tabs === */
.topic-tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.topic-tab {
  background: transparent;
  color: #64748b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 0.3rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-block;
  margin: 0.15rem;
}

.topic-tab:hover {
  color: var(--tab-hover);
  border-color: var(--tab-border);
}

.topic-tab.active {
  background: var(--tab-bg);
  color: var(--tab-color);
  border-color: var(--tab-border);
}

/* === Tag Filters === */
.tag-filters {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.tag-filter {
  background: transparent;
  color: #64748b;
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  padding: 0.2rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.02em;
  display: inline-block;
  margin: 0.15rem;
}

.tag-filter:hover {
  color: var(--accent-soft);
  border-color: var(--accent-border-hover);
}

.tag-filter.active {
  background: var(--accent-bg);
  color: var(--accent-soft);
  border-color: var(--accent-border);
}

/* === Q&A Cards === */
#qa-container {
  max-width: 900px;
  width: 100%;
}

.qa-card,
.practice-card {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 10px var(--accent-glow-subtle);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.qa-card:hover {
  transform: translateY(-3px);
  border-color: #475569;
  box-shadow: 0 8px 20px var(--accent-glow);
}

.practice-card button,
.practice-actions button {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #334155;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  margin-right: 0.5rem;
}

.practice-card button:hover,
.practice-actions button:hover {
  color: #e2e8f0;
  border-color: #475569;
  background: rgba(255, 255, 255, 0.04);
}

#verify-btn {
  color: var(--accent);
  border-color: var(--accent-border);
}

#verify-btn:hover {
  background: var(--accent-bg-strong);
  color: var(--accent);
  border-color: var(--accent-border-hover);
}

.practice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.type-tags-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.type-label {
  font-size: 0.75rem;
  background: var(--tab-bg);
  color: var(--tab-color);
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.tag {
  font-size: 0.7rem;
  background: var(--accent-bg);
  color: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--accent-border);
  display: inline-block;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.question {
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  color: #f1f5f9;
  line-height: 1.5;
}

.toggle-icon {
  float: right;
  color: #64748b;
  font-weight: bold;
  font-size: 1.2rem;
  transition: color 0.2s ease;
}

.question:hover .toggle-icon {
  color: var(--accent);
}

.answer {
  display: none;
  line-height: 1.75;
  color: #94a3b8;
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid #1e293b;
}

/* === Markdown in Answers === */
.answer p,
.answer-box p {
  margin: 0 0 0.6rem 0;
  text-align: justify;
}

.answer p:last-child,
.answer-box p:last-child {
  margin-bottom: 0;
}

.answer ul,
.answer ol,
.answer-box ul,
.answer-box ol {
  margin: 0.4rem 0 0.6rem 0;
  padding-left: 1.4rem;
}

.answer li,
.answer-box li {
  margin-bottom: 0.3rem;
}

.answer strong,
.answer-box strong {
  color: #e2e8f0;
  font-weight: 600;
}

.answer code,
.answer-box code {
  background: var(--accent-bg);
  color: var(--accent-soft);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.answer pre,
.answer-box pre {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 6px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}

.answer pre code,
.answer-box pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
  font-size: 0.85em;
}

.math-display {
  text-align: center;
  margin: 1rem 0;
}

/* === Practice Mode === */
.user-input {
  width: 100%;
  min-height: 80px;
  border-radius: 8px;
  border: 1px solid #334155;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #0f172a;
  color: #e2e8f0;
  margin-bottom: 1rem;
  resize: vertical;
  box-sizing: border-box;
  transition: border-color 0.2s ease;
}

.user-input:focus {
  outline: none;
  border-color: var(--accent);
}

.answer-box {
  margin-top: 1rem;
  background: rgba(30, 41, 59, 0.7);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.2rem;
  border-radius: 0 8px 8px 0;
  display: none;
  line-height: 1.75;
  color: #94a3b8;
}

.counter {
  text-align: right;
  color: #64748b;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 1rem;
}

.empty-msg {
  text-align: center;
  color: #94a3b8;
  font-size: 1.1rem;
  padding: 2rem;
}

/* === Verification Box === */
.verification-box {
  margin-top: 20px;
  padding: 20px;
  border-radius: 8px;
  background-color: rgba(30, 41, 59, 0.9);
  border: 2px solid #334155;
  color: #e2e8f0;
}

.verification-content {
  line-height: 1.6;
}

.score-display h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.verification-details {
  margin-top: 15px;
}

.verification-section {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #334155;
}

.verification-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.section-title {
  color: #e2e8f0;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.section-content {
  color: #cbd5e1;
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.verification-error {
  color: #f87171;
  padding: 10px;
  background-color: rgba(239, 68, 68, 0.1);
  border-radius: 5px;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* === Settings Button === */
.settings-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.3rem;
  transition: color 0.2s;
}

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

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 14px;
  padding: 2rem;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #1e293b;
}

.modal-header h2 {
  font-family: "Outfit", sans-serif;
  color: #f1f5f9;
  font-size: 1.3rem;
  margin: 0;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: #475569;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #e2e8f0;
}

.modal-body label {
  display: block;
  color: #e2e8f0;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-body input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid #1e293b;
  background: rgba(30, 41, 59, 0.5);
  color: #e2e8f0;
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.modal-body input:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-section {
  margin-bottom: 1.4rem;
}

.settings-hint {
  color: #475569;
  font-size: 0.78rem;
  margin: 0.4rem 0 0;
  line-height: 1.5;
}

.settings-hint a {
  color: var(--accent);
  text-decoration: none;
}

.settings-hint a:hover {
  text-decoration: underline;
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.settings-actions button {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #334155;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.settings-actions button:first-child {
  background: var(--accent-bg-strong);
  color: var(--accent);
  border-color: var(--accent-border);
}

.settings-actions button:first-child:hover {
  background: var(--accent-bg-strong);
}

.settings-actions button:hover {
  color: #e2e8f0;
  border-color: #475569;
}

.key-status {
  font-size: 0.8rem;
  margin-top: 0.8rem;
  margin-bottom: 0;
}

/* === Responsive === */
@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .topic-card {
    height: 220px;
  }

  #home-view h1 {
    font-size: 1.8rem;
  }

  .practice-actions {
    flex-direction: column;
  }

  .practice-actions button {
    margin-right: 0;
    width: 100%;
  }
}
