/* Dizayn: DESIGN.md. Telegram mavzusidan qat'i nazar doim qorong'i. */
:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --text: #ececf4;
  --muted: #8b8ba7;
  --accent: #2ee59d;
  --on-accent: #0b2e20;
  --soft-bad: #ff8a8a;
  --soft-bad-bg: #3a1f2a;
  --streak: #ffb547;
  --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { overflow-x: clip; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(20px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}
#topbar:not([hidden]) ~ #app { padding-top: calc(64px + var(--safe-top)); }

h1 { font-size: 30px; line-height: 1.2; margin: 0; text-align: center; font-weight: 700; }
h2 { font-size: 22px; line-height: 1.35; margin: 0 0 8px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hero { font-size: 80px; text-align: center; margin-top: 4vh; }
.small { font-size: 14px; }

/* Ijtimoiy isbot — faqat haqiqiy sonlar (/api/stats) */
.live { align-self: center; display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }
.ticker { overflow: hidden; mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent); }
.track { display: flex; gap: 8px; width: max-content; animation: marquee 40s linear infinite; }
.chip { background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
@keyframes marquee { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .track, .dot { animation: none; }
  .ticker { overflow-x: auto; }
}
.topic { color: var(--muted); font-size: 15px; }

.topics { list-style: none; padding: 0; margin: 20px 0 8px; display: grid; gap: 8px; }
.topics li { background: var(--card); border-radius: 14px; padding: 14px 16px; }

/* Tepadagi progress — savollar davomida doim ko'rinadi */
#topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg);
}
.progress { flex: 1; height: 8px; border-radius: 4px; background: var(--card); overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .45s cubic-bezier(.2, .8, .2, 1); }
#count { font-size: 15px; font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.icon-btn { background: none; border: 0; padding: 6px; font-size: 20px; line-height: 1; cursor: pointer; border-radius: 8px; }

#toast {
  position: fixed;
  top: calc(56px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--card);
  color: var(--streak);
  font-weight: 600;
  font-size: 16px;
  padding: 8px 16px;
  border-radius: 999px;
  white-space: nowrap;
}

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 16px;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease-out, background-color .2s, color .2s;
}
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--muted); }
.sticky { position: sticky; bottom: calc(12px + var(--safe-bottom)); margin-top: auto; }

.options { display: grid; gap: 10px; }
.option { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; font-weight: 500; }
.option:disabled { cursor: default; color: #5c5c78; }
.option.correct { background: var(--accent); color: var(--on-accent); }
.option.wrong { background: var(--soft-bad-bg); color: var(--soft-bad); }
.mark { font-size: 20px; line-height: 1; }

.feedback:empty { display: none; }
.feedback { display: grid; gap: 6px; padding: 16px; border-radius: 14px; background: var(--card); font-size: 16px; }
.feedback p { color: #c4c4d4; }
.feedback .basis { color: var(--muted); font-size: 14px; }

.result-label { margin-top: 6vh; font-size: 16px; }
.score { font-size: 88px; font-weight: 800; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.score small { font-size: 36px; color: #5c5c78; font-weight: 700; }
.percent { text-align: center; color: var(--accent); font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
/* Unvon — ekranning markaziy, eng katta elementi */
.rank {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 8px 0;
  padding: 16px 32px;
  border-radius: 24px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 28px;
  font-weight: 800;
  text-align: center;
}
.rank-emoji { font-size: 48px; line-height: 1; }
.breakdown { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.breakdown li { display: flex; justify-content: space-between; background: var(--card); border-radius: 12px; padding: 12px 16px; font-size: 16px; }
.breakdown .full { color: var(--accent); }
.actions { display: grid; gap: 10px; margin-top: auto; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti i { position: absolute; top: 0; width: 8px; height: 14px; border-radius: 2px; }
