:root {
  --bg: #f4f5fb; --card: #ffffff; --ink: #161a33; --muted: #6b7090; --line: #e3e5f0;
  --brand: #4f46e5; --brand-2: #7c3aed; --brand-soft: #eef0ff;
  --good: #16a34a; --good-soft: #e8f8ee; --bad: #dc2626; --bad-soft: #fdecec;
  --warn: #b45309; --warn-soft: #fff6e5; --gold: #f59e0b; --silver: #94a3b8; --bronze: #c2410c;
  --shadow: 0 1px 2px rgba(20,20,60,.06), 0 4px 16px rgba(20,20,60,.06);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1022; --card: #171a33; --ink: #e8e9f5; --muted: #9aa0c3; --line: #2a2e52;
    --brand: #818cf8; --brand-2: #a78bfa; --brand-soft: #23264a;
    --good: #4ade80; --good-soft: #13301f; --bad: #f87171; --bad-soft: #3a1a1f;
    --warn: #fbbf24; --warn-soft: #3a2c10; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
.wrap { max-width: 920px; margin: 0 auto; padding: 16px; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.logo { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; color: var(--ink); }
.logo .dot { width: 28px; height: 28px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-size: 15px; }
.spacer { flex: 1; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: .92rem; }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn { appearance: none; border: 0; border-radius: 11px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; background: var(--brand); color: #fff; transition: transform .05s, opacity .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn:active { transform: scale(.98); } .btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.line { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.red { background: var(--bad); } .btn.green { background: var(--good); }
.btn.sm { padding: 6px 10px; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; justify-content: center; padding: 13px; }
input, textarea, select { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
label { display: block; font-weight: 600; font-size: .88rem; margin: 10px 0 4px; }
.chk { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.chk input { width: auto; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.gray { background: var(--line); color: var(--muted); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background:
  radial-gradient(800px 400px at 10% 0%, color-mix(in srgb, var(--brand) 22%, transparent), transparent),
  radial-gradient(600px 400px at 100% 100%, color-mix(in srgb, var(--brand-2) 18%, transparent), transparent), var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 26px; }
.err { color: var(--bad); font-weight: 600; font-size: .9rem; min-height: 1.3em; margin-top: 8px; }

/* hero */
.hero { background: linear-gradient(135deg, #4f46e5, #7c3aed); color: #fff; border: 0; position: relative; overflow: hidden; }
.hero::after { content: "⚛"; position: absolute; right: -10px; bottom: -40px; font-size: 160px; opacity: .1; }
.hero .big { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.hero .lbl { opacity: .8; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.hero .stats { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 10px; }
.grade { display: inline-grid; place-items: center; min-width: 42px; height: 30px; padding: 0 8px; border-radius: 9px; font-weight: 800; background: rgba(255,255,255,.2); }
.mv-up { color: var(--good); font-weight: 800; } .mv-down { color: var(--bad); font-weight: 800; }
.hero .mv-up, .hero .mv-down { color: #fff; background: rgba(255,255,255,.18); padding: 1px 8px; border-radius: 8px; }

/* tips */
.tip { padding: 11px 14px; border-radius: 12px; margin-bottom: 8px; font-weight: 600; font-size: .93rem; display: flex; gap: 10px; align-items: center; }
.tip.warn { background: var(--warn-soft); color: var(--warn); }
.tip.info { background: var(--brand-soft); color: var(--brand); }
.tip.good { background: var(--good-soft); color: var(--good); }
.tip .btn { margin-left: auto; }

/* tests list */
.test { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.test:first-of-type { border-top: 0; }
.test .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); font-size: 20px; flex: none; }
.test .t { font-weight: 700; } .test .m { color: var(--muted); font-size: .84rem; }
.test .act { margin-left: auto; text-align: right; flex: none; }

/* leaderboard */
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 10px; align-items: end; margin: 6px 0 16px; }
.pod { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 8px; box-shadow: var(--shadow); }
.pod .medal { font-size: 30px; }
.pod .nm { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 2.5em; }
.pod .sc { font-weight: 800; font-size: 1.3rem; color: var(--brand); }
.pod.p1 { padding-top: 22px; border-color: var(--gold); box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 35%, transparent), var(--shadow); }
.lb { width: 100%; border-collapse: collapse; }
.lb th { white-space: nowrap; text-align: left; font-size: .75rem; text-transform: uppercase; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); }
.lb td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lb tr.me td { background: var(--brand-soft); }
.lb tr.me td:first-child { border-radius: 10px 0 0 10px; } .lb tr.me td:last-child { border-radius: 0 10px 10px 0; }
.lb .rk { font-weight: 800; width: 44px; text-align: center; }
.lb .sc { font-weight: 800; text-align: right; }
.prize { font-size: .76rem; color: var(--warn); font-weight: 700; }
.hide-sm { } @media (max-width: 560px) { .hide-sm { display: none; } .podium .pod .nm { font-size: .8rem; } }

/* quiz */
.quiz { max-width: 720px; margin: 0 auto; }
.qhead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s; }
.timer { position: relative; width: 64px; height: 64px; flex: none; }
.timer svg { transform: rotate(-90deg); }
.timer .num { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; }
.timer.low .num { color: var(--bad); }
.qtext { font-size: 1.12rem; font-weight: 600; white-space: pre-wrap; margin-bottom: 14px; }
.qimg { max-width: 100%; max-height: 340px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 14px; display: block; }
.opt { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 13px 14px; margin-bottom: 9px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
.opt .L { width: 30px; height: 30px; flex: none; border-radius: 9px; display: grid; place-items: center; font-weight: 800; background: var(--brand-soft); color: var(--brand); }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .L { background: var(--brand); color: #fff; }
.opt.ok { border-color: var(--good); background: var(--good-soft); }
.opt.no { border-color: var(--bad); background: var(--bad-soft); }
.open-in { font-size: 1.2rem; padding: 14px; text-align: center; font-weight: 700; }

/* result */
.res-big { display: flex; gap: 20px; justify-content: space-around; text-align: center; flex-wrap: wrap; }
.res-big .v { font-size: 2.2rem; font-weight: 800; color: var(--brand); line-height: 1.1; }
.rv { border-top: 1px solid var(--line); padding: 12px 0; }
.rv .h { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-weight: 700; }

/* bell + toasts */
.bell { position: relative; background: none; border: 0; font-size: 21px; cursor: pointer; padding: 4px 6px; color: var(--ink); }
.bell .badge { position: absolute; top: -2px; right: -4px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 800; min-width: 18px; height: 18px; border-radius: 99px; display: grid; place-items: center; padding: 0 4px; }
.bell.ring { animation: ring .9s ease 2; }
@keyframes ring { 0%,100% { transform: rotate(0) } 20% { transform: rotate(15deg) } 40% { transform: rotate(-12deg) } 60% { transform: rotate(8deg) } 80% { transform: rotate(-4deg) } }
.panel { position: fixed; top: 58px; right: 12px; width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow: auto; z-index: 40; display: none; }
.panel.show { display: block; }
.ntf { padding: 10px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.ntf.new { font-weight: 700; } .ntf .tm { font-size: .75rem; color: var(--muted); font-weight: 400; }
#toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.3); animation: tin .3s ease; }
@keyframes tin { from { transform: translateY(20px); opacity: 0 } }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.confetti { position: fixed; top: -10px; width: 9px; height: 14px; z-index: 70; animation: fall linear forwards; pointer-events: none; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* admin */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: var(--card); color: var(--muted); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th, table.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.tbl th { font-size: .75rem; text-transform: uppercase; color: var(--muted); }
.tblwrap { overflow-x: auto; }
.qrow { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.qrow .qt { white-space: pre-wrap; font-weight: 600; }
.qrow ol { margin: 6px 0 0; padding-left: 22px; }
.qrow li.ok { color: var(--good); font-weight: 700; }
.optrow { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.optrow input[type=radio] { width: auto; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
pre.fmt { background: var(--bg); border: 1px dashed var(--line); padding: 10px; border-radius: 10px; font-size: .82rem; white-space: pre-wrap; }
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,30,.5); z-index: 50; display: grid; place-items: center; padding: 12px; }
.modal { width: min(720px, 100%); max-height: 92vh; overflow: auto; }
.katex { font-size: 1.05em; }
