:root {
  --frame: #fafafa; --canvas: #f4f4f5; --surface: #fff; --surface-muted: #f7f7f8;
  --line: #e4e4e7; --line-strong: #d4d4d8; --ink: #18181b; --on-ink: #fff;
  --text: #18181b; --muted: #71717a; --accent: #2563eb;
  --ok-fg: #15803d; --ok-bg: #f0fdf4; --warn-fg: #b45309; --warn-bg: #fffbeb;
  --bad-fg: #be123c; --bad-bg: #fff1f2; --info-fg: #0369a1; --info-bg: #f0f9ff;
  --neu-fg: #52525b; --neu-bg: #f4f4f5;
  --shadow-1: 0 1px 2px rgb(16 24 40 / .04), 0 1px 3px rgb(16 24 40 / .06);
  --shadow-2: 0 1px 2px rgb(16 24 40 / .06), 0 2px 6px rgb(16 24 40 / .06);
  --shadow-4: 0 24px 48px -12px rgb(16 24 40 / .22);
  --card-border: transparent;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --frame: #0c0c0e; --canvas: #121215; --surface: #18181c; --surface-muted: #1f1f24;
    --line: #2a2a30; --line-strong: #3a3a42; --ink: #fafafa; --on-ink: #18181b;
    --text: #fafafa; --muted: #a1a1aa; --accent: #60a5fa;
    --ok-fg: #86efac; --ok-bg: #14532d66; --warn-fg: #fcd34d; --warn-bg: #78350f66;
    --bad-fg: #fda4af; --bad-bg: #88133766; --info-fg: #7dd3fc; --info-bg: #0c4a6e66;
    --neu-fg: #d4d4d8; --neu-bg: #27272a;
    --shadow-1: none; --shadow-2: none; --shadow-4: 0 24px 48px rgb(0 0 0 / .5);
    --card-border: var(--line);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--frame); color: var(--text);
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.num, td.n, .metric-value { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--on-ink); padding: 8px 12px; border-radius: 10px; z-index: 50; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; }

/* ---------- shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 264px; flex: none; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 6px 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; }
.brand-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.nav-label { font-size: 12px; font-weight: 500; color: var(--muted); padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 6px; border-radius: 14px; color: var(--text); text-decoration: none; font-weight: 500; transition: background .12s var(--ease); }
.nav a .ib { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); transition: border-color .12s var(--ease); }
.nav a:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.nav a:hover .ib { border-color: var(--line-strong); }
.nav a[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow-2); font-weight: 600; }
.nav a[aria-current="page"] .ib { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 999px; background: var(--neu-bg); color: var(--neu-fg); display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.side-foot .who { flex: 1; min-width: 0; line-height: 1.25; }
.side-foot .who b { display: block; font-size: 13px; }
.side-foot .who span { font-size: 12px; color: var(--muted); }

.inset { flex: 1; min-width: 0; margin: 8px 8px 8px 0; background: var(--canvas); border-radius: 20px; box-shadow: var(--shadow-1); outline: 1px solid color-mix(in srgb, var(--line-strong) 50%, transparent); display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--canvas); border-radius: 20px 20px 0 0; border-bottom: 1px solid transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.crumb { font-size: 14px; color: var(--muted); }
.crumb b { color: var(--text); font-weight: 600; }
.spacer { flex: 1; }
.menu-btn { display: none; }
main { padding: 8px 28px 40px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin: 8px 0 24px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.625rem, 2.6vw, 2.25rem); line-height: 1.15; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .grow { flex: 1; min-width: 220px; }

/* ---------- cards & grid */
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-1); border: 1px solid var(--card-border); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 12px; }
.card-head h2 { font-size: 16px; font-weight: 600; letter-spacing: -.005em; margin: 0; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.card-head .grow { flex: 1; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric { padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; }
.metric-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 500; color: var(--muted); }
.metric-top .ib { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-muted); display: grid; place-items: center; color: var(--muted); }
.metric-top .ib.strong { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.metric-value { font-size: 28px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-ctx { font-size: 13px; color: var(--muted); }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 24px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 24px; }
.mt24 { margin-top: 24px; }

/* ---------- badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.b-ok { color: var(--ok-fg); background: var(--ok-bg); }
.b-warn { color: var(--warn-fg); background: var(--warn-bg); }
.b-bad { color: var(--bad-fg); background: var(--bad-bg); }
.b-info { color: var(--info-fg); background: var(--info-bg); }
.b-neu { color: var(--neu-fg); background: var(--neu-bg); }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .12s var(--ease), border-color .12s var(--ease); }
.btn:hover { border-color: var(--line-strong); background: color-mix(in srgb, var(--text) 4%, var(--surface)); }
.btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 88%, var(--surface)); }
.btn.danger { background: var(--bad-fg); color: #fff; border-color: var(--bad-fg); }
.btn.danger-outline { color: var(--bad-fg); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 34px; height: 34px; padding: 0; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .38; cursor: not-allowed; }
.btn .spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 999px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.input, select.input { height: 40px; width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); transition: border-color .12s var(--ease); }
.input:hover { border-color: var(--line-strong); }
.input:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: var(--line-strong); }
.input.narrow { width: 110px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .lbl { font-size: 13px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.err { font-size: 13px; color: var(--bad-fg); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .input { flex: 1; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .01em; background: var(--surface-muted); padding: 10px 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.n, td.n { text-align: right; }
td .name { font-weight: 600; }
td .sub { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.ping-good { color: var(--ok-fg); font-weight: 600; }
.ping-mid { color: var(--warn-fg); font-weight: 600; }
.ping-bad { color: var(--bad-fg); font-weight: 600; }

/* ---------- lists / rows */
.qa { list-style: none; margin: 0; padding: 0 8px 8px; }
.qa li + li { border-top: 1px solid var(--line); }
.qa-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; background: none; border: 0; border-radius: 12px; cursor: pointer; }
.qa-row:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.qa-row .ib { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--info-bg); color: var(--accent); flex: none; }
.qa-row .t { flex: 1; min-width: 0; }
.qa-row .t b { display: block; font-weight: 600; }
.qa-row .t span { font-size: 13px; color: var(--muted); }
.qa-form { padding: 4px 22px 20px; display: flex; flex-direction: column; gap: 12px; }
.section { padding: 22px; }
.section + .section { border-top: 1px solid var(--line); }
.section h3 { margin: 0; font-size: 16px; font-weight: 600; }
.section > p.hint { margin: 2px 0 16px; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px 0; }
.setrow + .setrow { border-top: 1px solid var(--line); }
.setrow .t { flex: 1; min-width: 0; }
.setrow .t b { display: block; font-weight: 600; }
.setrow .t span { font-size: 13px; color: var(--muted); }
.setrow .ctl { width: 300px; max-width: 50%; flex: none; display: flex; justify-content: flex-end; }

/* switch */
.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background .12s var(--ease); pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .2); transition: transform .12s var(--ease); }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--on-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

/* game type choice */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.choice { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; background: var(--surface); }
.choice:hover { border-color: var(--line-strong); }
.choice input { position: absolute; opacity: 0; }
.choice b { font-weight: 600; }
.choice span { font-size: 13px; color: var(--muted); }
.choice:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

/* map rotation */
.maprow { display: flex; align-items: center; gap: 12px; padding: 10px 22px; border-top: 1px solid var(--line); }
.maprow.off { opacity: .6; }
.maprow .pos { width: 28px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.maprow .t { flex: 1; min-width: 0; }
.maprow .t b { font-weight: 600; }
.maprow .t span { display: block; font-size: 12px; color: var(--muted); }
.maprow input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ink); }

/* sticky action bar */
.actionbar { position: sticky; bottom: 0; margin-top: 24px; padding: 12px 16px; display: flex; align-items: center; gap: 16px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-2); border: 1px solid var(--card-border); flex-wrap: wrap; }
.actionbar .spacer { min-width: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.dirty { font-size: 13px; color: var(--warn-fg); font-weight: 600; }

/* log */
.tabs { display: flex; gap: 4px; padding: 0 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 12px; border: 0; background: none; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--ink); }
.log { list-style: none; margin: 0; padding: 4px 0; max-height: 65vh; overflow-y: auto; }
.log li { display: flex; gap: 12px; align-items: baseline; padding: 8px 22px; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log time { width: 52px; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.log .badge { flex: none; width: 92px; justify-content: flex-start; }
.log .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.console-out { margin: 0; padding: 16px 22px; background: var(--surface-muted); border-top: 1px solid var(--line); min-height: 220px; max-height: 55vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; border-radius: 0 0 16px 16px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 500; cursor: pointer; }
.chip:hover { border-color: var(--line-strong); }

/* empty / notice / skeleton */
.empty { padding: 36px 22px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-fg); }
.notice.bad { background: var(--bad-bg); color: var(--bad-fg); }
.notice.info { background: var(--info-bg); color: var(--info-fg); }
.skel { background: linear-gradient(90deg, var(--surface-muted), var(--line), var(--surface-muted)); background-size: 200% 100%; animation: sk 1.2s ease-in-out infinite; border-radius: 8px; height: 14px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.connect { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.connect code { padding: 6px 10px; background: var(--surface-muted); border-radius: 8px; border: 1px solid var(--line); }

/* dialog */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-4); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(9 9 11 / .4); backdrop-filter: blur(2px); }
.dlg { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--bad-bg); color: var(--bad-fg); }
.dlg .ico.warn { background: var(--warn-bg); color: var(--warn-fg); }
.dlg h2 { margin: 0; font-size: 18px; font-weight: 700; }
.dlg p { margin: 0; color: var(--muted); }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(480px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--on-ink); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-4); font-weight: 500; display: flex; gap: 10px; align-items: center; animation: tin .2s var(--ease); }
.toast.bad { background: var(--bad-fg); color: #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--canvas); padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.auth p { margin: 0; color: var(--muted); }

/* responsive */
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; background: var(--frame); transform: translateX(-100%); transition: transform .3s var(--ease); box-shadow: var(--shadow-4); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .inset { margin: 0; border-radius: 0; outline: 0; }
  .topbar { border-radius: 0; padding: 0 16px; }
  main { padding: 8px 16px 32px; }
  .setrow { flex-direction: column; align-items: stretch; gap: 10px; }
  .setrow .ctl { width: 100%; max-width: none; justify-content: flex-start; }
  .hide-sm { display: none; }
  td, th { padding: 10px 12px; }
  .log .badge { width: auto; }
}
.scrim { position: fixed; inset: 0; background: rgb(9 9 11 / .4); z-index: 25; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
