/* ============================================================
   Санҷиши барномасозон
   Classic, quiet, print-like: white paper, black ink, hairline
   rules, serif headings. Colour appears only where it carries
   meaning — pass, fail, warning.
   ============================================================ */

:root {
  color-scheme: light;

  --paper: #ffffff;
  --paper-tint: #fafafa;
  --ink: #111111;
  --ink-soft: #55555a;
  --ink-faint: #8b8b90;
  --rule: #e3e3e6;
  --rule-firm: #c9c9ce;

  --ok: #1a6b3c;
  --ok-tint: #f2f8f4;
  --danger: #a52019;
  --danger-tint: #fdf4f3;
  --warn: #7a5300;
  --warn-tint: #fdf9f0;

  --serif: Georgia, "Iowan Old Style", "Times New Roman", Times, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;

  --topbar: 60px;
  --radius: 3px;
}

* { box-sizing: border-box; }

/* Several rules below set `display`, which would otherwise beat the UA rule
   for the `hidden` attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Text is not selectable anywhere except where the candidate must type. */
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea { -webkit-user-select: text; user-select: text; }

/* Printing / print-to-PDF gets an empty page. */
@media print {
  body * { display: none !important; }
  body::after {
    content: "Чоп кардан манъ аст / Printing is disabled";
    display: block !important;
    font: 400 18px var(--serif);
    color: #000;
  }
}

img { -webkit-user-drag: none; user-drag: none; }

.icon { flex: none; vertical-align: -.15em; }

/* ------------------------------- watermark ------------------------------- */

#watermark {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  opacity: .045;
  font: 500 12px/1 var(--mono);
  color: #000;
  white-space: pre;
  overflow: hidden;
}
#watermark.on { display: block; }
#watermark span { position: absolute; transform: rotate(-28deg); transform-origin: left top; }

/* --------------------------------- topbar -------------------------------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--ink);
  color: var(--ink);
  flex: none;
}
.brand-text {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#lang-switch { margin-left: auto; display: flex; }
.lang-btn {
  border: 1px solid var(--rule-firm);
  border-right-width: 0;
  background: var(--paper);
  color: var(--ink-soft);
  padding: 7px 13px;
  font: 500 12px/1 var(--sans);
  letter-spacing: .06em;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.lang-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.lang-btn:last-child { border-right-width: 1px; border-radius: 0 var(--radius) var(--radius) 0; }
.lang-btn:hover { color: var(--ink); background: var(--paper-tint); }
.lang-btn.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

#test-meta { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.meta-timer {
  display: flex;
  align-items: center;
  gap: 7px;
  font: 500 15px/1 var(--mono);
  letter-spacing: .04em;
  color: var(--ink);
}
.meta-timer.low { color: var(--danger); }
.meta-count {
  font: 500 12px/1 var(--sans);
  letter-spacing: .06em;
  color: var(--ink-faint);
  white-space: nowrap;
}

#progress-bar {
  position: sticky;
  top: var(--topbar);
  z-index: 19;
  height: 2px;
  background: var(--rule);
}
#progress-fill { height: 100%; width: 0; background: var(--ink); transition: width .25s ease; }

/* ---------------------------------- page --------------------------------- */

.app {
  position: relative;
  z-index: 10;
  max-width: 680px;
  margin: 0 auto;
  padding: 44px 24px 72px;
}

.card { padding: 0; }
.card + .card { margin-top: 40px; padding-top: 36px; border-top: 1px solid var(--rule); }

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.25;
  letter-spacing: -.01em;
  margin: 0 0 14px;
}
h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22px;
  line-height: 1.3;
  margin: 0 0 10px;
}
h3 { font-size: 16px; font-weight: 600; margin: 0 0 5px; letter-spacing: -.005em; }

p { margin: 0 0 14px; color: var(--ink-soft); }
p.lead { color: var(--ink); font-size: 17px; }
b, strong { color: var(--ink); font-weight: 600; }
.center { text-align: center; }
.muted { color: var(--ink-faint); font-size: 14px; }

.tagline {
  color: var(--ink-faint);
  font-size: 13px;
  letter-spacing: .09em;
  text-transform: uppercase;
  margin: 0 0 26px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 8px;
}

/* --------------------------------- rules --------------------------------- */

.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--serif);
  font-size: 19px;
  margin: 32px 0 4px;
}

.rules { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.rules li {
  display: flex;
  gap: 14px;
  padding: 13px 0;
  color: var(--ink-soft);
  font-size: 15px;
  border-bottom: 1px solid var(--rule);
}
.rules li::before {
  content: counter(rule, decimal-leading-zero);
  counter-increment: rule;
  font: 500 12px/1.7 var(--mono);
  color: var(--ink-faint);
  flex: none;
}
.rules { counter-reset: rule; }

/* -------------------------------- notices -------------------------------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-left-width: 2px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.55;
  margin: 20px 0;
}
.notice > .icon { margin-top: 2px; }
.notice-warn { background: var(--warn-tint); border-color: var(--rule); border-left-color: var(--warn); color: var(--warn); }
.notice-danger { background: var(--danger-tint); border-color: var(--rule); border-left-color: var(--danger); color: var(--danger); }
.notice-ok { background: var(--ok-tint); border-color: var(--rule); border-left-color: var(--ok); color: var(--ok); }
.notice b { color: inherit; }

/* --------------------------------- forms --------------------------------- */

.field { margin-bottom: 20px; }
.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 7px;
}
.field input, .field textarea {
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--rule-firm);
  background: transparent;
  color: var(--ink);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.field textarea {
  min-height: 200px;
  resize: vertical;
  line-height: 1.7;
  padding: 12px 14px;
  border: 1px solid var(--rule-firm);
  border-radius: var(--radius);
}
.field input::placeholder, .field textarea::placeholder { color: #b8b8bd; }
.field input:focus, .field textarea:focus { border-color: var(--ink); }
.field .hint { font-size: 12.5px; color: var(--ink-faint); margin-top: 7px; }
.field .err { font-size: 12.5px; color: var(--danger); margin-top: 7px; display: none; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.field.invalid .err { display: block; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; gap: 0; } }

.lang-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lang-pick button {
  padding: 13px 6px;
  border: 1px solid var(--rule-firm);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-soft);
  font: 500 14px/1.3 var(--sans);
  cursor: pointer;
  transition: .12s;
}
.lang-pick button:hover { border-color: var(--ink); color: var(--ink); }
.lang-pick button.active { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* -------------------------------- buttons -------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 50px;
  padding: 13px 22px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: 500 15px/1 var(--sans);
  letter-spacing: .01em;
  cursor: pointer;
  text-decoration: none;
  transition: background .14s, color .14s, border-color .14s, opacity .14s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover:not(:disabled) { background: #000; }
.btn-ghost { border-color: var(--rule-firm); color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover:not(:disabled) { background: #145530; border-color: #145530; }
.btn-link { border-color: var(--rule-firm); color: var(--ink); }
.btn-link:hover { border-color: var(--ink); background: var(--paper-tint); }
.btn + .btn { margin-top: 12px; }

.nav-row { display: flex; gap: 12px; margin-top: 30px; }
.nav-row .btn { margin-top: 0; }
.nav-row .btn-ghost { flex: 0 0 33%; }

/* ------------------------------- questions ------------------------------- */

.q-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.q-level { color: var(--ink); font-weight: 600; white-space: nowrap; }

.q-text {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.45;
  font-weight: 400;
  color: var(--ink);
  margin: 0 0 20px;
}

pre.q-code {
  margin: 0 0 22px;
  padding: 16px 18px;
  background: var(--paper-tint);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--ink);
  border-radius: var(--radius);
  overflow-x: auto;
  font: 13.5px/1.7 var(--mono);
  color: #24242a;
  white-space: pre;
}

.options { display: flex; flex-direction: column; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  margin-top: -1px;
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15.5px/1.55 var(--sans);
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.option:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.option:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.option:hover { background: var(--paper-tint); }
.option .key {
  flex: none;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 1px solid var(--rule-firm);
  border-radius: 50%;
  font: 500 12px/1 var(--mono);
  color: var(--ink-faint);
  transition: .1s;
}
.option .val { min-width: 0; overflow-wrap: anywhere; }
.option.selected {
  border-color: var(--ink);
  background: var(--paper);
  position: relative;
  z-index: 1;
}
.option.selected .key { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* --------------------------------- result -------------------------------- */

.score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 8px 0 4px;
}
.score-ring {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--ink) calc(var(--p) * 1%), var(--rule) 0);
  position: relative;
  flex: none;
}
.score-ring::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--paper);
}
.score-ring div { position: relative; z-index: 1; text-align: center; }
.score-ring .big { font-family: var(--serif); font-size: 27px; line-height: 1; }
.score-ring .small { font-size: 11.5px; letter-spacing: .08em; color: var(--ink-faint); margin-top: 5px; }

.score-side { text-align: left; }
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 21px;
  padding: 7px 0;
  border-bottom: 2px solid var(--ink);
}
.level-badge.pass { color: var(--ok); border-bottom-color: var(--ok); }
.level-badge.fail { color: var(--danger); border-bottom-color: var(--danger); }

.level-table { margin-top: 30px; border-top: 1px solid var(--rule); }
.level-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13.5px;
}
.level-row .name { flex: 0 0 96px; color: var(--ink-soft); }
.level-row .bar { flex: 1; height: 4px; background: var(--rule); }
.level-row .bar i { display: block; height: 100%; background: var(--rule-firm); }
.level-row.done .name { color: var(--ink); }
.level-row.done .bar i { background: var(--ok); }
.level-row .num { flex: 0 0 36px; text-align: right; color: var(--ink-faint); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  text-align: left;
  padding: 22px;
  border: 1px solid var(--rule-firm);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .14s, background .14s;
  font-family: inherit;
}
.choice:hover { border-color: var(--ink); background: var(--paper-tint); }
.choice + .choice { margin-top: 14px; }
.choice .ico { color: var(--ink); margin-top: 2px; }
.choice h3 { margin: 0 0 4px; font-size: 16.5px; }
.choice p { margin: 0; font-size: 14px; color: var(--ink-soft); }

/* -------------------------------- overlays ------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 255, 255, .98);
}
.overlay[hidden] { display: none; }
/* Focus loss blanks the page completely, so an off-window capture gets nothing. */
.overlay-dark { background: #ffffff; }
.overlay-danger { background: rgba(255, 255, 255, .99); }

.overlay-box {
  max-width: 400px;
  width: 100%;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--rule-firm);
  border-radius: var(--radius);
  padding: 36px 28px;
}
.overlay-icon { color: var(--ink); margin-bottom: 16px; }
.overlay-danger .overlay-icon, .overlay-danger h2 { color: var(--danger); }
.overlay-box h2 { margin-bottom: 10px; }
.overlay-box p { margin-bottom: 0; }
.grace-count {
  font: 400 52px/1 var(--serif);
  color: var(--danger);
  margin: 18px 0 22px;
  font-variant-numeric: tabular-nums;
}
.modal-box { text-align: left; }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; }
.modal-actions .btn { margin-top: 0; }

/* --------------------------------- toast --------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 18px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  opacity: 0;
  transition: opacity .18s, transform .18s;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.noscript { padding: 60px 24px; text-align: center; color: var(--danger); }

/* -------------------------------- countdown ------------------------------- */

.countdown {
  font: 400 46px/1 var(--serif);
  color: var(--ink);
  text-align: center;
  margin: 22px 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.spinner {
  width: 22px;
  height: 22px;
  margin: 60px auto;
  border: 1.5px solid var(--rule);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------- responsive ------------------------------ */

@media (max-width: 560px) {
  :root { --topbar: 54px; }
  #topbar { padding: 0 16px; gap: 10px; }
  .app { padding: 30px 18px 56px; }
  h1 { font-size: 25px; }
  h2 { font-size: 20px; }
  .q-text { font-size: 18.5px; }
  .brand-text { display: none; }
  .lang-btn { padding: 7px 11px; }
  .nav-row .btn-ghost { flex: 0 0 38%; }
  .score { flex-direction: column; gap: 20px; text-align: center; }
  .score-side { text-align: center; }
  .level-row .name { flex: 0 0 78px; font-size: 12.5px; }
  .choice { padding: 18px; gap: 13px; }
  .card + .card { margin-top: 32px; padding-top: 28px; }
}
