:root {
  color-scheme: light;
  --surface-0: #f5f5f3;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --series-other: #8c8b86;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --grid: #e8e7e3;
  --better: #2a78d6;
  --worse: #e34948;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --series-other: #75746e;
    --grid: #2a2a28;
    --better: #3987e5;
    --worse: #e66767;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --series-other: #75746e;
  --grid: #2a2a28;
  --better: #3987e5;
  --worse: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.crumbs { flex: 1; color: var(--text-secondary); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.crumbs a { color: var(--text-secondary); }
.crumbs span + span::before, .crumbs a + span::before, .crumbs span + a::before, .crumbs a + a::before { content: " / "; color: var(--text-muted); }

.view { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.sub { color: var(--text-secondary); margin: 0 0 20px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

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

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.tile .label { color: var(--text-secondary); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap;
}
.pill.running { color: var(--text-primary); }
.pill.running::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  background: var(--surface-1); border: 1px solid var(--border); border-left-width: 4px;
}
.banner .icon { font-size: 18px; line-height: 1.2; }
.banner strong { display: block; font-size: 15px; margin-bottom: 2px; }
.banner.good { border-left-color: var(--good); }
.banner.warning { border-left-color: var(--warning); }
.banner.serious { border-left-color: var(--serious); }
.banner.critical { border-left-color: var(--critical); }
.banner.info { border-left-color: var(--accent); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

.check { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.check .mark { width: 16px; flex: none; text-align: center; font-weight: 700; }
.check.ok .mark { color: var(--good); }
.check.bad .mark { color: var(--critical); }
.check.warn .mark { color: var(--serious); }

button, .button {
  font: inherit; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
  padding: 7px 12px; cursor: pointer; font-weight: 550;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--critical); }
button.link { border: none; background: none; color: var(--text-secondary); padding: 4px; }
button:disabled { opacity: 0.5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions > input { width: auto; flex: 1 1 200px; max-width: 320px; }
.card-head select { width: auto; max-width: 100%; }

input, select, textarea {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%;
}
textarea { min-height: 64px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 12px; }
.variant-row { display: grid; grid-template-columns: 80px 1fr 1.4fr 90px 72px 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
.variant-row input[type="radio"] { width: auto; }
@media (max-width: 720px) {
  .variant-row { grid-template-columns: 1fr 1fr; }
}

.error { color: var(--critical); margin: 8px 0; }
.notice { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; margin: 8px 0; word-break: break-all; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--text-secondary); font-size: 12px; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .ref-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .hit { fill: transparent; cursor: default; }
.chart .row:hover .hit { fill: var(--surface-2); }
.metric-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 16px rgb(0 0 0 / 14%);
  padding: 8px 10px; font-size: 12px; font-variant-numeric: tabular-nums; max-width: 260px;
}
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-primary); font-weight: 600; }

.login { max-width: 380px; margin: 12vh auto; }
.empty { color: var(--text-muted); padding: 12px 0; }

/* ---- page structure ---- */
.card-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 12.5px; max-width: 70ch; }
.page-head { margin-bottom: 4px; }
.grid.two > .card { margin-bottom: 0; }
.grid.two { margin-bottom: 16px; }
.details-block { margin-bottom: 16px; }
.details-block > summary { cursor: pointer; padding: 10px 2px; list-style-position: inside; }
.details-block[open] > summary { margin-bottom: 8px; }

/* ---- games list ---- */
.game-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-bottom: 16px; }
.game-card {
  display: block; color: inherit; text-decoration: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s;
}
.game-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.game-name { font-size: 16px; font-weight: 650; }
.game-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }

/* ---- live ---- */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 8px; vertical-align: middle; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.tile .value.big { font-size: 34px; }

/* ---- charts ---- */
.chart-wrap { width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; font-size: 12.5px; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
.chart .zero-line { stroke: var(--text-muted); stroke-width: 1; }
.chart .end-label { fill: var(--text-secondary); font-size: 12px; }
.chart .value-label { fill: var(--text-secondary); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .step-label { fill: var(--text-primary); font-size: 12.5px; font-weight: 600; }
.chart .column .hit { fill: transparent; }
.chart .column:hover .hit { fill: var(--surface-2); }
.tooltip .t-key { display: inline-flex; align-items: center; gap: 6px; }

/* ---- hero tiles ---- */
.hero-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-bottom: 16px; }
.hero-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  border-top: 3px solid var(--accent-color); padding: 14px 16px; box-shadow: var(--shadow);
  display: grid; gap: 6px;
}
.hero-label { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text-secondary); font-size: 13px; }
.hero-value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.delta { font-weight: 600; font-size: 13.5px; color: var(--text-secondary); }
.delta.sure.better { color: var(--good); }
.delta.sure.worse { color: var(--critical); }
.delta-tag { margin-left: 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.delta.neutral { color: var(--text-muted); font-weight: 500; }
.meter-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; }

/* ---- scorecard ---- */
.scorecard th, .scorecard td { vertical-align: middle; }
.scorecard thead th { white-space: nowrap; }
.score-cell { text-align: center; border-left: 2px solid var(--surface-1); min-width: 120px; }
.score-lift { font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.pill.tiny { font-size: 10.5px; padding: 1px 6px; margin-left: 6px; }

/* ---- power ---- */
.power-table td { text-align: center; border-left: 2px solid var(--surface-1); }
.power-days { font-weight: 650; font-size: 15px; }

/* ---- funnel editor ---- */
.funnel-editor { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.funnel-editor > summary { cursor: pointer; color: var(--accent); font-weight: 550; }
.funnel-form { display: grid; gap: 10px; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 500; }

/* ---- decide popover ---- */
.popover { position: relative; }
.popover > summary { list-style: none; }
.popover > summary::-webkit-details-marker { display: none; }
.popover-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 4; width: min(340px, calc(100vw - 32px)); }

/* ---- live feed ---- */
.live-dot.off { background: var(--text-muted); animation: none; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; font-size: 13px; }
.feed li { display: grid; grid-template-columns: 92px 64px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 5px 4px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: none; }
.feed .feed-version { display: inline-flex; align-items: center; gap: 6px; }
.feed .feed-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed li.fresh { animation: arrive 1.6s ease-out; }
@keyframes arrive { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .feed li.fresh { animation: none; } }
@media (max-width: 560px) { .feed li { grid-template-columns: 76px 52px minmax(0, 1fr); } .feed .feed-user { display: none; } }
