:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2557d6; --accent-ink: #fff; --ok: #1f8a4c; --warn: #b7791f; --bad: #c53030;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
header { background: var(--card); border-bottom: 1px solid var(--line); }
header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
header a.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }
.narrow { max-width: 440px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 120px; resize: vertical; }
button, .btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font: inherit; cursor: pointer; text-decoration: none;
}
button.secondary, .btn.secondary { background: #fff; color: var(--accent); }
button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
button.small { padding: 4px 10px; font-size: 14px; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--bad); margin-top: 12px; min-height: 1.5em; }
.ok { color: var(--ok); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px; background: var(--line); }
.badge.published, .badge.online, .badge.submitted { background: #dcf3e5; color: var(--ok); }
.badge.away { background: #fdecc8; color: var(--warn); }
.badge.offline { background: #eceef2; color: var(--muted); }
.badge.flag { background: #fde2e2; color: var(--bad); }
.type-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.type-choice label { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; color: var(--text); }
.type-choice input { margin-right: 6px; }
.question { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.option { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.option input[type=text] { flex: 1; }
.code-box { font: 700 36px/1.2 ui-monospace, monospace; letter-spacing: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 13px; }
tr.flagged td { background: #fff7f7; }
.table-scroll { overflow-x: auto; }
.events { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow-y: auto; font-size: 14px; }
.events li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.events li.flag { color: var(--bad); }
.snippet { display: block; margin-top: 4px; padding: 6px 8px; background: var(--bg); border-radius: 6px; color: var(--text); white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto; }
.choice { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; color: var(--text); cursor: pointer; }
.notice { background: #eef3ff; border: 1px solid #c9d7fb; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 16px; }
@media (max-width: 600px) { .type-choice { grid-template-columns: 1fr; } }

/* Шапка кабинета */
/* Шапка на всю ширину. На широком экране — одна строка: меню слева, остальное справа;
   на узком меню переносится отдельной строкой под логотипом. */
header .wrap { flex-wrap: wrap; max-width: none; padding-left: 24px; padding-right: 24px; }
header a.brand, .nav a { white-space: nowrap; }
@media (min-width: 1100px) { header .wrap { flex-wrap: nowrap; } header .wrap > .row { flex-wrap: nowrap; white-space: nowrap; } }
@media (max-width: 1099px) { .nav { order: 3; width: 100%; margin-left: 0; } }
@media (max-width: 1250px) { #me { display: none; } }
header .wrap > .row { margin-left: auto; }
.nav { display: flex; gap: 16px; flex-wrap: wrap; margin-right: auto; margin-left: 12px; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a.active, .nav a:hover { color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: 14px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.center { text-align: center; }

/* Приветственная страница */
.hero { background: linear-gradient(180deg, #eef3ff, var(--bg)); padding: 40px 0 24px; }
.hero-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 32px; align-items: center; }
.hero h1 { font-size: 34px; line-height: 1.2; margin-bottom: 12px; }
.lead { font-size: 18px; color: var(--muted); margin: 0 0 20px; }
.code-card { margin: 0; }
.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.feature { margin: 0; }
.feature p { margin: 0; }
.feature-icon { font-size: 28px; margin-bottom: 8px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.steps li b { display: block; }

/* Профиль и анализ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat .muted { font-size: 13px; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 48px; gap: 8px; align-items: center; font-size: 14px; }
.bar { height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.g5 > span { background: var(--ok); } .bar.g4 > span { background: #3b82f6; }
.bar.g3 > span { background: var(--warn); } .bar.g2 > span { background: var(--bad); }
.pct-good { color: var(--ok); } .pct-mid { color: var(--warn); } .pct-bad { color: var(--bad); }
details summary { cursor: pointer; }

/* Библиотека */
.material { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.material .content { white-space: pre-wrap; max-height: 160px; overflow: auto; font-size: 14px; background: var(--bg); padding: 8px; border-radius: 6px; margin-top: 6px; }
.check-list { display: grid; gap: 4px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.check-list label { display: flex; gap: 8px; align-items: flex-start; margin: 0; color: var(--text); }
select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; max-width: 100%; }

@media (max-width: 800px) {
  .hero-grid { grid-template-columns: 1fr; }
  .features { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 28px; }
}
@media (max-width: 500px) {
  .features { grid-template-columns: 1fr; }
}

/* переключатель языка */
.lang-switch { width: auto; margin: 0; padding: 4px 8px; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); cursor: pointer; }
label.check { display: flex; gap: 8px; align-items: center; margin: 14px 0 2px; color: var(--text); cursor: pointer; }
label.check input { width: auto; margin: 0; }
p.small { font-size: 14px; margin: 0 0 8px; }
.order-list { display: grid; gap: 6px; margin: 8px 0; }
.order-item { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--card, #fff); }
.order-item .num { min-width: 1.6em; font-weight: 600; color: var(--muted, #666); }
.order-item .txt { flex: 1; }
.order-item input { flex: 1; margin: 0; }
.order-item button { padding: 4px 10px; font-size: 14px; }
.kind-tag { font-size: 13px; color: var(--muted, #666); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; font-weight: normal; }
.warn { color: var(--warn); }
.conn-bar { position: sticky; top: 0; z-index: 5; background: #fff7e6; border: 1px solid #f0c36d; color: #7a4b00; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-weight: 500; }

/* Вопросы с кодом */
textarea.code-editor, textarea.code-small, pre.code-output, pre.code-view {
  font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4;
}
textarea.code-editor { min-height: 200px; white-space: pre; overflow-wrap: normal; overflow-x: auto; background: #fbfcfe; }
textarea.code-small { min-height: 44px; white-space: pre; }
pre.code-output, pre.code-view {
  margin: 8px 0 0; padding: 10px 12px; background: #1e2430; color: #e6e9ef; border-radius: 8px;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
pre.code-view { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
pre.code-output .err { color: #ff9b9b; }
pre.code-output .note { color: #f6c86b; }
.test-row { display: grid; grid-template-columns: 28px 1fr 1fr auto; gap: 8px; align-items: start; margin-top: 8px; }
.test-row .num { padding-top: 10px; color: var(--muted); }
.test-row label { margin: 0 0 2px; }
@media (max-width: 600px) { .test-row { grid-template-columns: 1fr; } .test-row .num { padding: 0; } }

/* Отзывы ученикам: на экране область печати скрыта, при печати видна только она. */
#print-area { display: none; }
.sheet-text { white-space: pre-wrap; line-height: 1.5; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; }
  body.printing { background: #fff; }
  #print-area .sheet { break-after: page; padding: 0; }
  #print-area .sheet:last-child { break-after: auto; }
  #print-area h2 { margin: 0 0 4px; }
}

/* Карточка ученика на странице результатов: свёрнута, в заголовке имя и баллы. */
details.student > summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; list-style: none; }
details.student > summary::-webkit-details-marker { display: none; }
details.student > summary h2 { margin: 0; font-size: 18px; }
details.student > summary h2::before { content: '▸'; display: inline-block; width: 1em; color: var(--muted, #888); }
details.student[open] > summary h2::before { transform: rotate(90deg); }
details.student[open] > summary { margin-bottom: 8px; }

/* Инструменты на экзамене: кнопки внизу экрана и панель поверх страницы */
body.has-tools main.wrap { padding-bottom: 96px; }
.tools-dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 30; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.12); max-width: calc(100vw - 16px); }
.tools-dock button { padding: 6px 10px; font-size: 14px; }
.tools-dock button.active { background: var(--accent); color: var(--accent-ink); }
.tool-panel { position: fixed; right: 12px; bottom: 76px; z-index: 31; width: min(420px, calc(100vw - 16px)); max-height: calc(100vh - 100px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 28px rgba(0,0,0,.18); }
.tool-panel.wide { width: min(860px, calc(100vw - 16px)); }
@media (max-width: 600px) {
  .tool-panel { right: 8px; left: 8px; width: auto; } .tool-panel.wide { width: auto; }
  .tools-dock { left: 8px; right: 8px; transform: none; max-width: none; gap: 4px; }
  .tools-dock button { flex: 1 1 auto; padding: 6px 6px; font-size: 13px; }
}
.tool-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.tool-head h2 { margin: 0; font-size: 17px; }
.tool-sheet { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.small { font-size: 13px; }
.calc-input { font: 18px ui-monospace, monospace; margin-top: 8px; }
.calc-result { font: 600 22px ui-monospace, monospace; text-align: right; padding: 4px 2px 8px; min-height: 1.5em; word-break: break-all; }
.calc-pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.calc-key { padding: 8px 0; font-size: 15px; background: #f1f3f7; color: var(--text); border-color: var(--line); }
.calc-key.d { background: #fff; font-weight: 600; }
.calc-key.fn { color: var(--bad); }
.calc-key.eq { grid-column: span 2; background: var(--accent); color: var(--accent-ink); }
.calc-history { list-style: none; padding: 0; margin: 8px 0 0; font: 14px ui-monospace, monospace; max-height: 140px; overflow: auto; }
.calc-history li { padding: 3px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.graph-fn span { white-space: nowrap; }
.graph-fn { display: flex; gap: 8px; align-items: center; margin: 4px 0; color: var(--text); font: 15px ui-monospace, monospace; }
.graph-fn input.bad { border-color: var(--bad); }
.graph-canvas { display: block; width: 100%; height: 320px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; touch-action: none; cursor: crosshair; }
.graph-readout { min-height: 1.5em; margin-top: 4px; font-family: ui-monospace, monospace; }
.pt-grid { display: grid; grid-template-columns: repeat(18, minmax(40px, 1fr)); gap: 2px; min-width: 760px; }
.pt-el { display: flex; flex-direction: column; align-items: center; padding: 2px 0; border-radius: 4px; border: 1px solid rgba(0,0,0,.08); color: var(--text); line-height: 1.1; }
.pt-z { font-size: 9px; align-self: flex-start; padding-left: 3px; }
.pt-sym { font-weight: 700; font-size: 15px; }
.pt-m { font-size: 8px; color: #4b5563; }
.pt-gap { font-size: 9px; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.pt-info { min-height: 3.6em; margin-bottom: 8px; font-size: 14px; }
.pt-big { font-size: 22px; }
.pt-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.pt-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; }
.pt-alkali { background: #ffd8a8; } .pt-alkaline { background: #ffe8a3; } .pt-transition { background: #f3d9e8; }
.pt-post { background: #d3e4cd; } .pt-metalloid { background: #c7ecee; } .pt-nonmetal { background: #d0ebff; }
.pt-halogen { background: #e5dbff; } .pt-noble { background: #fcc2d7; } .pt-lanthanide { background: #e9ecc0; } .pt-actinide { background: #f8e1c4; }
/* Строгий режим экзамена */
.strict-gate { text-align: center; }
.strict-gate button { margin-top: 8px; }
body.strict #questions { -webkit-user-select: none; user-select: none; }
body.strict #questions textarea { -webkit-user-select: text; user-select: text; }
.strict-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; background: #2b2f36; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); }
.badge.locked { background: #fde2e2; color: var(--bad); }
@media print { body.strict main { display: none; } }
/* пока вопросы скрыты (заставка строгого режима, блокировка, работа сдана) — инструментов не видно */
body:has(#attempt[hidden]) .tools-dock, body:has(#attempt[hidden]) .tool-panel { display: none; }
.tool-notice { position: fixed; left: 50%; transform: translateX(-50%); bottom: 72px; z-index: 32; background: #dcf3e5; color: var(--text);
  border: 1px solid #b6e2c6; border-radius: 10px; padding: 8px 14px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.12); max-width: calc(100vw - 24px); }
.tool-ask-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tool-ask-row > span:first-child { flex: 1; }
.tool-req { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tool-req:last-child { border-bottom: 0; }
.confirm-dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: min(420px, calc(100vw - 32px)); box-shadow: 0 8px 28px rgba(0,0,0,.2); }
.confirm-dialog::backdrop { background: rgba(0,0,0,.35); }
.confirm-dialog p { margin-top: 0; }

/* Рубрика, проверка по вопросу, похожие ответы, банк вопросов */
.nowrap { white-space: nowrap; }
pre.answer-view { margin: 6px 0 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font: inherit; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
.rubric-table { width: auto; margin: 8px 0; font-size: 14px; }
.rubric-table td, .rubric-table th { padding: 4px 8px; }
.rubric-table input { margin: 0; }
.rubric-row { display: grid; grid-template-columns: 1fr 90px auto; gap: 8px; align-items: center; margin-top: 6px; }
.rubric-row input { margin: 0; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
@media (max-width: 600px) { .compare { grid-template-columns: 1fr; } .rubric-row { grid-template-columns: 1fr 80px auto; } }
details.copy-pair { border-top: 1px solid var(--line); padding: 8px 0; }
details.copy-pair summary { cursor: pointer; }
.bank-list { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.bank-item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.bank-item:last-child { border-bottom: 0; }
.bank-item label { margin: 0; color: var(--text); font-size: 15px; display: flex; gap: 8px; align-items: flex-start; }
.bank-item.disabled { opacity: .55; }
.bank-item > button { width: auto; justify-self: end; }
