:root {
  --bg: #0b1117;
  --bg-elevated: #111923;
  --bg-card: #16202c;
  --bg-hover: #1d2a38;
  --border: #253344;
  --text: #e6edf3;
  --text-muted: #8b9bb0;
  --emerald: #10b981;
  --emerald-dark: #059669;
  --emerald-glow: rgba(16, 185, 129, 0.22);
  --felt: #0f3a2e;
  --felt-border: #1b5c49;
  --amber: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top center, #13202e 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.fireworks-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 900;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease;
  color: var(--text);
  background: var(--bg-card);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.btn-lg {
  padding: 12px 20px;
  font-size: 0.98rem;
  width: 100%;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 0.78rem;
}

.btn-primary {
  background: var(--emerald);
  color: #042419;
}

.btn-primary:hover:not(:disabled) {
  background: #34d399;
}

.btn-secondary {
  background: #2563eb;
  color: #fff;
}

.btn-secondary:hover:not(:disabled) {
  background: #3b82f6;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}

.badge-emerald {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-slate {
  background: rgba(139, 155, 176, 0.14);
  color: #cbd5e1;
  border: 1px solid rgba(139, 155, 176, 0.25);
}

.badge-amber {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--emerald);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: slideIn 0.2s ease;
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* LOBBY */
.lobby {
  max-width: 980px;
  margin: 0 auto;
  padding: 48px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.lobby-header {
  text-align: center;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--emerald), #047857);
  color: #042419;
  font-size: 1.3rem;
  font-weight: 800;
  box-shadow: 0 4px 14px var(--emerald-glow);
}

.brand-mark.compact .brand-card {
  width: 28px;
  height: 34px;
  font-size: 1rem;
}

.brand-title {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.lobby-subtitle {
  color: var(--text-muted);
  margin: 12px auto 0;
  max-width: 560px;
  font-size: 1.02rem;
  line-height: 1.5;
}

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

@media (max-width: 780px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.22rem;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.field small {
  opacity: 0.75;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

input[type="text"],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.94rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  border-color: var(--emerald);
}

.input-code {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  accent-color: var(--emerald);
  width: 16px;
  height: 16px;
}

.lobby-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ROOM VIEW */
.room {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.room-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.passcode-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px 4px 12px;
  font-size: 0.82rem;
}

.passcode-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.passcode-pill strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  color: var(--emerald);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.timer-widget {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.timer-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.timer-controls {
  display: inline-flex;
  gap: 4px;
}

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.menu-check {
  font-size: 0.8rem;
}

.menu-sep {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.menu-item {
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--bg-hover);
}

/* Main Workspace */
.room-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
}

@media (max-width: 960px) {
  .room-layout {
    grid-template-columns: 1fr;
  }
}

.stage {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 24px 22px;
  gap: 18px;
}

.active-story {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.active-story-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.story-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--emerald);
  background: rgba(16, 185, 129, 0.12);
  padding: 2px 7px;
  border-radius: 5px;
}

.active-story-title {
  margin: 0;
  font-size: 1.15rem;
}

.active-story-desc {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Table Area */
.table-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin: auto 0;
}

.seats-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 78px;
}

.seat-card {
  width: 56px;
  height: 78px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  transition: transform 0.25s ease, background-color 0.2s ease, border-color 0.2s ease;
  border: 2px dashed var(--border);
  background: rgba(22, 32, 44, 0.55);
  color: var(--text-muted);
}

.seat-card.voted-hidden {
  border-style: solid;
  border-color: var(--emerald);
  background: repeating-linear-gradient(
    45deg,
    #0f3a2e,
    #0f3a2e 6px,
    #13493a 6px,
    #13493a 12px
  );
  color: transparent;
  box-shadow: 0 4px 12px var(--emerald-glow);
  transform: translateY(-3px);
}

.seat-card.revealed {
  border-style: solid;
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  animation: flipIn 0.28s ease;
}

.seat-card.high-outlier {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35), 0 6px 16px rgba(0, 0, 0, 0.35);
}

.seat-card.low-outlier {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.35), 0 6px 16px rgba(0, 0, 0, 0.35);
}

.seat-card.spectator {
  border-style: dotted;
  opacity: 0.6;
  font-size: 0.9rem;
}

@keyframes flipIn {
  from { transform: rotateY(90deg) scale(0.92); }
  to { transform: rotateY(0deg) scale(1); }
}

.seat-name {
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.seat-name.is-you {
  color: var(--emerald);
}

.poker-table {
  width: min(560px, 100%);
  min-height: 150px;
  border-radius: 999px;
  background: radial-gradient(circle at center, #144d3c 0%, var(--felt) 100%);
  border: 6px solid var(--felt-border);
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.45), var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 28px;
}

.table-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: center;
}

.vote-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 200px;
  font-size: 0.86rem;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--emerald);
  transition: width 0.25s ease;
}

.table-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.consensus-banner {
  background: rgba(16, 185, 129, 0.24);
  border: 1px solid var(--emerald);
  color: #a7f3d0;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.outlier-messages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.outlier-text {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.4;
}

.outlier-high {
  color: #fcd34d;
}

.outlier-low {
  color: #7dd3fc;
}

.stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.88rem;
}

.stat-item strong {
  font-size: 1.05rem;
  color: #fff;
}

.distribution-bars {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.dist-chip {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.82rem;
}

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

.accept-label {
  font-size: 0.8rem;
  color: #d1fae5;
}

.estimate-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.pill-btn.suggested {
  background: var(--emerald);
  color: #042419;
  border-color: var(--emerald);
}

.pill-btn:hover {
  transform: translateY(-1px);
}

/* Hand */
.hand-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.hand-notice {
  font-size: 0.86rem;
  color: var(--amber);
}

.card-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.poker-card {
  width: 58px;
  height: 84px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, border-color 0.14s ease, background-color 0.14s ease, box-shadow 0.14s ease;
}

.poker-card:hover:not(:disabled) {
  transform: translateY(-6px);
  border-color: var(--emerald);
}

.poker-card.selected {
  transform: translateY(-10px);
  background: var(--emerald);
  border-color: #6ee7b7;
  color: #042419;
  box-shadow: 0 8px 20px var(--emerald-glow);
}

.poker-card:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  max-height: calc(100vh - 58px);
}

@media (max-width: 960px) {
  .sidebar {
    border-left: 0;
    border-top: 1px solid var(--border);
    max-height: none;
  }
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-title-group h3 {
  margin: 0;
  font-size: 1rem;
}

.sidebar-btns {
  display: flex;
  gap: 6px;
}

.story-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.stories-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.story-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.story-item:hover {
  background: var(--bg-hover);
}

.story-item.active {
  border-color: var(--emerald);
  box-shadow: inset 0 0 0 1px var(--emerald);
}

.story-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.story-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}

.story-delete-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 5px;
  border-radius: 4px;
}

.story-delete-btn:hover {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}
