:root {
  --bg: #14151a;
  --bg-raise: #1d1f27;
  --bg-raise-2: #262935;
  --line: #32353f;
  --text: #e7e9ee;
  --muted: #9aa0ac;
  --accent: #9b59b6;
  --ok: #3fbb5a;
  --warn: #e0a82e;
  --bad: #e0574b;

  --cat-hud: #ff5e5e;
  --cat-kb: #4caf50;
  --cat-mb: #2196f3;
  --cat-snd: #ffc107;
  --cat-js: #8b0000;
  --cat-bo: #555a66;
  --cat-db: #c9a227;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
}

body.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

a { color: var(--accent); }

/* ---- top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-raise);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand .logo { font-size: 18px; }
.brand .title { letter-spacing: 0.2px; }
.controls { display: flex; align-items: center; gap: 14px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.field select {
  background: var(--bg-raise-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  max-width: 220px;
}
.icon-btn, .text-btn {
  background: var(--bg-raise-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.icon-btn { width: 32px; height: 32px; font-size: 16px; }
.text-btn { padding: 6px 12px; font-size: 13px; }
.icon-btn:hover, .text-btn:hover { background: var(--line); }

/* ---- status chips ---- */
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status.up   .dot { background: var(--ok);  box-shadow: 0 0 6px var(--ok); }
.status.warn .dot { background: var(--warn); }
.status.bad  .dot { background: var(--bad); }
.raid-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 999px;
}
.raid-badge.in-raid { color: #fff; background: var(--cat-js); border-color: var(--cat-js); }

/* ---- main layout: grid + side feed ---- */
.body-split { flex: 1; display: flex; min-height: 0; }
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---- game cover banner ---- */
.banner {
  height: 0;
  background-size: cover;
  background-position: center;
  transition: height 0.2s ease;
  position: relative;
  flex: none;
}
.banner.show { height: 96px; }
.banner::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,21,26,0.15), rgba(20,21,26,0.9));
}

/* ---- tabs ---- */
.tabs { display: flex; gap: 6px; padding: 10px 16px 0; flex: none; flex-wrap: wrap; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; gap: 7px;
}
.tab .swatch { width: 9px; height: 9px; border-radius: 2px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--bg-raise); border-color: var(--line); }
.tab .n { color: var(--muted); font-size: 11px; }
.tab.locked { opacity: 0.5; }

/* ---- search ---- */
.searchrow {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg-raise);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  flex: none;
}
#search {
  flex: 1;
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
}
.count { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---- grid ---- */
.grid {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
}
.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-raise);
  overflow: hidden;
  cursor: pointer;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  text-align: left;
  transition: transform 0.06s ease, border-color 0.15s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card:active { transform: translateY(0) scale(0.98); }
.card[disabled] { opacity: 0.4; cursor: not-allowed; }
.card[disabled]:hover { border-color: var(--line); transform: none; }
.card .tint { position: absolute; inset: 0; opacity: 0.9; }
.card .label {
  position: relative;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  line-height: 1.25;
}
.card .catpill {
  position: relative;
  align-self: flex-start;
  margin: 8px 0 0 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.35);
  padding: 2px 6px;
  border-radius: 4px;
}
.card.firing { outline: 2px solid var(--ok); }
.card.fire-err { outline: 2px solid var(--bad); }
.empty { color: var(--muted); padding: 30px; grid-column: 1 / -1; text-align: center; }

/* ---- DebtBound setup tab ---- */
/* Span the whole effect grid (otherwise it's squeezed into one card column). */
.debt-config { grid-column: 1 / -1; max-width: 640px; }
.debt-intro { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.debt-row {
  display: grid;
  grid-template-columns: 140px 120px auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raise);
  margin-bottom: 8px;
}
.debt-ev { font-weight: 600; white-space: nowrap; }
.debt-row select, .debt-amt input {
  background: var(--bg-raise-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 13px;
}
.debt-amt { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.debt-amt input { width: 90px; }
.debt-enabled { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.debt-row input:disabled, .debt-row select:disabled { opacity: 0.6; }
.debt-actions { margin-top: 14px; }
/* DebtBound account/contract binding */
.debt-binding {
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-raise);
  padding: 14px; margin-bottom: 18px;
}
.debt-bind-h { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.debt-link-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.debt-token { flex: 1; min-width: 220px; background: var(--bg-raise-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.debt-contract-sel { flex: 1; min-width: 220px; background: var(--bg-raise-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.debt-hint { display: block; color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ---- activity feed ---- */
.feed {
  width: 300px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--bg-raise);
  display: flex;
  flex-direction: column;
}
.feed h3 { margin: 0; padding: 12px 14px; font-size: 13px; border-bottom: 1px solid var(--line); color: var(--muted); }
.feed-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.feed-item {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(50,53,63,0.4);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.feed-item .who { color: var(--text); font-weight: 600; }
.feed-item .what { color: var(--muted); }
.feed-item.err .what { color: var(--bad); }
.feed-item.evt .who { color: var(--cat-mb); }
.feed-item time { color: var(--muted); font-size: 10px; }
@media (max-width: 760px) { .feed { display: none; } }

/* ---- debt ledger ---- */
.ledger { border-bottom: 1px solid var(--line); }
.ledger.hidden { display: none; }
.ledger h3 { margin: 0; padding: 12px 14px 6px; font-size: 13px; color: var(--muted); }
.ledger-totals { padding: 0 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.lt-net { font-size: 22px; font-weight: 700; }
.lt-net.owed { color: var(--bad); }
.lt-net.credit { color: var(--ok); }
.lt-sub { font-size: 11px; color: var(--muted); }
.penalty { color: var(--bad); }
.reward { color: var(--ok); }
.ledger-list { max-height: 160px; overflow-y: auto; }
.ledger-item {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 14px; font-size: 12px; border-bottom: 1px solid rgba(50,53,63,0.4);
}
.ledger-item .ev { color: var(--text); }
.ledger-item .amt { font-weight: 600; }
.ledger-item time { color: var(--muted); font-size: 10px; margin-left: 8px; }

/* ---- modal ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  width: 440px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.form-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-field > span { font-size: 12px; color: var(--muted); }
.form-field input, .form-field select {
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}
.form-field small { color: var(--muted); font-size: 11px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }
.primary-btn, .ghost-btn, .danger-btn {
  border-radius: 7px; padding: 8px 14px; font-size: 13px; cursor: pointer; border: 1px solid var(--line);
}
.primary-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary-btn:hover { filter: brightness(1.1); }
.ghost-btn { background: var(--bg-raise-2); color: var(--text); }
.ghost-btn:hover { background: var(--line); }
.danger-btn { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 80vw;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  z-index: 60;
}
.toast.hidden { display: none; }
.toast.err { border-left-color: var(--bad); }

/* ---- login page ---- */
body.login-page {
  display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0;
}
.login-card {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  width: 360px; max-width: 92vw;
}
.login-card .logo { font-size: 32px; text-align: center; }
.login-card h1 { font-size: 20px; margin: 8px 0 24px; text-align: center; }
.login-card .form-field { margin-bottom: 16px; }
.login-card .primary-btn { width: 100%; padding: 11px; }
.login-error { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 8px; text-align: center; }

/* ---- admin tables ---- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; overflow-y: auto; flex: 1; }
.admin-wrap section { margin-bottom: 36px; }
.admin-wrap h2 { font-size: 16px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td .pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg-raise-2); border: 1px solid var(--line); }
.row-actions { display: flex; gap: 6px; }
.token-reveal {
  background: var(--bg-raise-2); border: 1px solid var(--accent); border-radius: 8px;
  padding: 12px; margin: 10px 0; font-family: monospace; font-size: 13px; word-break: break-all;
}
.muted { color: var(--muted); }
