:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #1d1f23;
  --muted: #6b7280;
  --border: #dfe1e6;
  --accent: #2563eb;
  --ok: #15803d;
  --ok-bg: #e8f6ec;
  --bad: #b91c1c;
  --bad-bg: #fdecec;
  --warn-bg: #fff6db;
  --code-bg: #f3f4f6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --panel: #1d2026;
    --text: #e5e7eb;
    --muted: #9aa0aa;
    --border: #30343c;
    --accent: #60a5fa;
    --ok: #4ade80;
    --ok-bg: #12301c;
    --bad: #f87171;
    --bad-bg: #3a1717;
    --warn-bg: #3a3215;
    --code-bg: #262a31;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre { background: var(--code-bg); padding: 8px 10px; border-radius: 6px; overflow: auto; margin: 4px 0; white-space: pre-wrap; word-break: break-word; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.crumb { color: var(--muted); }
.spacer { flex: 1; }
.inline { display: inline; }
button { font: inherit; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--accent); padding: 0 4px; }
.narrow { max-width: 720px; margin: 24px auto; padding: 0 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.stack label { display: flex; flex-direction: column; gap: 4px; }
.stack label.check { flex-direction: row; align-items: center; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--code-bg); }
.badge.preview { background: var(--warn-bg); }
.verdict-accepted { background: var(--ok-bg); color: var(--ok); }
.verdict-partial, .verdict-timeout, .verdict-memory_limit { background: var(--warn-bg); }
.verdict-wrong, .verdict-compile_error, .verdict-runtime_error, .verdict-internal_error { background: var(--bad-bg); color: var(--bad); }
.alert { padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); }

/* страница задания */
.split { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.3fr); gap: 12px; padding: 12px; height: calc(100vh - 49px); }
.pane { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; overflow: auto; min-height: 0; }
.work { display: flex; flex-direction: column; gap: 8px; }
.meta { font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 8px; }
.meta b { color: var(--text); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.editor-head { display: flex; justify-content: space-between; font-size: 13px; }
.editor { height: 45vh; min-height: 240px; border: 1px solid var(--border); border-radius: 6px; display: none; }
.monaco-ready .editor { display: block; }
.code-fallback { width: 100%; height: 45vh; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.monaco-ready .code-fallback { display: none; }
.buttons { display: flex; gap: 8px; }
.custom textarea { width: 100%; margin: 6px 0; font-family: ui-monospace, Menlo, monospace; }
.result-panel:empty { display: none; }
.result { border-top: 1px solid var(--border); padding-top: 8px; }
.result-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.score { font-weight: 700; }
.tests { list-style: none; padding: 0; margin: 8px 0; }
.test { border: 1px solid var(--border); border-radius: 6px; margin: 4px 0; padding: 4px 8px; }
.test.pass { border-left: 4px solid var(--ok); }
.test.fail { border-left: 4px solid var(--bad); }
.test summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.test.pass .mark { color: var(--ok); }
.test.fail .mark { color: var(--bad); }
.reason { color: var(--bad); font-size: 13px; }
.hint { background: var(--warn-bg); padding: 4px 8px; border-radius: 4px; }
.io h5 { margin: 6px 0 2px; font-size: 12px; color: var(--muted); }
.diff-scroll { overflow-x: auto; }
.diff { border-collapse: collapse; width: 100%; table-layout: fixed; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.diff th { text-align: left; font: 600 12px/1.4 system-ui, sans-serif; color: var(--muted); padding: 2px 6px; border: 1px solid var(--border); background: var(--code-bg); }
.diff td { border: 1px solid var(--border); padding: 1px 6px; white-space: pre-wrap; word-break: break-all; vertical-align: top; }
.diff .ln { color: var(--muted); width: 3em; text-align: right; }
.diff tr.same td { color: var(--muted); }
.diff tr.bad td.exp { background: var(--ok-bg); }
.diff tr.bad td.act { background: var(--bad-bg); }
.diff mark { color: inherit; border-radius: 2px; padding: 0 1px; }
.diff mark.exp { background: color-mix(in srgb, var(--ok) 35%, transparent); }
.diff mark.act { background: color-mix(in srgb, var(--bad) 35%, transparent); }
.diff mark.ws { outline: 1px dashed currentColor; }
.diff mark.gap { display: inline-block; width: 2px; height: 1.1em; vertical-align: text-bottom; padding: 0; background: var(--bad); }
.tail.err { color: var(--bad); }
.history { width: 100%; border-collapse: collapse; font-size: 13px; }
.history th, .history td { text-align: left; border-bottom: 1px solid var(--border); padding: 4px; }
.history .actions { white-space: nowrap; }
.code-view .code-head { display: flex; justify-content: space-between; margin-top: 12px; font-size: 13px; }
.small { font-size: 13px; }
.buttons { flex-wrap: wrap; align-items: center; }
.busy-note { font-size: 13px; }
.buttons-help { margin: 2px 0 0; }
.draft-state.ok { color: var(--ok); }
.draft-state.bad { color: var(--bad); }
.progress { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: judge-spin .8s linear infinite; flex: none; }
@keyframes judge-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.submit-error .countdown { margin-left: 4px; font-weight: 600; }
.exhausted { margin: 4px 0; }
.history-wrap { overflow-x: auto; }
.status-queued, .status-running { background: var(--warn-bg); }
.status-error { background: var(--bad-bg); color: var(--bad); }
form[aria-busy="true"] .code-fallback { opacity: .85; }

/* узкий экран и iframe Moodle */
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; height: auto; padding: 8px; gap: 8px; }
  .pane { overflow: visible; }
  .editor, .code-fallback { height: 50vh; min-height: 220px; }
  .statement h1 { font-size: 1.4em; }
}
@media (max-width: 600px) {
  body { font-size: 14px; }
  .topbar { padding: 6px 10px; gap: 8px; flex-wrap: wrap; }
  .crumb { display: none; }
  .pane { padding: 8px 10px; border-radius: 6px; }
  .split { padding: 4px; }
  .buttons button { flex: 1 1 auto; }
  .history th:nth-child(4), .history td:nth-child(4) { display: none; }
  .diff { font-size: 12px; }
  .diff .ln { width: 2em; }
}
@media (max-height: 560px) and (min-width: 901px) {
  .split { height: auto; }
  .pane { overflow: visible; }
}
