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

:root {
  --bg:         #0d0d0f;
  --surface:    #16161a;
  --surface2:   #1e1e24;
  --border:     #2a2a32;
  --text:       #e0e0e8;
  --text-muted: #6b6b7e;
  --text-dim:   #9a9aaa;
  --accent:     #5c7cfa;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --green:  #2ecc71;
  --red:    #e74c3c;
  --yellow: #f1c40f;
  --gray:   #4a4a5a;

  --card-w: 58px;
  --card-h: 82px;
}

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.03em;
}

.header-session-id {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.back-link {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); }

.header-sep {
  color: var(--border);
  font-size: 14px;
}

.header-spacer { flex: 1; }

.user-info {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.logout-btn {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  transition: color 0.15s, border-color 0.15s;
}
.logout-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Connection dot */
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
  transition: background 0.3s;
}
.conn-dot.connected    { background: var(--green); }
.conn-dot.disconnected { background: var(--red); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Shared form elements ─────────────────────────────── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-hint {
  font-weight: 400;
  opacity: 0.6;
  text-transform: none;
}

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); opacity: 0.5; }

.form-input--inline {
  width: 300px;
}

.form-input--sm {
  padding: 6px 10px;
  font-size: 12px;
  width: 220px;
}

.form-error {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
  margin-top: 8px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-sm {
  padding: 5px 12px;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-sm:hover { color: var(--text); border-color: var(--text-dim); }

.btn-sm--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-sm--ghost:hover { color: var(--text-dim); border-color: transparent; }

/* ── Lobby ────────────────────────────────────────────── */
.lobby-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  gap: 28px;
}

.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 32px 36px;
  width: 100%;
  max-width: 420px;
}

.lobby-title {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.lobby-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.recent-note {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
}

.recent-note-dim {
  color: var(--text-muted);
  opacity: 0.5;
}

/* ── Guest overlay ────────────────────────────────────── */
.guest-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,13,15,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.guest-overlay[hidden] { display: none; }

.guest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 32px 36px;
  width: 100%;
  max-width: 360px;
}

.guest-title {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.guest-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

#guest-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Session UI shell ─────────────────────────────────── */
.session-ui {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-ui[hidden] { display: none; }

/* ── Topic area ───────────────────────────────────────── */
.topic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 0;
  gap: 10px;
  flex-shrink: 0;
}

.topic-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topic-label {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
  text-align: center;
}

.topic-label:empty::before {
  content: 'no topic set';
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.4;
  font-size: 13px;
}

.topic-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  transition: color 0.15s;
  line-height: 1;
}
.topic-edit-btn:hover { color: var(--text); }

.topic-edit-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topic-edit-form[hidden] { display: none; }

/* ── Vote table ───────────────────────────────────────── */
.vote-table-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 24px 16px;
  overflow: hidden;
}

.vote-table {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 16px;
  justify-content: center;
  align-items: flex-end;
  max-width: 900px;
}

/* Each participant's vote slot */
.vote-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s;
}

.vote-slot.offline { opacity: 0.35; }

/* The card face */
.vote-face {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  transition: border-color 0.2s, background 0.2s, color 0.2s, transform 0.25s;
  position: relative;
  overflow: hidden;
  user-select: none;
}

/* Not voted: empty dashed */
.vote-face--empty {
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
  color: transparent;
}

/* Voted, not revealed: face-down card */
.vote-face--down {
  border-color: var(--accent);
  background: rgba(92,124,250,.08);
  /* crosshatch pattern via CSS */
}
.vote-face--down::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 6px,
      rgba(92,124,250,.07) 6px,
      rgba(92,124,250,.07) 7px
    );
}

/* Revealed: show value */
.vote-face--revealed {
  border-color: var(--accent);
  background: rgba(92,124,250,.12);
  color: var(--text);
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(92,124,250,.18);
}

/* My own selected card in deck reflected up */
.vote-face--mine {
  border-color: rgba(92,124,250,.6);
  box-shadow: 0 0 0 1px rgba(92,124,250,.3);
}

/* Participant name below the card */
.vote-name {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
  max-width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.vote-badge {
  font-size: 9px;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.65;
}

/* ── Stats row ────────────────────────────────────────── */
.stats-row {
  display: flex;
  justify-content: center;
  padding: 0 24px 16px;
  flex-shrink: 0;
}

.stats-row[hidden] { display: none; }

.stats {
  display: flex;
  gap: 32px;
  align-items: flex-end;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat--avg .stat-value { color: var(--accent); }
.stat--avg .stat-value { font-size: 42px; }

/* ── Host controls ────────────────────────────────────── */
.host-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 24px 16px;
  flex-shrink: 0;
}

.host-controls[hidden] { display: none; }

.reset-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.reset-row[hidden] { display: none; }

/* ── Deck strip — pinned to bottom ────────────────────── */
.deck-strip {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  justify-content: center;
}

.card-deck {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 1200px;
}

.poker-card {
  width: var(--card-w);
  height: var(--card-h);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.12s, background 0.15s;
  user-select: none;
  flex-shrink: 0;
}
.poker-card:hover {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-5px);
}
.poker-card.selected {
  border-color: var(--accent);
  background: rgba(92,124,250,.15);
  color: #fff;
  transform: translateY(-10px);
  box-shadow: 0 4px 18px rgba(92,124,250,.25);
}

/* Locked during revealed state */
.card-deck.locked .poker-card {
  cursor: default;
  transform: none !important;
  opacity: 0.35;
}
.card-deck.locked .poker-card.selected {
  opacity: 0.6;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --card-w: 46px;
    --card-h: 66px;
  }

  .topic-label { font-size: 13px; }
  .vote-table { gap: 14px 10px; }
  .vote-table-wrap { padding: 20px 12px 12px; }
  .stats { gap: 20px; }
  .stat--avg .stat-value { font-size: 32px; }
  .deck-strip { padding: 12px 12px; }
  .card-deck { gap: 6px; }
  .poker-card { font-size: 15px; }
  .form-input--inline { width: 100%; max-width: 260px; }
  .form-input--sm { width: 160px; }
  header { padding: 0 14px; }
  .user-info { display: none; }
}
