:root {
  --bg-deep: #0b0c11;
  --bg-mid: #14161f;
  --bg-gradient:
    radial-gradient(1100px 700px at 15% -15%, rgba(79, 124, 255, 0.18), transparent 60%),
    radial-gradient(900px 650px at 105% 10%, rgba(138, 99, 255, 0.14), transparent 55%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 55%, var(--bg-deep) 100%);

  --surface-1: rgba(30, 33, 41, 0.68);
  --surface-1-hover: rgba(38, 42, 52, 0.78);
  --surface-1-border: rgba(255, 255, 255, 0.08);
  --surface-2: rgba(39, 61, 40, 0.55);
  --surface-2-border: rgba(112, 199, 116, 0.35);
  --surface-2-text: #b7f0b8;
  --surface-blur: 14px;

  --accent-start: #4f7cff;
  --accent-end: #8a63ff;
  --accent-gradient: linear-gradient(135deg, var(--accent-start) 0%, var(--accent-end) 100%);
  --accent-gradient-hover: linear-gradient(135deg, #3f6bf0 0%, #7a52f0 100%);

  --amber: #ffab5c;
  --amber-hover: #f0964a;
  --red: #ff5c5c;
  --red-hover: #e64848;

  --text-primary: #f2f3f7;
  --text-muted: #9aa0ad;

  --radius-sm: 8px;
  --radius-md: 12px;

  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --shadow-elevated: 0 16px 44px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-gradient);
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.screen-stack {
  display: grid;
  width: 100%;
  justify-items: center;
}

.screen {
  grid-area: 1 / 1;
  width: 100%;
  max-width: 900px;
  padding: 24px;
  transition: opacity 260ms ease;
}

.screen-hidden {
  opacity: 0;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

#setup-screen {
  text-align: center;
}

#setup-screen p {
  color: var(--text-muted);
  margin-top: 8px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.brand-mark {
  flex-shrink: 0;
}

.brand-name {
  font-size: 2.75rem;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.post-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.post-form button {
  margin-top: 0;
}

#topic-input {
  width: 100%;
  max-width: 400px;
  padding: 12px 16px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-1-border);
  background: var(--surface-1);
  backdrop-filter: blur(var(--surface-blur));
  color: #fff;
}

button {
  padding: 12px 20px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-gradient);
  box-shadow: var(--shadow-card);
  color: white;
  cursor: pointer;
  margin-top: 12px;
}

button:hover {
  background: var(--accent-gradient-hover);
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .topic-item,
  .my-listing-item,
  .status-dot {
    transition: none !important;
    animation: none !important;
  }
}

.lobby-columns {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 24px;
  text-align: left;
}

@media (min-width: 760px) {
  .lobby-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
  }
}

.lobby-column h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.2rem;
  text-align: left;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px 16px;
  background: var(--surface-1);
  border: 1px solid var(--surface-1-border);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(var(--surface-blur));
  color: var(--text-muted);
}

.status-left {
  display: flex;
  align-items: center;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--accent-start);
  animation: status-pulse 1.6s ease-out infinite;
}

@keyframes status-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(79, 124, 255, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(79, 124, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(79, 124, 255, 0);
  }
}

.status-dot.connected {
  background: #4ade80;
  animation: none;
  box-shadow: none;
}

.status-dot.lost {
  background: var(--red);
  animation: none;
  box-shadow: none;
}

#video-grid {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05060a;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated), 0 0 0 1px rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#local-video {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-card);
  object-fit: cover;
}

#controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

#skip-btn {
  background: var(--amber);
  box-shadow: var(--shadow-card);
}

#skip-btn:hover {
  background: var(--amber-hover);
}

#leave-btn {
  background: var(--red);
  box-shadow: var(--shadow-card);
}

#leave-btn:hover {
  background: var(--red-hover);
}

#lobby-status {
  color: var(--amber);
  font-weight: 500;
}

#my-listings,
#topics-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

#topics-list {
  max-height: 320px;
  overflow-y: auto;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row-enter {
  animation: row-in 220ms ease-out both;
}

.row-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.row-main {
  display: flex;
  align-items: center;
  min-width: 0;
}

.row-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-listing-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--surface-2-border);
}

.my-listing-item .row-text {
  color: var(--surface-2-text);
  font-weight: 500;
}

.cancel-listing-btn {
  margin-top: 0;
  padding: 8px 16px;
  font-size: 0.9rem;
  background: #333844;
  box-shadow: none;
}

.cancel-listing-btn:hover {
  background: #454b5a;
}

.empty-state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px dashed rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
}

.empty-state-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.topic-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--surface-1-border);
  backdrop-filter: blur(var(--surface-blur));
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.topic-item:hover {
  background: var(--surface-1-hover);
  border-color: var(--accent-start);
}

.spectator-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 14px auto 0;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  border: 1px solid var(--surface-1-border);
  backdrop-filter: blur(var(--surface-blur));
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #333844;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-gradient);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

@media (prefers-reduced-motion: reduce) {
  .toggle-slider,
  .toggle-slider::before {
    transition: none !important;
  }
}

#live-debates-section {
  margin-top: 32px;
  text-align: left;
}

#live-debates-section h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

#live-debates-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.live-debate-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--surface-2-border);
  backdrop-filter: blur(var(--surface-blur));
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.live-debate-item:hover {
  background: var(--surface-1-hover);
  border-color: var(--red);
}

.live-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  animation: status-pulse 1.6s ease-out infinite;
}

.live-debate-item .row-text {
  flex: 1;
}

.live-spectator-count {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chat-panel {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--surface-1-border);
  backdrop-filter: blur(var(--surface-blur));
}

.chat-header {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.chat-messages {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

.chat-label {
  color: var(--accent-start);
  font-weight: 600;
}

.reaction-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.reaction-btn {
  padding: 4px 10px;
  margin-top: 0;
  font-size: 1.1rem;
  background: var(--surface-1);
  box-shadow: none;
  border: 1px solid var(--surface-1-border);
}

.reaction-btn:hover {
  background: var(--surface-1-hover);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.chat-input-row input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-1-border);
  background: var(--surface-1);
  color: #fff;
}

.chat-input-row button {
  margin-top: 0;
  padding: 8px 16px;
}

#spectate-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 16px;
  background: var(--surface-1);
  border: 1px solid var(--surface-1-border);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(var(--surface-blur));
  color: var(--text-muted);
}

#spectate-status-bar button {
  margin-top: 0;
  background: var(--red);
}

#spectate-status-bar button:hover {
  background: var(--red-hover);
}

#spectate-video-grid {
  position: relative;
  display: flex;
  gap: 12px;
  width: 100%;
}

#spectate-video-grid video {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  background: #05060a;
  box-shadow: var(--shadow-elevated), 0 0 0 1px rgba(255, 255, 255, 0.06);
  object-fit: cover;
}

.reaction-burst {
  position: absolute;
  bottom: 8px;
  font-size: 1.8rem;
  animation: reaction-float 1.2s ease-out forwards;
  pointer-events: none;
}

@keyframes reaction-float {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-80px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-badge,
  .live-debate-item,
  .reaction-burst {
    transition: none !important;
    animation: none !important;
  }
}
