:root {
  --bg: #f6f5f1; --card: #fff; --text: #15184c; --muted: #646886; --line: #e3e1d8;
  --accent: #15184c; --accent-soft: #eceefa; --gold: #cdac6c; --gold-soft: #f7f0e1;
  --navy: #15184c; --navy-deep: #0e1035; --navy-2: #1d2163; --navy-line: #2b3074;
  --heading: 'Montserrat', system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; --ok: #16a34a; --ok-soft: #e7f7ec;
  --bad: #dc2626; --bad-soft: #fdecec; --warn: #d97706; --warn-soft: #fff4e5;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg);
  color: var(--text); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
h1 { font-family: var(--heading); font-weight: 800; font-size: 1.45rem; margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-family: var(--heading); font-weight: 700; font-size: 1.12rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.wrap { max-width: 960px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; }

.topbar { background: var(--navy); color: #fff; border-bottom: 3px solid var(--gold); position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top); }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: var(--heading); }
.topbar .brand img { height: 38px; width: 38px; object-fit: contain; flex: none; background: #fff; border-radius: 50%; padding: 5px; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.topbar .btn:hover { border-color: var(--gold); }
.topbar .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.topbar .brand span { overflow: hidden; text-overflow: ellipsis; }
.login-logo { width: 220px; max-width: 70%; height: auto; display: block; margin: 0 auto 8px; }
.school-name { color: var(--gold); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .85rem; }
.topbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.topbar .brand { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { display: flex; gap: 6px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 160px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text);
  cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { border-color: #b8c4d4; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #23276b; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.gold:hover { background: #d8ba80; }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gray { background: #eef1f5; color: var(--muted); }

.error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.notice { background: var(--accent-soft); padding: 12px; border-radius: 8px; margin-bottom: 12px; }
.hidden { display: none !important; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #f8fafc; }
.table-scroll { overflow-x: auto; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.4rem; font-weight: 700; }

.bars .bar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 8px; align-items: center; margin-bottom: 8px; font-size: .9rem; }
.bars .track { background: #eef1f5; border-radius: 6px; height: 16px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 6px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #1f2933; color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: calc(100% - 32px); }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; max-width: 460px; width: 100%; max-height: 90vh; overflow: auto; }

/* --- Тест редакторы --- */
.q-card { border-left: 4px solid var(--accent); }
.q-card.t-single { border-left-color: var(--accent); }
.q-card.t-match { border-left-color: var(--gold); }
.q-card.t-multi { border-left-color: #6b6fa8; }
.q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.q-head .title { font-weight: 700; flex: 1; }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt-row input[type=radio], .opt-row input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--ok); }
.opt-row .letter { width: 22px; font-weight: 700; color: var(--muted); flex: none; text-align: center; }
.match-row { display: grid; grid-template-columns: 26px 1fr 1fr 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 640px) { .match-row { grid-template-columns: 22px 1fr 34px; } .match-row .right-in { grid-column: 2; } }
.add-bar { display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }

/* --- Оқушының тест беті --- */
body.exam { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.exam-top { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 3px solid var(--gold); }
.exam-top .wrap { display: flex; align-items: center; gap: 10px; padding-top: 8px; padding-bottom: 8px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; padding: 4px 10px; border-radius: 8px; background: var(--accent); color: #fff; }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.qnav { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.qnav button { flex: none; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font: inherit; font-weight: 600; }
.qnav button.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.qnav button.current { outline: 2px solid var(--text); }
.q-text { font-size: 1.08rem; font-weight: 600; margin-bottom: 14px; white-space: pre-wrap; }
.choice { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 2px solid var(--line); border-radius: 10px;
  margin-bottom: 10px; background: #fff; cursor: pointer; width: 100%; text-align: left; font: inherit; color: inherit; }
.choice .mark { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; color: var(--muted); }
.choice.square .mark { border-radius: 6px; }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.selected .mark { background: var(--accent); border-color: var(--accent); color: #fff; }
.choice .txt { padding-top: 2px; white-space: pre-wrap; }
.match-list { margin-bottom: 14px; }
.match-list .item { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: #fff; white-space: pre-wrap; }
.match-list .item b { color: var(--gold); margin-right: 6px; }
.match-left { padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: #fff; }
.match-left .lt { font-weight: 600; margin-bottom: 8px; white-space: pre-wrap; }
.letters { display: flex; gap: 6px; flex-wrap: wrap; }
.letters button { width: 42px; height: 42px; border-radius: 8px; border: 2px solid var(--line); background: #fff; font: inherit; font-weight: 700; }
.letters button.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.letters button.used { color: #b8c4d4; }
.exam-nav { display: flex; gap: 10px; margin-top: 16px; }
.exam-nav .btn { flex: 1; }
.end-screen { text-align: center; padding: 40px 16px; }
.end-screen .icon { font-size: 56px; line-height: 1; margin-bottom: 12px; }

/* --- Басып шығару (логин карточкалары) --- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  .login-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .login-card { border: 1px dashed #999; padding: 10px; break-inside: avoid; font-size: 13px; }
}

/* --- Формулалар мен суреттер --- */
.katex { font-size: 1.08em; }
.q-image { display: block; max-width: 100%; max-height: 360px; margin: 0 auto 14px; border-radius: 8px; border: 1px solid var(--line); }
.fx-bar { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 8px; }
.fx-bar button { min-width: 40px; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font: inherit; font-size: .95rem; cursor: pointer; color: var(--text); }
.fx-bar button:hover { border-color: var(--gold); background: var(--gold-soft); }
.fx-bar .sep { width: 1px; background: var(--line); margin: 0 4px; }
.fx-bar .hint { flex-basis: 100%; font-size: .78rem; color: var(--muted); }
.fx-prev { font-size: .95rem; padding: 6px 10px; margin: -4px 0 8px 30px; background: var(--gold-soft); border-radius: 6px; overflow-x: auto; }
.fx-prev:empty { display: none; }
.match-row .right-in { display: block; }
.match-row.extra { background: var(--gold-soft); border-radius: 8px; padding: 4px 0; }
@media (max-width: 640px) { .match-row.extra .muted { grid-column: 2; } }
.match-row + .fx-prev, .fx-prev + .fx-prev { margin-left: 34px; }
.img-row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.img-row img { max-height: 120px; max-width: 220px; border-radius: 6px; border: 1px solid var(--line); }

/* --- Кіру беті --- */
body.login-page { background: var(--navy-deep); color: #fff; }
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; }
.hero { position: relative; overflow: hidden; background: linear-gradient(150deg, var(--navy-2) 0%, var(--navy) 55%, var(--navy-deep) 100%);
  display: flex; align-items: center; padding: 48px; }
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; pointer-events: none; }
.hero::before { width: 620px; height: 620px; right: -260px; top: -200px; border: 70px solid rgba(255,255,255,.04); }
.hero::after { width: 380px; height: 380px; left: -170px; bottom: -190px; border: 50px solid rgba(205,172,108,.08); }
.hero-inner { position: relative; z-index: 1; max-width: 520px; }
.logo-badge { width: 112px; height: 112px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.35), 0 0 0 6px rgba(205,172,108,.25); margin-bottom: 28px; }
.logo-badge img { width: 78%; height: auto; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.3rem); line-height: 1.08; color: #fff; margin-bottom: 18px; }
.hero .lead { font-size: 1.12rem; color: rgba(255,255,255,.78); margin: 0 0 22px; max-width: 34em; }
.features { list-style: none; padding: 0; margin: 0 0 28px; display: grid; gap: 10px; }
.features li { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.88); font-size: .98rem; }
.features li span { width: 34px; height: 34px; flex: none; border-radius: 10px; background: rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.school { font-family: var(--heading); font-weight: 700; color: var(--gold); letter-spacing: .08em; text-transform: uppercase; font-size: .85rem; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.login-form { width: 100%; max-width: 400px; }
.login-form h2 { font-size: 1.5rem; color: #fff; margin-bottom: 6px; }
.login-form .sub { color: rgba(255,255,255,.6); margin: 0 0 22px; font-size: .95rem; }
.login-form label.field > span { color: rgba(255,255,255,.7); font-weight: 600; }
.login-form input { background: #171b4f; border: 1px solid var(--navy-line); color: #fff; padding: 14px 16px; border-radius: 12px; font-size: 1rem; }
.login-form input::placeholder { color: rgba(255,255,255,.3); }
.login-form input:focus { border-color: var(--gold); outline: 3px solid rgba(205,172,108,.2); }
.login-form .btn.gold { min-height: 52px; border-radius: 12px; font-size: 1.05rem; margin-top: 6px; font-family: var(--heading); }
.login-form .hint { color: rgba(255,255,255,.45); font-size: .85rem; text-align: center; margin-top: 18px; }
.login-form .error { background: rgba(220,38,38,.15); color: #fca5a5; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0;
  background: transparent; color: #fff; font-size: 1.1rem; cursor: pointer; opacity: .6; border-radius: 8px; }
.pw-toggle:hover { opacity: 1; }
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .hero { padding: calc(32px + env(safe-area-inset-top)) 24px 36px; border-bottom-right-radius: 0; }
  .hero::before { width: 420px; height: 420px; right: -200px; top: -140px; border-width: 55px; }
  .logo-badge { width: 92px; height: 92px; margin-bottom: 20px; }
  .features { display: none; }
  .login-panel { align-items: flex-start; padding-top: 28px; }
}

/* --- Тест тапсыру экранының жоғарғы жолағы (қою көк) --- */
.exam-top { background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top); }
.exam-top .muted { color: rgba(255,255,255,.65); }
.exam-top b { font-family: var(--heading); }
.timer { background: var(--gold); color: var(--navy); }
.timer.low { background: var(--bad); color: #fff; }
.qnav button { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
.qnav button.answered { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.qnav button.current { outline: 2px solid #fff; outline-offset: 1px; }
.end-screen h1 { font-size: 1.6rem; }

/* --- Тақырыптар --- */
.topic-sel { width: auto; max-width: 260px; padding: 6px 10px; font-size: .88rem; border-color: var(--gold); background: var(--gold-soft); }
.topic-sel.empty { border-style: dashed; background: #fff; color: var(--muted); }
table.heat th { white-space: nowrap; font-size: .75rem; }
table.heat td:first-child { white-space: nowrap; }
