:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #cdd2da;
  --text: #16181d;
  --text-2: #5a6170;
  --text-3: #8a909c;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-soft: #ededfc;
  --accent-text: #4141b8;
  --ok: #18794e;
  --ok-soft: #e6f6ed;
  --warn: #a35200;
  --warn-soft: #fff3e0;
  --danger: #cd2b31;
  --danger-soft: #fdecec;
  --inters: #0b6bcb;
  --inters-soft: #e5f1fd;
  --reward: #8a4bd6;
  --reward-soft: #f3ebfd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --border: #2a2f39; --border-strong: #3a404c;
    --text: #e9ebef; --text-2: #a4abb8; --text-3: #6f7685;
    --accent: #7b7bf0; --accent-hover: #8e8ef5; --accent-soft: #23234a; --accent-text: #b4b4ff;
    --ok: #4cc38a; --ok-soft: #12291e; --warn: #f1a10d; --warn-soft: #2d2210; --danger: #ff6369; --danger-soft: #3a1618;
    --inters: #52a9ff; --inters-soft: #10263d; --reward: #be93fd; --reward-soft: #291a3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --border: #2a2f39; --border-strong: #3a404c;
  --text: #e9ebef; --text-2: #a4abb8; --text-3: #6f7685;
  --accent: #7b7bf0; --accent-hover: #8e8ef5; --accent-soft: #23234a; --accent-text: #b4b4ff;
  --ok: #4cc38a; --ok-soft: #12291e; --warn: #f1a10d; --warn-soft: #2d2210; --danger: #ff6369; --danger-soft: #3a1618;
  --inters: #52a9ff; --inters-soft: #10263d; --reward: #be93fd; --reward-soft: #291a3d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body {
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.hidden { display: none !important; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 13px; }
.btn.icon { width: 30px; height: 30px; padding: 0; justify-content: center; }
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 80px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { font-size: 12.5px; }
.input.warn { border-color: var(--warn); }
.input.bad { border-color: var(--danger); }
.input.blank { background: var(--surface-2); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-weight: 500; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--text-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--border-strong); cursor: pointer;
  transition: background .15s; }
.switch span::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.inters { background: var(--inters-soft); color: var(--inters); }
.badge.rewarded { background: var(--reward-soft); color: var(--reward); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.danger { background: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-h .sub { color: var(--text-3); font-size: 13px; }
.card-b { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.login h1 { font-size: 20px; margin: 22px 0 4px; }
.login p { margin: 0 0 20px; color: var(--text-2); }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert code { font-family: var(--mono); font-size: 12px; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 264px 1fr; height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0; }
.side-top { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.side-search { position: relative; }
.side-search svg { position: absolute; left: 10px; top: 9px; color: var(--text-3); }
.side-search .input { padding-left: 32px; height: 32px; }
.side-label { padding: 6px 16px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); display: flex; align-items: center; }
.games { flex: 1; overflow: auto; padding: 0 8px 8px; }
.game-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 0; background: none; text-align: left; cursor: pointer; }
.game-item:hover { background: var(--surface-2); }
.game-item.active { background: var(--accent-soft); }
.game-item.active .gi-name { color: var(--accent-text); }
.avatar { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-weight: 700;
  font-size: 13px; color: #fff; flex: none; }
.gi-text { min-width: 0; flex: 1; }
.gi-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gi-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 6px; align-items: center; }
.side-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 4px; }
.user-btn .badge { height: 18px; font-size: 11px; background: var(--surface-2); color: var(--text-2); }
.user-btn .badge.accent { background: var(--accent-soft); color: var(--accent-text); }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.users-t td { vertical-align: middle; }
.users-t .acts { text-align: right; white-space: nowrap; }

.main { overflow: auto; min-width: 0; position: relative; }
.page { max-width: 1120px; margin: 0 auto; padding: 24px 28px 120px; }
.page-h { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.page-h .avatar { width: 44px; height: 44px; font-size: 17px; border-radius: 11px; }
.page-h h1 { margin: 0; font-size: 21px; line-height: 1.2; }
.page-h .meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 13px; color: var(--text-2); }
.chip { font-family: var(--mono); font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); cursor: pointer; }
.chip:hover { border-color: var(--border-strong); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto;
  overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 9px 12px; border: 0; background: none; cursor: pointer; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; gap: 6px; align-items: center;
  white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { font-size: 11.5px; color: var(--text-3); font-weight: 600; }
.tab .mod { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }

/* ---------- stats */
.stat { padding: 14px 16px; }
.stat .label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .delta { font-size: 12px; color: var(--text-3); }
.chart { width: 100%; height: 180px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar2 { fill: var(--ok); }
.chart .axis { fill: var(--text-3); font-size: 10px; }
.chart .grid { stroke: var(--border); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.checklist { display: flex; flex-direction: column; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.check:last-child { border-bottom: 0; }
.check .ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.check .ic svg { width: 13px; height: 13px; stroke-width: 3; }
.check .ic.ok { background: var(--ok-soft); color: var(--ok); }
.check .ic.warn { background: var(--warn-soft); color: var(--warn); }
.check .t { flex: 1; }
.check .t small { display: block; color: var(--text-3); font-size: 12px; }

.endpoint { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); }
.endpoint .method { font-family: var(--mono); font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px;
  background: var(--ok-soft); color: var(--ok); }
.endpoint .method.post { background: var(--inters-soft); color: var(--inters); }
.endpoint code { font-family: var(--mono); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
pre.code { margin: 0; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; overflow: auto; max-height: 420px; line-height: 1.55; }

/* ---------- tables */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap; }
.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
  color: var(--text-2); font-weight: 500; display: flex; gap: 5px; align-items: center; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button .n { font-size: 11.5px; color: var(--text-3); }
.tsearch { position: relative; width: 220px; }
.tsearch svg { position: absolute; left: 9px; top: 8px; color: var(--text-3); width: 14px; height: 14px; }
.tsearch .input { height: 30px; padding-left: 28px; font-size: 13px; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 9px 10px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
table.t th:first-child, table.t td:first-child { padding-left: 16px; }
table.t th:last-child, table.t td:last-child { padding-right: 16px; }
table.t td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.group td { background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-2); padding-top: 7px;
  padding-bottom: 7px; }
table.t tr.changed td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.t .input { height: 30px; font-size: 13px; }
table.t .input.mono { font-size: 12.5px; }
table.t td.act { width: 1%; white-space: nowrap; text-align: right; }
.empty-row td { text-align: center; padding: 28px !important; color: var(--text-3); }
.table-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.type-sel { width: 118px; }

/* ---------- save bar */
.savebar { position: fixed; left: calc(50% + 132px); transform: translate(-50%, 20px); bottom: 20px; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 12px; background: var(--text);
  color: var(--bg); box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  width: min(720px, calc(100vw - 264px - 40px)); }
.savebar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.savebar .msg { font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.savebar .msg .dot { background: var(--warn); }
.savebar input { flex: 1; min-width: 80px; height: 32px; border-radius: 8px; border: 1px solid transparent; padding: 0 10px;
  background: color-mix(in srgb, var(--bg) 14%, transparent); color: var(--bg); outline: none; }
.savebar input::placeholder { color: color-mix(in srgb, var(--bg) 55%, transparent); }
.savebar .btn.ghost { color: var(--bg); }
.savebar .btn.ghost:hover { background: color-mix(in srgb, var(--bg) 14%, transparent); }
.savebar kbd { font-family: var(--mono); font-size: 11px; opacity: .7; margin-left: 2px; }

/* ---------- modal / drawer */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 40; display: grid; place-items: center;
  padding: 20px; animation: fade .12s; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow: auto; animation: pop .14s; }
.modal.wide { max-width: 760px; }
.modal.xl { max-width: 1040px; height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; }
.modal.xl .card-h .seg { margin-right: 6px; }
.save-b { flex: 1; min-height: 0; overflow: auto; }
.save-b.editing { overflow: hidden; }
.save-keys { display: flex; flex-direction: column; gap: 8px; }
.save-key { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.save-key summary { display: flex; gap: 10px; align-items: center; padding: 8px 12px; cursor: pointer; font-weight: 600;
  list-style: none; }
.save-key summary::-webkit-details-marker { display: none; }
.save-key summary::before { content: '▸'; color: var(--text-3); transition: transform .12s; }
.save-key[open] summary::before { transform: rotate(90deg); }
.save-key summary .muted { margin-left: auto; font-weight: 400; font-size: 12px; }
.save-key pre.code { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; max-height: none; }
.j-key { color: var(--accent-text); }
.j-str { color: var(--ok); }
.j-num { color: var(--inters); }
.j-lit { color: var(--warn); }
.editor { flex: 1; min-height: 240px; display: flex; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2); overflow: hidden; }
.editor .gutter { margin: 0; padding: 10px 8px 10px 10px; text-align: right; color: var(--text-3); user-select: none;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; overflow: hidden; border-right: 1px solid var(--border);
  min-width: 44px; }
.editor .gutter b { color: var(--danger); }
.editor textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.55; white-space: pre; overflow: auto; tab-size: 2; }
.err-text { color: var(--danger); font-size: 12.5px; }
.ok-text { color: var(--ok); font-size: 12.5px; }
.modal-f .grow { flex: 1; align-self: center; font-size: 12px; }
.modal-f kbd { font-family: var(--mono); font-size: 11px; padding: 0 4px; border: 1px solid var(--border); border-radius: 4px; }
.modal .card-b { display: flex; flex-direction: column; gap: 14px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.drawer-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 16, .35); animation: fade .12s; }
.drawer { position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slide .16s; }
.drawer-b { flex: 1; overflow: auto; }
.hist { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.hist:hover { background: var(--surface-2); }
.hist.active { background: var(--accent-soft); }
.hist .v { font-family: var(--mono); font-weight: 600; font-size: 12.5px; width: 44px; flex: none; }
.hist .when { font-size: 12px; color: var(--text-3); }
.diff { font-family: var(--mono); font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.diff .add { color: var(--ok); } .diff .del { color: var(--danger); } .diff .chg { color: var(--warn); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }

#toasts { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .14s; max-width: 380px; }
.toast.ok svg { color: var(--ok); } .toast.err svg { color: var(--danger); }

.empty { text-align: center; padding: 64px 20px; }
.empty .big { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 16px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); }
.empty .big svg { width: 26px; height: 26px; }
.empty h2 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 0 18px; color: var(--text-2); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.secret-state { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 13px; }
.skeleton { height: 14px; border-radius: 6px; background: var(--surface-2); }
.pager { display: flex; align-items: center; gap: 8px; }
.copyable { cursor: pointer; }
.copyable:hover { color: var(--accent-text); }

.menu-btn { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 30; transform: translateX(-100%); transition: transform .18s;
    box-shadow: var(--shadow-lg); }
  .shell.nav-open .side { transform: none; }
  .menu-btn { display: inline-flex; }
  .page { padding: 16px 16px 120px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .savebar { left: 50%; width: calc(100vw - 24px); }
  .savebar input { display: none; }
  .tsearch { width: 100%; }
  .hide-sm { display: none; }
}
