:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --fg: #1b1f24;
  --muted: #5c6672;
  --border: #e2e6eb;
  --grid: #eceff3;
  --accent: #2f6df6;
  --accent-fg: #ffffff;
  --error: #c0392b;
  --ok: #1e8e4e;
  --radius: 10px;
  --maxw: 900px;
  /* categorical series (validated light palette) */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
}

/* Dark tokens: applied when the OS is dark (unless the viewer forced light),
   and whenever the viewer forced dark. Keep the two blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216; --panel: #171b21; --fg: #e7eaee; --muted: #9aa4b1;
    --border: #262c34; --grid: #20262e; --accent: #5b8cff; --error: #ff6b5e; --ok: #4cd08a;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216; --panel: #171b21; --fg: #e7eaee; --muted: #9aa4b1;
  --border: #262c34; --grid: #20262e; --accent: #5b8cff; --error: #ff6b5e; --ok: #4cd08a;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  background: var(--border); padding: .1em .4em; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.brand { font-weight: 650; color: var(--fg); }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.who { color: var(--muted); font-size: .9em; }

.theme-toggle {
  margin: 0; padding: 4px 10px; font-size: 1rem; line-height: 1.4; cursor: pointer;
  background: transparent; color: var(--fg); border: 1px solid var(--border); border-radius: 999px;
}
.theme-toggle:hover { border-color: var(--accent); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 24px 16px 48px; }
.wrap-wide { max-width: 90vw; }
.foot { max-width: var(--maxw); margin: 0 auto; padding: 16px; color: var(--muted); font-size: .85em; }

h1 { font-size: 1.7rem; margin: .2em 0 .4em; }
h2 { font-size: 1.15rem; margin: 0 0 .5em; }
.lead { font-size: 1.1rem; color: var(--fg); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: var(--error); font-weight: 550; }
.notice { color: var(--ok); font-weight: 550; }

/* forms */
form label { display: block; margin: 14px 0 4px; font-weight: 550; }
input[type=password], input[type=text], input[type=search] {
  width: 100%; padding: 10px 12px; font-size: 1rem;
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  margin-top: 14px; padding: 10px 18px; font-size: 1rem; cursor: pointer;
  background: var(--accent); color: var(--accent-fg);
  border: none; border-radius: var(--radius); font-weight: 550;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link, .inline button.link {
  background: none; color: var(--accent); padding: 0; margin: 0; font-weight: 500;
}
button.link:hover { text-decoration: underline; }
form.inline { display: inline; margin: 0; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

/* gate / auth */
.gate { max-width: 380px; margin: 8vh auto 0; background: var(--panel);
  padding: 28px; border: 1px solid var(--border); border-radius: var(--radius); }
.auth-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; }
.auth-card.active { border-color: var(--accent); }
@media (max-width: 620px) { .auth-cards { grid-template-columns: 1fr; } }

/* tools list on the briefing */
.tools { margin: 6px 0 4px; padding-left: 20px; }
.tools li { margin: 4px 0; }

/* challenge list / page */
.chlist { list-style: none; padding: 0; }
.chlist li { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.chlist a {
  flex: 1; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg);
}
.chlist a:hover { border-color: var(--accent); text-decoration: none; }
.chtitle { font-weight: 550; }
.ch-right { display: inline-flex; align-items: center; gap: 10px; }
.chpts { color: var(--muted); font-size: .85em; font-weight: 500; }
.done { color: var(--ok); font-weight: 700; }

/* difficulty badges */
.meta-row { display: flex; align-items: center; gap: 10px; margin: 0 0 .6em; }
.diff {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .72em; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  border: 1px solid transparent;
}
.diff-easy   { color: #0f6b3b; background: #d8f3e3; border-color: #aee3c6; }
.diff-medium { color: #8a5200; background: #fdecc8; border-color: #f4d79a; }
.diff-hard   { color: #9a1f1f; background: #fadada; border-color: #f0b4b4; }
.diff-bonus  { color: #40348a; background: #e4e0fb; border-color: #cfc8f3; }
:root[data-theme="dark"] .diff-easy,
:root:not([data-theme="light"]) .diff-easy   { color: #7fe3ad; background: #11331f; border-color: #1d5233; }
:root[data-theme="dark"] .diff-medium,
:root:not([data-theme="light"]) .diff-medium { color: #f3c879; background: #352611; border-color: #5a4320; }
:root[data-theme="dark"] .diff-hard,
:root:not([data-theme="light"]) .diff-hard   { color: #f09a9a; background: #3a1718; border-color: #5f2a2b; }
:root[data-theme="dark"] .diff-bonus,
:root:not([data-theme="light"]) .diff-bonus  { color: #c7bdfb; background: #231d44; border-color: #3a3170; }

.next-link { margin-top: 18px; font-weight: 600; }

/* hints */
.pts-pen { color: var(--error); font-size: .85em; font-weight: 500; }
.hints { list-style: none; padding: 0; margin: 0; }
.hints .hint { margin: 8px 0; }
.hint-label { font-weight: 650; }
.hint-cost { color: var(--muted); font-size: .85em; }
.hint-text { margin-top: 4px; padding: 10px 12px; background: var(--panel);
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); }
.hint-reveal { background: transparent; color: var(--accent); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 8px 14px; margin: 0; font-weight: 550; }
.hint-reveal:hover:not(:disabled) { border-color: var(--accent); }

/* first blood */
.firstblood { list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.firstblood li { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.firstblood .fb-chal { font-size: .82em; color: var(--muted); }
.firstblood .fb-holder { font-weight: 650; margin-top: 2px; }
.firstblood .fb-time { font-size: .8em; color: var(--muted); margin-top: 2px; }
.firstblood .fb-open { color: var(--muted); font-style: italic; }
.back { display: inline-block; margin-bottom: 8px; font-size: .9em; }
.challenge .body { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; }
.solved-banner { color: var(--ok); font-weight: 600; }
.files { list-style: none; padding: 0; }
.files li { margin: 6px 0; }
.files a { display: inline-block; padding: 8px 14px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); }

/* scoreboard layout: standings left (full height), side stack right */
.sb-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: stretch; }
.sb-side { display: flex; flex-direction: column; gap: 16px; }
.sb-grid .table-card { margin-bottom: 0; }
.sb-side .card { margin-bottom: 0; }
@media (max-width: 760px) { .sb-grid { grid-template-columns: 1fr; } }

/* chart */
.chart { margin: 0; }
.chart-area { width: 100%; }
.chart-area svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .series-line { fill: none; stroke-width: 2; }
.chart .series-dot { stroke: var(--panel); stroke-width: 2; }
.chart .end-label { font-size: 11px; font-weight: 600; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; padding: 0; }
.legend .chip { display: inline-flex; align-items: center; gap: 6px; font-size: .88em; color: var(--fg); }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5; max-width: 240px;
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: .82em; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.chart-tooltip .tt-time { color: var(--muted); margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tooltip .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#progression { position: relative; }

/* recent submissions */
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92em; }
.recent li:last-child { border-bottom: none; }
.recent .r-handle { font-weight: 600; }
.recent .r-chal { color: var(--muted); }
.recent .r-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85em; margin-top: 2px; }
.recent .r-pts { color: var(--ok); font-weight: 600; }

/* standings table */
.controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; }
.controls input[type=search] { max-width: 220px; }
.chk { display: inline-flex; align-items: center; gap: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { cursor: pointer; user-select: none; font-size: .9em; }
th.sorted-asc::after { content: " ▲"; color: var(--muted); }
th.sorted-desc::after { content: " ▼"; color: var(--muted); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
td.rank { color: var(--muted); font-variant-numeric: tabular-nums; }
td.pts { font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 480px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  th:nth-child(5), td:nth-child(5) { display: none; }
}
