:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --border: #2a313b;
  --text: #e7eaee;
  --muted: #98a2ae;
  --faint: #6b7480;
  --accent: #f5b83d;
  --accent-ink: #1d1400;
  --good: #4cc38a;
  --bad: #ef6461;
  --warn: #f0a03c;
  --info: #5aa9e6;
  --good-bg: rgba(76, 195, 138, .13);
  --bad-bg: rgba(239, 100, 97, .13);
  --warn-bg: rgba(240, 160, 60, .14);
  --info-bg: rgba(90, 169, 230, .13);
  --accent-bg: rgba(245, 184, 61, .13);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .18);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  /* chart tokens (validated against the panel surface in both themes) */
  --series-1: #3987e5;
  --deemph: #898781;
  --grid: #252b33;
  --axis: #3a424d;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b2026;
  --muted: #5d6773;
  --faint: #8a939e;
  --accent: #c98a0c;
  --accent-ink: #ffffff;
  --good: #1f9d63;
  --bad: #d64541;
  --warn: #c7790f;
  --info: #2f7fc1;
  --good-bg: rgba(31, 157, 99, .1);
  --bad-bg: rgba(214, 69, 65, .1);
  --warn-bg: rgba(199, 121, 15, .1);
  --info-bg: rgba(47, 127, 193, .1);
  --accent-bg: rgba(201, 138, 12, .1);
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 6px 18px rgba(0, 0, 0, .06);
  --series-1: #2a78d6;
  --deemph: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand img, .brand .logo {
  width: 36px; height: 36px; border-radius: 8px; flex: none;
  display: grid; place-items: center; background: var(--accent-bg); color: var(--accent); font-size: 20px;
}
.brand .name { font-weight: 700; line-height: 1.15; }
.brand .sub { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 550;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-bg); color: var(--accent); }
.nav .ico { width: 18px; text-align: center; }
.nav .count {
  margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 700;
}
.sidebar .foot { margin-top: auto; padding: 8px; color: var(--faint); font-size: 12px; }
.sidebar .foot button { margin-top: 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.syncpill { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }
.dot.busy { background: var(--info); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
.content { padding: 20px 24px 48px; max-width: 1400px; width: 100%; }
.banner {
  margin: 12px 24px 0; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid; font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
}
.banner.bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.banner.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.banner.good { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.banner .grow { flex: 1; }

/* ---------------------------------------------------------------- building blocks */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.dash { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card > .hd {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card > .hd h2 { flex: 1; }
.card > .bd { padding: 14px 16px; }
.card > .bd.flush { padding: 0; }
.card.accent-bad { border-top: 3px solid var(--bad); }
.card.accent-good { border-top: 3px solid var(--good); }
.card.accent-warn { border-top: 3px solid var(--warn); }
.card.accent-info { border-top: 3px solid var(--info); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.kpi .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 6px 12px;
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }

input[type=text], input[type=search], input[type=number], input[type=password], select, textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font: inherit; min-width: 0;
}
input[type=number] { width: 84px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field > span { font-weight: 600; }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .s { position: absolute; inset: 0; background: var(--border); border-radius: 20px; transition: .15s; cursor: pointer; }
.switch .s::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .s { background: var(--good); }
.switch input:checked + .s::before { transform: translateX(14px); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; }
.tabs a {
  padding: 8px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- badges & chips */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; background: var(--panel-2); color: var(--muted); white-space: nowrap;
  border: 1px solid transparent;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.accent { background: var(--accent-bg); color: var(--accent); }
.badge.outline { background: transparent; border-color: var(--border); }
.role { font-size: 11.5px; font-weight: 650; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.role.leader { background: var(--accent-bg); color: var(--accent); }
.role.coLeader { background: var(--info-bg); color: var(--info); }
.role.admin { background: var(--good-bg); color: var(--good); }
.th { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; font-size: 11.5px; border-radius: 6px; padding: 1px 5px; background: var(--panel-2); color: var(--muted); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); font-size: 12.5px; }
.stars { color: var(--accent); letter-spacing: -1px; white-space: nowrap; }
.stars .off { color: var(--border); }
.result { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; font-weight: 800; font-size: 12px; }
.result.win { background: var(--good-bg); color: var(--good); }
.result.lose { background: var(--bad-bg); color: var(--bad); }
.result.tie { background: var(--panel-2); color: var(--muted); }

/* ---------------------------------------------------------------- tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650;
  background: var(--panel); position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { opacity: .4; margin-left: 3px; }
th.sorted .arrow { opacity: 1; color: var(--accent); }
tbody tr:hover > td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
td.num, th.num { text-align: right; }
td.ctr, th.ctr { text-align: center; }
tr.cut > td { border-bottom: 2px dashed var(--accent); }
tr.dim > td { opacity: .55; }
tr.expand > td { background: var(--panel-2); padding: 12px 16px; }
tr.clickable { cursor: pointer; }
.cell-mini { display: inline-flex; gap: 2px; }
.mini {
  display: inline-grid; place-items: center; min-width: 22px; height: 20px; border-radius: 4px; padding: 0 3px;
  font-size: 11px; font-weight: 700; background: var(--panel-2); color: var(--faint);
}
.mini.s3 { background: var(--good-bg); color: var(--good); }
.mini.s2 { background: var(--accent-bg); color: var(--accent); }
.mini.s1 { background: var(--warn-bg); color: var(--warn); }
.mini.s0 { background: var(--bad-bg); color: var(--bad); }
.mini.miss { background: var(--bad); color: #fff; }
.mini.pend { background: var(--info-bg); color: var(--info); }
.mini.unk { background: transparent; border: 1px dashed var(--faint); color: var(--faint); }
.mini.none { background: transparent; color: var(--border); }
.mini.low { box-shadow: inset 0 -2px 0 var(--bad); }
.th.rushed { background: var(--warn-bg); color: var(--warn); margin-left: 3px; min-width: 0; }

.checks { width: 100%; }
.checks td { border: 0; padding: 3px 8px; }
.checks .met { font-weight: 700; }
.checks .met.good { color: var(--good); }
.checks .met.bad { color: var(--bad); }
.checks .met.warn { color: var(--warn); }
.checks .fail { color: var(--faint); }

/* ---------------------------------------------------------------- explainer / math */
details.math {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--info);
  border-radius: var(--radius); margin-bottom: 16px;
}
details.math > summary { cursor: pointer; padding: 10px 14px; font-weight: 650; list-style: none; display: flex; gap: 8px; align-items: center; }
details.math > summary::-webkit-details-marker { display: none; }
details.math > summary::before { content: "▸"; color: var(--info); transition: transform .15s; }
details.math[open] > summary::before { transform: rotate(90deg); }
details.math .body { padding: 0 16px 12px 30px; }
details.math ul, .card ul.plain { margin: 4px 0 10px; padding-left: 18px; }
details.math li { margin: 3px 0; }
.formula { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 8px 10px; border-radius: 6px; margin: 6px 0; }

.list { display: flex; flex-direction: column; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list .item:last-child { border-bottom: 0; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.skeleton { color: var(--muted); padding: 40px; text-align: center; }

.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; text-align: center; }
.versus .side .n { font-weight: 700; }
.versus .score { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--good); }

.winner { font-size: 20px; font-weight: 800; color: var(--accent); }
.roll-anim { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 1100px) {
  .grid.dash, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; }
  .brand { padding: 0 8px 0 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 6px 8px; }
  .nav .label { display: none; }
  .sidebar .foot { display: none; }
  .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .banner { margin-left: 16px; margin-right: 16px; }
}

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
svg.viz { display: block; overflow: visible; font-family: inherit; }
.viz .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.viz .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .ln.main { stroke: var(--series-1); }
.viz .ln.deemph { stroke: var(--deemph); stroke-width: 1.5; opacity: .55; }
.viz .dot.deemph { fill: var(--deemph); opacity: .8; }
.viz .end, .viz .focus { fill: var(--series-1); stroke: var(--panel); stroke-width: 2; }
.viz .lbl { fill: var(--text); font-size: 11.5px; font-weight: 650; }
.viz .col { fill: var(--series-1); }
.viz .col.hot { opacity: .75; }
.viz .cross { stroke: var(--muted); stroke-width: 1; }
.viz .pt { fill: var(--series-1); stroke: var(--panel); stroke-width: 2; }
.viz .pt.hot { r: 7; }
.viz .hit { fill: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.legend .key, .viz-tip .k { display: inline-block; width: 14px; height: 2px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.key.main { background: var(--series-1); }
.key.deemph { background: var(--deemph); }
.key.none { background: transparent; }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 12.5px; min-width: 130px; max-width: 280px; }
.viz-tip .t { color: var(--muted); margin-bottom: 4px; }
.viz-tip .r { display: flex; align-items: center; gap: 6px; }
.viz-tip .r .k { margin-right: 0; }
.viz-tip b { font-variant-numeric: tabular-nums; color: var(--text); }
.viz-tip .r span:last-child { color: var(--muted); }
details.tableview { margin-top: 8px; }
details.tableview > summary { cursor: pointer; }
.barcell { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.barcell .track { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; }
.barcell .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.barcell .v { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.seg { display: inline-flex; gap: 4px; }
.sidebar .foot .terms { display: block; color: var(--faint); font-size: 11.5px; margin: 4px 0; }

/* ---------------------------------------------------------------- login / read-only clan view */
body.viewer .admin-only { display: none !important; }

/* ---------------------------------------------------------------- leader login corner, tags, search */
.leader { position: relative; display: flex; gap: 6px; align-items: center; }
.leader-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: 240px; display: flex; flex-direction: column;
  gap: 8px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.leader-pop.hidden { display: none; }
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.tag-war, .tag-raid, .tag-cwl { background: var(--good-bg); color: var(--good); }
.tag-downer { background: var(--bad-bg); color: var(--bad); }
tr.hl > td { background: var(--accent-bg) !important; }
.viz .pt.sel { fill: var(--accent); }
.chart.searching .viz .pt:not(.sel) { opacity: .3; }
.tags.compact { flex-wrap: nowrap; gap: 3px; }
.tag.icon { padding: 1px 5px; font-size: 12px; }

/* dashboard: new-rules notice, calendar, prediction */
a.banner.newrules { margin: 0 0 16px; color: inherit; text-decoration: none; align-items: center; }
a.banner.newrules:hover { border-color: var(--good); }
.cal { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cal li { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; padding: 8px 0 8px 14px;
  border-left: 2px solid var(--border); position: relative; }
.cal li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--border); }
.cal li.done { opacity: .6; }
.cal li.done::before { background: var(--border); }
.cal li.now { border-left-color: var(--accent); }
.cal li.now::before { background: var(--accent); border-color: var(--accent); }
.cal .when { text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.warhead { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(180px, 1fr); gap: 24px; align-items: center; }
.warhead .hero .v { font-size: 40px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.warhead .hero .l { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.atk { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.atk .plan { font-size: 12.5px; }
.bar.meter { height: 8px; }
table.predict td { vertical-align: middle; }
table.predict .barcell { min-width: 90px; }
pre.posted { white-space: pre-wrap; margin: 0; font: inherit; font-size: 13.5px; line-height: 1.55; }
@media (max-width: 720px) { .warhead { grid-template-columns: 1fr; } }

/* stats: member groups on the scatter (neutral outlines - the groups are told apart by position and icon) */
.viz .zone { fill: var(--text); fill-opacity: .035; stroke: var(--muted); stroke-opacity: .7; stroke-width: 1.25; stroke-dasharray: 5 4; }
.viz .zlbl { fill: var(--text); font-size: 12px; font-weight: 650; }
.viz .thr-lbl { fill: var(--text); font-weight: 700; }
.viz .pt.few { fill: var(--panel); stroke: var(--deemph); stroke-width: 1.5; }
.legend.groups { gap: 6px 16px; color: var(--text); font-size: 12.5px; margin-bottom: 10px; }
.viz .pt.picked { stroke: var(--text); stroke-width: 2.5; }
