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

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --bg-input: #0d0d0d;
  --border: #222222;
  --border-light: #333333;
  --text-primary: #e8e8e8;
  --text-secondary: #888888;
  --text-muted: #555555;
  --accent: #ff0033;
  --accent-hover: #cc0029;
  --accent-glow: rgba(255, 0, 51, 0.15);
  --success: #00c853;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --radius-sm: 4px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.url-bar {
  flex: 1;
  display: flex;
  gap: 8px;
}

.url-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.url-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.url-bar input::placeholder {
  color: var(--text-muted);
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

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

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border);
}

.room-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.room-badge span {
  color: var(--accent);
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Main Layout ── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Video Section ── */
.video-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  min-width: 0;
}

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #000;
}

.video-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.video-placeholder svg {
  width: 64px;
  height: 64px;
  opacity: 0.3;
}

.video-placeholder p {
  font-size: 0.95rem;
  max-width: 280px;
  line-height: 1.5;
}

#youtube-player,
#youtube-player iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.video-info {
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Chat Section ── */
.chat-section {
  width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header .online-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 2px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 0.2s ease;
}

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

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.message-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.message-text {
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-primary);
  word-break: break-word;
}

.message.system .message-text {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 0.8rem;
}

.message.system .message-author {
  color: var(--text-secondary);
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.username-row {
  display: flex;
  gap: 8px;
}

.username-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 10px;
  font-size: 0.8rem;
  outline: none;
}

.username-row input:focus {
  border-color: var(--border-light);
}

.message-row {
  display: flex;
  gap: 8px;
}

.message-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.message-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.message-row input::placeholder {
  color: var(--text-muted);
}

/* ── Mobile: video + chat juntos na mesma tela ── */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .header {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .url-bar {
    flex: 1;
    min-width: 0;
    flex-direction: row;
    gap: 6px;
  }

  .url-bar input {
    padding: 10px 12px;
    font-size: 16px;
    border-radius: 10px;
    min-width: 0;
  }

  .url-bar .btn {
    width: auto;
    padding: 10px 14px;
    font-size: 0.85rem;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .room-badge {
    display: flex;
    width: 100%;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.8rem;
  }

  .room-badge .btn-secondary {
    padding: 5px 12px !important;
    font-size: 0.75rem !important;
    margin-left: 6px !important;
  }

  .main {
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }

  .video-section {
    flex: 0 0 auto;
    background: #000;
    border-bottom: 1px solid var(--border);
  }

  .video-container {
    flex: none;
    aspect-ratio: 16 / 9;
    width: 100%;
    max-height: 36vh;
  }

  .video-placeholder {
    padding: 16px;
  }

  .video-placeholder svg {
    width: 40px;
    height: 40px;
  }

  .video-placeholder p {
    font-size: 0.8rem;
  }

  .video-info {
    padding: 6px 12px;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-section {
    flex: 1;
    width: 100%;
    min-height: 0;
    border-left: none;
    display: flex;
    flex-direction: column;
  }

  .chat-header {
    padding: 10px 14px;
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  .messages {
    flex: 1;
    min-height: 0;
    padding: 10px 12px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .message-text {
    font-size: 0.9rem;
  }

  .chat-input-area {
    flex-shrink: 0;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    background: var(--bg-secondary);
  }

  .username-row input,
  .message-row input {
    padding: 10px 12px;
    font-size: 16px;
    border-radius: 10px;
  }

  .message-row .btn {
    padding: 10px 14px;
    border-radius: 10px;
    min-width: 64px;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .main {
    flex-direction: row;
  }

  .video-section {
    flex: 1;
    min-width: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .video-container {
    max-height: none;
    height: 100%;
    aspect-ratio: unset;
  }

  .video-info {
    display: none;
  }

  .chat-section {
    flex: 0 0 45%;
    max-width: 360px;
  }

  .header {
    flex-wrap: nowrap;
  }

  .room-badge {
    width: auto;
    flex-shrink: 0;
  }
}
