:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #16191f; --muted: #5d6573; --line: #e2e5ea;
  --accent: #1f6feb; --accent-ink: #ffffff; --accent-soft: #e7f0ff;
  --live: #d92d20; --live-soft: #fdecea; --ok: #12805c; --ok-soft: #e3f5ee; --warn: #b54708; --warn-soft: #fff4e5;
  --code: #f2f4f7; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px; --nav-h: 64px;
  color-scheme: light dark;
}
/* тёмная тема: по системе, если пользователь не выбрал светлую, или по выбору */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #181b21; --text: #eceef2; --muted: #9aa3b2; --line: #2a2f38;
    --accent: #4c8dff; --accent-ink: #ffffff; --accent-soft: #1b2a45; --live: #ff6b5e; --live-soft: #3a1d1b; --ok: #3cc28f; --ok-soft: #14302a;
    --warn: #f5a524; --warn-soft: #3a2a10; --code: #22262e; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #181b21; --text: #eceef2; --muted: #9aa3b2; --line: #2a2f38;
    --accent: #4c8dff; --accent-ink: #ffffff; --accent-soft: #1b2a45; --live: #ff6b5e; --live-soft: #3a1d1b; --ok: #3cc28f; --ok-soft: #14302a;
    --warn: #f5a524; --warn-soft: #3a2a10; --code: #22262e; --shadow: none;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.2em 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.1rem; } h4 { font-size: 1rem; }
p { margin: .6em 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 12px 0; border: 1px solid var(--line); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 9px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; min-height: 40px; }
.btn:hover { border-color: var(--accent); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--live); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }

/* выбор темы */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--code); border-radius: 12px; }
.seg-b { flex: 1 1 0; min-width: 0; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; font-size: .875rem; cursor: pointer; padding: 6px 8px; line-height: 1.2; }
.seg-b.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.btn.icon { width: 36px; min-width: 36px; padding: 0; font-size: 1rem; }
.theme-ask { border-color: var(--accent); }

label.f { display: block; margin: 10px 0; font-weight: 500; font-size: .9rem; }
label.f > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--code); color: var(--muted); white-space: nowrap; }
.badge.live { background: var(--live-soft); color: var(--live); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); display: inline-block; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.ava { border-radius: 50%; object-fit: cover; flex: none; vertical-align: middle; }
.ava-t { display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md img.md-img { display: block; border-radius: 10px; border: 1px solid var(--line); margin: 12px 0; width: 100%; height: auto; }
.md code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.md .code { position: relative; margin: 12px 0; }
.md pre { background: var(--code); padding: 14px; padding-top: 38px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; font-size: .875rem; line-height: 1.45; margin: 0; }
.md pre code { background: none; padding: 0; }
.md .copy { position: absolute; top: 6px; right: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 3px 10px; font-size: .8rem; cursor: pointer; }
/* таблицы: слова не рвём по буквам (у .md перенос «где угодно» — в таблице он сжимает столбцы до букв);
   длинное слово растягивает столбец, а если таблица шире экрана — она прокручивается вбок внутри .tbl */
.md .tbl { overflow-x: auto; margin: 12px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: .9rem; overflow-wrap: break-word; word-break: normal; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--code); font-weight: 700; }
.md td:first-child { min-width: 5.5em; }
.md table.cols-2 td:first-child { width: 34%; }
/* на телефоне таблица из 3+ столбцов — стопка карточек: подпись столбца над значением */
@media (max-width: 400px) { .md th, .md td { padding: 6px 7px; } }
@media (max-width: 560px) {
  .md table.stack, .md table.stack tbody, .md table.stack tr, .md table.stack td { display: block; width: 100%; }
  .md table.stack thead { display: none; }
  .md table.stack tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 0 0 8px; background: var(--card); }
  .md table.stack td { border: 0; padding: 3px 0; min-width: 0; text-align: left !important; }
  .md table.stack td::before { content: attr(data-label); display: block; font-size: .75rem; font-weight: 600; color: var(--muted); }
  .md table.stack td:first-child { font-weight: 700; font-size: 1rem; }
  .md table.stack td:first-child::before { display: none; }
  .md table.stack td:empty { display: none; }
}
.md blockquote { margin: 12px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md li { margin: .25em 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--live); color: #fff; }

/* ---------- портал участника ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 10px; height: 56px; }
.brand { font-weight: 700; letter-spacing: .01em; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }
.livebar { display: flex; align-items: center; gap: 10px; background: var(--live-soft); color: var(--text); text-decoration: none; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.livebar .t { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--live); }
main { padding-bottom: calc(var(--nav-h) + 24px); }
.nav { position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; position: relative; }
.nav a.on { color: var(--accent); }
.nav svg { width: 22px; height: 22px; }
.nav .pip { position: absolute; top: 8px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--live); }

.module h2 { margin: 22px 0 4px; }
.lesson { display: flex; gap: 12px; align-items: center; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; text-decoration: none; color: var(--text); }
.lesson .n { width: 32px; height: 32px; border-radius: 10px; background: var(--code); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; color: var(--muted); }
.lesson.open .n { background: var(--ok-soft); color: var(--ok); }
.lesson.live { border-color: var(--live); box-shadow: 0 0 0 3px var(--live-soft); }
.lesson.live .n { background: var(--live-soft); color: var(--live); }
.lesson.locked { opacity: .65; }
.lesson .t { font-weight: 600; }
.lesson.brk { background: transparent; border-style: dashed; padding: 8px 16px; }

.timer { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1; }
.timer.over { color: var(--live); }
.viewer { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.viewer img { width: 100%; height: 100%; object-fit: contain; display: block; }
.viewer .nav-btn { position: absolute; top: 0; bottom: 0; width: 22%; border: 0; background: transparent; cursor: pointer; }
.viewer .nav-btn.l { left: 0; } .viewer .nav-btn.r { right: 0; }
.viewer .ctr { position: absolute; bottom: 8px; right: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 8px; border-radius: 8px; font-size: .8rem; }
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; }
.thumbs img { height: 52px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; flex: none; }
.thumbs img.on { border-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; user-select: none; }
.switch input { width: 18px; height: 18px; }

.file { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.file:last-child { border-bottom: 0; }
.file .ic { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 800; flex: none; text-transform: uppercase; }
.q { border-bottom: 1px solid var(--line); padding: 12px 0; }
.q:last-child { border-bottom: 0; }
.ans { background: var(--ok-soft); border-radius: 10px; padding: 10px 12px; margin-top: 8px; white-space: pre-wrap; }
.post { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.post .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: .875rem; text-decoration: none; color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.auth { max-width: 460px; margin: 40px auto; padding: 0 16px; }
.photo-pick { display: flex; align-items: center; gap: 12px; }
.photo-pick .ava { width: 64px; height: 64px; }

/* ---------- пульт тренера ---------- */
.admin main { padding-bottom: 40px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a { padding: 8px 12px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; position: relative; }
.tabs a.on { background: var(--accent-soft); color: var(--accent); }
.tabs .cnt { background: var(--live); color: #fff; border-radius: 999px; font-size: .7rem; padding: 1px 6px; margin-left: 4px; }
.admin .wrap { max-width: 1200px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.ctl { display: flex; gap: 8px; flex-wrap: wrap; }
.tlist .it { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tlist .it:last-child { border-bottom: 0; }
.tlist .it.live { background: var(--live-soft); margin: 0 -16px; padding: 9px 16px; }
.tbl-a { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl-a th, .tbl-a td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl-a th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.scroll-x { overflow-x: auto; }
.slides-edit { display: flex; gap: 8px; flex-wrap: wrap; }
.slides-edit figure { margin: 0; position: relative; }
.slides-edit img { height: 70px; border-radius: 6px; border: 1px solid var(--line); display: block; }
.slides-edit button { position: absolute; top: 2px; right: 2px; }
.qr { background: #fff; padding: 8px; border-radius: 10px; display: inline-block; }
.kbd { font-size: .75rem; color: var(--muted); }

/* ---------- экран для проектора ---------- */
.screen { min-height: 100vh; display: flex; flex-direction: column; padding: 3vh 4vw; gap: 2vh; }
.screen .big { font-size: min(15vh, 16vw); white-space: nowrap; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.screen .ttl { font-size: 5vh; font-weight: 700; }

/* ---------- режим «Смотреть презентацию» ---------- */
.pres { position: fixed; inset: 0; z-index: 100; background: #000; color: #fff; overflow: hidden; touch-action: none; }
.pres .stage { position: absolute; top: 0; left: 0; transform-origin: top left; display: flex; align-items: center; justify-content: center; }
.pres .stage > img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.pres-zone { position: absolute; top: 0; bottom: 0; width: 30%; border: 0; background: transparent; cursor: pointer; }
.pres-zone.l { left: 0; } .pres-zone.r { right: 0; }
.pres-x { position: absolute; top: 10px; left: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 18px; cursor: pointer; z-index: 2; }
.pres-info { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,.55); padding: 5px 10px; border-radius: 8px; font-size: 14px; font-variant-numeric: tabular-nums; z-index: 2; }
.pres-info .t { font-weight: 700; }
.pres-info .t.over { color: #ff6b5e; }
.pres-follow { border: 0; background: #1f6feb; color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 13px; cursor: pointer; }
.pres-title { font-size: 1.6rem; font-weight: 700; text-align: center; padding: 0 10%; }
