/* Quizzy — базовые стили. Светлая/тёмная тема через prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1b1d24;
  --muted: #5f6577;
  --border: #dde1ea;
  --primary: #6c5ce7;
  --primary-hover: #5a4bd6;
  --primary-text: #ffffff;
  --danger: #d63c4a;
  --success: #1f9d61;
  --shadow: 0 1px 2px rgba(20, 22, 40, .06), 0 6px 24px rgba(20, 22, 40, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Цвета вариантов ответа = цвета плиток в игре (плюс фигура: △ ◇ ○ □ ☆ ⬡) */
  --opt-1: #D7263D; --opt-2: #1368CE; --opt-3: #B07600; --opt-4: #26890C; --opt-5: #8E44AD; --opt-6: #0E8F8F;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1c1f27;
    --surface-2: #252935;
    --text: #e9ebf1;
    --muted: #9aa1b2;
    --border: #2f3442;
    --primary: #8b7cf6;
    --primary-hover: #9d90f8;
    --primary-text: #0f1015;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  font: 16px/1.5 var(--font);
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.5vw, 2.1rem); }
h2 { font-size: 1.25rem; }
p { margin: 0 0 1em; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.center { text-align: center; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__user form { margin: 0; }
.user-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--danger); color: #fff; vertical-align: middle; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.narrow { max-width: 480px; margin: 24px auto; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.actions form { margin: 0; }
.hero { padding: 16px 0; }
.lead { font-size: 1.1rem; margin-bottom: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.empty { text-align: center; padding: 40px 20px; }
.empty__icon { font-size: 48px; line-height: 1; margin-bottom: 12px; }

/* Forms */
.field { display: block; border: 0; padding: 0; margin: 0 0 14px; }
.field > span, .field > legend { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.input--code { font: 700 1.6rem/1.2 var(--mono); letter-spacing: .3em; text-align: center; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 16px; min-height: 44px; transition: background .15s, border-color .15s; }
.btn--primary { background: var(--primary); color: var(--primary-text); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { min-height: 34px; padding: 6px 12px; font-size: .9rem; }
.btn--block { width: 100%; margin-top: 8px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.msg { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 8px; }
.msg--error { color: var(--danger); }
.msg--success { color: var(--success); }

/* Экраны Svelte-приложений */
.host-shell { min-height: calc(100dvh - 56px); padding: 24px; }
.player-shell { min-height: 100dvh; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
.player-shell > #player-app { flex: 1; display: flex; flex-direction: column; }

@media (max-width: 560px) {
  .topbar__inner { gap: 8px; }
  .brand span { display: none; }
  .container { padding-top: 16px; }
}
@media print {
  .topbar, .btn, .actions { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* ===================================================================== */
/* Общие мелочи                                                           */
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.08); }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; line-height: 1.5; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill--error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.pill--ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.page-head__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-head__actions form { margin: 0; }

/* Выпадающие панели на <details> (без JS) */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown__panel { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: min(300px, 86vw); padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.dropdown--right .dropdown__panel { left: auto; right: 0; }
.dropdown__panel form { margin: 0; }
.dropdown__panel .btn--block { margin-top: 0; justify-content: flex-start; }
.dropdown__panel .field { margin-bottom: 8px; }

/* Список викторин */
.quiz-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.quiz-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.quiz-card__main { flex: 1; min-width: 0; }
.quiz-card__title { display: block; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-card__title:hover { color: var(--primary); }
.quiz-card__meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .875rem; margin-top: 2px; align-items: center; }
.quiz-card__actions { display: flex; gap: 6px; align-items: center; }
@media (max-width: 560px) {
  .quiz-card { flex-wrap: wrap; }
  .quiz-card__actions { width: 100%; justify-content: flex-end; }
}

/* ===================================================================== */
/* Редактор                                                               */
.editor-shell { max-width: none; padding: 12px 16px 16px; }
.editor { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - 56px - 28px); min-height: 480px; }
.editor__bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editor__title { margin: 0; font-size: 1.15rem; flex: 1; min-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor__status { font-size: .85rem; white-space: nowrap; }
.editor__status[data-kind="error"] { color: var(--danger); white-space: normal; }
.editor__status[data-kind="warn"] { color: #b7791f; }
.editor__status[data-kind="ok"] { color: var(--success); }
.editor__tools { display: flex; gap: 6px; align-items: center; }
.editor__tools label.btn { cursor: pointer; }
.editor__panes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.editor__pane { min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.editor__cm { flex: 1; min-height: 0; overflow: hidden; }
.editor__fallback { width: 100%; height: 100%; border: 0; border-radius: 0; resize: none; font-family: var(--mono); }
.editor__issues { max-height: 32%; overflow: auto; border-top: 1px solid var(--border); background: var(--surface-2); font-size: .875rem; }
.issues__ok { margin: 0; padding: 8px 12px; color: var(--success); }
.issues__list { list-style: none; margin: 0; padding: 4px; }
.issue { display: flex; gap: 10px; width: 100%; text-align: left; font: inherit; color: var(--text); background: none; border: 0; border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.issue:hover { background: var(--surface); }
.issue__line { flex: none; font-family: var(--mono); font-size: .8rem; padding-top: 2px; min-width: 9.5em; }
.issue--error .issue__line { color: var(--danger); }
.issue--warning .issue__line { color: #b7791f; }
.editor__pane--preview { overflow: auto; }
.editor__tabs { display: none; }
.editor__hint { margin: 0; }
@media (max-width: 860px) {
  .editor { height: auto; min-height: 0; }
  .editor__tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); }
  .editor__tabs button { flex: 1; font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 8px; background: none; color: var(--muted); }
  .editor__tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .tab-badge { display: inline-block; min-width: 1.4em; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; }
  .editor__panes { display: block; }
  .editor__pane { height: calc(100dvh - 210px); min-height: 420px; }
  .editor__panes[data-active="source"] .editor__pane--preview,
  .editor__panes[data-active="preview"] .editor__pane--source { display: none; }
  .editor__hint { display: none; }
  .editor__status { order: 5; width: 100%; }
}

/* Предпросмотр */
.preview { padding: 16px; }
.pv-empty { padding: 24px; text-align: center; }
.pv-title { margin-bottom: 2px; }
.pv-meta { font-size: .875rem; }
.pv-q { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; cursor: pointer; background: var(--bg); }
.pv-q:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.pv-q--error { border-color: var(--danger); }
.pv-q__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; margin-bottom: 8px; }
.pv-q__num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-weight: 700; }
.pv-q__text { font-size: 1.1rem; margin: 0 0 8px; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md pre, .md .highlight { border-radius: 8px; overflow: auto; }
.md .highlight pre { margin: 0; padding: 10px 12px; }
.md blockquote { margin: 0 0 1em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--border); padding: 4px 8px; }
.pv-opts { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.pv-opt { --c: var(--opt-1); display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; color: #fff; font-weight: 600; background: var(--c); opacity: .55; }
.pv-opt.is-correct { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); }
.pv-opt--2 { --c: var(--opt-2); } .pv-opt--3 { --c: var(--opt-3); } .pv-opt--4 { --c: var(--opt-4); }
.pv-opt--5 { --c: var(--opt-5); } .pv-opt--6 { --c: var(--opt-6); }
.pv-opt__mark { width: 1.2em; text-align: center; }
.pv-opt__text code { background: rgba(0,0,0,.2); color: inherit; }
.pv-accepted { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.pv-expl { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: .95rem; }
.pv-expl__label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.pv-expl > :last-child, .pv-q__body > :last-child { margin-bottom: 0; }
.tab-badge[hidden] { display: none !important; }
.nav a { white-space: nowrap; }
@media (max-width: 560px) {
  .user-name { display: none; }
}

/* ===================================================================== */
/* Игра: экраны ведущего/игрока без шапки сайта                            */
.screen-host .host-shell { padding: 0; min-height: 100dvh; }
.screen-host #host-app { min-height: 100dvh; }

/* История и результаты                                                   */
.pill--live { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: table-cell; text-align: right; margin: 0; }
.table .actions .btn + .btn { margin-left: 6px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }
.results-block { margin-bottom: 20px; }
.results-block > h2 { margin-bottom: 12px; }
.table--results .place { font-weight: 800; width: 5em; }
.table--results tr.is-gold .place::before { content: "🥇 "; }
.table--results tr.is-silver .place::before { content: "🥈 "; }
.table--results tr.is-bronze .place::before { content: "🥉 "; }
.who { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.avatar-sm { width: 28px; height: 28px; flex: none; }
.qstats { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.qstat { padding: 14px 16px; break-inside: avoid; }
.qstat--skipped { opacity: .6; }
.qstat__head { display: flex; align-items: flex-start; gap: 10px; }
.qstat__n { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-weight: 700; }
.qstat__text { flex: 1; font-weight: 700; font-size: 1.05rem; padding-top: 2px; }
.qstat__nums { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9rem; margin: 8px 0 6px 38px; }
.qstat__nums b { color: var(--text); }
.qstat__opts, .qstat__texts { list-style: none; margin: 0 0 0 38px; padding: 0; display: grid; gap: 4px; }
.qstat__opts li { display: grid; grid-template-columns: 18px minmax(0, 1.4fr) minmax(60px, 2fr) 3ch 1.2em; align-items: center; gap: 10px; font-size: .95rem; }
.qstat__opts li.is-correct .qstat__opt { font-weight: 700; }
.qstat__opts .bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.qstat__opts .bar span { display: block; height: 100%; background: var(--muted); border-radius: 999px; }
.qstat__opts li.is-correct .bar span { background: var(--success); }
.qstat__opts .num { text-align: right; font-variant-numeric: tabular-nums; }
.qstat__opts .ok { color: var(--success); font-weight: 900; }
.qstat__texts { display: flex; flex-wrap: wrap; gap: 6px; }
.qstat__texts li { padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.qstat__texts li.is-correct { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); font-weight: 600; }
.qshape { display: inline-block; width: 16px; height: 16px; background: var(--c, var(--muted)); }
.qshape--triangle { --c: var(--opt-1); clip-path: polygon(50% 4%, 98% 92%, 2% 92%); }
.qshape--diamond { --c: var(--opt-2); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.qshape--circle { --c: var(--opt-3); border-radius: 50%; }
.qshape--square { --c: var(--opt-4); border-radius: 2px; }
.qshape--star { --c: var(--opt-5); clip-path: polygon(50% 0, 63% 35%, 100% 38%, 71% 61%, 81% 98%, 50% 77%, 19% 98%, 29% 61%, 0 38%, 37% 35%); }
.qshape--hexagon { --c: var(--opt-6); clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%); }
@media (max-width: 640px) {
  .qstat__opts, .qstat__texts, .qstat__nums { margin-left: 0; }
  .qstat__opts li { grid-template-columns: 18px minmax(0, 1fr) 60px 3ch 1.2em; }
}
@media print {
  .no-print, .nav, .messages { display: none !important; }
  .container { max-width: none; padding: 0; }
  .page-results h1 { font-size: 20pt; }
  .table th, .table td { padding: 4px 8px; border-bottom: 1px solid #bbb; }
  .table--results { font-size: 11pt; }
  .results-block { break-inside: auto; }
  .qstat { border: 1px solid #ccc; padding: 8px 10px; }
  .qstat__opts .bar { border: 1px solid #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .qshape, .qstat__opts .bar span { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pill { border: 1px solid #ccc; }
}
