:root {
  --bg: #0b0c10;
  --panel: #14161d;
  --panel-2: #1a1d26;
  --border: #262a36;
  --text: #e6e8ee;
  --muted: #8b91a3;
  --accent: #e0533b;
  --accent-soft: rgba(224, 83, 59, 0.18);
  --good: #4ade80;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header h1::before {
  content: "♥ ";
  color: var(--accent);
  margin-right: 4px;
}

.auth-status {
  font-size: 12px;
  color: var(--muted);
}

.auth-status .pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  margin-left: 6px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hidden { display: none; }

form label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

form label small { color: var(--muted); opacity: 0.7; }

form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

form button {
  padding: 8px 14px;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

form button:hover { filter: brightness(1.1); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.live-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-card.stale {
  opacity: 0.6;
}

.live-card .user {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.live-card .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 var(--good);
  animation: pulse 1.6s infinite;
}

.live-card.stale .dot { background: var(--muted); animation: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  100% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
}

.live-card .bpm {
  font-size: 42px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.live-card .bpm small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }

.live-card .zone {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}

.live-card canvas {
  height: 60px !important;
  width: 100% !important;
}

.steam-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  min-height: 32px;
}

.steam-row img.avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--panel);
  flex-shrink: 0;
}

.steam-row .steam-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.steam-row .persona {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.steam-row .state {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.steam-row.in-game .state { color: var(--good); }
.steam-row.online .state  { color: #60a5fa; }
.steam-row.away .state    { color: var(--warn); }
.steam-row.offline .state { color: var(--muted); }

.steam-row.empty,
.discord-row.empty,
.vrchat-row.empty { display: none; }

/* Discord & VRChat rows share the steam-row layout via these aliases */
.discord-row,
.vrchat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  margin-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--muted);
  min-height: 28px;
}

.discord-row .badge,
.vrchat-row .badge {
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  font-size: 14px;
}

.discord-row .info,
.vrchat-row .info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.discord-row .label,
.vrchat-row .label {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.discord-row .detail,
.vrchat-row .detail {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.discord-row.online .label  { color: var(--good); }
.discord-row.idle .label    { color: var(--warn); }
.discord-row.dnd .label     { color: var(--accent); }
.discord-row.offline .label { color: var(--muted); }

.vrchat-row.active .label    { color: #f97316; }
.vrchat-row.join-me .label   { color: var(--good); }
.vrchat-row.ask-me .label    { color: #60a5fa; }
.vrchat-row.busy .label      { color: var(--accent); }
.vrchat-row.offline .label   { color: var(--muted); }

.table-wrap {
  margin: 0 -20px;
  padding: 0 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 8px 0;
}

@media (max-width: 640px) {
  header { padding: 14px 16px; }
  main { padding: 14px; gap: 14px; }
  .card { padding: 14px 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .grid { gap: 10px; }
  .live-card { padding: 12px 14px; }
  .live-card .bpm { font-size: 36px; }
}

/* User-roster table */
#users-table td.actions {
  text-align: right;
  white-space: nowrap;
}
#users-table td.actions button {
  margin-left: 6px;
}

.btn-primary, .btn-secondary, .btn-danger {
  padding: 7px 14px;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  font-size: 12px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-danger:hover { background: var(--accent-soft); }

#add-user-btn { margin-top: 14px; }

/* Modal */
.modal-root {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-root.hidden { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 460px;
}
.modal h3 {
  margin: 0 0 16px;
  font-size: 15px;
}
.modal label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}
.modal label small { display: block; color: var(--muted); opacity: 0.7; margin-top: 2px; }
.modal input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.modal .error {
  color: var(--accent);
  font-size: 12px;
  margin-bottom: 10px;
}
.modal .token-display {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin: 10px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  word-break: break-all;
  color: var(--good);
}
