:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #16181d;
  --muted: #667085;
  --border: #dfe3ea;
  --accent: #2459d6;
  --accent-soft: #e6edfc;
  --accent-text: #ffffff;
  --ok: #178a4c;
  --ok-soft: #e3f4ea;
  --bad: #c9362b;
  --bad-soft: #fbe7e5;
  --warn: #a36300;
  --warn-soft: #fff3dc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);

  --fs: 17px;
  --lh: 1.55;
  --opt-pad: 13px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --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));
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #22262e;
  --text: #eceef2;
  --muted: #98a0ad;
  --border: #2c313a;
  --accent: #5b8cff;
  --accent-soft: #1d2a47;
  --accent-text: #0b1020;
  --ok: #4cc27f;
  --ok-soft: #15301f;
  --bad: #ff6b5e;
  --bad-soft: #3a1b18;
  --warn: #f0b24a;
  --warn-soft: #3a2c12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
:root[data-size="1"] { --fs: 15px; }
:root[data-size="2"] { --fs: 17px; }
:root[data-size="3"] { --fs: 20px; }
:root[data-size="4"] { --fs: 23px; }
:root[data-spacing="tight"] { --lh: 1.35; }
:root[data-spacing="normal"] { --lh: 1.55; }
:root[data-spacing="wide"] { --lh: 1.85; }
:root[data-font="readable"] { --font: "Atkinson Hyperlegible", Verdana, sans-serif; }
:root[data-buttons="large"] { --opt-pad: 19px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font); font-size: 16px; line-height: 1.45; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 6px; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }

.screen { min-height: 100vh; padding-top: var(--safe-top); }
.center { display: grid; place-items: center; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.row.end { justify-content: flex-end; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 11px 16px; border-radius: 12px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.big { width: 100%; padding: 15px; font-size: 17px; margin-top: 8px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.link-btn { background: none; border: 0; color: var(--accent); padding: 4px 0 12px; font-weight: 600; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; padding: 0; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-btn.close { border: 0; background: var(--surface-2); font-size: 15px; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Bosh sahifa */
.home-head { display: flex; gap: 12px; align-items: center; margin: 4px 0 16px; }
.logo { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; font-size: 24px; }
.code-form label { display: block; font-weight: 600; margin-bottom: 8px; }
.code-form input { flex: 1; min-width: 0; font: inherit; font-size: 20px; letter-spacing: 3px; text-transform: uppercase; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.code-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.section-title { margin: 22px 2px 10px; }
.list { display: grid; gap: 10px; }
.test-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.test-item b { display: block; }
.test-item small { color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.badge.lock { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 18px; }

/* Test haqida */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.facts div { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.notice { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 12px; font-weight: 600; }
.rules { color: var(--muted); font-size: 14px; padding-left: 20px; }
@media (max-width: 420px) { .facts { grid-template-columns: 1fr 1fr; } .facts div:last-child { grid-column: span 2; } }

/* Test oynasi */
.exam { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); padding-top: var(--safe-top); }
.topbar-in { max-width: 760px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); min-width: 86px; text-align: center; }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.progress-num { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.tools { margin-left: auto; display: flex; gap: 6px; }
.progress { height: 3px; background: var(--surface-2); }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.exam .screen { padding-top: 0; }
#s-exam.screen { padding-top: 0; }
.question-area { flex: 1; width: 100%; padding-bottom: 110px; }
.q-text { font-size: var(--fs); line-height: var(--lh); font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 14px; }
.q-img { display: block; max-width: 100%; max-height: 50vh; margin: 0 auto 16px; border-radius: 12px; border: 1px solid var(--border); background: #fff; }
.options { display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; padding: var(--opt-pad) 14px; font-size: var(--fs); line-height: var(--lh); }
.opt .letter { flex: none; width: 1.9em; height: 1.9em; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface-2); font-size: .9em; }
.opt .otext { padding-top: .1em; overflow-wrap: anywhere; white-space: pre-wrap; }
.opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.opt.selected .letter { background: var(--accent); color: var(--accent-text); }
.bottombar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); z-index: 5; }
.bottombar-in { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; }
.btn.finish { color: var(--bad); border-color: var(--bad); background: transparent; }

/* Pastdan chiquvchi oynalar */
.sheet { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--surface); width: 100%; max-width: 560px; max-height: 85vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + var(--safe-bottom)); animation: up .18s ease-out; }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-body { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.grid button { height: 44px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface); font-weight: 700; }
.grid button.done { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.grid button.current { outline: 2px solid var(--text); outline-offset: 1px; }
.legend { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1.5px solid var(--border); margin-left: 6px; }
.dot.done { background: var(--accent-soft); border-color: var(--accent); margin-left: 0; }

.calc-display { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; text-align: right; margin-bottom: 12px; min-height: 76px; }
.calc-expr { color: var(--muted); min-height: 22px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.calc-res { font-size: 30px; font-weight: 700; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-keys button { height: 54px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 20px; font-weight: 600; }
.calc-keys .k-fn { background: var(--surface-2); }
.calc-keys .k-op { background: var(--accent-soft); color: var(--accent); }
.calc-keys .k-eq { background: var(--accent); color: var(--accent-text); grid-row: span 2; height: auto; }
.calc-keys .k-wide { grid-column: span 2; }

.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 11px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg[data-key="size"] button:nth-child(1) { font-size: 12px; }
.seg[data-key="size"] button:nth-child(2) { font-size: 14px; }
.seg[data-key="size"] button:nth-child(3) { font-size: 17px; }
.seg[data-key="size"] button:nth-child(4) { font-size: 20px; }

.modal { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal-body { background: var(--surface); border-radius: 18px; padding: 20px; max-width: 400px; width: 100%; }
.modal-body p { color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 70px); z-index: 40; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }

/* Natija */
.result-card { text-align: center; }
.score-ring { width: 132px; height: 132px; border-radius: 50%; margin: 14px auto; display: grid; place-content: center; background: conic-gradient(var(--accent) calc(var(--p, 0) * 1%), var(--surface-2) 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--surface); }
.score-ring span, .score-ring small { position: relative; }
.score-ring span { font-size: 38px; font-weight: 800; line-height: 1; }
.score-ring small { color: var(--muted); }
.tabs { display: flex; gap: 6px; margin: 22px 0 12px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 14px; }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.rv { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 12px; padding: 12px 14px; }
.rv.wrong { border-left-color: var(--bad); }
.rv .rv-q { font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 8px; }
.rv img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin-bottom: 8px; }
.rv .ans { font-size: 14px; margin: 2px 0; overflow-wrap: anywhere; }
.rv .ans.me { color: var(--bad); }
.rv .ans.ok { color: var(--ok); }

/* ---------------- Test yaratish ---------------- */
.create-cta { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; margin-bottom: 12px; border: 1.5px dashed var(--accent); background: var(--accent-soft); }
.create-cta b { display: block; color: var(--accent); }
.create-cta small { color: var(--muted); }
.cta-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 22px; font-weight: 700; flex: none; }
.create-wrap { padding-bottom: 110px; }
.create-wrap .card { margin-bottom: 12px; }
.create-head { display: flex; justify-content: space-between; align-items: center; }
.field-label { display: block; font-weight: 600; margin: 4px 0 8px; font-size: 14px; }
.input { width: 100%; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; }
.input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.input.area { resize: vertical; min-height: 84px; line-height: 1.45; }
#imp-textarea { min-height: 220px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.setting.compact { padding: 4px 0 12px; border: 0; }
.duration-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.duration-row .input { width: 96px; font-size: 18px; font-weight: 700; text-align: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600; }
.chips button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.create-wrap .field-label { margin-top: 14px; }
.create-wrap .card > .field-label:first-of-type { margin-top: 4px; }
.status-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 18px; margin-bottom: 4px; }
.st-err { font-size: 13px; font-weight: 700; color: var(--bad); background: var(--bad-soft); padding: 4px 10px; border-radius: 999px; }
.st-ok { color: var(--ok); background: var(--ok-soft); }
.progress.thin { height: 6px; border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.row.gap.left { justify-content: flex-start; }
.row.gap.between { justify-content: space-between; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.qc { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.qc.bad { border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }
.qc-top { display: flex; gap: 10px; align-items: flex-start; }
.qc-n { flex: none; min-width: 30px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 13px; padding: 0 6px; }
.qc-text { font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.qc-img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); flex: none; margin-left: auto; }
.qc-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.qc-opts span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qc-opts .ok { color: var(--ok); font-weight: 700; }
.qc-opts .empty-opt { color: var(--bad); }
.qc-err { margin-top: 8px; font-size: 13px; color: var(--bad); font-weight: 600; }
.qc-opts { gap: 2px 10px; }
.bottombar-in.single { grid-template-columns: 1fr; }
.bottombar-in.single .btn.big { margin-top: 0; }

.tabs.slim { margin: 0 0 12px; }
.drop { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 28px 16px; border: 2px dashed var(--border); border-radius: 16px; cursor: pointer; background: var(--surface-2); }
.drop-icon { font-size: 30px; }
.fmt-help { margin: 12px 0 4px; font-size: 14px; }
.fmt-help summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.fmt-help pre { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; }

.ed-image { margin: 10px 0 6px; }
.ed-image img { display: block; max-width: 100%; max-height: 200px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 8px; background: #fff; }
.small-btn { padding: 8px 12px; font-size: 14px; display: inline-block; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt-radio { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--surface-2); font-weight: 800; }
.opt-radio.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt-row .input { padding: 9px 12px; }

.success-icon { width: 64px; height: 64px; margin: 4px auto 12px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 32px; font-weight: 800; }
.code-box { display: inline-grid; gap: 2px; margin: 14px auto 8px; padding: 10px 26px; border-radius: 14px; background: var(--surface-2); }
.code-box b { font-size: 30px; letter-spacing: 4px; font-variant-numeric: tabular-nums; }
.link-box { font-size: 14px; color: var(--accent); overflow-wrap: anywhere; }
.cr-note { margin-top: 14px; }
