:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #d6336c;
  --accent-text: #ffffff;
  --code-bg: #1e2329;
  --code-text: #e6e9ed;
  --ok-bg: #e6f6ec;
  --ok-border: #3aa564;
  --ok-text: #1d6b3b;
  --warn-bg: #fff6e0;
  --warn-border: #d99a1b;
  --warn-text: #7a5500;
  --bad-bg: #fdecec;
  --bad-border: #d64545;
  --bad-text: #8f2323;
  --gold: #f2c94c;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e6e9ed;
    --muted: #97a1ad;
    --border: #2e353e;
    --accent: #f06595;
    --accent-text: #12151a;
    --code-bg: #0d0f12;
    --ok-bg: #12291b;
    --ok-text: #7fd6a0;
    --warn-bg: #2b2310;
    --warn-text: #f0c66b;
    --bad-bg: #2d1515;
    --bad-text: #f19a9a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .3rem; }
.muted { color: var(--muted); }
code, pre, textarea, .mono { font-family: var(--mono); font-size: 13.5px; }
var { font-style: italic; font-family: "Times New Roman", serif; font-size: 1.08em; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--accent); }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a {
  text-decoration: none; color: var(--muted);
  padding: .35rem .75rem; border-radius: 6px; font-weight: 500;
}
.topbar nav a.active { color: var(--text); background: var(--surface-2); }
.who {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .3rem .8rem; border-radius: 999px; cursor: pointer; font: inherit;
}

main { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }

button { font: inherit; cursor: pointer; }
.primary {
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 8px; padding: .55rem 1.1rem; font-weight: 600;
}
.primary:disabled { opacity: .55; cursor: wait; }
.ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: .25rem .65rem; font-size: 13px;
}
.ghost:hover { background: var(--surface-2); }
a.ghost { text-decoration: none; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
}

/* problem list */
.intro { margin-bottom: 1.5rem; max-width: 760px; }
.intro p { margin: .4rem 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.pcard {
  display: block; text-decoration: none; color: inherit;
  transition: border-color .15s, transform .15s;
}
.pcard:hover { border-color: var(--accent); transform: translateY(-1px); }
.pcard .num { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.pcard h2 { font-size: 1.1rem; margin: .2rem 0 .8rem; }
.badge {
  display: inline-block; border-radius: 999px; padding: .1rem .6rem;
  font-size: 12.5px; font-weight: 600;
}
.badge.todo { background: var(--surface-2); color: var(--muted); }
.badge.done { background: var(--ok-bg); color: var(--ok-text); }
.badge.perfect { background: var(--gold); color: #3d2e00; }
.badge.stress { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }

/* problem page */
.problem-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.problem-head .meta { color: var(--muted); font-size: 13.5px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.side { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; }
}
.statement p { margin: .4rem 0; }
.statement h3:first-child { margin-top: 0; }
.samples { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.samples .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; }
pre.io {
  margin: 0; padding: .6rem .8rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; overflow-x: auto; white-space: pre;
}
.code-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.code-head h3 { margin: 0; flex: 1; }
pre.code {
  margin: 0; padding: 1rem; background: var(--code-bg); color: var(--code-text);
  border-radius: 8px; overflow-x: auto; max-height: 520px;
}
.compile { margin-top: .5rem; font-size: 13px; color: var(--muted); }
.compile code { background: var(--surface-2); padding: .1rem .4rem; border-radius: 4px; }

textarea {
  width: 100%; min-height: 180px; resize: vertical;
  padding: .7rem .8rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.submit-row { display: flex; align-items: center; gap: 1rem; margin-top: .6rem; }
.submit-row .size { flex: 1; color: var(--muted); font-size: 13.5px; }
.hint { font-size: 13px; color: var(--muted); margin-top: .6rem; }

.result { border-left: 4px solid var(--border); }
.result h3 { margin: 0 0 .3rem; }
.result.found { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.result.same { background: var(--surface); }
.result.invalid, .result.wrong_failed { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.result.internal { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad-text); }
.result .outputs { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .8rem; color: var(--text); }
.result .outputs .full { grid-column: 1 / -1; }
.result .label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.points { font-size: 1.6rem; font-weight: 800; }
.reason { margin-top: .4rem; }
pre.scroll { max-height: 260px; overflow: auto; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: center; }
td.total { font-weight: 800; }
.cell-done { color: var(--ok-text); font-weight: 600; }
.cell-perfect { background: color-mix(in srgb, var(--gold) 35%, transparent); font-weight: 700; }
tr.me td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.rank { color: var(--muted); width: 2.5rem; }
td pre { margin: 0; max-height: 140px; overflow: auto; }

.toolbar { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; flex-wrap: wrap; }
select, input {
  font: inherit; padding: .35rem .6rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.5rem; width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin-top: 0; }
dialog input { width: 100%; margin: .5rem 0 1rem; padding: .55rem .7rem; }
dialog button { width: 100%; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .5rem 1rem; border-radius: 8px; font-size: 14px;
}

/* code runner */
.tabs { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 6px; padding: .25rem .65rem; font-family: var(--mono); font-size: 13px;
}
.tab.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
textarea.editor {
  min-height: 380px; background: var(--code-bg); color: var(--code-text);
  border: 0; border-radius: 8px; padding: 1rem; tab-size: 4; white-space: pre; line-height: 1.5;
}
textarea.stdin { min-height: 90px; }
.stdin-head { display: flex; align-items: center; justify-content: space-between; margin: .7rem 0 .25rem; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.run-output:not(:empty) { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.run-status { font-weight: 600; padding: .4rem .7rem; border-radius: 6px; }
.run-status.ok { background: var(--ok-bg); color: var(--ok-text); }
.run-status.ce, .run-status.re, .run-status.tle { background: var(--warn-bg); color: var(--warn-text); }
.run-status.internal { background: var(--bad-bg); color: var(--bad-text); }
.compile-out { margin-top: .5rem; max-height: 260px; overflow: auto; white-space: pre-wrap; }
.run-stdout, .run-stderr { max-height: 300px; overflow: auto; }
.run-stderr { color: var(--warn-text); }

/* sections */
.psection { margin-bottom: 2rem; }
.psection-head { display: flex; align-items: baseline; gap: .8rem; }
.psection-head h2 { font-size: 1.2rem; margin: 0; }
.psection-hint { margin: .25rem 0 .9rem; max-width: 760px; }
.board-tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: .5rem 0 .25rem; }
.board-tabs .tab { font-family: inherit; font-size: 14px; }
.cell-pts { color: var(--muted); font-weight: 400; font-size: 12px; }
a.th-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
a.th-link:hover { color: var(--accent); border-color: var(--accent); }
