:root {
  --bg-color: #0f172a;
  --surface-color: #1e293b;
  --surface-hover: #334155;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --correct-bg: #064e3b;
  --correct-border: #10b981;
  --correct-text: #6ee7b7;
  --wrong-bg: #450a0a;
  --wrong-border: #ef4444;
  --wrong-text: #fca5a5;
  --radius: 12px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

[data-theme="light"] {
  --bg-color: #f1f5f9;
  --surface-color: #ffffff;
  --surface-hover: #f8fafc;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --correct-bg: #ecfdf5;
  --correct-border: #10b981;
  --correct-text: #065f46;
  --wrong-bg: #fef2f2;
  --wrong-border: #ef4444;
  --wrong-text: #991b1b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge-csdd {
  background: #dc2626;
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  background-color: var(--surface-hover);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

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

.btn.active {
  background-color: var(--accent-color);
  border-color: var(--accent-hover);
  color: white;
}

.search-box-container {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.search-input {
  width: 100%;
  padding: 12px 40px 12px 42px;
  font-size: 1.05rem;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.clear-search-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
}

.filters-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.76);
  backdrop-filter: blur(6px);
}

.dialog-backdrop.active {
  display: flex;
}

.collector-dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-color);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.dialog-header,
.status-line,
.rounds-control {
  display: flex;
  align-items: center;
}

.dialog-header {
  justify-content: space-between;
  gap: 16px;
}

.dialog-header h2 {
  font-size: 1.35rem;
}

.dialog-kicker {
  margin-bottom: 2px;
  color: var(--accent-color);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dialog-close {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--surface-hover);
  color: var(--text-main);
  cursor: pointer;
}

.dialog-description {
  margin: 14px 0 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.collector-form label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

.collector-form label small {
  color: var(--text-muted);
  font-weight: 500;
}

.rounds-control {
  gap: 10px;
}

#collector-rounds {
  width: 96px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  outline: none;
  background: var(--bg-color);
  color: var(--text-main);
  font: inherit;
  font-weight: 700;
}

#collector-rounds:focus {
  border-color: var(--accent-color);
}

.collector-start-btn {
  flex: 1;
  justify-content: center;
}

.collector-status {
  margin-top: 20px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-color);
}

.status-line {
  gap: 9px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}

.collector-status.running .status-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.14);
  animation: status-pulse 1.2s infinite;
}

.collector-status.success .status-dot { background: var(--correct-border); }
.collector-status.error .status-dot { background: var(--wrong-border); }

.status-text {
  margin-top: 7px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.progress-track {
  height: 5px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-hover);
}

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

.collector-log {
  max-height: 150px;
  margin-top: 12px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text-muted);
  font: 0.74rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.collector-log:empty { display: none; }

@keyframes status-pulse {
  50% { opacity: 0.45; }
}

.filter-tags {
  display: flex;
  gap: 8px;
}

.filter-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 20px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active, .filter-btn:hover {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

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

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

.questions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

.question-card {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
}

.question-card:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  border-color: #475569;
}

.card-media {
  width: 100%;
  height: 220px;
  background-color: #000;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.card-media:hover img {
  transform: scale(1.03);
}

.card-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-header-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.question-number {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-color);
  text-transform: uppercase;
}

.btn-bookmark {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  transition: color 0.2s;
}

.btn-bookmark.bookmarked {
  color: #f59e0b;
}

.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
  color: var(--text-main);
}

.answer-status {
  margin: -6px 0 14px;
  padding: 9px 11px;
  border: 1px solid var(--wrong-border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.option-item {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-color);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
  cursor: default;
}

.option-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  flex-shrink: 0;
}

/* Solver Mode (Шпаргалка): правильный ответ подсвечен всегда */
body.mode-solver .option-item.correct {
  background-color: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--correct-text);
  font-weight: 600;
}

body.mode-solver .option-item.correct .option-marker {
  background-color: var(--correct-border);
  color: white;
  border-color: var(--correct-border);
}

body.mode-solver .option-item:not(.correct) {
  opacity: 0.65;
}

/* Quiz Mode (Тренажер): ответ открывается по клику */
body.mode-quiz .option-item {
  cursor: pointer;
}

body.mode-quiz .option-item:hover {
  border-color: var(--accent-color);
}

body.mode-quiz .option-item.selected-correct {
  background-color: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--correct-text);
  font-weight: 600;
}

body.mode-quiz .option-item.selected-wrong {
  background-color: var(--wrong-bg);
  border-color: var(--wrong-border);
  color: var(--wrong-text);
}

body.mode-quiz .option-item.revealed-correct {
  border-color: var(--correct-border);
  color: var(--correct-text);
  font-weight: 600;
}

.highlight {
  background-color: #fef08a;
  color: #0f172a;
  padding: 0 2px;
  border-radius: 2px;
}

/* Lightbox Modal */
.lightbox-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.lightbox-modal.active {
  display: flex;
}

.lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 2rem;
  background: none;
  border: none;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

@media (max-width: 640px) {
  .questions-grid {
    grid-template-columns: 1fr;
  }
  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .header-controls {
    width: 100%;
    flex-wrap: wrap;
  }
  .header-controls .btn {
    flex: 1;
    justify-content: center;
  }
  .rounds-control {
    align-items: stretch;
    flex-direction: column;
  }
  #collector-rounds {
    width: 100%;
  }
}
