:root {
  --bg-main: #0e0e10;
  --bg-elevated: #18181b;
  --bg-card: #1f1f23;
  --bg-hover: #26262c;
  --border: #2e2e35;
  --text: #efeff1;
  --text-muted: #adadb8;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --live: #eb0400;
  --tip-bg: #fef08a;
  --tip-text: #18181b;
  --focus-ring: #fbbf24;
}

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

body.dark-theme {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-main);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.small-note {
  font-size: 0.82rem;
}

/* Keyboard Focus States */
:is(
  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .nav-link,
  .pill-btn,
  .chat-tab,
  .tip-btn,
  .tag-chip,
  .fav-star,
  .icon-close,
  .brand-logo,
  .sidebar-item
):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 440px;
  width: 100%;
  padding: 1.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* Topbar */
.topbar {
  min-height: 56px;
  background: rgba(24, 24, 27, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

.brand-mark {
  background: var(--accent);
  color: #111;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text);
  background: var(--bg-card);
}

.topbar-center {
  flex: 1 1 240px;
  max-width: 440px;
}

.search-box {
  display: flex;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  width: 100%;
}

.search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  outline: none;
}

.search-box select {
  background: var(--bg-card);
  color: var(--text);
  border: none;
  border-left: 1px solid var(--border);
  padding: 0 0.55rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.token-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.84rem;
  display: flex;
  gap: 0.35rem;
}

.token-pill strong {
  color: var(--accent);
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 235px 1fr;
  min-height: calc(100dvh - 56px);
}

/* Left Sidebar */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.sidebar-title {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}

.sidebar-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.42rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

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

.sidebar-item-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

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

.tag-cloud,
.country-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.76rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}

.tag-chip:hover,
.tag-chip.active {
  color: var(--text);
  border-color: var(--accent);
}

/* Main Content */
.main-content {
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* Featured Spotlight Banner */
.featured-banner {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  overflow: hidden;
}

.featured-preview {
  position: relative;
  min-height: 210px;
  background: radial-gradient(circle at top left, #27272f, #0d0d10);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.featured-overlay {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  max-width: 440px;
}

.featured-meta {
  padding: 1.25rem;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.75rem;
}

.featured-creator-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* Filter Strip */
.filter-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.category-pills,
.filter-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.pill-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active,
.pill-btn:hover {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.active-filter {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.advanced-filters {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.filter-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
}

.filter-field select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.84rem;
  cursor: pointer;
}

/* Directory Body Grid + Right Rail */
.directory-body-grid {
  display: grid;
  grid-template-columns: 1fr 195px;
  gap: 1rem;
  align-items: start;
}

.directory-body-grid.no-rail {
  grid-template-columns: 1fr;
}

.section-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-heading-row h2 {
  font-size: 1.05rem;
}

.right-rail {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.icon-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
}

/* Rooms Grid */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 0.95rem;
}

.room-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  display: flex;
  flex-direction: column;
}

.room-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.room-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #141418;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text-muted);
}

.badge-live {
  background: var(--live);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.16rem 0.45rem;
  border-radius: 4px;
  letter-spacing: 0.04em;
  width: fit-content;
}

.room-thumb .badge-live {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
}

.fav-star {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  cursor: pointer;
}

.fav-star.active {
  color: var(--accent);
  border-color: var(--accent);
}

.room-viewers {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  background: rgba(0, 0, 0, 0.78);
  font-size: 0.74rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.room-country-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.78);
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.room-card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.room-card-title {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.mini-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
}

/* Live Room View */
.room-shell {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.room-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

.room-title-group,
.room-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.room-title-group h1 {
  font-size: 1.12rem;
}

.room-tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.viewer-pill {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.room-stage-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  min-height: calc(100dvh - 165px);
}

.video-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
}

.video-screen {
  position: relative;
  flex: 1;
  min-height: 260px;
  background: #070709;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  overflow: hidden;
}

.video-watermark {
  position: absolute;
  top: 0.85rem;
  right: 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.35);
  z-index: 2;
}

.video-placeholder {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  max-width: 480px;
  width: 100%;
}

.pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 6px rgba(235, 4, 0, 0.2);
}

.feed-slot,
#videoFeedSlot {
  width: 100%;
  min-height: 120px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: rgba(24, 24, 27, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.feed-slot:empty,
#videoFeedSlot:empty {
  display: none;
}

.feed-slot video,
.feed-slot iframe,
#videoFeedSlot video,
#videoFeedSlot iframe {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: cover;
  border: none;
}

/* Chat Panel */
.chat-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 360px;
}

.chat-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}

.chat-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.65rem 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.chat-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.chat-body,
#chatTabContent,
#messagesTabContent,
#usersTabContent {
  flex: 1;
  padding: 0.75rem;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.room-notice {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding: 0.55rem 0.65rem;
  font-size: 0.78rem;
  border-radius: 4px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.chat-msg {
  font-size: 0.84rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-msg strong {
  color: var(--accent);
}

.tip-alert {
  background: var(--tip-bg);
  color: var(--tip-text);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
}

.users-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.users-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.82rem;
}

.tip-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.tip-btn {
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.4rem;
  cursor: pointer;
}

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

.chat-input-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-main);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-small {
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  color: #111;
  border: none;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
}

.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

@media (max-width: 1100px) {
  .directory-body-grid {
    grid-template-columns: 1fr;
  }
  .right-rail {
    display: none;
  }
  .featured-banner {
    grid-template-columns: 1fr;
  }
  .featured-meta {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .room-stage-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }
}

@media (max-width: 600px) {
  .main-content,
  .room-shell {
    padding: 0.75rem;
  }
  .rooms-grid {
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 0.65rem;
  }
  .topbar-center {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }
  .video-screen {
    min-height: 220px;
    padding: 1rem;
  }
  .chat-panel {
    min-height: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-body,
  #chatTabContent,
  #messagesTabContent,
  #usersTabContent {
    scroll-behavior: auto;
  }
  .room-card {
    transition: none;
  }
}
