:root {
  --bg: #1e1f22;
  --card: #2b2d31;
  --card-down: #35373c;
  --border: #3f4147;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --dim: #6e737d;
  --blue: #2563eb;
  --blue-down: #1d4ed8;
  --green: #4ade80;
  --green-bg: #143d2a;
  --green-bd: #22c55e;
  --red: #f87171;
  --red-bg: #451a1c;
  --red-bd: #ef4444;
  --amber: #fbbf24;
  --orange-bg: #3a2410;
  --orange-bd: #f97316;
  --orange: #fdba74;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

/* шапка */
.top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand small { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; }

/* кнопки */
.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: var(--radius); padding: 12px 16px; cursor: pointer; min-height: 46px;
  transition: background .1s; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--card-down); }
.btn:active { background: var(--card-down); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover, .btn.primary:active { background: var(--blue-down); }
.btn.orange { background: var(--orange-bg); border: 2px solid var(--orange-bd); color: var(--orange); }
.btn.danger { background: transparent; border-color: #b91c1c; color: var(--red); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn.ghost { background: transparent; }

/* вкладки предметов */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.tab { flex: 0 0 auto; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border); background: transparent; cursor: pointer; }
.tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }

h1 { font-size: 26px; margin: 4px 0 6px; text-align: center; }
.sub { color: var(--muted); text-align: center; margin: 0 auto 22px; max-width: 820px; font-size: 15px; }
.sub p { margin: 4px 0; }

/* варианты */
.vars { display: grid; gap: 14px; grid-template-columns: repeat(var(--cols, 5), 1fr); margin-bottom: 26px; }
.var { display: flex; flex-direction: column; gap: 6px; }
.var .btn { font-weight: 600; font-size: 18px; min-height: 64px; border-width: 2px; }
.var .vrange { font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.var .btn.done { border-color: var(--green-bd); }
.var .btn.part { border-color: var(--amber); }
.var .score { text-align: center; font-size: 14px; color: var(--muted); line-height: 1.3; }
.var .score.done { color: var(--green); }
.var .score.part { color: var(--amber); }
.modes { display: grid; gap: 14px; grid-template-columns: repeat(3, 1fr); margin-bottom: 24px; }
.center { text-align: center; }

/* карточки и формы */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.auth { max-width: 420px; margin: 8vh auto 0; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; color: var(--muted); font-size: 14px; margin-bottom: 4px; }
.input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; outline: none; min-height: 46px;
}
.input:focus { border-color: var(--blue); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .input { flex: 1; min-width: 180px; }
.msg { min-height: 22px; font-size: 14px; margin-top: 8px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }
.note { color: var(--muted); font-size: 14px; }
.redeem { max-width: 640px; margin: 0 auto 24px; }
.redeem h3 { margin: 0 0 6px; }

/* тест */
.qtop { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.qtext { font-weight: 600; font-size: 20px; margin: 0 0 16px; user-select: none; -webkit-user-select: none; }
.opts { display: flex; flex-direction: column; gap: 8px; user-select: none; -webkit-user-select: none; }
.opt {
  text-align: left; border: 1px solid var(--border); background: var(--card); border-radius: var(--radius);
  padding: 13px 14px; cursor: pointer; font-size: 17px; min-height: 50px; -webkit-tap-highlight-color: transparent;
}
.opt:hover { background: var(--card-down); }
.opt.right { background: var(--green-bg); border: 2px solid var(--green-bd); color: #bbf7d0; }
.opt.wrong { background: var(--red-bg); border: 2px solid var(--red-bd); color: #fecaca; }
.opt.dim { color: var(--dim); }
.opt.locked { cursor: default; }
.opt.locked:hover { background: var(--card); }
.opt.right:hover { background: var(--green-bg); }
.opt.wrong:hover { background: var(--red-bg); }
.fb { min-height: 30px; font-weight: 600; font-size: 18px; margin: 12px 0; }
.fb.ok { color: var(--green); }
.fb.bad { color: var(--red); }
.nav { display: flex; gap: 10px; align-items: center; }
.nav .grow { flex: 1; }

/* результаты */
.res-head { font-size: 22px; font-weight: 600; margin-bottom: 14px; }
.res-list { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 6px 16px; max-height: 62vh; overflow: auto; }
.res-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.res-item:last-child { border-bottom: 0; }
.res-item .q { font-weight: 600; margin-bottom: 6px; }
.res-item .yours { color: #fecaca; }
.res-item .right { color: #bbf7d0; }
.res-sec { font-weight: 700; color: var(--muted); margin: 14px 0 4px; letter-spacing: .3px; }

/* админка */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.tbl { overflow-x: auto; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); }
.pill.free { color: var(--green); border-color: var(--green-bd); }
.pill.used { color: var(--muted); }
.pill.blocked { color: var(--red); border-color: var(--red-bd); }
.admin-grid { display: grid; gap: 16px; }
textarea.input { min-height: 120px; font-family: ui-monospace, Consolas, monospace; }

/* водяной знак */
.wm {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; opacity: .05;
  font-size: 22px; font-weight: 700; color: #fff; line-height: 120px; white-space: nowrap;
  transform: rotate(-24deg) scale(1.5); transform-origin: center;
}
.quiz { position: relative; z-index: 1; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111214; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; opacity: 0; transition: opacity .2s;
  pointer-events: none; max-width: 90vw; z-index: 10;
}
#toast.show { opacity: 1; }

/* телефон */
@media (max-width: 720px) {
  .wrap { padding: 12px 12px 96px; }
  h1 { font-size: 22px; }
  .vars { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .var .btn { font-size: 16px; min-height: 56px; }
  .modes { grid-template-columns: 1fr; gap: 10px; }
  .qtext { font-size: 18px; }
  .opt { font-size: 16px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(30, 31, 34, .97); border-top: 1px solid var(--border); z-index: 5;
  }
  .nav .btn { padding: 10px 12px; }
  .nav .finish-label { display: none; }
  .res-list { max-height: none; }
  #toast { top: 14px; bottom: auto; }
}
