:root {
  --bg: #f4f6fa; --card: #fff; --text: #172033; --muted: #687387; --line: #dde1e8; --line-strong: #a9b1bf;
  --accent: #2563eb; --accent-soft: #e8f0ff; --ok: #16a34a; --ok-soft: #dcf5e3; --bad: #dc2626; --bad-soft: #fde2e2;
  --warn: #b45309; --warn-soft: #fef3c7; --code-bg: #eef1f6;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }

.nav { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; padding: 10px 24px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; color: var(--text); }
#crumbs { display: flex; gap: 6px; color: var(--muted); min-width: 0; overflow: hidden; white-space: nowrap; }
#crumbs a { color: var(--muted); }
#crumbs span.sep::before { content: "›"; }
main { max-width: 1240px; margin: 0 auto; padding: 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 9px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.danger { color: var(--bad); }
.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.big-btn { padding: 12px 22px; font-size: 1.05rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
button.icon { padding: 5px 9px; }

input[type=text], input[type=number], input[type=password], textarea, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; resize: vertical; min-height: 70px; }
label.f { display: block; font-weight: 600; margin: 12px 0 5px; font-size: .9rem; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--code-bg); color: var(--muted); }
.badge.lobby { background: var(--warn-soft); color: var(--warn); }
.badge.running { background: var(--accent-soft); color: var(--accent); }
.badge.finished { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.err-box { background: var(--bad-soft); color: var(--bad); padding: 10px 14px; border-radius: 10px; margin: 10px 0; }

/* список тем: предмет — сворачиваемая карточка */
.grid > .card { margin-top: 0; }  /* иначе .card + .card опускает в сетке все карточки, кроме первой */
.subject { padding: 0; }
.subject + .subject { margin-top: 12px; }
.subject-head { position: relative; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px;
  padding: 14px 20px 14px 40px; cursor: pointer; list-style: none; user-select: none; }
.subject-head::-webkit-details-marker { display: none; }
.subject-head::before { content: "▸"; position: absolute; left: 20px; top: 15px; color: var(--muted); transition: transform .15s; }
.subject[open] > .subject-head::before { transform: rotate(90deg); }
.subject-head h2 { margin: 0; }
.subject-head .sdesc { flex-basis: 100%; }
.subject[open] > .subject-head { border-bottom: 1px solid var(--line); }
.subject > :not(summary) { margin-left: 20px; margin-right: 20px; }
.subject-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 12px; }
.subject > .grid { margin-bottom: 20px; }
.subject .topic-card { background: var(--bg); }

/* наборы групп */
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.presets:empty { display: none; }
.chip { padding: 4px 12px; border-radius: 99px; font-size: .88rem; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.preset-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.preset-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 6px; }
@media (max-width: 560px) { .preset-row { grid-template-columns: 1fr auto; } .preset-row [data-g] { grid-column: 1; } }
.topic-card { display: flex; flex-direction: column; gap: 8px; }
.topic-card h3 { font-size: 1.05rem; }
.topic-card .actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 16px; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* редактор */
.editor-top { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.editor-top input.title { width: 100%; font-size: 1.3rem; font-weight: 700; border-color: transparent; padding: 6px 8px; }
.editor-top input.title:hover { border-color: var(--line); }
.savebar { position: sticky; top: 52px; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 10px 0; background: var(--bg); }
.q-card { position: relative; }
.q-card.drag-over { outline: 2px dashed var(--accent); }
.q-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.q-num { font-weight: 800; font-size: 1.05rem; min-width: 2.2em; }
.q-head select, .q-head input { padding: 5px 8px; }
.q-head input[type=number] { width: 70px; }
.q-body { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 18px; }
/* варианты вопроса — вкладки над содержимым; видны, только когда вариантов больше одного */
.variants { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: -2px 0 12px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); }
.variants .vtab { min-width: 32px; padding: 3px 8px; font-weight: 700; }
.variants .vtab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.variants .vtab.add { font-weight: 400; }
.variants .vhint { flex-basis: 100%; }
.qlist .qvars { margin-top: 6px; }
.qlist .qvars summary { cursor: pointer; color: var(--accent); }
.qlist .qvar { margin-top: 8px; padding-left: 10px; border-left: 3px solid var(--line); }
.toolbar { display: flex; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.toolbar button { padding: 2px 9px; font-size: .85rem; }
.imgbox { border: 1px dashed var(--line-strong); border-radius: 10px; padding: 10px; text-align: center; color: var(--muted); font-size: .85rem; min-height: 110px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.imgbox img { max-width: 100%; max-height: 180px; background: #fff; }
.opt-row { display: grid; grid-template-columns: 28px 22px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; margin: 6px 0; }
.opt-row input[type=text] { width: 100%; }
.opt-row .letter { font-weight: 700; color: var(--muted); text-align: center; }
.opt-row.correct input[type=text] { border-color: var(--ok); background: var(--ok-soft); }
.opt-img { display: flex; align-items: center; gap: 6px; grid-column: 3 / 6; }
.opt-img img { max-height: 60px; max-width: 160px; border: 1px solid var(--line); background: #fff; }
.deps { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: .9rem; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: .85rem; }
.chip button { border: 0; background: none; padding: 0 6px; color: inherit; }
.warn { color: var(--warn); }
.add-q { display: flex; gap: 8px; justify-content: center; padding: 18px; border: 2px dashed var(--line-strong); border-radius: 14px; margin-top: 14px; }

/* предпросмотр (телефон) */
.phone { width: 375px; max-width: 100%; height: 700px; max-height: 80vh; overflow-y: auto; border: 10px solid #1d2330; border-radius: 34px; background: #f4f6fa; padding: 18px 14px; }
.phone .qhead { display: flex; justify-content: space-between; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.phone .pcard { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; }

/* модальные окна */
.modal-bg { position: fixed; inset: 0; z-index: 100; background: rgba(15, 20, 30, .45); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--card); border-radius: 16px; padding: 22px 24px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: auto; }
.xlsx-errors { margin: 8px 0 0; padding-left: 20px; color: var(--bad); }
.xlsx-errors li { margin: 4px 0; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.seg label input { margin-right: 6px; }
.seg .muted { display: block; font-size: .82rem; margin-top: 4px; font-weight: 400; }

/* пульт проведения */
.live { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 18px; align-items: start; }
.qrbox { text-align: center; }
.qrbox img { width: 100%; max-width: 360px; aspect-ratio: 1; background: #fff; }
.qrbox .url { font-size: 1.05rem; font-weight: 600; word-break: break-all; margin-top: 6px; }
.qrbox .code { font-size: 2rem; font-weight: 800; letter-spacing: .15em; }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.counter { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.counter .n { font-size: 2.3rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counter .l { color: var(--muted); font-size: .88rem; }
.counter.ready .n { color: var(--ok); }
.counter.visitors .n { color: var(--warn); }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.progress { height: 10px; background: var(--code-bg); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.ptable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ptable th, .ptable td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.ptable th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.ptable tr.kicked td { opacity: .45; text-decoration: line-through; }
.ptable tr.kicked td:last-child { text-decoration: none; opacity: 1; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.dot.on { background: var(--ok); }
.mini-progress { display: inline-block; width: 90px; height: 7px; background: var(--code-bg); border-radius: 9px; overflow: hidden; vertical-align: middle; }
.mini-progress > div { height: 100%; background: var(--accent); }
.group-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.rating { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 14px 0; }
.rating-item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; text-align: center; }
.rating-item.none { opacity: .6; }
.rating-item .r-icon { font-size: 1.8rem; line-height: 1; }
.rating-item .r-title { color: var(--muted); font-size: .85rem; margin: 6px 0 4px; }
.rating-item .r-name { font-size: 1.25rem; font-weight: 800; }
.rating-item .r-group { color: var(--muted); font-size: .88rem; }
.rating-item .r-value { font-weight: 700; color: var(--accent); margin-top: 4px; font-variant-numeric: tabular-nums; }
.timer-big { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.projector { position: fixed; inset: 0; z-index: 200; background: #fff; color: #111; display: grid; grid-template-columns: auto 1fr; gap: 5vw; align-items: center; padding: 4vw; }
.projector img { height: 82vh; aspect-ratio: 1; }
.projector .p-url { font-size: 2.6vw; font-weight: 700; word-break: break-all; }
.projector .p-code { font-size: 6vw; font-weight: 800; letter-spacing: .12em; }
.projector .p-count { font-size: 2.4vw; margin-top: 3vh; }
.projector .p-count b { font-size: 4vw; }
.projector .p-close { position: absolute; top: 16px; right: 16px; }

/* результаты */
.res-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.res { border-collapse: separate; border-spacing: 0; font-size: .88rem; min-width: 100%; }
.res th, .res td { padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.res thead th { position: sticky; top: 0; z-index: 2; background: #f7f8fb; font-weight: 600; color: var(--muted); }
.res tfoot td { position: sticky; bottom: 0; background: #f7f8fb; font-weight: 600; }
.res td.name, .res th.name { position: sticky; left: 0; z-index: 1; background: var(--card); }
.res thead th.name { z-index: 3; background: #f7f8fb; }
.res td.c { text-align: center; cursor: pointer; font-weight: 700; min-width: 36px; }
.res td.c.ok { background: var(--ok-soft); color: var(--ok); }
.res td.c.bad { background: var(--bad-soft); color: var(--bad); }
.res td.c.none { color: var(--line-strong); }
.res td.c.ovr { box-shadow: inset 0 0 0 2px var(--warn); }
.res tr.kicked td { opacity: .4; }
.res th.q { text-align: center; }
.res th[data-sort] { cursor: pointer; user-select: none; }
.res th[data-sort]:hover { color: var(--text); }
.res td.c small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); line-height: 1.1; }
.res td.c .blur-n { color: var(--bad); font-weight: 700; }
.res td.ua { color: var(--muted); max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.res td.geo-c { cursor: pointer; }
.qlist { margin-top: 18px; }
.qlist .qi { display: grid; grid-template-columns: 50px minmax(0, 1fr) 220px 110px 170px; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: start; }
.qlist .qi-head { padding: 0 0 4px; }
.geo { font-weight: 600; white-space: nowrap; cursor: help; }
.geo.in { color: var(--ok); }
.geo.out { color: var(--bad); }
.geo.unk { color: var(--warn); }
.qlist .bad-t { color: var(--bad); font-weight: 600; }
.qlist .warn-t { background: #fde68a; color: #713f12; padding: 0 4px; border-radius: 4px; font-weight: 600; }
.qlist .tl { margin-top: 4px; }
.qlist .tl input { width: 64px; padding: 2px 6px; }
.qlist .tl button { padding: 2px 8px; }
.qlist .qi img { max-height: 80px; max-width: 100%; }
.pop { position: fixed; z-index: 120; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.18); max-width: 380px; }
.pop .ans { background: var(--code-bg); padding: 8px 10px; border-radius: 8px; margin: 6px 0 10px; white-space: pre-wrap; word-break: break-word; }

.login { max-width: 360px; margin: 12vh auto; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 300; background: #1f2735; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 420px; }
.toast.err { background: var(--bad); }

@media (max-width: 900px) {
  .q-body, .live { grid-template-columns: 1fr; }
  .counters { grid-template-columns: 1fr 1fr; }
  .qlist .qi { grid-template-columns: 40px minmax(0, 1fr); }
  .qlist .qi > :nth-child(n+3) { grid-column: 2; }
  .qlist .qi-head { display: none; }
}

/* полноэкранная сетка проверки присутствия */
.projector.presence-proj { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 4vh; }
.presence-proj .pp-title { font-size: 2.4vw; font-weight: 700; text-align: center; }
.presence-proj .pp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3vw; }
.presence-proj .pp-cell { display: flex; align-items: center; justify-content: center; gap: 2vw; border: 3px solid #d5dbe5; border-radius: 2vw; padding: 3vh 2vw; }
.presence-proj .pp-icon { font-size: 9vw; line-height: 1; }
.presence-proj .pp-n { font-size: 9vw; font-weight: 800; font-variant-numeric: tabular-nums; }
.presence-proj .pp-bar { height: 1.2vh; background: #e6eaf0; border-radius: 99px; overflow: hidden; }
.presence-proj .pp-bar > div { height: 100%; width: 0; background: #2563eb; transition: width .2s linear; }
