:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --seq-hi: #184f95;
  --good-text: #006300;
  --bad-text: #b02a2a;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --seq-hi: #3987e5;
    --good-text: #0ca30c;
    --bad-text: #e66767;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; text-decoration: none; color: var(--text-primary); }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand-mark svg { display: block; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }

.sidebar { background: var(--surface-1); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 0 8px; }
.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(--text-secondary); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--text-primary); }
.nav svg { flex: none; }
.nav a.ext { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
.nav .ext-mark { margin-left: auto; color: var(--text-muted); font-size: 12px; }
a.btn { display: inline-block; text-decoration: none; color: var(--text-primary); }
.sidebar-foot { margin-top: auto; padding: 0 8px; color: var(--text-muted); font-size: 12px; }

.main { min-width: 0; }

.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface-1); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); background: var(--surface-2); white-space: nowrap; }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.user-email { color: var(--text-secondary); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

select, .input { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 34px; }
select:focus-visible, .input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; background: transparent; padding: 7px 12px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-wash); color: var(--text-primary); }

.btn { border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.content { padding: 24px 28px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; letter-spacing: -0.01em; }
.page-head p { color: var(--text-secondary); margin-top: 2px; }

[hidden] { display: none !important; }
.btn.toggle[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

/* ---------- empty state ---------- */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.banner h2 { font-size: 16px; font-weight: 600; }
.banner p { color: var(--text-secondary); margin-top: 2px; max-width: 60ch; }
.tile.blank .tile-value { color: var(--text-muted); }
.empty-plot { height: 220px; display: grid; place-items: center; text-align: center; color: var(--text-muted); border-top: 1px solid var(--grid); border-bottom: 1px solid var(--axis); background: repeating-linear-gradient(to bottom, transparent 0, transparent 54px, var(--grid) 54px, var(--grid) 55px); }
.empty-plot.short { height: 120px; background: none; border-bottom: 0; }

/* ---------- profile & games ---------- */
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }
.idline { margin-top: 10px !important; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pad { padding: 4px 0 8px; }
.empty-games { text-align: center; padding: 28px 16px 22px; border-top: 1px solid var(--grid); }
.empty-games h4 { margin: 0 0 2px; font-size: 15px; font-weight: 600; }
.empty-games .btn { margin-top: 14px; }

/* ---------- add-game wizard ---------- */
.wizard { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-1); color: var(--text-primary); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35); overflow: auto; }
.wizard::backdrop { background: rgba(0, 0, 0, 0.55); }
.wz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.wz-head h2 { font-size: 17px; font-weight: 600; }
.wz-steps { list-style: none; margin: 0; padding: 20px 22px 22px; }
.wz-step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 0 14px; position: relative; padding-bottom: 20px; }
.wz-step:last-child { padding-bottom: 0; }
.wz-step:not(:last-child)::before { content: ""; position: absolute; left: 13.5px; top: 30px; bottom: 2px; width: 1px; background: var(--axis); }
.wz-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 600; border: 1px solid var(--axis); color: var(--text-secondary); background: var(--surface-1); }
.wz-step.current .wz-num { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.wz-step.done .wz-num { background: var(--accent-wash); border-color: transparent; color: var(--text-primary); }
.wz-body { min-width: 0; padding-top: 3px; }
.wz-body h3 { font-size: 15px; font-weight: 600; }
.wz-step.todo h3 { color: var(--text-muted); font-weight: 500; }
.wz-body > p { margin-top: 4px; color: var(--text-secondary); }
.wz-body form { margin-top: 14px; }
.wz-body fieldset { border: 0; padding: 0; margin-left: 0; margin-right: 0; min-width: 0; }
.wz-body legend { padding: 0; font-weight: 500; font-size: 13px; margin-bottom: 5px; }
.wz-body .field .input { width: 100%; min-height: 38px; }
.hint { margin-top: 5px; color: var(--text-muted); font-size: 12.5px; }
.opts { display: flex; gap: 8px; flex-wrap: wrap; }
.opt { position: relative; cursor: pointer; }
.opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.opt span { display: block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; color: var(--text-secondary); font-weight: 500; }
.opt input:checked + span { border-color: var(--accent); background: var(--accent-wash); color: var(--text-primary); }
.opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.wz-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.idbox { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.idbox code { background: none; padding: 0; font-size: 15px; overflow-wrap: anywhere; }
.wz-list { margin: 10px 0 14px; padding-left: 18px; color: var(--text-secondary); display: grid; gap: 6px; }
ul.wz-list { list-style: disc; }
.idbox span { color: var(--text-secondary); }
.idbox span b { color: var(--text-primary); }
.wz-list b { color: var(--text-primary); font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
a.user-link { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; border-radius: 8px; }
a.user-link:hover .user-email { color: var(--text-primary); }

.int-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.int-head > div { flex: 1; min-width: 0; }
.int-head h3 { font-size: 15px; font-weight: 600; }
.int-head p { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.int-badge { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 16px; background: var(--surface-2); border: 1px solid var(--border); flex: none; }
.status i.off { background: var(--axis); color: var(--text-primary); }
.status { white-space: nowrap; }
.grid.below { margin-top: 16px; }
.guide ol { margin: 4px 0 12px; padding-left: 20px; display: grid; gap: 8px; color: var(--text-secondary); max-width: 80ch; }
.guide ol b { color: var(--text-primary); font-weight: 600; }
.guide > p { max-width: 80ch; }
.int-actions { margin-top: 14px; }
.card .field select { min-width: 0; max-width: 100%; }
p.pad { padding: 10px 0 4px; }
.grid.below > .banner { grid-column: 1 / -1; margin-bottom: 0; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 6px; }
.tile-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.tile-delta { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.delta-up { color: var(--good-text); font-weight: 600; }
.delta-down { color: var(--bad-text); font-weight: 600; }
.delta-flat { color: var(--text-secondary); font-weight: 600; }
.spark { flex: none; }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid > .wide { grid-column: 1 / -1; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 14px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-head p { color: var(--text-secondary); font-size: 13px; margin-top: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 2px 0 8px; color: var(--text-secondary); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; touch-action: pan-y; }
.chart text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text-secondary); font-size: 12px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
.muted { color: var(--text-muted); }
.sharebar { display: inline-block; height: 6px; border-radius: 3px; background: var(--series-1); vertical-align: middle; margin-right: 8px; }

.heat td.cell { text-align: center; padding: 0; border-bottom: 2px solid var(--surface-1); border-left: 2px solid var(--surface-1); }
.heat td.cell span { display: block; padding: 8px 6px; border-radius: 4px; min-width: 48px; }
.heat td.cell.empty span { color: var(--text-muted); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.status i { width: 14px; height: 14px; border-radius: 50%; display: inline-grid; place-items: center; font-style: normal; font-size: 10px; font-weight: 700; color: #fff; flex: none; }
.status.good i { background: var(--status-good); }
.status.warn i { background: var(--status-warning); color: #0b0b0b; }
.status.bad i { background: var(--status-critical); }

/* ---------- funnel ---------- */
.hbars { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; gap: 9px 12px; align-items: center; }
.hbars .lab { color: var(--text-secondary); }
.hbars .track { height: 18px; }
.hbars .bar { height: 18px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; text-align: right; }
.hbars .row { display: contents; }

/* ---------- remote config ---------- */
.cfg td { vertical-align: middle; }
.cfg code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; }
.cfg .desc { color: var(--text-secondary); font-size: 12px; white-space: normal; }
.cfg .input { width: 130px; }
.cfg tr.dirty td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--axis); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- tooltip + toast ---------- */
#tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14); font-size: 12.5px; min-width: 120px; max-width: 260px; }
#tip .tt { color: var(--text-secondary); margin-bottom: 4px; }
#tip .tr { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
#tip .tr span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
#tip .tr b { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 14px; }
#tip .tot { border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 4px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text-primary); color: var(--page); padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 60; max-width: calc(100vw - 32px); }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 21px; margin: 22px 0 4px; letter-spacing: -0.01em; }
.auth-card .sub { color: var(--text-secondary); margin-bottom: 20px; }
.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field label { font-weight: 500; font-size: 13px; }
.field .input { width: 100%; min-height: 40px; }
.auth-card .btn.primary { width: 100%; min-height: 40px; margin-top: 4px; }
.auth-note { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--text-secondary); font-size: 12.5px; }
.auth-alt { margin-top: 16px; text-align: center; color: var(--text-secondary); }
.input.code { font-size: 22px; letter-spacing: 0.35em; text-align: center; font-variant-numeric: tabular-nums; min-height: 48px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
.link[disabled] { opacity: 0.6; cursor: default; }
.error { color: var(--bad-text); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .sidebar .brand span.word { display: none; }
  .sidebar .brand { padding: 0; }
  .nav { flex-direction: row; }
  .nav a.ext { margin-top: 0; padding-top: 8px; border-top: 0; border-radius: 8px; }
  .nav .ext-mark { margin-left: 2px; }
  .sidebar-foot { display: none; }
  .topbar { padding: 10px 16px; position: static; }
  .content { padding: 18px 16px 40px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .user-email { display: none; }
}
