/* Imtihon javob varaqasi: chiziqli qog'oz, doiracha belgilar, natija muhri.
   Ranglar Telegram mavzusidan olinadi, brauzerda esa qog'oz palitrasi ishlaydi. */
:root {
  --paper: var(--tg-theme-bg-color, #f7f2e6);
  --ink: var(--tg-theme-text-color, #1d1a15);
  --hint: var(--tg-theme-hint-color, #84796a);
  --accent: var(--tg-theme-button-color, #a8321c);
  --accent-ink: var(--tg-theme-button-text-color, #fff8ec);
  --card: var(--tg-theme-secondary-bg-color, #eee6d3);
  --ok: #1d8656;
  --bad: #cc3d27;
  --rule: color-mix(in srgb, var(--ink) 9%, transparent);
  --line: color-mix(in srgb, var(--ink) 16%, transparent);
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --mono: "Martian Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.5 var(--serif);
  overflow-wrap: anywhere;
}
#app {
  max-width: 620px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
}
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.label {
  font: 600 10.5px/1.4 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--hint);
}
.mono { font-family: var(--mono); font-size: .8em; }
.hint { color: var(--hint); font-size: 15px; }
.stack { display: grid; gap: 12px; }

.masthead { padding: 6px 0 18px; border-bottom: 2px solid var(--ink); margin-bottom: 18px; }
.masthead h1 { font-size: 31px; line-height: 1.12; font-weight: 700; letter-spacing: -.012em; margin-top: 6px; }

.tabs { display: flex; gap: 20px; margin-bottom: 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { padding: 8px 0 10px; font: 600 11px/1.4 var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--hint); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--accent); }

.row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 15px 2px;
  border-bottom: 1px solid var(--line);
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; line-height: 1.3; }
.row .chev { color: var(--hint); font-family: var(--mono); }
.list { border-top: 1px solid var(--line); animation: rise .28s ease both; }

.notice {
  display: grid; gap: 10px; padding: 15px 16px; margin-bottom: 20px;
  border: 1.5px solid var(--accent); border-radius: 3px;
}
.notice .title { font-weight: 700; font-size: 18px; line-height: 1.3; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.btn { padding: 12px 18px; border-radius: 3px; font: 600 12px/1.3 var(--mono); letter-spacing: .03em; border: 1.5px solid var(--line); min-height: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn.small { padding: 7px 11px; min-height: 36px; font-size: 11px; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; }

/* ─── Savol varag'i ─────────────────────────────────────────────────────── */
.sheet-page {
  min-height: inherit;
  display: flex; flex-direction: column;
}
.paper {
  flex: 1;
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px);
  background-position: 0 8px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; }
.topbar .num { font: 600 13px/1 var(--mono); }
.topbar .num b { font-size: 21px; color: var(--accent); }
.icon-btn { min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; font: 600 11px/1 var(--mono); border: 1.5px solid var(--line); border-radius: 3px; padding: 0 10px; }
.timer { font: 600 14px/1 var(--mono); color: var(--accent); }
.timer.low { color: var(--bad); animation: pulse 1s ease-in-out infinite; }

.progress { height: 3px; background: var(--line); margin-bottom: 8px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.tally { display: flex; justify-content: space-between; margin-bottom: 22px; }
.tally span { font: 600 11px/1.3 var(--mono); }
.tally .good { color: var(--ok); }
.tally .wrong { color: var(--bad); }

.question { font-size: 21px; line-height: 32px; font-weight: 600; margin-bottom: 24px; animation: rise .22s ease both; }

.options { display: grid; gap: 4px; background: var(--paper); }
.option {
  display: flex; gap: 14px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 12px 8px; min-height: 56px;
  border-radius: 3px;
  background: var(--paper);
  transition: background .15s ease, opacity .2s ease;
}
.option:not(:disabled):active { background: var(--card); }
.bubble {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: grid; place-items: center;
  font: 600 12px/1 var(--mono);
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .18s ease;
}
.option .text { padding-top: 3px; line-height: 1.4; }
.option.dim { opacity: .42; }
.option.is-correct .bubble { background: var(--ok); border-color: var(--ok); color: #fff; transform: scale(1.08); }
.option.is-correct .text { font-weight: 600; }
.option.is-wrong .bubble { background: var(--bad); border-color: var(--bad); color: #fff; }
.option.is-wrong .text { text-decoration: line-through; text-decoration-thickness: 1px; }

.feedback { padding-top: 16px; background: var(--paper); font: 600 12px/1.4 var(--mono); min-height: 34px; }
.feedback.good { color: var(--ok); }
.feedback.wrong { color: var(--bad); }

.footer {
  position: sticky; bottom: 0;
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 14px 0 calc(10px + env(safe-area-inset-bottom));
  background: var(--paper);
  margin-top: 20px;
}

/* ─── Javob varaqasi ────────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--ink) 45%, transparent); z-index: 10; display: flex; align-items: flex-end; animation: fade .18s ease both; }
.drawer { background: var(--paper); width: 100%; max-width: 620px; margin: 0 auto; max-height: 78vh; display: flex; flex-direction: column; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ink); animation: up .22s ease both; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 7px; overflow-y: auto; padding: 2px; }
.cell { aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--line); font: 600 10px/1 var(--mono); color: var(--hint); }
.cell.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.cell.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.cell.skipped { border-color: var(--hint); color: var(--ink); }
.cell.now { border-color: var(--accent); border-width: 2.5px; color: var(--accent); }

/* ─── Natija ────────────────────────────────────────────────────────────── */
.result { text-align: center; padding-top: 34px; }
.stamp {
  display: inline-grid; place-items: center; align-content: center;
  width: 196px; height: 196px; margin: 26px 0 24px;
  border: 5px double var(--accent); border-radius: 50%;
  color: var(--accent);
  transform: rotate(-7deg);
  animation: stamp .42s cubic-bezier(.2, 1.5, .4, 1) both;
}
.stamp b { font: 600 46px/1 var(--mono); letter-spacing: -.04em; }
.stamp span { font: 600 10.5px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; margin-top: 7px; }
.result .score { font-size: 19px; font-weight: 600; }
.result .actions { justify-content: center; margin-top: 26px; }

/* ─── Formalar ──────────────────────────────────────────────────────────── */
.field { display: grid; gap: 6px; }
.input { width: 100%; padding: 12px; background: transparent; border: 1.5px solid var(--line); border-radius: 3px; min-height: 46px; }
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 92px; }
.answer-row { display: flex; gap: 10px; align-items: center; }
.answer-row .bubble { background: transparent; }
.answer-row .bubble[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.inline-form { display: flex; gap: 10px; margin-bottom: 16px; }
.inline-form .input { flex: 1; min-width: 0; }

.toggle { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 1.5px solid var(--ink); transition: background .15s ease; }
.toggle[aria-checked="true"] { background: var(--ok); border-color: var(--ok); box-shadow: inset 0 0 0 4px var(--paper); }

.state { padding: 60px 8px; text-align: center; display: grid; gap: 12px; }
.state .big { font-size: 24px; font-weight: 700; line-height: 1.25; }
.loader { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); margin: 90px auto; animation: spin .8s linear infinite; }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; border-radius: 3px; max-width: 88vw; width: max-content;
  font: 600 12px/1.45 var(--mono);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 20;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes stamp { from { opacity: 0; transform: rotate(-7deg) scale(1.7); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
