:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #6b7280; --border: #e3e6eb;
  --accent: #2563eb; --ok: #15803d; --bad: #dc2626; --warn: #b45309; --info: #475569;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --card: #1a1e24; --text: #e5e7eb; --muted: #9aa3af; --border: #2b313a;
          --accent: #60a5fa; --ok: #4ade80; --bad: #f87171; --warn: #fbbf24; --info: #94a3b8; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1050px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 20px; padding-bottom: 60px; }
h1 { font-size: 1.6rem; margin: .4em 0 .6em; }
h2 { font-size: 1.2rem; margin: 1.6em 0 .6em; display: flex; align-items: center; gap: 12px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar nav { display: flex; align-items: center; gap: 18px; height: 52px; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar a { color: var(--text); }
.spacer { flex: 1; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.card.narrow { max-width: 380px; margin: 40px auto; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.tag { font-size: .75em; background: var(--border); color: var(--muted); padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--card); }
.flash.error { border-color: var(--bad); color: var(--bad); }
.flash.info { border-color: var(--accent); }

.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; font-size: .85em; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: none; }
.table.kv { width: auto; min-width: 380px; }
.table.kv th { text-transform: none; font-size: .95em; }
.narrowcol { width: 28px; }

form label { display: block; margin-bottom: 12px; font-weight: 500; }
form label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.code, pre, code { font-family: var(--mono); font-size: 13.5px; }
textarea.code { tab-size: 4; resize: vertical; }
.row { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 160px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
form.inline { display: inline; }

.btn { display: inline-block; padding: 8px 16px; border-radius: 7px; border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: .85em; }
.linklike { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike.bad { color: var(--bad); }

pre { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 0; white-space: pre; }
pre.code { max-height: 600px; }
code.preview { white-space: nowrap; display: inline-block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; color: var(--muted); }

.problem-head h1 { margin-bottom: .2em; }
.problem-head { margin-bottom: 16px; }
.statement { line-height: 1.7; }
.statement :first-child { margin-top: 0; }
.statement pre { background: var(--bg); }
.sample { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.sample-label { font-size: .8em; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.submit-form textarea { margin-bottom: 12px; }
.pager { display: flex; gap: 20px; margin-top: 12px; }

.v { font-weight: 600; }
.v-AC { color: var(--ok); }
.v-WA, .v-RE, .v-SE { color: var(--bad); }
.v-TLE, .v-MLE, .v-OLE { color: var(--warn); }
.v-CE { color: var(--info); }
.v-QUEUED, .v-COMPILING, .v-RUNNING { color: var(--muted); }
.v-QUEUED::after, .v-COMPILING::after, .v-RUNNING::after { content: "…"; }

/* --- Nav badge --- */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--bad);
         color: #fff; font-size: .72em; font-weight: 700; line-height: 18px; text-align: center; vertical-align: middle; }

/* --- Code editor (CodeMirror) --- */
.CodeMirror { height: auto; min-height: 320px; border: 1px solid var(--border); border-radius: 8px;
              font-family: var(--mono); font-size: 13.5px; }
.submission-source .CodeMirror, #source + .CodeMirror { min-height: 0; }
.editor-actions { margin-top: 12px; align-items: center; }

/* --- Editorial & questions --- */
.editorial summary { cursor: pointer; font-weight: 600; }
.editorial .statement { margin-top: 12px; }
.questions { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.q-head { margin-bottom: 6px; }
.q-text { white-space: pre-wrap; }
.q-answer { margin-top: 10px; padding: 10px 14px; border-left: 3px solid var(--ok); background: var(--bg); border-radius: 0 8px 8px 0; }
.q-answer p:first-child { margin-top: 0; } .q-answer p:last-child { margin-bottom: 0; }
.admin-answer { margin-top: 10px; }
.admin-answer summary { cursor: pointer; color: var(--accent); }
.admin-answer textarea, .question form textarea { margin: 8px 0; }
.ask-form textarea { margin-bottom: 10px; }

/* --- Failed sample diff --- */
.diff { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 860px) { .diff { grid-template-columns: 1fr; } }
pre.lines .ln { display: block; min-height: 1.4em; }
pre.lines .ln:empty::before { content: "\200b"; }
pre.lines .diffline { background: color-mix(in srgb, var(--bad) 18%, transparent); outline: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); }
.stderr-label { margin-top: 14px; }
pre.stderr { color: var(--bad); max-height: 300px; overflow: auto; }
