:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --correct: #16a34a;
  --wrong: #dc2626;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #0b1120 0%, #111827 100%);
  color: var(--text);
}

body.menu-open {
  overflow: hidden;
}

button, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--accent);
  color: #08120a;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-weight: 700;
}

button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
button.danger {
  background: var(--danger);
  color: white;
}
button.small {
  padding: 0.45rem 0.7rem;
  font-size: 0.875rem;
  border-radius: 10px;
}

button.is-correct {
  background: rgba(22, 163, 74, 0.18);
  color: #dcfce7;
  border-color: rgba(22, 163, 74, 0.5);
}
button.is-wrong {
  background: rgba(220, 38, 38, 0.16);
  color: #fee2e2;
  border-color: rgba(220, 38, 38, 0.45);
}

select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  padding: 0.7rem 0.9rem;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

h1, h2, h3, p {
  margin-top: 0;
}

.subtitle, .muted {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.panel {
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.inner-panel {
  margin-top: 1rem;
  background: rgba(31, 41, 55, 0.7);
}

.filter-group + .filter-group {
  margin-top: 1rem;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.section-title-row.compact {
  margin-bottom: 0.5rem;
}

.inline-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 280px;
  overflow: auto;
  padding-right: 0.25rem;
}

.checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(51, 65, 85, 0.7);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
}

.checkbox-item input {
  margin-top: 0.15rem;
}

.checkbox-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.content {
  display: grid;
  gap: 1rem;
}

.question-meta {
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
}

.question-text {
  line-height: 1.4;
  margin-bottom: 1rem;
}

.image-wrap {
  margin-bottom: 1rem;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.15);
  background: #0b1220;
}

.image-wrap img {
  display: block;
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  background: #0b1220;
}

.hidden { display: none !important; }

.answers {
  display: grid;
  gap: 0.75rem;
}

.answer-option {
  display: block;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: rgba(15, 23, 42, 0.72);
  transition: 0.15s ease;
}

.answer-option:hover {
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(30, 41, 59, 0.82);
}

.answer-option.selected {
  border-color: rgba(34, 197, 94, 0.55);
  background: var(--accent-soft);
}

.answer-option.correct {
  border-color: rgba(22, 163, 74, 0.8);
  background: rgba(22, 163, 74, 0.16);
}

.answer-option.wrong {
  border-color: rgba(220, 38, 38, 0.75);
  background: rgba(220, 38, 38, 0.14);
}

.answer-option input {
  margin-right: 0.75rem;
}

.question-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.question-actions button {
  flex: 1;
}


.overview-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stat-card {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(51, 65, 85, 0.7);
  border-radius: 14px;
  padding: 0.85rem;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.stats-table th,
.stats-table td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid rgba(51, 65, 85, 0.65);
}

.stats-table th {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.empty-state {
  color: var(--muted);
  padding: 0.5rem 0;
}

.mobile-only {
  display: none;
}

.mobile-sidebar-header {
  margin-bottom: 1rem;
  display: none;
  justify-content: space-between;
  align-items: center;
}

.sidebar-backdrop {
  display: none;
}

.next-btn {
  position: relative;
  overflow: hidden;
  background-color: var(--muted);
}

.next-progress {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 100%;
  background: rgba(255,255,255,0.25);
  transform: translateX(100%);
}

.next-btn.auto .next-progress {
  animation: nextProgress 1.2s linear forwards;
}

@keyframes nextProgress {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0%);
  }
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 0.75rem;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .mobile-only {
    display: inline-flex;
  }

  .mobile-sidebar-header {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 30;
    width: min(92vw, 420px);
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    overflow: auto;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .overview-stats {
    grid-template-columns: 1fr 1fr;
  }

  .section-title-row,
  .question-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #resetProgressBtn {
    display: none;
  }
}


@media (max-width: 768px) {
  .question-actions {
    gap: 0.5rem;
  }

  .question-actions button {
    padding: 0.62rem 0.8rem;
    font-size: 0.95rem;
    border-radius: 10px;
    min-height: 42px;
  }
}

/* ---------- relv additions ---------- */

.answer-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -0.4rem 0 0.75rem;
}

.answer-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  cursor: pointer;
}

.answer-option input {
  margin: 0.2rem 0 0;
  flex-shrink: 0;
}

.answer-key {
  flex-shrink: 0;
  min-width: 1.4rem;
  height: 1.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.answer-text {
  flex: 1;
  line-height: 1.4;
}

.answer-option.missed {
  border: 2px dashed rgba(22, 163, 74, 0.8);
  background: rgba(22, 163, 74, 0.06);
}

.answer-badge {
  flex-shrink: 0;
  align-self: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #86efac;
  border: 1px solid rgba(22, 163, 74, 0.5);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  margin-left: 0.5rem;
}

button.is-partial {
  background: rgba(245, 158, 11, 0.16);
  color: #fef3c7;
  border-color: rgba(245, 158, 11, 0.45);
}

.result-note {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.explanation {
  margin-top: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.55);
}

.explanation summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-weight: 700;
  color: var(--muted);
}

.explanation-body {
  padding: 0 1rem 0.75rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: #cbd5e1;
}

.explanation-body p {
  margin: 0 0 0.6rem;
  white-space: pre-line;
}

.exam-progress {
  margin-bottom: 0.75rem;
}

.exam-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(51, 65, 85, 0.7);
  overflow: hidden;
}

.exam-progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.exam-actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
}

.exam-summary {
  margin: 1rem 0;
}

.review-title {
  margin-top: 1.5rem;
}

.review-item {
  border-top: 1px solid rgba(51, 65, 85, 0.65);
  padding: 1rem 0;
}

.review-item h3 {
  line-height: 1.4;
  margin-bottom: 0.6rem;
}

.review-answers {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.4rem;
}

.review-answer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  color: var(--muted);
}

.review-answer.correct {
  color: var(--text);
  border-color: rgba(22, 163, 74, 0.8);
  background: rgba(22, 163, 74, 0.16);
}

.review-answer.missed {
  color: var(--text);
  border: 2px dashed rgba(22, 163, 74, 0.8);
}

.review-answer.wrong {
  color: var(--text);
  border-color: rgba(220, 38, 38, 0.75);
  background: rgba(220, 38, 38, 0.14);
}

@media (max-width: 680px) {
  .answer-key {
    display: none;
  }
}
