:root {
  --bg: #ffffff;
  --fg: #1a1d23;
  --muted: #555c68;
  --border: #d6dae1;
  --surface: #f5f7fa;
  --accent: #1f5fbf;
  --accent-fg: #ffffff;
  --success-bg: #e6f4ea;
  --success-fg: #1e5b2c;
  --error-bg: #fdecea;
  --error-fg: #8a1c14;
  --info-bg: #e8f0fb;
  --info-fg: #1c3f73;
  --warn-bg: #fff4d6;
  --warn-fg: #6b4a00;
  --radius: 6px;
  --focus: 3px solid #f0a500;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e8eaed;
    --muted: #a5acb8;
    --border: #353a43;
    --surface: #1d2026;
    --accent: #6ea8ff;
    --accent-fg: #0b1220;
    --success-bg: #173a22;
    --success-fg: #b8e6c4;
    --error-bg: #45191a;
    --error-fg: #ffc9c4;
    --info-bg: #182a45;
    --info-fg: #c6dbff;
    --warn-bg: #3d3113;
    --warn-fg: #ffe3a1;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible,
[tabindex]:focus-visible { outline: var(--focus); outline-offset: 2px; }

.container { max-width: 960px; margin: 0 auto; padding: 0 1rem; }
main.container { padding-top: 1.5rem; padding-bottom: 3rem; }
main:focus { outline: none; }
.narrow { max-width: 32rem; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-fg); padding: .5rem 1rem; z-index: 10;
}
.skip-link:focus { left: 1rem; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding-top: .75rem; padding-bottom: .75rem; }
.nav ul { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; list-style: none; margin: 0; padding: 0; }
.nav a { text-decoration: none; }
.nav a[aria-current="page"] { font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.brand { font-weight: 700; color: var(--fg) !important; }
.handle { color: var(--muted); font-family: ui-monospace, monospace; }
.nav form { margin: 0; }

/* Text */
h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.lead { font-size: 1.1rem; }
.muted { color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; color: var(--muted); }
.breadcrumb { font-size: .9rem; color: var(--muted); margin-bottom: .5rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; overflow-x: auto; }

.statement { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: .5rem 0 1rem; margin: 1rem 0; overflow-wrap: anywhere; }
.statement img { max-width: 100%; height: auto; }
.statement table { border-collapse: collapse; }
.statement th, .statement td { border: 1px solid var(--border); padding: .3rem .6rem; }

.window { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; margin: 1rem 0; }
.window dt { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.window dd { margin: 0; font-weight: 600; }
.categories { padding-left: 1.25rem; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1.5rem 0; }
.stack { display: grid; gap: .75rem; margin-top: 1.5rem; }

/* Buttons */
.button, button[type="submit"]:not(.link-button) {
  display: inline-block; cursor: pointer; border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: var(--accent-fg); padding: .55rem 1.1rem; font: inherit; font-weight: 600; text-decoration: none;
}
.button:hover, button[type="submit"]:not(.link-button):hover { filter: brightness(1.08); }
.button-secondary { background: transparent; color: var(--accent); }
.button-wide { width: 100%; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
fieldset[disabled] button { opacity: .5; cursor: not-allowed; }

/* Forms (Django's default div rendering) */
.form > div, .form fieldset > div { margin-bottom: 1rem; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type="text"], input:not([type]), input[type="url"], textarea, select {
  width: 100%; max-width: 100%; padding: .5rem .6rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}
textarea { resize: vertical; }
.helptext { display: block; font-size: .88rem; color: var(--muted); margin-top: .25rem; }
.errorlist { list-style: none; margin: 0 0 .5rem; padding: .5rem .75rem; border-radius: var(--radius); background: var(--error-bg); color: var(--error-fg); }
[aria-invalid="true"] { border-color: var(--error-fg); }

/* Messages and tags */
.messages { margin-bottom: 1rem; }
.message { padding: .65rem .9rem; border-radius: var(--radius); margin: 0 0 .5rem; }
.message-success { background: var(--success-bg); color: var(--success-fg); }
.message-error { background: var(--error-bg); color: var(--error-fg); }
.message-info, .message-warning { background: var(--info-bg); color: var(--info-fg); }
.tag { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); vertical-align: middle; }
.tag-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.status { font-weight: 600; }
.status-solved, .status-answered { color: var(--success-fg); }
.status-partial { color: var(--warn-fg); }
.status-attempted { color: var(--error-fg); }

/* Tables */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .85rem; color: var(--muted); border-bottom-width: 2px; }
.table tbody th { font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.leaderboard tr.is-me { background: var(--info-bg); }
.problem-group .table td:first-child { width: 70%; }

@media (max-width: 600px) {
  h1 { font-size: 1.45rem; }
  .problem-group .table td:first-child { width: auto; }
}

/* Graded problems */
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; line-height: 1.45; tab-size: 4; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.limits { display: grid; gap: .35rem; margin: 0 0 1rem; }
.limits > div { display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
.limits dt { font-weight: 600; min-width: 8rem; }
.limits dd { margin: 0; }
.rules { margin: 1rem 0; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul, .rules ol { margin: .5rem 0 0; padding-left: 1.25rem; }
.targets { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.target { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; background: var(--surface); }
.target img { display: block; height: auto; border: 1px solid var(--border); }
.target-desktop img { width: min(640px, 100%); }
.target-mobile img { width: 195px; }
.target figcaption { font-size: .85rem; color: var(--muted); margin-top: .35rem; }
.preview { margin-top: 2rem; }
.preview-sizes { display: flex; gap: .5rem; margin-bottom: .75rem; }
.preview-sizes [aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.preview-wrap { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.preview-frame { position: absolute; top: 0; left: 0; border: 0; transform-origin: top left; background: #fff; }
pre.output { max-height: 24rem; overflow: auto; white-space: pre-wrap; }
.result-summary { font-size: 1.1rem; }
