:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --border: #dfe3ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #2f6feb;
  --accent-soft: #e7effd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);

  --ok: #14804a;      --ok-bg: #e3f5eb;
  --bad: #c2334d;     --bad-bg: #fdeaee;
  --warn: #9a6400;    --warn-bg: #fdf1dc;
  --info: #2f6feb;    --info-bg: #e7effd;
  --neutral: #5b6472; --neutral-bg: #eceff4;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #191c23;
    --surface-2: #21252e;
    --border: #2c313c;
    --text: #e6e8ec;
    --muted: #949cab;
    --accent: #5b91ff;
    --accent-soft: #1b2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);

    --ok: #4ade80;      --ok-bg: #10291d;
    --bad: #f87f92;     --bad-bg: #2e1620;
    --warn: #eab661;    --warn-bg: #2b2113;
    --info: #7aa7ff;    --info-bg: #16203a;
    --neutral: #9aa3b2; --neutral-bg: #232833;
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is enforced only by the UA stylesheet, which *any*
   author rule outranks — `label { display: block }` below was silently
   un-hiding hidden labels. Restore it with a rule nothing else can beat. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
#account { display: flex; align-items: center; gap: 10px; font-size: 14px; }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
main.wide { max-width: 1400px; }

.footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 32px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: var(--mono);
}

/* ---------- primitives ---------- */

h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 18px; letter-spacing: -.01em; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 20px 0 8px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card > :first-child { margin-top: 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar nav a { padding: 6px 8px; }
  main { padding: 20px 14px 48px; }
}

button, .btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
/* `.btn` is the same control rendered as a link, so every state pairs the two. */
.btn { display: inline-block; }
button:hover:not(:disabled), .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled), .btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }

input, select, textarea {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; color: var(--text); }
textarea.code {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  min-height: 340px;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}
.error { color: var(--bad); font-size: 13px; }

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

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; background: var(--surface-2);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 13px; }
td.wide { white-space: normal; }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: .01em;
  white-space: nowrap;
}
.v-AC { background: var(--ok-bg); color: var(--ok); }
.v-WA, .v-RE, .v-IE { background: var(--bad-bg); color: var(--bad); }
.v-TLE, .v-MLE, .v-OLE { background: var(--warn-bg); color: var(--warn); }
.v-CE { background: var(--neutral-bg); color: var(--neutral); }
.v-PENDING, .v-JUDGING { background: var(--info-bg); color: var(--info); }
.v-JUDGING { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.state-running { background: var(--ok-bg); color: var(--ok); }
.state-before { background: var(--info-bg); color: var(--info); }
.state-ended { background: var(--neutral-bg); color: var(--neutral); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: baseline; }
.dot.solved { background: var(--ok); }
.dot.attempted { background: var(--warn); }
.dot.untouched { background: var(--border); }

.pill {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 5px;
}

/* ---------- statement ---------- */

.statement { line-height: 1.65; }
.statement h1 { font-size: 19px; margin: 22px 0 8px; }
.statement h2 { font-size: 16px; margin: 22px 0 8px; }
.statement h3 { font-size: 14.5px; margin: 18px 0 6px; }
.statement p { margin: 0 0 12px; }
.statement ul, .statement ol { margin: 0 0 12px; padding-left: 22px; }
.statement li { margin-bottom: 4px; }
.statement code {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .5px 4px; border-radius: 4px;
}
.statement pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; overflow-x: auto;
}
.statement pre code { background: none; border: none; padding: 0; }

pre.io {
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin: 0;
  overflow-x: auto; max-height: 260px; overflow-y: auto;
}
pre.source {
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; overflow-x: auto; margin: 0;
}
.sample-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
@media (max-width: 700px) { .sample-grid { grid-template-columns: 1fr; } }
.sample-grid h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- scoreboard ---------- */

/* Let the name column absorb the slack so the problem cells stay compact. */
.scoreboard th:nth-child(2), .scoreboard td:nth-child(2) { width: 99%; }
.scoreboard td.cell { text-align: center; font-family: var(--mono); font-size: 13px; padding: 6px 10px; min-width: 74px; }
.cell.solved { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.cell.failed { background: var(--bad-bg); color: var(--bad); }
.cell.pending { background: var(--info-bg); color: var(--info); }
/* Frozen cells must read as "deliberately hidden", not as "nothing here" —
   the stripes distinguish them from an empty cell at a glance. */
.cell.frozen {
  background: repeating-linear-gradient(
    -45deg, var(--info-bg), var(--info-bg) 6px, var(--surface-2) 6px, var(--surface-2) 12px);
  color: var(--info);
}
.freeze-banner {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
}
.cell .sub { display: block; font-size: 11px; opacity: .8; font-weight: 400; }
.rank { font-family: var(--mono); color: var(--muted); }

.countdown { font-family: var(--mono); font-size: 14px; font-weight: 600; }

/* ---------- toasts & dialog ---------- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 14px; max-width: 360px;
  animation: slide-in .18s ease-out;
}
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--ok); }
@keyframes slide-in { from { opacity: 0; transform: translateY(6px); } }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  width: min(380px, 92vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog .row { justify-content: flex-end; margin-top: 6px; }

details.admin-section { margin-bottom: 14px; }
details.admin-section > summary {
  cursor: pointer; font-weight: 600; padding: 10px 0; list-style-position: inside;
}
