/* Dark theme, matching the existing desktop app's palette. */

:root {
  --bg: #0b0d12;
  --bg-panel: #12151c;
  --bg-panel-2: #181c25;
  --bg-hover: #1f2431;
  --border: #262c3a;
  --text: #e6e9ef;
  --text-dim: #98a0b3;
  --text-faint: #6b7488;
  --accent: #fe2c55;
  --accent-soft: rgba(254, 44, 85, 0.14);
  --accent-2: #25f4ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 10px;
  --radius-sm: 7px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 0 0 auto;
}

.brand-mark {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-faint);
}

.connect-form {
  display: flex;
  gap: 8px;
  flex: 1 1 420px;
  min-width: 280px;
}

#handle-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

#handle-input::placeholder { color: var(--text-faint); }
#handle-input:focus { border-color: var(--accent); }

.btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.chips {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-dim);
  white-space: nowrap;
}

.chip.is-ok { color: var(--ok); border-color: rgba(52, 211, 153, 0.35); }
.chip.is-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
.chip.is-err { color: var(--err); border-color: rgba(248, 113, 113, 0.35); }
.chip.is-live { color: var(--accent); border-color: rgba(254, 44, 85, 0.45); background: var(--accent-soft); }
.chip-demo { color: var(--accent-2); border-color: rgba(37, 244, 238, 0.4); }

/* ------------------------------------------------------------- banner */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  background: rgba(248, 113, 113, 0.12);
  border-bottom: 1px solid rgba(248, 113, 113, 0.3);
  color: #ffd7d7;
  font-size: 13px;
}

.banner.is-warn {
  background: rgba(251, 191, 36, 0.1);
  border-bottom-color: rgba(251, 191, 36, 0.3);
  color: #ffe9b8;
}

.banner-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
.banner-close:hover { opacity: 1; }

/* ------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
  flex: 1 1 auto;
  min-height: 0;
}

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stats-panel { order: -1; }
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--text-faint);
  font-weight: 700;
}

/* -------------------------------------------------------------- feed */

.feed-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* Checkbox filter bar: event types on the left, audience on the right. */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex: 0 0 auto;
}

/* The real checkbox stays in the a11y tree but invisible; the label is the chip. */
.check {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}

.check:hover { background: var(--bg-hover); color: var(--text); }

.check input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Checked = active chip; the leading tick makes state obvious without hover. */
.check:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(254, 44, 85, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.check:has(input:checked) span::before {
  content: '✓ ';
  font-size: 10.5px;
  opacity: 0.9;
}

.check:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Audience filters read as a distinct group. */
.check-aud:has(input:checked) {
  background: rgba(37, 244, 238, 0.12);
  border-color: rgba(37, 244, 238, 0.45);
  color: var(--accent-2);
}

.check-aud:has(input:focus-visible) { outline-color: var(--accent-2); }

.link-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11.5px;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 4px;
  flex: 0 0 auto;
}
.link-btn:hover { color: var(--text); }

.feed-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.feed-scroll::-webkit-scrollbar { width: 9px; }
.feed-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  animation: row-in 0.22s ease-out;
  word-break: break-word;
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.row:hover { background: var(--bg-panel-2); }
.row.is-hidden { display: none; }

.row-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--bg-hover);
  object-fit: cover;
  margin-top: 1px;
}

.row-body { flex: 1 1 auto; min-width: 0; }

.row-name {
  font-weight: 650;
  font-size: 12.5px;
  color: var(--accent-2);
}
.row-name::after { content: ':'; color: var(--text-faint); font-weight: 400; }

.row-text { color: var(--text); }

/* role badges: MOD / fan club level / star for subscriber */
.badge {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 1px;
  font-family: var(--mono);
  line-height: 15px;
}

.badge-mod {
  background: rgba(52, 211, 153, 0.18);
  color: var(--ok);
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.badge-fan {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.38);
}

.badge-sub {
  background: rgba(168, 85, 247, 0.16);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

/* Highlight rows from notable audience members. */
.row.is-mod { box-shadow: inset 2px 0 0 var(--ok); }
.row.is-fan { box-shadow: inset 2px 0 0 var(--warn); }
.row.is-sub { box-shadow: inset 2px 0 0 #a855f7; }

/* gift rows */
.row.kind-gift { background: rgba(254, 44, 85, 0.07); }
.row.kind-gift .gift-line {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.gift-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex: 0 0 auto;
}
.gift-name { color: var(--accent); font-weight: 650; }
.gift-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--warn);
  background: rgba(251, 191, 36, 0.12);
  padding: 1px 6px;
  border-radius: 5px;
}
.gift-diamonds {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

/* compact system-ish rows */
.row.is-compact {
  padding: 3px 9px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.row.is-compact .row-avatar { width: 16px; height: 16px; }
.row.is-compact .row-name { color: var(--text-dim); font-weight: 600; }

.kind-like .row-text { color: #ff8fab; }
.kind-join .row-text { color: var(--text-faint); }
.kind-follow .row-text { color: var(--ok); }
.kind-share .row-text { color: var(--accent-2); }
.kind-subscribe .row-text { color: var(--warn); font-weight: 600; }

.row.kind-system {
  justify-content: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  background: var(--bg-panel-2);
  border: 1px dashed var(--border);
  text-align: center;
}

.jump-latest {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--bg-panel-2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  z-index: 5;
}
.jump-latest:hover { background: var(--accent-soft); }

/* ------------------------------------------------------------- stats */

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 11px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tile-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}

.tile-value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tile-accent .tile-value { color: var(--accent); }

.leaderboards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.leaderboard h3 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-weight: 700;
}

.lb-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 5px 8px;
  background: var(--bg-panel-2);
  border-radius: var(--radius-sm);
}

.lb-rank {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  width: 12px;
  flex: 0 0 auto;
}

.lb-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-hover);
  object-fit: cover;
  flex: 0 0 auto;
}

.lb-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-value {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
  flex: 0 0 auto;
}

.lb-empty {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  padding: 3px 0;
}

.session-meta {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  word-break: break-all;
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
