:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e2e6f0;
  --text: #172036;
  --muted: #64708a;
  --accent: #3e63dd;
  --accent-ink: #ffffff;
  --good: #1f8a55;
  --good-bg: #e3f5ec;
  --warn: #a35f00;
  --warn-bg: #fff3d6;
  --bad: #c62a2f;
  --bad-bg: #fde8e8;
  --info-bg: #e8eefe;
  --side: #121a33;
  --side-text: #c4cbe0;
  --side-active: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 48, .06), 0 2px 8px rgba(16, 24, 48, .04);
  --c-red: #e5484d;
  --c-green: #30a46c;
  --c-yellow: #e9a800;
  --c-blue: #3e63dd;
  --chart-1: #3e63dd;
  --chart-2: #b7c5f5;
  --chart-3: #30a46c;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1222; --surface: #161d33; --surface-2: #1d2540; --border: #283152; --text: #e6e9f3; --muted: #95a0bd;
    --accent: #6e8ff0; --good: #4cc38a; --good-bg: #133326; --warn: #f1b43a; --warn-bg: #3a2c0d; --bad: #ff6b6f; --bad-bg: #3d1719;
    --info-bg: #1c2850; --side: #0a0f1d; --chart-1: #6e8ff0; --chart-2: #34406a; --chart-3: #4cc38a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1222; --surface: #161d33; --surface-2: #1d2540; --border: #283152; --text: #e6e9f3; --muted: #95a0bd;
  --accent: #6e8ff0; --good: #4cc38a; --good-bg: #133326; --warn: #f1b43a; --warn-bg: #3a2c0d; --bad: #ff6b6f; --bad-bg: #3d1719;
  --info-bg: #1c2850; --side: #0a0f1d; --chart-1: #6e8ff0; --chart-2: #34406a; --chart-3: #4cc38a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login h1 { font-size: 18px; margin: 0; }
.login label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 20px; justify-content: center; padding: 10px; }
.error-text { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 650; }
.logo { width: 28px; height: 28px; flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); }
.nav a.active { background: rgba(110, 143, 240, .22); color: var(--side-active); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge-live { margin-left: auto; background: var(--c-green); color: #fff; font-size: 11px; padding: 0 7px; border-radius: 10px; font-weight: 600; }
.side .foot { margin-top: auto; padding: 8px; font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.side .foot button { background: transparent; border: 1px solid rgba(255, 255, 255, .15); color: var(--side-text); border-radius: 8px; padding: 7px 10px; cursor: pointer; text-align: left; }
.side .foot button:hover { background: rgba(255, 255, 255, .06); }

.main { min-width: 0; padding: 22px 28px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.page-head .spacer { flex: 1; }
.updated { font-size: 12px; color: var(--muted); }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card h3 { font-size: 14px; margin: 0 0 12px; font-weight: 600; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.drawer .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.half { grid-template-columns: 1fr 1fr; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--c-green); box-shadow: 0 0 0 0 rgba(48, 164, 108, .6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(48, 164, 108, 0); } 100% { box-shadow: 0 0 0 0 rgba(48, 164, 108, 0); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 200px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.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); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.good { color: var(--good); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { flex: 1 1 220px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
th.r, td.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--accent); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.red { background: var(--c-red); } .dot.green { background: var(--c-green); } .dot.yellow { background: var(--c-yellow); } .dot.blue { background: var(--c-blue); }
.who { display: inline-flex; align-items: center; gap: 6px; }
.players-cell { display: flex; flex-direction: column; gap: 2px; }
.crown { color: var(--c-yellow); }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }

/* live rooms */
.rooms { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.room { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.room-top { display: flex; align-items: center; gap: 8px; }
.room-code { font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; }
.room-top .spacer { flex: 1; }
.room-players { display: flex; flex-direction: column; gap: 6px; }
.rp { display: flex; align-items: center; gap: 8px; }
.rp .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp.turn .name { font-weight: 650; }
.pips { display: inline-flex; gap: 3px; }
.pip { width: 8px; height: 8px; border-radius: 2px; background: var(--surface-2); border: 1px solid var(--border); }
.pip.on { background: var(--good); border-color: var(--good); }
.room-foot { display: flex; gap: 10px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.room-foot .spacer { flex: 1; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 12, 24, .5); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: min(720px, 100%); height: 100%; background: var(--bg); overflow-y: auto; box-shadow: -8px 0 30px rgba(0, 0, 0, .2); }
.drawer-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 18px; display: flex; align-items: center; gap: 10px; z-index: 1; }
.drawer-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 14px; }
.close { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.close:hover { background: var(--surface-2); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row input[type=text] { flex: 1 1 180px; }
pre.json { background: var(--surface-2); border-radius: 8px; padding: 12px; overflow: auto; max-height: 360px; font-size: 12px; margin: 0; }
details summary { cursor: pointer; color: var(--muted); }
.logs { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); }
.health { display: flex; align-items: center; gap: 10px; }
.health .big { width: 12px; height: 12px; border-radius: 50%; }
.health .big.ok { background: var(--good); } .health .big.down { background: var(--bad); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; font-weight: 500; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
.toast.err { background: var(--bad); color: #fff; }
.note { background: var(--info-bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.mobile-bar { display: none; }

@media (max-width: 1000px) {
  .two, .half { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 0 30% 0 0; z-index: 60; height: 100%; }
  .side.open { display: flex; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; background: var(--side); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 40; font-weight: 650; }
  .mobile-bar button { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 0 4px; }
  .main { padding: 16px 16px 40px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .kpi .value { font-size: 22px; }
  th, td { padding: 8px 10px; }
  .hide-sm { display: none; }
}
