:root {
  --bg: #f4f5f0;
  --surface: #ffffff;
  --ink: #1b1f1a;
  --muted: #646b62;
  --line: #dde0d6;
  --pitch: #1f6b3a;
  --pitch-ink: #ffffff;
  --pitch-soft: #e3efe6;
  --amber: #a15c00;
  --amber-soft: #fbefdc;
  --red: #b3261e;
  --red-soft: #fbe5e3;
  --pick-1: #1f5fa8;
  --pick-x: #5b5f57;
  --pick-2: #b0431b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 2px 8px rgba(20, 30, 20, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1b1f1b;
    --ink: #e8ebe4;
    --muted: #9aa196;
    --line: #2d332c;
    --pitch: #3f9c62;
    --pitch-ink: #0d140f;
    --pitch-soft: #1f3326;
    --amber: #e3a14a;
    --amber-soft: #3a2c17;
    --red: #f08a80;
    --red-soft: #3d1f1c;
    --pick-1: #7fb1ec;
    --pick-x: #b9bdb4;
    --pick-2: #f0956c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 650; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--pitch);
  color: var(--pitch-ink);
  font: 700 12px/1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .04em;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
h1 { margin: 0 0 2px; font-size: 24px; letter-spacing: -.01em; }
h2 { margin: 0 0 6px; font-size: 16px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--pitch); outline-offset: 2px; }
.btn.primary { background: var(--pitch); border-color: var(--pitch); color: var(--pitch-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .6; cursor: progress; }

.export-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.export-bar > span { margin-right: auto; font-weight: 600; font-size: 14px; }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.topics { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.topic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: background-color .6s;
}
.topic.flash { background: var(--pitch-soft); }
.topic-title { font-weight: 600; overflow-wrap: anywhere; }
.topic-title a { color: inherit; text-decoration: none; }
.topic-title a:hover { text-decoration: underline; }
.topic-meta { color: var(--muted); font-size: 13px; }
.topic-actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  background: var(--bg);
  color: var(--muted);
}
.badge.ok { background: var(--pitch-soft); color: var(--pitch); }
.badge.new { background: var(--amber-soft); color: var(--amber); }
.badge.err { background: var(--red-soft); color: var(--red); }

@media (max-width: 720px) {
  .topic { grid-template-columns: 1fr; gap: 10px; }
  .badge { justify-self: start; }
}

.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--ink); }

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.stat { padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat b { display: block; font-size: 20px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat.warn b { color: var(--amber); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grid th.m, .grid td.m { text-align: center; width: 40px; padding-left: 4px; padding-right: 4px; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tr.flagged td { background: var(--amber-soft); }
.grid td.note { white-space: normal; color: var(--amber); font-size: 13px; min-width: 160px; }
.grid .player { font-weight: 600; }
.grid .empty-row { text-align: center; color: var(--muted); padding: 28px; }

.pick { display: inline-block; min-width: 22px; font-weight: 700; font-family: ui-monospace, Menlo, Consolas, monospace; }
.pick-1 { color: var(--pick-1); }
.pick-X { color: var(--pick-x); }
.pick-2 { color: var(--pick-2); }

.matches { margin: 0 0 16px; }
.matches ol { margin: 6px 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; font-size: 14px; }
.matches li b { display: inline-block; min-width: 34px; color: var(--muted); font-variant-numeric: tabular-nums; }

.panel { margin-top: 20px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel.warn { border-color: var(--amber); }
.panel summary { cursor: pointer; font-weight: 600; }
.posts { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.posts li { padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.posts .who { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.posts pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.45 ui-monospace, Menlo, Consolas, monospace; }

.offscreen { position: fixed; left: -9999px; opacity: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  font-size: 14px;
}
.toast.err { background: var(--red); color: #fff; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 8px 14px;
  margin-bottom: -1px;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--surface); border-color: var(--line); border-bottom-color: var(--surface); }

/* Statistics */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.match-card { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.match-card h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.match-card h3 b { color: var(--muted); font-weight: 600; margin-right: 6px; }
.bar-row { display: grid; grid-template-columns: 20px 1fr 76px; align-items: center; gap: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.bar-row + .bar-row { margin-top: 4px; }
.bar-row .label { font-weight: 700; font-family: ui-monospace, Menlo, Consolas, monospace; }
.bar-row .value { text-align: right; color: var(--muted); }
.bar-row.top .value { color: var(--ink); font-weight: 600; }
.bar-track { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--muted); }
.bar-fill.p-1 { background: var(--pick-1); }
.bar-fill.p-X { background: var(--pick-x); }
.bar-fill.p-2 { background: var(--pick-2); }
.bbcode {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  resize: vertical;
}

/* Header */
.bar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bar-right form { margin: 0; }
#forum-state { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 20px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { font-weight: 600; font-size: 14px; }
.login-card input {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.login-card input:focus-visible { outline: 2px solid var(--pitch); outline-offset: 1px; }
.login-card .btn { justify-content: center; margin-top: 6px; }
.login-msg { margin: 0; font-size: 14px; color: var(--muted); }
.login-msg.err { color: var(--red); }

/* History */
.panel.first { margin-top: 0; }
.small-grid th, .small-grid td { padding: 6px 10px; font-size: 13px; }
.small-grid td.err { color: var(--red); white-space: normal; }
.version { margin-top: 6px; }
.version .when { font-size: 12px; color: var(--muted); }
.version.old pre { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--amber-soft); color: var(--amber); }
.tag.removed { background: var(--red-soft); color: var(--red); }
#runs-panel { margin-top: 24px; }

/* Admin area */
.admin-mark { background: #7c2d12; }
.login-foot { margin: 16px 0 0; font-size: 13px; }
.login-foot a { color: var(--muted); }
ul.plain { margin: 6px 0 0; padding-left: 18px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.small-grid td.detail { white-space: normal; min-width: 240px; overflow-wrap: anywhere; }
.small-grid tr.bad td { background: var(--red-soft); }
.small-grid th[scope], #a-settings-table th { text-align: left; width: 220px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--ink); }
.ok { color: var(--pitch); font-weight: 700; }
.err { color: var(--red); font-weight: 700; }

/* Results tab */
.res-matches { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.res-match { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.res-match:first-child { border-top: 0; }
.res-name { min-width: 0; overflow-wrap: anywhere; }
.res-name b { color: var(--muted); font-weight: 600; }
.res-buttons { display: inline-flex; gap: 6px; flex-shrink: 0; }
.res-pick {
  min-width: 42px; height: 36px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: 700 15px/1 ui-monospace, Menlo, Consolas, monospace; cursor: pointer;
}
.res-pick:hover { border-color: var(--muted); }
.res-pick:focus-visible { outline: 2px solid var(--pitch); outline-offset: 2px; }
.res-pick[aria-pressed="true"] { background: var(--pitch); border-color: var(--pitch); color: var(--pitch-ink); }
.res-pick.res-skip[aria-pressed="true"] { background: var(--muted); border-color: var(--muted); }
.res-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.res-manual { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.res-manual label { font-weight: 600; font-size: 14px; }
.res-manual select { min-height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.winner-text { margin: 6px 0 0; font-size: 15px; }
.inner-bar { margin: 0; padding: 0; border: 0; }
#r-table td.hit { background: var(--pitch-soft); color: var(--pitch); font-weight: 700; }
#r-table td.miss { color: var(--muted); }
#r-table tr.res-row td { font-weight: 700; background: var(--bg); }
#r-table tr.winner-row td.player { color: var(--pitch); }
@media (max-width: 560px) {
  .res-match { flex-direction: column; align-items: stretch; gap: 6px; }
  .res-buttons { justify-content: space-between; }
  .res-pick { flex: 1; }
}
