/* =========
   Темы
   ========= */
:root {
  --bg: #faf9f5;
  --fg: #3d3929;
  --muted: #8c8677;
  --card: #f0eee6;
  --border: #e5e2d8;
  --accent: #c96442;
  --accent-hover: #b55638;
  --correct: #5a7c3a;
  --correct-bg: #e8f0d8;
  --wrong: #c4472f;
  --wrong-bg: #f5dcd2;
  --note-bg: #f5e6d3;

  --font-serif: 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html.dark {
  --bg: #262624;
  --fg: #f0eee6;
  --muted: #a09a8a;
  --card: #30302e;
  --border: #3d3d3a;
  --accent: #d97757;
  --accent-hover: #e08765;
  --correct: #7a9c5a;
  --correct-bg: #2d3a20;
  --wrong: #d97757;
  --wrong-bg: #3a2320;
  --note-bg: #3a2f20;
}

/* =========
   Базовые стили
   ========= */
* { box-sizing: border-box; }

html {
  font-size: clamp(15px, 1vw + 12px, 18px);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

h1, h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  margin: 0 0 1rem;
}

h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(56px, 8vw, 72px) clamp(16px, 4vw, 24px) clamp(24px, 4vw, 48px);
}

.hidden { display: none !important; }

/* =========
   Тулбар (тема + QR)
   ========= */
.toolbar {
  position: fixed;
  top: clamp(8px, 2vw, 16px);
  right: clamp(8px, 2vw, 16px);
  display: flex;
  gap: 8px;
  z-index: 10;
}

.toolbar-btn {
  width: clamp(36px, 6vw, 42px);
  height: clamp(36px, 6vw, 42px);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--fg);
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toolbar-btn:hover {
  background: var(--card);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.toolbar-btn:active { transform: translateY(0); }

.toolbar-btn svg,
.toolbar-btn img { pointer-events: none; }

.toolbar-icon {
  width: 50%;
  height: 50%;
  filter: var(--icon-filter, none);
}

html:not(.dark) .toolbar-icon {
  filter: brightness(0) saturate(100%);
}

html.dark .toolbar-icon {
  filter: brightness(0) saturate(100%) invert(1) brightness(0.94) sepia(0.05);
}

/* =========
   QR-модалка
   ========= */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-in 0.2s ease-out;
}

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

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

.qr-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: clamp(24px, 4vw, 36px) clamp(20px, 4vw, 32px) clamp(20px, 3vw, 28px);
  text-align: center;
  max-width: 300px;
  width: 88%;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.08);
  animation: modal-in 0.25s ease-out;
}

.qr-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
}

.qr-modal canvas {
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  max-width: 100%;
  height: auto;
}

.qr-url {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 1.25rem 0 1rem;
  word-break: break-all;
  line-height: 1.4;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border-radius: 6px;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

/* =========
   Ошибка / подзаголовок
   ========= */
.error {
  color: var(--wrong);
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--wrong-bg);
  border-radius: 8px;
  font-size: 0.875rem;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

/* =========
   Экран вопроса
   ========= */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

.counter {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 0.5rem;
}

.question-text {
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  margin: 0 0 1.5rem;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: clamp(10px, 2vw, 14px) clamp(12px, 2vw, 16px);
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: clamp(0.875rem, 2vw, 1rem);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.option-btn:hover:not(:disabled) { background: var(--card); }
.option-btn:disabled { cursor: default; }

.option-correct {
  border-color: var(--correct) !important;
  background: var(--correct-bg) !important;
  color: var(--fg) !important;
}

.option-wrong {
  border-color: var(--wrong) !important;
  background: var(--wrong-bg) !important;
  color: var(--fg) !important;
}

.option-muted {
  color: var(--muted) !important;
  opacity: 0.6;
}

.note-block {
  background: var(--note-bg);
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  font-style: italic;
  margin-bottom: 1rem;
  color: var(--fg);
}

/* =========
   Кнопки
   ========= */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

#btn-next, #btn-start { display: block; margin: 0 auto; }

.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: var(--card); }

.pack-options {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}

.pack-option {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.pack-option:hover { background: var(--card); }
.pack-option input { margin: 0; }

/* =========
   Экран итогов
   ========= */
.score {
  font-size: clamp(1.125rem, 3vw, 1.5rem);
  font-weight: 500;
  margin: 1rem 0 1.5rem;
}

.mistakes-list {
  margin-bottom: 1.5rem;
}

.all-correct {
  color: var(--correct);
  font-size: 1rem;
  margin: 0;
}

.mistake-item {
  background: var(--card);
  border-radius: 8px;
  padding: clamp(12px, 2vw, 16px) clamp(14px, 2.5vw, 20px);
  margin-bottom: 0.75rem;
  border-left: 3px solid var(--wrong);
}

.mistake-question {
  margin: 0 0 0.5rem;
  font-weight: 500;
}

.mistake-picked, .mistake-correct {
  margin: 0.25rem 0;
  font-size: 0.875rem;
}

.wrong-text { color: var(--wrong); }
.correct-text { color: var(--correct); }

.mistake-note {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--muted);
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.results-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* =========
   Открытые вопросы
   ========= */
.open-answer-area {
  margin-bottom: 1rem;
}

.word-hint {
  color: var(--muted);
  font-size: 0.8125rem;
  margin: 0 0 0.625rem;
  font-style: italic;
}

.open-input {
  width: 100%;
  padding: clamp(10px, 2vw, 14px) clamp(12px, 2vw, 16px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: clamp(0.875rem, 2vw, 1rem);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.open-input::placeholder { color: var(--muted); opacity: 0.6; }

.open-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.open-input:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-submit {
  margin-top: 0.75rem;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.open-feedback {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  display: none;
}

.open-feedback.visible {
  display: block;
}

.open-feedback p { margin: 0 0 0.25rem; }
.open-feedback p:last-child { margin: 0; }

.open-feedback-correct {
  background: var(--correct-bg);
  border-left: 3px solid var(--correct);
  color: var(--correct);
  font-weight: 500;
}

.open-feedback-wrong {
  background: var(--wrong-bg);
  border-left: 3px solid var(--wrong);
  color: var(--fg);
}

/* =========
   Просмотр ответов
   ========= */
.browse-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.browse-item {
  background: var(--card);
  border-radius: 8px;
  padding: clamp(12px, 2vw, 16px) clamp(14px, 2.5vw, 20px);
  position: relative;
}

.browse-num {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.browse-question {
  margin: 0.25rem 0 0.5rem;
  font-weight: 500;
  line-height: 1.45;
}

.browse-answer {
  margin: 0;
  color: var(--correct);
  font-weight: 500;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

#btn-browse-back {
  margin-top: 1rem;
}
