:root {
  --bg: #f6f4ef;
  --bg-dot: rgba(24, 24, 27, 0.055);
  --surface: #ffffff;
  --surface-muted: #faf9f6;
  --border: #e4e0d8;
  --border-strong: #cfc9bd;
  --text: #18181b;
  --text-muted: #52525b;
  --primary: #3730a3;
  --primary-bright: #4f46e5;
  --primary-hover: #312e81;
  --primary-soft: #eef2ff;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --teal: #0f766e;
  --teal-bg: #f0fdfa;
  --success: #15803d;
  --success-bg: #ecfdf5;
  --success-border: #6ee7b7;
  --danger: #be123c;
  --danger-bg: #fff1f2;
  --danger-border: #fda4af;
  --radius: 16px;
  --shadow-sm: 0 2px 8px rgba(24, 24, 27, 0.04);
  --shadow: 0 10px 30px rgba(24, 24, 27, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 72px;
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

/* Brand Header */
.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-bright) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.28);
  flex-shrink: 0;
}

.brand-header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-header p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.shortcut-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
}

/* Settings */
.settings-card {
  margin-bottom: 20px;
  animation: fadeSlideUp 0.25s ease-out;
}

.section-title {
  margin: 0 0 14px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 10px;
}

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.toggle-item:hover {
  border-color: var(--border-strong);
  background: #fff;
}

.toggle-label strong {
  display: block;
  font-size: 0.9rem;
}

.toggle-label span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Custom Pill Switch */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.slider {
  position: absolute;
  inset: 0;
  background: #d4d4d8;
  border-radius: 999px;
  transition: background 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.switch input:checked + .slider {
  background: var(--primary-bright);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

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

.deck-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  animation: fadeSlideUp 0.3s ease-out;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.deck-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

.deck-accent {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.deck-accent.history {
  background: linear-gradient(90deg, #d97706, #ea580c);
}

.deck-accent.tech {
  background: linear-gradient(90deg, #0d9488, #059669);
}

.deck-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.deck-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.deck-badge.history {
  color: var(--amber);
  background: var(--amber-bg);
}

.deck-badge.tech {
  color: var(--teal);
  background: var(--teal-bg);
}

.best-score-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  padding: 3px 9px;
  border-radius: 999px;
}

.deck-card h2 {
  margin: 10px 0 6px;
  font-size: 1.12rem;
  line-height: 1.35;
}

.deck-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.89rem;
}

/* Lesson / Topic Picker */
.lesson-picker {
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.lesson-picker-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.lesson-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lesson-chip {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.lesson-chip:hover {
  border-color: var(--primary-bright);
  color: var(--primary);
}

.lesson-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary-bright);
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-bright) 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary) 100%);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

.btn-amber {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: var(--amber-border);
}

.btn-amber:hover:not(:disabled) {
  background: #fef3c7;
}

.btn-icon {
  padding: 8px 11px;
  font-size: 0.95rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Quiz Topbar */
.quiz-topbar {
  position: sticky;
  top: 10px;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px 10px;
  margin-bottom: 16px;
}

.quiz-topbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.quiz-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-pill,
.timer-pill,
.streak-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.streak-pill {
  color: var(--amber);
  background: var(--amber-bg);
  border-color: var(--amber-border);
}

.quiz-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-track {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-bright), #10b981);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Question Card */
.question-card {
  margin-bottom: 16px;
  animation: fadeSlideUp 0.22s ease-out;
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.question-topic {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-bright);
  background: var(--primary-soft);
  padding: 3px 10px;
  border-radius: 999px;
}

.question-text {
  margin: 0 0 18px;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.5;
}

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

.option-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
  font-family: inherit;
  font-size: 0.96rem;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary-bright);
  background: var(--primary-soft);
}

.option-btn.selected {
  border-color: var(--primary-bright);
  background: var(--primary-soft);
}

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

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

.option-key {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  flex-shrink: 0;
}

.option-btn.selected .option-key {
  background: var(--primary-bright);
  border-color: var(--primary-bright);
  color: #fff;
}

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

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

/* True/False Cluster */
.tf-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tf-row {
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  transition: border-color 0.15s, background 0.15s;
}

.tf-row.correct {
  border-color: var(--success-border);
  background: var(--success-bg);
}

.tf-row.wrong {
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

.tf-statement {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.tf-buttons {
  display: flex;
  gap: 8px;
}

.tf-btn {
  flex: 1;
  max-width: 125px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.tf-btn.active {
  border-color: var(--primary-bright);
  background: var(--primary-bright);
  color: #fff;
}

.explanation-box {
  margin-top: 14px;
  padding: 11px 14px;
  border-left: 3px solid var(--primary-bright);
  border-radius: 0 10px 10px 0;
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.88rem;
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.nav-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-dot {
  width: 35px;
  height: 35px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.nav-dot:hover {
  border-color: var(--primary-bright);
}

.nav-dot.current {
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.22);
}

.nav-dot.answered {
  background: var(--primary-soft);
  border-color: var(--primary-bright);
  color: var(--primary);
}

.nav-dot.dot-correct {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.nav-dot.dot-wrong {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

/* Result View */
.result-summary {
  text-align: center;
  margin-bottom: 18px;
  animation: fadeSlideUp 0.25s ease-out;
}

.score-ring {
  width: 118px;
  height: 118px;
  margin: 8px auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary-bright) calc(var(--pct, 0) * 1%), var(--border) 0);
}

.score-ring-inner {
  width: 94px;
  height: 94px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-ring-pct {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}

.score-ring-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.review-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.review-item {
  margin-bottom: 12px;
}

/* Confetti */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 100;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(540deg);
    opacity: 0;
  }
}

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: confettiFall 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@media (max-width: 600px) {
  .card {
    padding: 16px;
  }
  .brand-header h1 {
    font-size: 1.32rem;
  }
  .shortcut-hint {
    display: none;
  }
}
