:root {
  --brand: #0b5cad;
  --brand-dark: #083f78;
  --brand-soft: #e8f1fb;
  --ink: #1c2733;
  --muted: #5b6b7c;
  --faint: #8493a3;
  --paper: #eef3f8;
  --panel: #ffffff;
  --line: #d5dee8;
  --line-strong: #b8c7d8;
  --link: #0b5cad;
  --link-visited: #0b5cad;
  --accent: #eef5fd;
  --ok: #157347;
  --ok-bg: #e8f6ee;
  --bad: #b02a37;
  --bad-bg: #fcecee;
  --warn: #8a5a00;
  --warn-bg: #fff5d9;
  --code-bg: #f4f7fa;
  --radius: 5px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: var(--sans);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  background:
    linear-gradient(180deg, #e8eef5 0, var(--paper) 190px) no-repeat;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  font-family: var(--sans);
  line-height: 1.2;
  letter-spacing: -0.012em;
  margin: 0 0 0.45em;
  color: #152333;
}
h1 { font-size: 1.85rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 700; }
h4 { font-size: 0.95rem; font-weight: 700; }

p { margin: 0 0 0.9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.4rem 0; }
small { font-size: 0.84em; }
code, kbd, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--code-bg); padding: 0.08em 0.3em; border-radius: 3px; }
pre { background: var(--code-bg); border: 1px solid var(--line); padding: 0.9rem 1rem; overflow-x: auto; border-radius: var(--radius); }
pre code { background: none; padding: 0; }

.wrap { width: min(1180px, calc(100% - 2rem)); margin-inline: auto; }
.main-content { padding: 1.4rem 0 3rem; min-height: 60vh; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline-form { display: inline; margin: 0; }
.linkish { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; }
.linkish:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- header */

.site-header {
  border-top: 3px solid var(--brand);
  border-bottom: 1px solid var(--line-strong);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(14, 39, 69, 0.08);
}
.header-inner {
  display: flex;
  align-items: stretch;
  gap: 0.7rem;
  min-height: 48px;
  flex-wrap: nowrap;
}
.brand { display: flex; align-items: center; gap: 0.45rem; color: var(--ink); flex: 0 0 auto; }
.brand:visited { color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-family: var(--sans); font-size: 0.94rem; font-weight: 800; letter-spacing: 0.01em; }
.brand-text small { font-size: 0.52rem; letter-spacing: 0.09em; color: var(--muted); margin-top: 1px; }

.main-nav { display: flex; gap: 0; flex-wrap: nowrap; flex: 1; align-items: stretch; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  display: flex;
  align-items: center;
  white-space: nowrap;
  color: #34495e;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0 0.52rem;
  border-bottom: 2px solid transparent;
}
.main-nav a:hover { text-decoration: none; color: var(--brand); background: var(--accent); border-bottom-color: #9bc0e8; }
.main-nav a.active { color: var(--brand); border-bottom-color: var(--brand); background: #f4f8fd; }
.main-nav a.admin-link { color: var(--bad); }
.main-nav a.admin-link.active { border-bottom-color: var(--bad); }

.header-right { display: flex; align-items: center; gap: 0.45rem; flex-wrap: nowrap; font-size: 0.8rem; margin-left: auto; min-width: 0; }
.user-chip { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 700; color: #22364b; white-space: nowrap; }
.user-chip:hover { text-decoration: none; }
.header-role { display: inline-flex; }
.tts-trigger { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.tts-trigger.speaking { color: var(--bad); }

/* ---------------------------------------------------------------- navigation / flash */

.flash {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  background: var(--ok-bg);
  padding: 0.7rem 1rem;
}
.flash-bad { border-left-color: var(--bad); background: var(--bad-bg); }
.flash-warn { border-left-color: var(--warn); background: var(--warn-bg); }

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  padding: 0.03rem 0.42rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  line-height: 1.45;
  vertical-align: 1px;
  color: var(--muted);
  background: var(--panel);
}
.role-contest_maker { color: #0b4f8a; border-color: #0b4f8a; }
.role-exam_decision_maker { color: #8a4b00; border-color: #8a4b00; }
.role-overseer { color: #9d1030; border-color: #9d1030; font-weight: 700; }
.status-running, .status-open, .status-valid, .status-published { color: var(--ok); border-color: var(--ok); }
.status-finished, .status-closed, .status-revoked, .status-failed { color: var(--bad); border-color: var(--bad); }
.status-scheduled, .status-draft, .status-under_review, .status-pending { color: var(--warn); border-color: var(--warn); }
.status-certified, .status-passed, .status-approved { color: var(--ok); border-color: var(--ok); }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0 0.38rem;
  margin: 0 0.22rem 0.2rem 0;
  background: var(--panel);
}
.tag:hover { color: var(--ink); border-color: var(--ink); text-decoration: none; }

/* ---------------------------------------------------------------- layout */

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 0.7rem 0.9rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 0.15rem 0 0; }
.kicker { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brand); margin-bottom: 0.2rem; }
.section { margin-top: 1.6rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--brand);
  padding: 0 0 0.35rem;
  margin-bottom: 0.65rem;
}
.section-head h2 { margin: 0; font-size: 1.05rem; color: #15385d; }
.section-head a { font-size: 0.82rem; font-weight: 600; }

.card {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0.95rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(20, 47, 77, 0.04);
}
.card h2, .card h3 { margin-top: 0; }
.card-list { display: grid; gap: 0.7rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(250px, 1fr); gap: 1.2rem; }
.stack > * + * { margin-top: 0.65rem; }
.empty { color: var(--muted); font-style: normal; padding: 0.8rem; background: var(--panel); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

.hero {
  padding: 1.5rem 1.7rem 1.3rem;
  border: 1px solid var(--brand-dark);
  border-radius: 7px;
  background:
    radial-gradient(circle at 92% 5%, rgba(93, 168, 255, 0.36), transparent 38%),
    linear-gradient(128deg, #0a4f96 0%, #0d3f75 62%, #102f57 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(12, 42, 76, 0.16);
}
.hero h1 { font-size: clamp(1.65rem, 4vw, 2.35rem); letter-spacing: -0.025em; max-width: 24ch; margin-bottom: 0.25rem; color: #fff; }
.hero .kicker { font-family: var(--sans); font-size: 0.7rem; letter-spacing: 0.16em; color: #b9d8fb; text-transform: uppercase; font-weight: 700; margin-bottom: 0.35rem; }
.hero .lede { font-family: var(--sans); font-size: 0.98rem; color: #dceafa; max-width: 72ch; margin-bottom: 0.9rem; }
.hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; }
.hero .btn { background: #fff; border-color: #fff; color: #0a4c90; font-weight: 700; }
.hero .btn:hover { background: #e9f3ff; border-color: #e9f3ff; color: #083d74; }
.hero .btn-ghost { background: transparent; border-color: rgba(255,255,255,0.55); color: #fff; }
.hero .btn-ghost:hover { background: rgba(255,255,255,0.13); border-color: #fff; color: #fff; }

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.08);
  border-radius: 5px;
  margin-top: 1.2rem;
  overflow: hidden;
}
.stats-strip div { padding: 0.7rem 0.9rem; border-right: 1px solid rgba(255,255,255,0.2); }
.stats-strip div:last-child { border-right: 0; }
.stats-strip strong { display: block; font-family: var(--sans); font-size: 1.35rem; font-weight: 700; line-height: 1.1; color: #fff; }
.stats-strip span { font-size: 0.68rem; color: #c9dff6; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------------------------------------------------------------- buttons */

.btn, button.btn {
  display: inline-block;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn:visited { color: #fff; }
.btn-small { padding: 0.16rem 0.5rem; font-size: 0.78rem; }
.btn-ghost { background: #fff; color: var(--brand); border-color: #a9c5e3; }
.btn-ghost:hover { background: var(--accent); color: var(--brand-dark); border-color: var(--brand); }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: #8f202b; border-color: #8f202b; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }

/* ---------------------------------------------------------------- tables */

.table-scroll { overflow-x: auto; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th, .data-table td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid #e3eaf2; vertical-align: top; }
.data-table th { background: #f1f6fc; color: #36536f; font-size: 0.72rem; text-transform: none; letter-spacing: 0.015em; font-weight: 700; white-space: nowrap; border-bottom: 2px solid #cbd9e8; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #f5f9fe; }
.data-table .num, .data-table .right { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .tiny { font-size: 0.76rem; }
.data-table .solved { color: var(--ok); font-weight: 700; }
.data-table .attempted { color: var(--bad); }
.data-table .empty-cell { color: var(--faint); }
.data-table caption { caption-side: top; text-align: left; padding: 0.55rem 0.65rem; font-size: 0.8rem; color: var(--muted); border-bottom: 1px solid var(--line); }

.standings-table td { white-space: nowrap; }
.standings-table .rank { font-family: var(--mono); font-weight: 700; }
.standings-table .problem-cell { text-align: center; min-width: 52px; font-family: var(--mono); font-size: 0.78rem; }
.standings-table .problem-cell .ok { color: var(--ok); font-weight: 700; display: block; }
.standings-table .problem-cell .no { color: var(--bad); display: block; }
.standings-table .problem-cell .partial { color: var(--warn); display: block; }

/* ---------------------------------------------------------------- forms */

.form { max-width: 760px; }
.form-wide { max-width: none; }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field > label, .label { font-size: 0.78rem; letter-spacing: 0.01em; color: #40556b; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="datetime-local"], input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0.46rem 0.55rem;
  font: inherit;
  font-size: 0.92rem;
  border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c6ddf5; border-color: var(--brand); }
textarea { min-height: 140px; resize: vertical; font-family: var(--mono); font-size: 0.88rem; line-height: 1.5; }
textarea.short { min-height: 72px; }
textarea.statement { min-height: 280px; }
input[type="checkbox"] { accent-color: var(--ink); width: auto; }
.checkline { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.9rem; }
.form-error { color: var(--bad); font-weight: 600; background: var(--bad-bg); border-left: 3px solid var(--bad); padding: 0.5rem 0.7rem; }
.help { font-size: 0.8rem; color: var(--muted); }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 0.4rem; }

/* ---------------------------------------------------------------- problems / contests */

.problem-list { display: grid; gap: 0; border: 1px solid var(--line); background: var(--panel); }
.problem-row { display: grid; grid-template-columns: 6.2rem minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--line); }
.problem-row:last-child { border-bottom: 0; }
.problem-row:hover { background: var(--accent); }
.problem-id { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }
.problem-title { font-weight: 600; }
.problem-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.points { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); white-space: nowrap; }

.contest-meta { display: flex; gap: 1.4rem; flex-wrap: wrap; font-size: 0.88rem; color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0.6rem 0; margin: 0.9rem 0 1.2rem; }
.contest-meta strong { color: var(--ink); font-weight: 600; }

.statement { font-size: 1rem; }
.statement h1, .statement h2, .statement h3 { margin-top: 1.4em; }
.statement ul, .statement ol { padding-left: 1.4rem; }
.statement blockquote { margin: 1em 0; padding: 0.2em 1em; border-left: 3px solid var(--line); color: var(--muted); }
.statement table { border-collapse: collapse; margin: 1em 0; }
.statement th, .statement td { border: 1px solid var(--line); padding: 0.35rem 0.55rem; }
.statement img { max-width: 100%; }

.target-box { border: 1px solid var(--line-strong); background: var(--accent); padding: 0.7rem 0.9rem; margin: 1rem 0; font-size: 0.9rem; }
.target-box .mono { font-size: 0.85rem; word-break: break-all; }

.task-block { border-top: 1px solid var(--line); padding: 0.8rem 0; }
.task-block:first-of-type { border-top: 0; }
.task-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.task-name { font-weight: 600; }
.task-points { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.subtask { border-left: 2px solid var(--line); padding-left: 0.8rem; margin: 0.8rem 0; }
.subtask-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; margin-bottom: 0.2rem; }
.subtask-head strong { font-family: var(--serif); font-size: 1.05rem; }
.submit-row { display: flex; gap: 0.4rem; margin-top: 0.35rem; }
.submit-row input { max-width: 380px; }
.solved-mark { color: var(--ok); font-family: var(--mono); font-size: 0.75rem; font-weight: 700; }
.unsolved-mark { color: var(--faint); font-family: var(--mono); font-size: 0.75rem; }

/* ---------------------------------------------------------------- forum */

.thread-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; padding: 0.65rem 0.75rem; border-bottom: 1px solid #e3eaf2; background: var(--panel); }
.thread-row:first-child { border-top: 1px solid var(--line); }
.thread-row:last-child { border-bottom: 0; }
.thread-title { font-family: var(--sans); font-size: 0.96rem; font-weight: 700; color: #174b7f; }
.thread-meta { font-size: 0.8rem; color: var(--muted); }
.vote-box { display: flex; align-items: center; gap: 0.25rem; }
.vote-box form { display: inline; }
.vote-btn { border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-family: var(--mono); font-size: 0.75rem; padding: 0.05rem 0.35rem; cursor: pointer; }
.vote-btn:hover { border-color: var(--ink); color: var(--ink); }
.score { font-family: var(--mono); font-weight: 700; min-width: 1.6rem; text-align: center; }
.score-pos { color: var(--ok); }
.score-neg { color: var(--bad); }

.post-body { font-size: 1.02rem; }
.comment { border-top: 1px solid var(--line); padding: 0.8rem 0 0.2rem; }
.comment .comment { margin-left: 0; }
.comment-children { margin-left: 1.4rem; border-left: 1px solid var(--line); padding-left: 1rem; }
.comment-head { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.comment-author { font-weight: 700; color: var(--ink); }
.comment-actions { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; font-size: 0.8rem; }
.comment-body { margin-top: 0.25rem; }
.comment-body p:last-child { margin-bottom: 0.4rem; }
details.reply > summary { cursor: pointer; color: var(--link); font-size: 0.8rem; }
details.reply[open] > summary { margin-bottom: 0.4rem; }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--ink);
}
.avatar-large { width: 44px; height: 44px; font-size: 1.2rem; }

/* ---------------------------------------------------------------- notices */

.notice-list { display: grid; gap: 0.65rem; }
.notice-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 1px solid var(--line); border-left: 4px solid var(--brand); background: var(--panel); padding: 0.8rem 1rem; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20, 47, 77, 0.04); }
.notice-card h2, .notice-card h3 { margin: 0.1rem 0 0.25rem; }
.notice-card .kicker { margin: 0; }
.notice-card-main { min-width: 0; }
.pdf-shell { border: 1px solid var(--line); border-radius: var(--radius); background: #e9eef5; overflow: hidden; }
.pdf-frame { display: block; width: 100%; height: min(78vh, 900px); min-height: 480px; border: 0; background: #fff; }

/* ---------------------------------------------------------------- exams */

.exam-card { border: 1px solid var(--line); background: var(--panel); padding: 0.9rem 1rem; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20, 47, 77, 0.04); }
.exam-card h3 { margin-bottom: 0.3rem; }
.exam-pill { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.exam-rules { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin: 1rem 0; }
.exam-rules div { background: var(--panel); padding: 0.7rem 0.9rem; }
.exam-rules strong { display: block; font-family: var(--serif); font-size: 1.35rem; }
.exam-rules span { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }

.exam-topbar { position: sticky; top: 61px; z-index: 15; display: flex; justify-content: space-between; gap: 1rem; align-items: center; background: var(--bad-bg); border: 1px solid var(--bad); padding: 0.55rem 0.85rem; margin-bottom: 1rem; flex-wrap: wrap; }
.exam-timer { font-family: var(--mono); font-weight: 700; font-size: 1.1rem; }
.exam-watermark { display: none; }
.exam-mode { user-select: none; -webkit-user-select: none; }
.exam-mode .main-content { position: relative; }
.exam-mode .exam-watermark {
  display: block;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.045;
  background-image: repeating-linear-gradient(-35deg, transparent 0 80px, currentColor 80px 82px);
  color: var(--ink);
  overflow: hidden;
  font-size: 0.7rem;
}
.exam-mode .exam-watermark span { position: absolute; top: 40%; left: 8%; transform: rotate(-25deg); font-family: var(--mono); font-weight: 700; }
.exam-mode::after { content: "EXAM IN PROGRESS"; position: fixed; right: 0.6rem; bottom: 0.6rem; font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.18em; color: var(--faint); z-index: 6; }
.exam-focus-lost { outline: 8px solid var(--bad); }

.mcq { border: 1px solid var(--line); background: var(--panel); padding: 0.85rem 1rem; margin-bottom: 0.75rem; }
.mcq-q { font-weight: 600; margin-bottom: 0.45rem; }
.mcq-options { display: grid; gap: 0.3rem; }
.mcq-options label { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.25rem 0.4rem; border: 1px solid transparent; cursor: pointer; }
.mcq-options label:hover { border-color: var(--line); background: var(--accent); }
.mcq-options input { margin-top: 0.35rem; }
.practical-section { border: 1px solid var(--line); background: var(--panel); padding: 1rem; margin-bottom: 1rem; }
.practical-section h3 { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.practical-section h3 span { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }

.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin: 1rem 0; }
.result-grid div { background: var(--panel); padding: 0.8rem 1rem; }
.result-grid strong { display: block; font-family: var(--serif); font-size: 1.5rem; }
.result-grid span { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.pass { color: var(--ok); }
.fail { color: var(--bad); }

/* ---------------------------------------------------------------- certificates */

.certificate {
  border: 3px double var(--line-strong);
  background: var(--panel);
  padding: 3rem 3.4rem;
  margin: 1.5rem auto;
  max-width: 900px;
  position: relative;
  text-align: center;
}
.certificate::before { content: ""; position: absolute; inset: 8px; border: 1px solid var(--line); pointer-events: none; }
.certificate .cert-org { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
.certificate .cert-title { font-family: var(--serif); font-size: 2.2rem; letter-spacing: 0.04em; margin: 0.6rem 0; }
.certificate .cert-name { font-family: var(--serif); font-size: 2.6rem; margin: 1.3rem 0 0.3rem; }
.certificate .cert-exam { font-size: 1.12rem; font-weight: 600; }
.certificate .cert-meta { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); margin-top: 1.4rem; }
.certificate .cert-id { font-family: var(--mono); font-weight: 700; letter-spacing: 0.08em; }
.cert-seal { display: inline-block; border: 2px solid var(--ok); color: var(--ok); text-transform: uppercase; letter-spacing: 0.12em; font-family: var(--mono); font-size: 0.7rem; padding: 0.4rem 0.65rem; margin-top: 1rem; }
.cert-revoked { opacity: 0.72; }
.cert-revoked .cert-seal { border-color: var(--bad); color: var(--bad); }
.cert-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- stats / admin */

.admin-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; border-bottom: 1px solid var(--line); margin-bottom: 1.4rem; padding-bottom: 0.6rem; }
.admin-nav a { padding: 0.22rem 0.6rem; border: 1px solid var(--line); font-size: 0.84rem; color: var(--ink); background: var(--panel); }
.admin-nav a:hover { background: var(--accent); text-decoration: none; }
.admin-nav a.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.stat-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 1.5rem; }
.stat-cards div { background: var(--panel); padding: 0.9rem 1rem; }
.stat-cards strong { display: block; font-family: var(--serif); font-size: 1.8rem; line-height: 1.1; }
.stat-cards span { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.bar-row { display: grid; grid-template-columns: 8rem minmax(0, 1fr) 3rem; gap: 0.7rem; align-items: center; margin-bottom: 0.35rem; font-size: 0.84rem; }
.bar-track { height: 10px; background: var(--accent); border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--ink); }
.bar-row .num { text-align: right; font-family: var(--mono); font-size: 0.78rem; }
.audit-event { display: grid; grid-template-columns: 11rem 12rem minmax(0, 1fr); gap: 0.7rem; border-bottom: 1px solid var(--line); padding: 0.35rem 0; font-size: 0.82rem; }
.audit-event .when { font-family: var(--mono); color: var(--muted); }
.audit-event .who { font-weight: 600; }
.audit-event .what { font-family: var(--mono); color: var(--muted); word-break: break-word; }

.task-editor { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.task-editor th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0.25rem; }
.task-editor td { padding: 0.22rem 0.25rem; vertical-align: top; }
.task-editor input { font-size: 0.82rem; padding: 0.3rem 0.4rem; }
.task-editor .pts { width: 5rem; }
.task-editor .act { width: 2.2rem; text-align: center; }
.row-remove { border: 1px solid var(--line); background: var(--panel); color: var(--bad); width: 1.8rem; height: 1.8rem; cursor: pointer; line-height: 1; }
.subtask-label { width: 9rem; }
.admin-code { font-family: var(--mono); background: var(--code-bg); border: 1px solid var(--line); padding: 0.12rem 0.4rem; user-select: all; }
.credential { font-family: var(--mono); font-size: 0.82rem; background: var(--warn-bg); border: 1px solid var(--warn); padding: 0.1rem 0.35rem; user-select: all; }

.notice { border: 1px solid var(--line); border-left: 4px solid var(--warn); background: var(--warn-bg); padding: 0.75rem 1rem; margin: 1rem 0; }
.notice-danger { border-left-color: var(--bad); background: var(--bad-bg); }
.notice-info { border-left-color: var(--link); background: var(--accent); }

.pagination { display: flex; gap: 1rem; justify-content: space-between; align-items: center; margin-top: 1rem; font-size: 0.85rem; color: var(--muted); }
.pagination a { font-weight: 600; }

.tabs { display: flex; gap: 0.5rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs a { padding: 0.35rem 0.7rem; font-size: 0.88rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.tabs a:hover { text-decoration: none; }

.kv { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 0.4rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------------------------------------------------------------- footer */

.site-footer { margin-top: 2.2rem; border-top: 2px solid var(--brand); background: #fff; padding: 1.1rem 0 1.3rem; color: var(--muted); font-size: 0.8rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; }
.footer-right { text-align: right; }
.footer-inner strong { color: #173b60; font-family: var(--sans); font-size: 0.86rem; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .grid-3, .grid-4, .stat-cards, .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-strip div:nth-child(2) { border-right: 0; }
  .stats-strip div { border-bottom: 1px solid var(--line); }
  .exam-rules { grid-template-columns: 1fr; }
  .header-inner { gap: 0.6rem; flex-wrap: wrap; min-height: 0; padding: 0.4rem 0 0; }
  .main-nav { order: 3; width: 100%; gap: 0; flex-wrap: nowrap; overflow-x: auto; border-top: 1px solid var(--line); }
  .main-nav a { padding: 0.4rem 0.6rem; white-space: nowrap; }
  .header-role { display: none; }
  .notice-card { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 640px) {
  html { font-size: 15px; }
  .brand-text small { display: none; }
  .brand-text strong { font-size: 0.86rem; }
  .header-right { gap: 0.35rem; font-size: 0.76rem; }
  .grid-2, .grid-3, .grid-4, .form-grid, .stat-cards, .result-grid { grid-template-columns: 1fr; }
  .problem-row { grid-template-columns: 4.8rem minmax(0, 1fr); }
  .problem-row .points { display: none; }
  .certificate { padding: 2rem 1.2rem; }
  .certificate .cert-name { font-size: 1.9rem; }
  .certificate .cert-title { font-size: 1.5rem; }
  .audit-event { grid-template-columns: 1fr; gap: 0.1rem; }
  .kv { grid-template-columns: 1fr; }
  .footer-right { text-align: left; }
  .submit-row { flex-direction: column; }
  .submit-row input { max-width: none; }
}

@media print {
  .site-header, .site-footer, .flash, .cert-actions, .tts-trigger { display: none !important; }
  body { background: #fff; color: #000; }
  .certificate { border-color: #000; page-break-inside: avoid; }
  .main-content { padding: 0; }
  a { color: #000; text-decoration: none; }
}

/* ---------------------------------------------------------------- ratings, avatars, profiles */

:root {
  --rating-newcomer: #7a8794;
  --rating-initiate: #178a50;
  --rating-pupil: #0b8f9e;
  --rating-specialist: #1b5fc1;
  --rating-expert: #8a2be2;
  --rating-candidate: #c26b00;
  --rating-grandmaster: #d8262f;
  --rating-master: #9d0b0b;
  --rating-legend: #6f0018;
  --rating-line: #1b63b5;
}

.uname { font-weight: 700; }
.uname:visited { color: inherit; }
.uname.rating-newcomer { color: var(--rating-newcomer); }
.uname.rating-initiate { color: var(--rating-initiate); }
.uname.rating-pupil { color: var(--rating-pupil); }
.uname.rating-specialist { color: var(--rating-specialist); }
.uname.rating-expert { color: var(--rating-expert); }
.uname.rating-candidate { color: var(--rating-candidate); }
.uname.rating-grandmaster { color: var(--rating-grandmaster); }
.uname.rating-master { color: var(--rating-master); }
.uname.rating-legend { color: var(--rating-legend); text-shadow: 0 0 1px rgba(111, 0, 24, 0.35); }
.uname:hover { text-decoration: underline; }

.rating-pill {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.02rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  background: #fff;
  vertical-align: middle;
  white-space: nowrap;
}
.rating-pill.rating-newcomer { color: var(--rating-newcomer); }
.rating-pill.rating-initiate { color: var(--rating-initiate); }
.rating-pill.rating-pupil { color: var(--rating-pupil); }
.rating-pill.rating-specialist { color: var(--rating-specialist); }
.rating-pill.rating-expert { color: var(--rating-expert); }
.rating-pill.rating-candidate { color: var(--rating-candidate); }
.rating-pill.rating-grandmaster { color: var(--rating-grandmaster); }
.rating-pill.rating-master { color: var(--rating-master); }
.rating-pill.rating-legend { color: var(--rating-legend); }

.avatar { overflow: hidden; flex: 0 0 auto; }
img.avatar { object-fit: cover; display: inline-block; vertical-align: middle; border-radius: 50%; }
.avatar-small { width: 22px; height: 22px; font-size: 0.66rem; }
.avatar-xlarge { width: 96px; height: 96px; font-size: 2.4rem; border-radius: 50%; border-width: 2px; }
.account-profile-head { display: flex; gap: 1rem; align-items: center; margin-top: 0.8rem; }
.account-profile-name { margin: 0 0 0.25rem; font-size: 1.1rem; font-weight: 700; }

.type-badge { border-color: #9bc0e8; color: var(--brand); background: var(--brand-soft); }
.invite-badge { border-color: #e5b86b; color: #7a4b00; background: #fff5d9; }

.profile-head {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  padding: 1.2rem 1.35rem;
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(20, 47, 77, 0.06);
  margin-bottom: 1.1rem;
}
.profile-identity { min-width: 0; }
.profile-name { font-size: 2rem; margin-bottom: 0.1rem; }
.profile-sub { margin-bottom: 0.5rem; color: var(--muted); }
.profile-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.profile-layout { margin-top: 0.2rem; }
.profile-bio { white-space: pre-line; max-width: 70ch; }

.rating-card { padding-bottom: 0.85rem; }
.rating-summary { display: flex; gap: 1.6rem; margin: 0.45rem 0 0.65rem; }
.rating-summary div { display: flex; flex-direction: column; }
.rating-summary strong { font-family: var(--mono); font-size: 1.35rem; line-height: 1.1; color: var(--ink); }
.rating-summary span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.delta-up { color: var(--ok) !important; }
.delta-down { color: var(--bad) !important; }

.rating-graph { width: 100%; height: auto; display: block; overflow: visible; }
.rating-bg { fill: #fbfdff; stroke: var(--line); stroke-width: 1; }
.rating-gridline { stroke: #e5edf5; stroke-width: 1; stroke-dasharray: 2 3; }
.rating-axis-label { fill: var(--faint); font-family: var(--mono); font-size: 10px; }
.rating-line { fill: none; stroke: var(--rating-line); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.rating-dot { fill: #fff; stroke-width: 2; }
.rating-dot.rating-newcomer { stroke: var(--rating-newcomer); }
.rating-dot.rating-initiate { stroke: var(--rating-initiate); }
.rating-dot.rating-pupil { stroke: var(--rating-pupil); }
.rating-dot.rating-specialist { stroke: var(--rating-specialist); }
.rating-dot.rating-expert { stroke: var(--rating-expert); }
.rating-dot.rating-candidate { stroke: var(--rating-candidate); }
.rating-dot.rating-grandmaster { stroke: var(--rating-grandmaster); }
.rating-dot.rating-master { stroke: var(--rating-master); }
.rating-dot.rating-legend { stroke: var(--rating-legend); }

.rating-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.32rem; font-size: 0.84rem; }
.rating-legend li { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 0.5rem; }
.rating-legend li span:last-child { color: var(--muted); font-family: var(--mono); font-size: 0.7rem; }
.rating-legend .rating-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 3px solid currentColor; }
.rating-legend .rating-dot.rating-newcomer { color: var(--rating-newcomer); }
.rating-legend .rating-dot.rating-initiate { color: var(--rating-initiate); }
.rating-legend .rating-dot.rating-pupil { color: var(--rating-pupil); }
.rating-legend .rating-dot.rating-specialist { color: var(--rating-specialist); }
.rating-legend .rating-dot.rating-expert { color: var(--rating-expert); }
.rating-legend .rating-dot.rating-candidate { color: var(--rating-candidate); }
.rating-legend .rating-dot.rating-grandmaster { color: var(--rating-grandmaster); }
.rating-legend .rating-dot.rating-master { color: var(--rating-master); }
.rating-legend .rating-dot.rating-legend { color: var(--rating-legend); }

@media (max-width: 720px) {
  .profile-head { align-items: flex-start; }
  .avatar-xlarge { width: 68px; height: 68px; font-size: 1.8rem; }
  .profile-name { font-size: 1.5rem; }
  .rating-summary { gap: 1rem; }
  .rating-summary strong { font-size: 1.1rem; }
}

/* ---------------------------------------------------------------- leaderboard */

.leaderboard-card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(20, 47, 77, 0.05); }
.leaderboard-table .rank-col { width: 3.2rem; }
.leaderboard-table td { vertical-align: middle; }
.leaderboard-table tbody tr:nth-child(even) { background: #fbfdff; }
.leaderboard-table tbody tr:hover { background: var(--accent); }
.leaderboard-user { display: inline-flex; align-items: center; gap: 0.45rem; }
.leaderboard-table .rank {
  display: inline-grid;
  place-items: center;
  min-width: 1.85rem;
  height: 1.85rem;
  padding: 0 0.35rem;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
}
.leaderboard-table .rank-plain { color: var(--muted); }
.leaderboard-table .rank-1 { background: #fff4c2; color: #7a5a00; border: 1px solid #e7c75c; }
.leaderboard-table .rank-2 { background: #eef2f6; color: #526272; border: 1px solid #c2cdd8; }
.leaderboard-table .rank-3 { background: #fbe9dd; color: #8b4a20; border: 1px solid #e0b08c; }
.me-row { background: #eef6ff !important; box-shadow: inset 4px 0 0 var(--brand); scroll-margin-top: 90px; }
.me-row:target { animation: me-pulse 1.6s ease-out 1; }
.me-badge { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
@keyframes me-pulse {
  0% { background: #d8eaff; }
  100% { background: #eef6ff; }
}
.rating-tier-badge { background: #fff; }
.rating-tier-badge.rating-newcomer { color: var(--rating-newcomer); border-color: currentColor; }
.rating-tier-badge.rating-initiate { color: var(--rating-initiate); border-color: currentColor; }
.rating-tier-badge.rating-pupil { color: var(--rating-pupil); border-color: currentColor; }
.rating-tier-badge.rating-specialist { color: var(--rating-specialist); border-color: currentColor; }
.rating-tier-badge.rating-expert { color: var(--rating-expert); border-color: currentColor; }
.rating-tier-badge.rating-candidate { color: var(--rating-candidate); border-color: currentColor; }
.rating-tier-badge.rating-grandmaster { color: var(--rating-grandmaster); border-color: currentColor; }
.rating-tier-badge.rating-master { color: var(--rating-master); border-color: currentColor; }
.rating-tier-badge.rating-legend { color: var(--rating-legend); border-color: currentColor; }

@media (max-width: 720px) {
  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3),
  .leaderboard-table th:nth-child(6),
  .leaderboard-table td:nth-child(6),
  .leaderboard-table th:nth-child(7),
  .leaderboard-table td:nth-child(7) { display: none; }
}
