:root {
  /* Падаємо на дефолти, якщо Telegram не інжектнув теми */
  --bg: var(--tg-theme-bg-color, #0e1621);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #5eb5f7);
  --button: var(--tg-theme-button-color, #3a8ee6);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #6c8cff;
  --danger: #e05656;
  --ok: #4caf7d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px 24px;
}

/* ---------- Topbar / timer ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px;
  background: var(--bg);
}
#brand { font-weight: 600; color: var(--hint); font-size: 14px; }
#timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--secondary-bg);
  color: var(--text);
}
#timer.warn { background: rgba(224, 86, 86, 0.18); color: var(--danger); }

/* ---------- Screens ---------- */
.screen { display: none; flex: 1; flex-direction: column; }
.screen.active { display: flex; }

#screen-loading { align-items: center; justify-content: center; gap: 16px; color: var(--hint); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Quiz ---------- */
.quiz-meta { margin-top: 8px; }
#q-header { font-size: 15px; font-weight: 600; color: var(--hint); margin: 0 0 4px; }
#q-progress { font-size: 13px; color: var(--hint); }
.q-text { font-size: 20px; font-weight: 600; margin: 16px 0 20px; }

.options { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.option {
  text-align: left;
  width: 100%;
  padding: 16px;
  font-size: 16px;
  color: var(--text);
  background: var(--secondary-bg);
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.05s;
}
.option:active { transform: scale(0.99); }
.option.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--secondary-bg));
}

/* ---------- Buttons ---------- */
.primary-btn {
  margin-top: 20px;
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  color: var(--button-text);
  background: var(--button);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}
.primary-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- Result ---------- */
#screen-result { align-items: center; justify-content: center; text-align: center; gap: 8px; }
.result-icon { font-size: 64px; line-height: 1; margin-bottom: 8px; }
#result-title { font-size: 24px; margin: 0; }
.result-msg { color: var(--hint); max-width: 320px; margin: 4px 0 16px; }
#result-action { max-width: 320px; }
