/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-glow: rgba(124, 58, 237, 0.35);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --table-felt: #14532d;
  --table-felt2: #166534;
  --table-rim: #1e3a5f;
  --card-back: #1e3a8a;
  --card-back2: #1e40af;
  --radius: 12px;
  --transition: 0.2s ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 16px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost {
  background: transparent; color: var(--text-muted); border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Full-screen overlays ───────────────────────────────────────────────── */
.fullscreen-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 24px;
  background: var(--bg);
}
.overlay-icon { font-size: 64px; }
.overlay-title { font-size: 28px; font-weight: 700; }
.overlay-subtitle { color: var(--text-muted); font-size: 16px; text-align: center; max-width: 400px; }

/* Spinner */
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Landing page ───────────────────────────────────────────────────────── */
#landing {
  min-height: 100vh; overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.landing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%; max-width: 500px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.logo { text-align: center; margin-bottom: 40px; }
.logo-icon { font-size: 52px; display: block; margin-bottom: 8px; }
.logo h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input, .form-group select {
  width: 100%; padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group select option { background: var(--surface2); }

.scale-preview {
  margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px;
}
.scale-chip {
  padding: 2px 8px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}

.form-actions { margin-top: 24px; }
.form-actions .btn { width: 100%; padding: 12px; font-size: 16px; border-radius: 10px; }

.divider {
  text-align: center; position: relative; margin: 28px 0;
  color: var(--text-muted); font-size: 13px;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%; width: calc(50% - 24px);
  height: 1px; background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.join-box {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
}
.join-box h3 { font-size: 15px; margin-bottom: 12px; }
.join-invite-info {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg);
  border-radius: 8px; margin-bottom: 12px;
  font-size: 13px; color: var(--text-muted);
}
.join-invite-info strong { color: var(--text); }

.error-msg {
  color: var(--danger); font-size: 13px;
  margin-top: 8px; display: flex; align-items: center; gap: 4px;
}

.notfound-box {
  text-align: center; padding: 8px 0 4px;
}
.notfound-icon { font-size: 44px; margin-bottom: 10px; }
.notfound-box p { color: var(--text-muted); font-size: 14px; line-height: 1.5; }

.theme-picker { display: flex; gap: 10px; margin-top: 8px; }
.theme-option {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 8px; border: 2px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: border-color var(--transition), background var(--transition);
  user-select: none; overflow: hidden;
}
.theme-option:hover { border-color: var(--accent); background: rgba(124,58,237,0.06); }
.theme-option.selected { border-color: var(--accent); background: rgba(124,58,237,0.12); }
.theme-option span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.theme-option.selected span { color: var(--text); }
.theme-card-preview {
  flex-shrink: 0;
  width: 40px; height: 56px;
  max-width: 40px; max-height: 56px;
  border-radius: 5px; object-fit: cover;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  display: block;
}

/* ── App Layout ─────────────────────────────────────────────────────────── */
#app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
}

/* Row that holds table + sidebar */
#main-row {
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#table-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* ── Participants sidebar ────────────────────────────────────────────────── */
#participants-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-muted);
}
.sidebar-count {
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 20px;
  min-width: 20px; text-align: center;
}

#sidebar-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.sidebar-participant {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  margin-bottom: 4px;
  transition: background var(--transition);
}
.sidebar-participant:hover { background: var(--surface2); }
.sidebar-participant.offline { opacity: 0.45; }

.p-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sidebar-participant.offline .p-avatar { background: var(--border); }

.p-info { flex: 1; min-width: 0; }
.p-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-role {
  font-size: 11px; margin-top: 2px; display: block;
}
.p-role.host    { color: #f59e0b; }
.p-role.voted   { color: var(--success); }
.p-role.waiting { color: var(--text-muted); }
.p-role.voted-val {
  color: var(--accent); font-weight: 800; font-size: 13px;
}

.p-status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.p-status-dot.online  { background: var(--success); }
.p-status-dot.offline { background: var(--border); }

/* ── Top bar ────────────────────────────────────────────────────────────── */
#top-bar {
  grid-row: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  gap: 12px;
}
.top-bar-left { display: flex; align-items: center; gap: 10px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }
.app-logo { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; color: inherit; text-decoration: none; }
.app-logo:hover { opacity: 0.8; }
.scale-badge {
  padding: 3px 10px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; color: var(--text-muted);
}
.participants-count {
  font-size: 13px; color: var(--text-muted);
  display: flex; align-items: center; gap: 5px;
}
.participants-count::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

/* ── Table area ─────────────────────────────────────────────────────────── */
#table-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

/* Square poker table — fills available height, stays square via aspect-ratio */
#poker-table {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  background: radial-gradient(ellipse at 30% 30%, var(--table-felt2), var(--table-felt));
  border-radius: 28px;
  box-shadow:
    0 0 0 10px var(--table-rim),
    0 0 0 14px #0d1b2a,
    0 20px 60px rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 12px;
  overflow: hidden;
  z-index: 1;
}

/* Table inner border decoration */
#poker-table::before {
  content: '';
  position: absolute; inset: 10px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.06);
  pointer-events: none;
  z-index: 0;
}

/* Top-left header: host card + story title side by side */
#table-header {
  display: flex;
  align-items: flex-start;
  gap: clamp(8px, 1.8vmin, 20px);
  flex-shrink: 1;
  min-height: 0;
  position: relative;
  z-index: 1;
}

#host-slot-area {
  flex-shrink: 0;
}

/* Story display — left-aligned inside the table header */
#story-display {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  padding-top: 4px;
}
#story-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: rgba(255,255,255,0.35); margin-bottom: 6px;
}
#story-title-display {
  font-size: 78px; font-weight: 700;
  color: rgba(255,255,255,0.85);
  line-height: 1.25;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical;
}
/* Empty state: size driven by JS fitStoryTitle — color/style only here */
#story-title-display.empty { color: rgba(255,255,255,0.22); font-style: italic; }

/* Center section: participant cards — flex-wrap grid */
#table-players {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: clamp(6px, 1.8vmin, 20px);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.participant-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

/* ── Table cards ────────────────────────────────────────────────────────── */
.table-card-wrap {
  position: relative;
  width: clamp(44px, 10.5vmin, 116px);
  height: clamp(62px, 14.8vmin, 162px);
  perspective: 1200px;
}

.table-card {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.table-card.revealed {
  transform: rotateY(180deg);
}

/* Card appear animation */
@keyframes cardAppear {
  from { opacity: 0; transform: scale(0.5) rotateY(-30deg) translateY(-20px); }
  to   { opacity: 1; transform: scale(1) rotateY(0deg) translateY(0); }
}
.table-card-wrap.appeared .table-card {
  animation: cardAppear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Card vanish animation */
@keyframes cardVanish {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.4) translateY(-30px); }
}
.table-card-wrap.vanishing .table-card {
  animation: cardVanish 0.3s ease-in forwards;
}

.card-face {
  position: absolute; inset: 0;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  background-image: linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover;
  background-position: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  overflow: hidden;
}
body[data-card-theme="classic"] .card-back {
  background-image: url('/img/classic/back-classic.png'),
    linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover, cover; background-position: center, center;
}
body[data-card-theme="pokemon"] .card-back {
  background-image: url('/img/pokemon/back-pokemon.png'),
    linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover, cover; background-position: center, center;
}

/* Subtle border visible when image not loaded */
.card-back::before {
  content: '';
  position: absolute; inset: 4px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  pointer-events: none;
  z-index: 1;
}
.card-back::after { content: none; }

.card-front {
  background: #fff;
  transform: rotateY(180deg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  flex-direction: column;
}
.card-front .card-value {
  font-size: clamp(18px, 3.6vmin, 39px); font-weight: 900;
  color: #1e293b; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.card-front.special .card-value { font-size: clamp(22px, 4.4vmin, 47px); }

/* Colored top stripe on card-front */
.card-front::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 4px; border-radius: 8px 8px 0 0;
  background: var(--accent);
}

/* Empty slot when participant hasn't voted */
.slot-empty {
  width: clamp(38px, 9vmin, 96px);
  height: clamp(53px, 12.5vmin, 135px);
  border: 2px dashed rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}

.participant-name-tag {
  font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5);
  padding: 2px 8px; border-radius: 20px;
  backdrop-filter: blur(4px);
  max-width: 90px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.participant-name-tag.is-host::after {
  content: ' 👑'; font-size: 10px;
}
.participant-name-tag.disconnected { opacity: 0.4; }

/* ── Bottom section ─────────────────────────────────────────────────────── */
#bottom-section {
  grid-row: 3;
  position: relative;
  z-index: 5;
  overflow: visible;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 20px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  /* Reserves space equal to the fixed #host-controls bar so the table
     never overlaps it. For participants the hand-container is already taller. */
  min-height: 68px;
}

/* Host controls — fixed bar, slightly above viewport bottom */
#host-controls {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 24px;
  background: rgba(13, 17, 23, 0.97);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
}
#story-form {
  display: flex; gap: 10px; align-items: center;
}
#story-title-input {
  padding: 10px 17px; width: 360px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 17px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#story-title-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#host-controls .btn {
  padding: 10px 19px;
  font-size: 17px;
  border-radius: 10px;
}
#voting-controls { display: flex; gap: 10px; }

/* "Show stats" button — anchored to the left edge of the fixed host-controls bar */
#btn-show-stats {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
}

/* Card hand */
#hand-container {
  width: 100%;
  /* height scales with card size: headroom for hover (22px) + card + scrollbar room (12px) */
  height: clamp(110px, calc(40px + 14.8vmin), 160px);
  /* scroll lives here so the container itself is the scroll boundary */
  overflow-x: auto;
  display: flex; align-items: flex-end; justify-content: safe center;
  /* bottom padding makes space for the scrollbar track without touching cards */
  padding: 0 16px 12px;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.28) var(--surface2);
}

/* Webkit / Blink scrollbar */
#hand-container::-webkit-scrollbar        { height: 5px; }
#hand-container::-webkit-scrollbar-track  {
  background: var(--surface2);
  border-radius: 20px;
  margin: 0 12px;
}
#hand-container::-webkit-scrollbar-thumb  {
  background: rgba(255,255,255,0.28);
  border-radius: 20px;
}
#hand-container::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

#card-hand {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100%;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* ── Hand cards ─────────────────────────────────────────────────────────── */
.hand-card {
  position: relative;
  flex-shrink: 0;
  width: clamp(44px, 10.5vmin, 72px);
  height: clamp(62px, 14.8vmin, 102px);
  border-radius: 8px;
  background-image: linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover;
  background-position: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.18s ease;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.08);
  user-select: none;
  will-change: transform;
  isolation: isolate;
}

.hand-card .hand-card-value {
  font-size: clamp(15px, 3.6vmin, 24px); font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 6px rgba(0,0,0,0.9),
    0 2px 10px rgba(0,0,0,0.8),
    1px 1px 0 rgba(0,0,0,0.7);
  pointer-events: none;
  position: relative; z-index: 1;
}
.hand-card.special .hand-card-value { font-size: clamp(19px, 4.4vmin, 29px); }

/* Dark overlay so value text is readable over the card back image */
.hand-card::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.28);
  border-radius: 6px;
  pointer-events: none;
  z-index: 0;
}
.hand-card.selected::after {
  background: rgba(109, 40, 217, 0.5);
}
.hand-card .hand-card-value {
  position: relative; z-index: 1;
}

.hand-card:hover {
  transform: translateY(-16px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.6), 0 0 20px var(--accent-glow);
  z-index: 50;
  border-color: rgba(124, 58, 237, 0.5);
}

.hand-card.selected {
  transform: translateY(-22px);
  background: linear-gradient(135deg, #4c1d95, #6d28d9) !important;
  border-color: #a78bfa !important;
  box-shadow: 0 16px 40px rgba(109, 40, 217, 0.6) !important;
  z-index: 50 !important;
}

body[data-card-theme="classic"] .hand-card {
  background-image: url('/img/classic/back-classic.png'),
    linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover, cover; background-position: center, center;
}
body[data-card-theme="pokemon"] .hand-card {
  background-image: url('/img/pokemon/back-pokemon.png'),
    linear-gradient(135deg, var(--card-back) 0%, var(--card-back2) 100%);
  background-size: cover, cover; background-position: center, center;
}

/* Host Joker card — image on BOTH faces, always visible */
.table-card.host-joker {
  pointer-events: none;
}

/* Both faces show the Joker; backface-visibility: visible ensures
   the image renders regardless of which face is toward the viewer */
.table-card.host-joker .card-back,
.table-card.host-joker .card-front {
  background-size: cover !important;
  background-position: center !important;
  background-color: #1c1033 !important;
  backface-visibility: visible !important;
  -webkit-backface-visibility: visible !important;
  border: 2px solid rgba(167, 139, 250, 0.7) !important;
  box-shadow: 0 0 14px rgba(124, 58, 237, 0.5) !important;
}
body[data-card-theme="classic"] .table-card.host-joker .card-back,
body[data-card-theme="classic"] .table-card.host-joker .card-front {
  background-image: url('/img/classic/joker-classic.png') !important;
}
body[data-card-theme="pokemon"] .table-card.host-joker .card-back,
body[data-card-theme="pokemon"] .table-card.host-joker .card-front {
  background-image: url('/img/pokemon/joker-pokemon.png') !important;
}

/* Remove the white base and the purple top stripe from the front face */
.table-card.host-joker .card-front::before { display: none !important; }
.table-card.host-joker .card-back::before  { display: none !important; }
.table-card.host-joker .card-back::after   { content: none !important; }
.table-card.host-joker .card-value         { display: none !important; }

/* Voted indicator overlay on hand */
.hand-voted-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6); border-radius: 8px;
  font-size: 24px;
  pointer-events: none;
}

.spectator-label {
  font-size: 13px; color: var(--text-muted);
  padding: 6px 16px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
}

/* ── Stats panel (slide from left) ─────────────────────────────────────── */
#stats-panel-left {
  position: fixed; left: -380px; top: 0;
  width: 360px; height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 400;
  transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
  box-shadow: 20px 0 60px rgba(0,0,0,0.5);
}
#stats-panel-left.open { left: 0; }

.stats-left-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: 8px;
}
.stats-left-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); font-weight: 700; margin-bottom: 4px;
}
.stats-left-story {
  font-size: 14px; font-weight: 700; line-height: 1.4;
  color: var(--text); max-width: 260px;
}

.stats-left-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
}

.stats-numbers {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 16px;
}
.stat-box {
  background: var(--surface2); border-radius: 10px;
  padding: 12px 8px; text-align: center;
}
.stat-box .stat-value { font-size: 20px; font-weight: 800; line-height: 1; }
.stat-box .stat-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

.consensus-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.consensus-badge.perfect { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.consensus-badge.good    { background: rgba(245,158,11,0.15); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.consensus-badge.spread  { background: rgba(239,68,68,0.15);  color: var(--danger);  border: 1px solid rgba(239,68,68,0.3); }

.stats-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); font-weight: 700;
  margin: 16px 0 10px;
}

/* ── Histogram ───────────────────────────────────────────────────────────── */
#stats-histogram { display: flex; flex-direction: column; gap: 8px; }

.hist-row {
  display: grid;
  grid-template-columns: 36px 1fr 24px;
  align-items: center;
  gap: 8px;
}

.hist-value {
  text-align: right; font-weight: 800; font-size: 15px;
  color: var(--accent); font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.hist-bar-wrap {
  display: flex; flex-direction: column; gap: 3px;
}

.hist-bar-container {
  height: 20px; background: var(--surface2);
  border-radius: 4px; overflow: hidden;
}
.hist-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 4px;
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.hist-names {
  font-size: 10px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hist-count {
  text-align: center; font-size: 12px; font-weight: 700;
  color: var(--text-muted);
}

.hist-empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

.stats-actions {
  margin-top: 20px; display: flex; gap: 8px; flex-direction: column;
}
.stats-actions .btn { width: 100%; justify-content: center; }

/* ── History panel ──────────────────────────────────────────────────────── */
#history-panel {
  position: fixed; right: -420px; top: 0;
  width: 400px; height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 300;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.4);
}
#history-panel.open { right: 0; }

.history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px; border-bottom: 1px solid var(--border);
}
.history-header h3 { font-size: 16px; font-weight: 700; }
.history-list { overflow-y: auto; flex: 1; padding: 12px; }

.history-item {
  background: var(--surface2); border-radius: 12px; padding: 14px;
  margin-bottom: 10px; cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}
.history-item:hover { border-color: var(--accent); }
.history-item-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.history-item-meta {
  font-size: 12px; color: var(--text-muted);
  display: flex; gap: 12px;
}

.history-empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: 14px;
}

/* ── Scale modal ────────────────────────────────────────────────────────── */
#scale-modal {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}
.scale-modal-content {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px;
  width: 100%; max-width: 480px;
  animation: slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.scale-modal-content h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

.scale-option {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--border);
  margin-bottom: 10px;
  transition: border-color var(--transition), background var(--transition);
}
.scale-option:hover { background: var(--surface2); }
.scale-option.selected { border-color: var(--accent); background: rgba(124,58,237,0.1); }
.scale-option input[type="radio"] { display: none; }
.scale-option-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.scale-option-values { font-size: 12px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 3px; }
.scale-option-chip {
  padding: 1px 6px; border-radius: 4px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 11px;
}
.scale-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Toast notifications ────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 20px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.out { animation: toastOut 0.25s ease forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateY(10px) scale(0.95); }
}

/* ── Custom numeric scale ───────────────────────────────────────────────── */
.label-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.custom-scale-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.custom-scale-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.custom-scale-input::placeholder { color: var(--text-muted); }

/* custom scale section inside the scale-change modal */
.custom-scale-modal-section {
  margin-top: 12px;
  padding: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.custom-scale-modal-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.custom-scale-modal-section .scale-preview { margin-top: 10px; }

/* ── Card fly animation ─────────────────────────────────────────────────── */

/* The flying clone is a .hand-card with position:fixed applied inline.
   JS sets transition:none before reflow and the real transition after,
   so no CSS transition override is needed here. */
.hand-card.fly-clone {
  transform: none;
}

/* fly-in: card arrives at another participant's slot from below the table */
@keyframes flyIn {
  from {
    opacity: 0;
    transform: translateY(55px) scale(0.72) rotate(6deg);
  }
  65% {
    opacity: 1;
    transform: translateY(-5px) scale(1.04) rotate(-1deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}
.table-card.fly-in {
  animation: flyIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* vote-pulse: played when the user changes their vote (card already on table) */
@keyframes votePulse {
  0%   { transform: scale(1)    rotate(0deg);  }
  35%  { transform: scale(1.12) rotate(3deg);  }
  70%  { transform: scale(0.95) rotate(-1deg); }
  100% { transform: scale(1)    rotate(0deg);  }
}
.table-card.vote-pulse {
  animation: votePulse 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  .hand-card.fly-clone     { display: none !important; }
  .table-card.fly-in       { animation: none; opacity: 1; }
  .table-card.vote-pulse   { animation: none; }
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE — session page
   ════════════════════════════════════════════════════════════════ */

/* ── Tablet / small desktop (≤768px) ─────────────────────────── */
@media (max-width: 768px) {

  /* Sidebar becomes a slide-in overlay so the table gets full width */
  #participants-sidebar {
    position: fixed;
    right: -100%;
    top: 0;
    height: 100dvh;
    width: min(260px, 85vw);
    z-index: 200;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0,0,0,0.5);
  }
  #participants-sidebar.open { right: 0; }

  /* Backdrop shown when sidebar is open */
  #sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 199;
    backdrop-filter: blur(2px);
  }
  body.sidebar-open #sidebar-backdrop { display: block; }

  /* Top bar — tighten and hint that participants count is tappable */
  #top-bar { padding: 8px 12px; gap: 8px; }
  .app-logo { font-size: 16px; }
  .scale-badge { display: none; }
  .top-bar-right { gap: 6px; }
  #participants-count { cursor: pointer; text-decoration: underline dotted; }

  /* Table area fills all available width */
  #table-area { padding: 8px; }
  #poker-table {
    aspect-ratio: auto;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    padding: 14px;
    gap: 10px;
  }

  /* Table cards: clamp() in base rules handles sizing — only constrain name tag */
  .participant-name-tag { max-width: 72px; }

  /* Host controls — fluid input, unstick the stats button */
  #host-controls { padding: 10px 16px; gap: 8px; }
  #story-form { flex: 1 1 100%; }
  #story-title-input {
    width: auto;
    flex: 1;
    font-size: 15px;
    padding: 9px 14px;
  }
  #host-controls .btn { font-size: 15px; padding: 9px 16px; }
  #btn-show-stats { position: static; transform: none; }
  #voting-controls { flex-wrap: wrap; justify-content: center; }
  /* Spacer for the fixed host-controls bar (two wrapped rows ≈ 112px) */
  #bottom-section { min-height: 112px; }

  /* Panels — cap at viewport width on narrow screens */
  #stats-panel-left { width: min(360px, 100vw); }
  #history-panel    { width: min(400px, 100vw); }
}

/* ── Phone (≤480px) ──────────────────────────────────────────── */
@media (max-width: 480px) {
  #top-bar { padding: 6px 10px; }
  .app-logo { font-size: 14px; }
  .btn-sm { font-size: 11px; padding: 5px 9px; }

  #poker-table { padding: 10px; border-radius: 16px; gap: 8px; }
  .participant-name-tag { max-width: 58px; font-size: 10px; }

}

/* ── Small phone (≤360px) ────────────────────────────────────── */
@media (max-width: 360px) {
  .app-logo { font-size: 13px; }
  .btn-sm { font-size: 10px; padding: 4px 8px; }

  #poker-table { padding: 8px; gap: 6px; border-radius: 14px; }
  .participant-name-tag { max-width: 48px; font-size: 9px; padding: 2px 5px; }

  #story-title-input { font-size: 13px; padding: 7px 10px; }
  #host-controls .btn { font-size: 13px; padding: 7px 12px; }
}

/* ── Overflow guard — prevent global horizontal scroll ───────── */
#app { overflow-x: hidden; }
body { overflow-x: hidden; }
