:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #637083;
  --line: #dde3ea;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --ok: #1f8a5b;
  --warn: #c27c0e;
  --bad: #c0392b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --card: #1b2129; --text: #e6ebf1; --muted: #93a0b2;
    --line: #2b333e; --accent: #5b9bd5; --accent-ink: #0d1117;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0 0 .4em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
          padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--accent); font-family: ui-monospace, monospace; }
.topbar nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.who { color: var(--muted); }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { max-width: 440px; margin: 24px auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.section { margin-top: 32px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.test-card { display: flex; flex-direction: column; }
.test-card form { margin-top: auto; }
.meta { list-style: none; padding: 0; margin: 8px 0 16px; display: flex; gap: 14px; color: var(--muted); font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 600; }
.field input, .filters select, .filters input[type=search] { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
                                font: inherit; background: var(--bg); color: var(--text); }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field ul { margin: 4px 0; padding-left: 18px; color: var(--muted); font-size: .85rem; }
.err { color: var(--bad); }

.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
       padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.big { width: 100%; padding: 14px; margin-top: 8px; }

.msg { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--line); background: var(--card); }
.msg-error { border-color: var(--bad); color: var(--bad); }
.msg-success { border-color: var(--ok); color: var(--ok); }
.msg-warning { border-color: var(--warn); color: var(--warn); }

.attempt-head { display: flex; justify-content: space-between; align-items: center; gap: 12px;
                position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 2; }
.attempt-head { margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.attempt-progress { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; flex: 1; }
.attempt-head .btn-small { flex: none; }
.btn-small { padding: 6px 12px; font-size: .9rem; }
.btn[hidden] { display: none; }
@media (max-width: 480px) { .wide-only { display: none; } .attempt-head { gap: 8px; } }
.question { scroll-margin-top: calc(var(--bar-h, 64px) + 8px); }  /* при переходе вопрос не прячется под полоской */
.question.flash { outline: 2px solid var(--accent); outline-offset: 2px; }
.timer { font: 700 1.4rem ui-monospace, monospace; padding: 6px 14px; border-radius: 8px;
         background: var(--card); border: 1px solid var(--line); }
.timer.warn { color: var(--bad); border-color: var(--bad); }
.question { margin: 0 0 16px; }
.question legend { font-weight: 600; padding: 0; float: left; width: 100%; margin-bottom: 4px; }
.question legend + * { clear: both; }
.qnum { display: inline-block; min-width: 28px; height: 28px; line-height: 28px; text-align: center;
        border-radius: 50%; background: var(--accent); color: var(--accent-ink); margin-right: 6px; font-size: .9rem; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line);
          border-radius: 8px; margin-top: 8px; cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice input { margin-top: 4px; }

.score { font-size: 4rem; font-weight: 800; margin: 8px 0; }
.grade-5 { color: var(--ok); } .grade-4 { color: var(--accent); } .grade-3 { color: var(--warn); } .grade-2 { color: var(--bad); }
.pill { font-weight: 700; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
         border-radius: var(--radius); overflow: hidden; display: block; overflow-x: auto; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: .9rem; }

/* --- Защита вопросов от копирования (страница теста) --- */
.no-copy, .no-copy * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;   /* долгое нажатие на телефоне */
}
.no-copy img { pointer-events: none; }
@media print {
  .no-copy { display: none !important; }
  body::after { content: "Печать теста запрещена"; display: block; padding: 40px; font-size: 20px; }
}

/* --- Код проверки результата --- */
.verify { margin: 18px 0; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; display: grid; gap: 4px; }
.code { font-family: ui-monospace, monospace; letter-spacing: 1px; color: var(--text); }

/* ---------- Раздел «Отдых» ---------- */
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head-row h1 { margin-bottom: .3em; }
.btn-rest { background: var(--ok); text-decoration: none; }
.game-card { display: flex; flex-direction: column; }
.game-card .btn.big { margin-top: auto; text-align: center; text-decoration: none; }
.leaders { list-style: none; counter-reset: r; padding: 0; margin: 6px 0 14px; font-size: .92rem; }
.leaders li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); }
.leaders li:last-child { border-bottom: 0; }
.leaders li::before { counter-increment: r; content: counter(r) "."; color: var(--muted); min-width: 1.6em; }
.leaders li > span { flex: 1; min-width: 0; }
.leaders li > span .small { display: block; font-size: .8rem; }
.leaders li.me { color: var(--accent); font-weight: 600; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; margin-top: 12px; }
@media (max-width: 760px) { .game-layout { grid-template-columns: minmax(0, 1fr); } }
.game-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.game-bar { display: flex; justify-content: space-between; width: 100%; max-width: 420px; }
.stage { width: 100%; max-width: 420px; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: #0e1a12; }
.game-status { min-height: 1.5em; margin: 0; color: var(--muted); text-align: center; }
.pad { display: none; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 48px); gap: 6px; }
.pad button { font-size: 1.2rem; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; }
.pad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.pad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.pad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.pad [data-dir="right"] { grid-column: 3; grid-row: 2; }
@media (pointer: coarse), (max-width: 760px) { .stage-snake ~ .pad { display: grid; } }

/* 2048 */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px; background: #bbada0; border-radius: 10px; aspect-ratio: 1; }
.tile { display: flex; align-items: center; justify-content: center; border-radius: 6px; font-weight: 700;
        font-size: clamp(1rem, 6vw, 2rem); background: #cdc1b4; color: #776e65; }
.v2 { background: #eee4da; } .v4 { background: #ede0c8; }
.v8 { background: #f2b179; color: #fff; } .v16 { background: #f59563; color: #fff; }
.v32 { background: #f67c5f; color: #fff; } .v64 { background: #f65e3b; color: #fff; }
.v128 { background: #edcf72; color: #fff; font-size: clamp(.9rem, 5vw, 1.7rem); }
.v256 { background: #edcc61; color: #fff; font-size: clamp(.9rem, 5vw, 1.7rem); }
.v512 { background: #edc850; color: #fff; font-size: clamp(.9rem, 5vw, 1.7rem); }
.v1024, .v2048, .vbig { background: #edc22e; color: #fff; font-size: clamp(.8rem, 4vw, 1.4rem); }
.vbig { background: #3c3a32; }

/* Реакция */
.react { aspect-ratio: 4 / 3; border-radius: 10px; display: flex; align-items: center; justify-content: center;
         text-align: center; padding: 16px; font-size: 1.3rem; font-weight: 700; cursor: pointer; color: #fff; background: #2f5d8a; }
.react.wait { background: #c0392b; }
.react.go { background: #1f8a5b; }

/* ---------- Уход со страницы теста ---------- */
body.away #quiz-form { filter: blur(14px); }
body.away #quiz-form * { visibility: hidden; }   /* даже если фильтр не сработал */

/* Главная студента: результаты читаются и на телефоне */
.table.history { display: table; }
.table.history td:first-child { white-space: normal; }
.table.history td, .table.history th { padding-left: 10px; padding-right: 10px; }
.test-card form .muted { margin-left: 6px; }
.meta { flex-wrap: wrap; row-gap: 4px; }
.meta li, .nowrap { white-space: nowrap; }
