/* ============================================================
   CSS CUSTOM PROPERTIES — central theming, never hardcode colors
   ============================================================ */
:root {
  --color-primary:       #4F46E5;
  --color-primary-hover: #4338CA;
  --color-primary-light: #EEF2FF;
  --color-success:       #10B981;
  --color-success-light: #D1FAE5;
  --color-danger:        #EF4444;
  --color-danger-light:  #FEE2E2;
  --color-warning:       #F59E0B;
  --color-warning-light: #FEF3C7;

  /* Light theme surfaces & text */
  --bg:          #F3F4F6;
  --surface:     #FFFFFF;
  --surface-2:   #F9FAFB;
  --border:      #E5E7EB;
  --text:        #111827;
  --text-muted:  #6B7280;
  --text-subtle: #9CA3AF;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -2px rgba(0,0,0,.05);

  --radius-sm: 0.375rem;
  --radius:    0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;

  --transition: 150ms ease;
  --max-width: 900px;
  --navbar-height: 56px;
}

/* Dark theme via explicit attribute */
[data-theme="dark"],
:root:not([data-theme="light"]):has(body.force-dark) {
  --bg:          #0F172A;
  --surface:     #1E293B;
  --surface-2:   #334155;
  --border:      #334155;
  --text:        #F1F5F9;
  --text-muted:  #94A3B8;
  --text-subtle: #64748B;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -1px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.5), 0 4px 6px -2px rgba(0,0,0,.3);
  --color-primary-light: #1e1b4b;
  --color-success-light: #064e3b;
  --color-danger-light:  #450a0a;
  --color-warning-light: #451a03;
}

/* System dark mode (auto) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg:          #0F172A;
    --surface:     #1E293B;
    --surface-2:   #334155;
    --border:      #334155;
    --text:        #F1F5F9;
    --text-muted:  #94A3B8;
    --text-subtle: #64748B;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -1px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.5), 0 4px 6px -2px rgba(0,0,0,.3);
    --color-primary-light: #1e1b4b;
    --color-success-light: #064e3b;
    --color-danger-light:  #450a0a;
    --color-warning-light: #451a03;
  }
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; }

button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
}
label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.375rem; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app { min-height: 100dvh; }

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fade-in 150ms ease;
}

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

.main-content {
  flex: 1;
  padding: 1.25rem 1rem 2rem;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   APP HEADER (home)
   ============================================================ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  min-height: var(--navbar-height);
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}
.app-header__logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.app-header__logo h1 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-primary);
}
.logo-icon { font-size: 1.25rem; }

/* ============================================================
   NAVBAR (exam view)
   ============================================================ */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: var(--navbar-height);
}
.navbar__title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.navbar__actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}
.btn-back {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-primary);
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-back:hover { background: var(--color-primary-light); }

@media (max-width: 560px) {
  .navbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--navbar-height);
    padding-block: 0.5rem;
  }
  .navbar__title {
    order: 3;
    flex-basis: 100%;
  }
  .navbar__actions {
    order: 2;
    margin-left: auto;
  }
}

/* ============================================================
   TAB BAR
   ============================================================ */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--navbar-height);
  z-index: 9;
}
.tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  text-align: center;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* ============================================================
   TAB CONTENT WRAPPER
   ============================================================ */
.tab-content {
  flex: 1;
  overflow-y: auto;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger-ghost {
  color: var(--color-danger);
  border-color: transparent;
}
.btn-danger-ghost:hover:not(:disabled) {
  background: var(--color-danger-light);
  border-color: var(--color-danger-light);
}

.btn-large {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border-radius: var(--radius);
}

.btn-full { width: 100%; }

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background var(--transition);
  flex-shrink: 0;
  color: var(--text-muted);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

.btn-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-close:hover { background: var(--surface-2); color: var(--text); }

/* ============================================================
   SECTION HEADER
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.section-header h2 { font-size: 1.125rem; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============================================================
   EXAM CARDS GRID
   ============================================================ */
.exams-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 560px) {
  .exams-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .exams-grid { grid-template-columns: repeat(3, 1fr); }
  .main-content { padding: 1.5rem 1.5rem 3rem; }
}

.exam-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}
.exam-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.exam-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.exam-card__name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  word-break: break-word;
}
.exam-card__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.exam-card__actions .btn-primary { flex: 1; }
.btn-icon-only {
  width: 38px;
  height: 38px;
  padding: 0;
  flex-shrink: 0;
  font-size: 1rem;
}
.exam-card__stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar--thick { height: 10px; }
.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), #818CF8);
  border-radius: var(--radius-xl);
  transition: width 600ms ease;
}
.progress-bar__fill--success {
  background: linear-gradient(90deg, var(--color-success), #34D399);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-xl);
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-info { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-sm { font-size: 0.6875rem; padding: 0.0625rem 0.375rem; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.empty-state p + p { margin-top: 0.5rem; }
.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
}

/* ============================================================
   STUDY TAB — start screen
   ============================================================ */
.study-start {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  gap: 2rem;
  min-height: calc(100dvh - var(--navbar-height) * 2 - 2px);
}
.study-start__info {
  display: flex;
  gap: 3rem;
}
.study-start__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.stat-big {
  font-size: 3rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}
.stat-label { font-size: 0.8125rem; color: var(--text-muted); }
.study-start__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}
.study-start__actions .btn { width: 100%; }

/* ============================================================
   STUDY TAB — active session
   ============================================================ */
.study-session {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  min-height: calc(100dvh - var(--navbar-height) * 2 - 2px);
}

.session-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.session-counter {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 3.5rem;
}
.session-score {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-success);
  white-space: nowrap;
}

/* Question card */
.question-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition);
  flex: 1;
}
.question-card.answered-correct { border-color: var(--color-success); }
.question-card.answered-wrong   { border-color: var(--color-danger); }

.question-card__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.5rem;
}

.question-card__text {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

@media (min-width: 768px) {
  .question-card__text { font-size: 1.25rem; }
}

/* Answer section */
.answer-section { display: flex; flex-direction: column; gap: 1rem; }

/* Auto-check input */
.answer-input-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.answer-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.answer-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.answer-input.error { border-color: var(--color-danger); }

/* Self-assess section */
.self-assess-section { display: flex; flex-direction: column; gap: 0.875rem; }
.self-assess-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-style: italic;
}
.self-assess-buttons {
  display: flex;
  gap: 0.75rem;
}
.self-assess-buttons .btn {
  flex: 1;
  padding: 0.625rem 1rem;
  font-size: 1rem;
}

.btn-show-answer { align-self: flex-start; }

/* ── Answer result card ───────────────────────────────────── */
.result-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid;
  display: flex;
  flex-direction: column;
}
.result-card.result-correct { border-color: var(--color-success); }
.result-card.result-wrong   { border-color: var(--color-danger);  }

/* Coloured header band */
.result-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: #fff;
}
.result-correct .result-banner { background: var(--color-success); }
.result-wrong   .result-banner { background: var(--color-danger);  }

.result-icon-lg { font-size: 1.375rem; line-height: 1; }

/* Detail area (wrong answer reveal or MC options) */
.result-body {
  padding: 0.875rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Streak / learned footer */
.result-footer {
  padding: 0.625rem 1.25rem;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.5rem;
}

/* Wrong answer reveal inside result-body */
.correct-answer-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.correct-answer-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.correct-answer-text {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.result-learned {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--color-success);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Wide "Weiter" button below the result card */
.btn-next-wide {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-radius: var(--radius);
}

/* Streak dots */
.streak-dots { display: flex; gap: 4px; align-items: center; }
.streak-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition), transform var(--transition);
}
.streak-dot.filled {
  background: var(--color-warning);
  transform: scale(1.1);
}
.streak-mini { display: flex; gap: 3px; align-items: center; }
.streak-mini .streak-dot { width: 8px; height: 8px; }

.streak-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
}

.btn-next { align-self: flex-start; }

/* Session complete / celebration */
.session-complete,
.celebration {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 1rem;
  min-height: calc(100dvh - var(--navbar-height) * 2 - 2px);
}
.complete-icon,
.celebration-icon { font-size: 3rem; }
.session-complete h3,
.celebration h3 { font-size: 1.5rem; }
.session-complete p,
.celebration p { color: var(--text-muted); }
.session-actions,
.celebration-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 260px;
  margin-top: 0.5rem;
}
.session-actions .btn,
.celebration-actions .btn { width: 100%; }

/* ============================================================
   PROGRESS TAB
   ============================================================ */
.progress-view {
  padding: 1.25rem 1rem 3rem;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.progress-overview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

@media (min-width: 560px) {
  .progress-overview {
    flex-direction: row;
    align-items: center;
    gap: 2rem;
  }
}

/* SVG progress circle */
.progress-circle-container {
  position: relative;
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}
.progress-circle {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.progress-circle__track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}
.progress-circle__fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 800ms ease;
}
.progress-circle__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.progress-percent {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.progress-sublabel {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Stats grid */
.progress-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  flex: 1;
  width: 100%;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.stat-card.stat-learned .stat-value { color: var(--color-success); }
.stat-card.stat-progress .stat-value { color: var(--color-warning); }
.stat-card .stat-label { font-size: 0.75rem; color: var(--text-muted); }

/* Questions progress list */
.questions-progress-list { display: flex; flex-direction: column; gap: 0.5rem; }
.questions-progress-list h3 { font-size: 0.9375rem; margin-bottom: 0.25rem; }

.question-progress-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  transition: border-color var(--transition);
}
.question-progress-item.status-learned { border-left: 3px solid var(--color-success); }
.question-progress-item.status-progress { border-left: 3px solid var(--color-warning); }
.question-progress-item.status-untouched { border-left: 3px solid var(--border); }

.question-progress-status {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}
.status-learned .question-progress-status { color: var(--color-success); }
.status-progress .question-progress-status { color: var(--color-warning); }
.status-untouched .question-progress-status { color: var(--text-subtle); }

.question-progress-text {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.question-progress-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.question-score { font-size: 0.75rem; color: var(--text-muted); min-width: 2rem; text-align: right; }

.reset-section { text-align: center; padding-top: 1rem; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
  animation: overlay-in 150ms ease;
  backdrop-filter: blur(2px);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (min-width: 560px) {
  .modal-overlay {
    align-items: center;
    padding: 1rem;
  }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: modal-in 200ms ease;
  max-height: 90dvh;
  overflow: hidden;
}

@media (min-width: 560px) {
  .modal {
    border-radius: var(--radius-xl);
    max-height: 85dvh;
  }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal--sm { max-width: 380px; }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal__header h3 { font-size: 1rem; font-weight: 600; }

.modal__body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  overflow-y: auto;
  flex: 1;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* Modal form elements */
.modal-input,
.modal-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9375rem;
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.modal-input:focus,
.modal-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.modal-input.error,
.modal-textarea.error { border-color: var(--color-danger); }

.required { color: var(--color-danger); }
.optional { color: var(--text-subtle); font-weight: 400; }

/* ============================================================
   SERVER LOADING OVERLAY
   ============================================================ */
.server-loading {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(17,24,39,.32);
  backdrop-filter: blur(2px);
}
.server-loading__panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(360px, 100%);
  padding: 0.875rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.server-loading__spinner {
  width: 1.125rem;
  height: 1.125rem;
  border: 3px solid var(--color-primary-light);
  border-right-color: var(--color-primary);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 700ms linear infinite;
}
.server-loading__text {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}

/* ============================================================
   THEME TOGGLE
   ============================================================ */
#theme-toggle {
  font-size: 1.125rem;
  width: 36px;
  height: 36px;
}

/* ============================================================
   SCROLLBAR (subtle)
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-xl);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ============================================================
   IMPORT FILE LABEL BUTTON STYLE
   ============================================================ */
label.btn { cursor: pointer; }

/* ============================================================
   4-TAB BAR — slightly smaller font on narrow screens
   ============================================================ */
.exam-view .tab { font-size: 0.8125rem; padding: 0.75rem 0.25rem; }
@media (min-width: 480px) { .exam-view .tab { font-size: 0.875rem; padding: 0.75rem 0.5rem; } }

/* ============================================================
   QUESTION MODAL — TYPE SELECTOR (segmented control)
   ============================================================ */
.type-selector {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.type-btn {
  flex: 1;
  padding: 0.375rem 0.25rem;
  border-radius: calc(var(--radius) - 3px);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  text-align: center;
  white-space: nowrap;
}
.type-btn:hover  { color: var(--text); }
.type-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   QUESTION MODAL — MC OPTION ROWS
   ============================================================ */
.mc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.mc-modal-header label { margin-bottom: 0; }

.mc-option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.mc-option-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition);
}
.mc-option-input:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

/* Toggle button to mark an option correct */
.mc-correct-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-subtle);
  font-size: 0.875rem;
  font-weight: 700;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  cursor: pointer;
}
.mc-correct-toggle:hover   { border-color: var(--color-success); color: var(--color-success); }
.mc-correct-toggle.is-correct {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}

.mc-option-delete {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  font-size: 0.875rem;
}

.hint-text {
  font-size: 0.8125rem;
  color: var(--text-subtle);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* ============================================================
   STUDY — MULTIPLE CHOICE OPTION BUTTONS
   ============================================================ */
.mc-options-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mc-option-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  font-size: 0.9375rem;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  transition: border-color var(--transition), background var(--transition);
  font-family: inherit;
}
.mc-option-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}
.mc-option-btn.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

/* Visual checkbox inside MC option button */
.mc-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  /* flex centering so ::after is a centered flex item (no absolute positioning needed) */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}
.mc-checkbox.checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
/* Checkmark as a flex child — inherits centering from parent */
.mc-checkbox.checked::after {
  content: '';
  display: block;
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  /* slight upward nudge to optically centre the L-shape */
  transform: rotate(-45deg) translateY(-1px);
}
.mc-option-label { flex: 1; }

/* ============================================================
   STUDY — MC RESULT ITEMS (shown after checking answer)
   ============================================================ */
.mc-result-grid { margin-top: 0.5rem; }

.mc-result-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 0.375rem;
}
.mc-result-marker { width: 1rem; text-align: center; font-weight: 700; flex-shrink: 0; }

.mc-result-item.correct-hit  { background: var(--color-success-light); color: var(--color-success); }
.mc-result-item.correct-miss { background: var(--color-warning-light); color: var(--color-warning); }
.mc-result-item.wrong-hit    { background: var(--color-danger-light);  color: var(--color-danger);  }
.mc-result-item.neutral      { background: var(--surface-2);           color: var(--text-muted);    }

/* ============================================================
   OVERVIEW TAB
   ============================================================ */
.overview-view {
  padding: 1.25rem 1rem 3rem;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.overview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-bottom: 0.25rem;
}
.overview-toolbar h3 {
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.overview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  transition: box-shadow var(--transition);
}
.overview-card:hover    { box-shadow: var(--shadow-md); }
.overview-card.is-learned { border-left: 3px solid var(--color-success); }

.overview-card__header {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.overview-card__num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-subtle);
  min-width: 1.25rem;
  padding-top: 0.2rem;
  flex-shrink: 0;
}
.overview-card__question {
  flex: 1;
  min-width: 180px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.overview-card__badges {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
  padding-top: 0.125rem;
}
.overview-card__actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}
.overview-card__answer {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

/* MC options in overview */
.overview-options { display: flex; flex-direction: column; gap: 0.375rem; }

.overview-option {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid transparent;
}
.overview-option.is-correct {
  background: var(--color-success-light);
  color: var(--color-success);
  border-color: var(--color-success);
  font-weight: 600;
}
.overview-option-marker { font-weight: 700; min-width: 1rem; flex-shrink: 0; }

/* Text answer in overview */
.overview-answer {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--color-success-light);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-sm);
}
.overview-answer-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-success);
  white-space: nowrap;
  padding-top: 0.125rem;
  flex-shrink: 0;
}
.overview-answer-text {
  color: var(--color-success);
  font-size: 0.9375rem;
  font-weight: 500;
  word-break: break-word;
}

.overview-self-label {
  font-size: 0.8125rem;
  color: var(--text-subtle);
  font-style: italic;
}

/* ============================================================
   STUDY EMPTY STATE (inside tab-content)
   ============================================================ */
.study-empty {
  min-height: calc(100dvh - var(--navbar-height) * 2 - 2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: auto;
  max-width: 360px;
  text-align: center;
}
.toast.toast-visible { opacity: 1; transform: translateY(0); }
.toast-error { border-left: 3px solid var(--color-danger);  color: var(--color-danger);  }
.toast-info  { border-left: 3px solid var(--color-primary); }

/* ============================================================
   EXPORT DIALOG — choice cards
   ============================================================ */
.export-choice-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.export-choice {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  user-select: none;
  position: relative;
}
.export-choice:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.export-choice.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.export-choice__body { flex: 1; }
.export-choice__title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  display: block;
}
.export-choice__desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: block;
  margin-top: 0.125rem;
}

/* Selection indicator dot */
.export-choice__indicator {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}
.export-choice.selected .export-choice__indicator {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.export-choice.selected .export-choice__indicator::after {
  content: '';
  display: block;
  width: 7px;
  height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

/* ============================================================
   IMPORT DIALOG — file info + options
   ============================================================ */
.import-file-info {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.import-file-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 0.375rem;
}
.import-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Checkbox-style option label (used in import dialog) */
.option-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 0;
}
.option-checkbox-label:hover { border-color: var(--color-primary); background: var(--color-primary-light); }

.option-checkbox-label input[type="checkbox"] {
  margin-top: 0.125rem;
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  flex-shrink: 0;
  cursor: pointer;
}
.option-checkbox-content { flex: 1; }
.option-checkbox-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.option-checkbox-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* ============================================================
   STUDY EMPTY STATE (inside tab-content)
   ============================================================ */
.study-empty {
  min-height: calc(100dvh - var(--navbar-height) * 2 - 2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: auto;
  max-width: 360px;
  text-align: center;
}
.toast.toast-visible { opacity: 1; transform: translateY(0); }
.toast-error { border-left: 3px solid var(--color-danger); color: var(--color-danger); }
.toast-info  { border-left: 3px solid var(--color-primary); }

/* ============================================================
   HOME TWO-COLUMN LAYOUT
   ============================================================ */
.home-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  align-items: start;
}
@media (min-width: 680px) {
  .home-columns { grid-template-columns: 1fr 1fr; }
}
.home-column { min-width: 0; } /* prevent grid overflow */
.home-column .section-header {
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}
/* Override global exams-grid breakpoints inside columns */
.home-column .exams-grid { grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .home-column .exams-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* ============================================================
   AUTH HEADER
   ============================================================ */
.app-header__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
  min-width: 0;
}
.auth-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
  flex-wrap: wrap;
}
.auth-buttons {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-shrink: 0;
}
.auth-user {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
  padding: 0.1875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.auth-username {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-primary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 0.375rem;
}
.btn-sm {
  font-size: 0.8125rem;
  padding: 0.3125rem 0.75rem;
  height: auto;
}

@media (max-width: 560px) {
  .app-header__inner {
    align-items: flex-start;
    flex-direction: column;
  }
  .app-header__right {
    width: 100%;
    justify-content: space-between;
  }
  .auth-header {
    justify-content: flex-start;
  }
  .auth-username {
    max-width: 150px;
  }
}

/* ============================================================
   PUBLIC EXAMS SECTION
   ============================================================ */
.exam-card__owner {
  font-size: 0.75rem;
  color: var(--text-subtle);
}
.public-loading {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.5rem 0 1rem;
}
.loading-spinner {
  display: inline-block;
  width: 0.875em;
  height: 0.875em;
  margin-right: 0.375rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: .9;
  vertical-align: -0.125em;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   LOGIN MODAL TABS
   ============================================================ */
.modal-tab-bar {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.modal-tab {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.modal-tab.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}
.modal-tab:hover:not(.active) {
  background: var(--surface-2);
  color: var(--text);
}
.auth-error-text {
  font-size: 0.8125rem;
  color: var(--color-danger);
  margin-top: 0.625rem;
}

/* ============================================================
   AUTH LOADING SKELETON
   ============================================================ */
.auth-loading {
  width: 140px;
  height: 32px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  animation: auth-skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes auth-skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
