*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --checked: #22c55e;
  --unchecked: #1e293b;
  --cb-border: #475569;
  --header-h: 56px;
  --status-h: 32px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  flex-shrink: 0;
  z-index: 10;
}

.header-left h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}
.header-left h1 span { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .82rem;
  color: var(--text-muted);
}

.header-right strong { color: var(--text); }

#user-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: .2rem .65rem;
  font-size: .78rem;
  font-weight: 600;
}

.btn-sm {
  padding: .3rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
}
.btn-sm:hover { background: var(--border); color: var(--text); }

/* ── Grid area ──────────────────────────────────────────────────────────── */
#grid-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Scroll container — provides the native scrollbar */
#scroll-layer {
  position: absolute;
  inset: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  z-index: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#scroll-layer::-webkit-scrollbar { width: 8px; }
#scroll-layer::-webkit-scrollbar-track { background: transparent; }
#scroll-layer::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Phantom element gives the scrollbar its full height */
#phantom { width: 1px; pointer-events: none; }

/* Canvas sits on top of the phantom, rendered by JS */
#grid-canvas {
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
  display: block;
  pointer-events: none; /* clicks handled by scroll-layer */
}

/* ── Status bar ─────────────────────────────────────────────────────────── */
#status-bar {
  height: var(--status-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  font-size: .78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

#conn-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #ef4444;
  margin-right: 5px;
  vertical-align: middle;
  transition: background .3s;
}
#conn-dot.connected { background: var(--checked); }

#rate-msg {
  color: #f59e0b;
  font-weight: 600;
  opacity: 0;
  transition: opacity .3s;
}
#rate-msg.visible { opacity: 1; }

/* ── Login overlay (anonymous users) ───────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 380px;
  width: 90%;
}
.login-card h2 { font-size: 1.4rem; margin-bottom: .5rem; }
.login-card p  { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .9rem; line-height: 1.5; }

.btn-login {
  display: inline-block;
  padding: .7rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s;
}
.btn-login:hover { background: var(--accent-hover); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header { padding: 0 .75rem; }
  .header-right { gap: .5rem; font-size: .75rem; }
  #checked-count { display: none; }
}
