:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --text: var(--tg-theme-text-color, #111827);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f6fed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 1100px; margin: 0 auto; padding: 12px 12px 90px; }
h1 { font-size: 22px; margin: 4px 0 2px; }
h2 { font-size: 18px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 6px 0; }
.hint { color: var(--hint); font-size: 13px; }
.center { display: flex; align-items: center; justify-content: center; min-height: 60vh; flex-direction: column; gap: 14px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px;
  padding: 11px 16px; font-size: 15px; font-weight: 600; background: var(--accent); color: var(--accent-text); cursor: pointer; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--bg2); color: var(--text); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg2); color: var(--text); }
.pill.accent { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

.header { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px 6px; }
.credits { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; }

.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 4px; gap: 4px; margin: 8px 0; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--hint); cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-text); }

.test-card h3 { font-size: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.empty { text-align: center; color: var(--hint); padding: 40px 10px; }

/* --- Imtihon --- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); margin: -12px -12px 8px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; padding: 4px 10px; border-radius: 10px; background: var(--bg2); }
.timer.low { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .75; } }
.steps { display: flex; gap: 4px; margin: 4px 0 10px; }
.step { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.step.done { background: var(--ok); }
.step.cur { background: var(--accent); }

.q { padding: 12px 0; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; }
.qhead { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.qnum { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--bg2); display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 13px; }
.qnum.answered { background: var(--accent); color: var(--accent-text); }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); cursor: pointer; }
.opt .key { font-weight: 700; color: var(--hint); }
.opt.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.opt.sel .key { color: var(--accent); }
.tf { display: flex; gap: 6px; flex-wrap: wrap; }
.tf .opt { flex: 1; justify-content: center; min-width: 80px; font-weight: 600; font-size: 13px; }
input.gap, select, textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; }
input.gap:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 260px; resize: vertical; line-height: 1.55; }

.passage { white-space: pre-wrap; line-height: 1.65; font-size: 15px; }
.passage-title { font-weight: 700; font-size: 17px; margin-bottom: 8px; }
.split { display: block; }
.view-toggle { display: flex; gap: 6px; margin: 6px 0; }
@media (min-width: 900px) {
  .split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .split > .card { margin: 0; max-height: calc(100vh - 150px); overflow: auto; }
  .view-toggle { display: none; }
  .split .hide-m { display: block !important; }
}
.instr { background: var(--bg2); border-radius: 10px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; }
.media-img { max-width: 100%; border-radius: 10px; margin: 8px 0; }

.audio-box { display: flex; align-items: center; gap: 12px; background: var(--bg2); border-radius: 12px; padding: 12px; margin: 8px 0; }
.bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .3s linear; }

.rec { text-align: center; padding: 24px 10px; }
.rec-dot { width: 90px; height: 90px; border-radius: 50%; margin: 10px auto 14px; display: flex; align-items: center;
  justify-content: center; font-size: 30px; font-weight: 800; background: var(--bg2); }
.rec-dot.on { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
.rec-dot.prep { background: var(--warn); color: #fff; }

/* --- Natija --- */
.score-big { text-align: center; padding: 18px 10px; }
.score-big .val { font-size: 54px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: 12px; padding: 12px; text-align: center; }
.stat .v { font-size: 24px; font-weight: 800; }
.crit { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.crit div { background: var(--bg2); border-radius: 10px; padding: 8px 4px; text-align: center; font-size: 12px; color: var(--hint); }
.crit b { display: block; font-size: 18px; color: var(--text); }
.mist { font-size: 14px; padding: 6px 0; border-top: 1px dashed var(--line); }
.mist s { color: var(--bad); }
.mist b { color: var(--ok); }
table.review { width: 100%; border-collapse: collapse; font-size: 14px; }
table.review td, table.review th { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.okc { color: var(--ok); font-weight: 700; }
.badc { color: var(--bad); font-weight: 700; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: #111; color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; transition: transform .25s; z-index: 99; max-width: 90%; }
.toast.show { transform: translateX(-50%) translateY(0); }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); z-index: 9; }
.bottom .inner { max-width: 1100px; margin: 0 auto; }
.hide-m { }
