:root {
  --bg: #0e1014;
  --bg-elevated: #161920;
  --bg-surface: #1d212b;
  --bg-hover: #252b38;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f3f5f8;
  --text-muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-hover: #3b7bff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --success: #22c55e;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --transition: 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-theme="light"] {
  --bg: #f6f7fa;
  --bg-elevated: #ffffff;
  --bg-surface: #eef1f6;
  --bg-hover: #e3e7f0;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #111827;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --success: #16a34a;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.hidden {
  display: none !important;
}

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.85;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Header */
.topbar {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

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

.icon-btn:active {
  transform: scale(0.96);
}

/* Buttons & Inputs */
.btn {
  height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition), transform var(--transition);
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

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

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

.btn-ghost:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.input {
  height: 46px;
  width: 100%;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

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

/* Views */
.view {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
}

/* HOME VIEW */
.home-container {
  flex: 1;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
}

.home-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 500;
}

.home-title {
  font-size: clamp(2rem, 5vw, 2.85rem);
  line-height: 1.12;
  letter-spacing: -0.03em;
  font-weight: 650;
}

.home-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.55;
  margin-top: -12px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.join-row {
  display: flex;
  gap: 10px;
}

.join-row .input {
  flex: 1;
}

.home-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.home-divider::before,
.home-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.home-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.feature-item {
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.feature-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* LOBBY VIEW */
.lobby-container {
  flex: 1;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 24px;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 36px;
  align-items: center;
}

.preview-card {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #101319;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.preview-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-surface);
  color: var(--text-muted);
}

.avatar-circle {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.preview-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-pill);
  background: rgba(15, 17, 21, 0.72);
  backdrop-filter: blur(12px);
}

.preview-status {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(15, 17, 21, 0.72);
  color: #f3f5f8;
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lobby-title {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.room-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.room-chip strong {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 500;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.device-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.select-input {
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  max-width: 100%;
}

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

.lobby-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.lobby-actions .btn-primary {
  flex: 1;
}

/* MEETING VIEW */
.meeting-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.meeting-header {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.meeting-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.meeting-room-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  transition: background var(--transition);
}

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

.meeting-timer {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.meeting-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  padding: 16px;
  gap: 16px;
}

/* Video Grid */
.video-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 12px;
  align-content: center;
  justify-content: center;
}

.video-stage[data-count="1"] {
  grid-template-columns: minmax(0, 960px);
  grid-template-rows: minmax(0, 1fr);
}

.video-stage[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
}

.video-stage[data-count="3"],
.video-stage[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.video-stage[data-count="5"],
.video-stage[data-count="6"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.video-stage[data-count="many"] {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  grid-auto-rows: minmax(180px, 1fr);
}

.video-tile {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 180px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition);
}

.video-tile.pinned {
  grid-column: 1 / -1;
  border-color: var(--accent);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-tile.is-local:not(.is-screen) video {
  transform: scaleX(-1);
}

.video-tile.is-screen video {
  object-fit: contain;
  background: #0a0c10;
}

.tile-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-surface);
}

.tile-footer {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.tile-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: rgba(15, 17, 21, 0.72);
  color: #f3f5f8;
  font-size: 0.82rem;
  font-weight: 500;
  backdrop-filter: blur(8px);
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-muted-icon {
  color: #fca5a5;
  display: inline-flex;
}

.tile-pin-btn {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(15, 17, 21, 0.65);
  color: #f3f5f8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}

.video-tile:hover .tile-pin-btn,
.video-tile.pinned .tile-pin-btn {
  opacity: 1;
}

.tile-pin-btn:hover {
  background: rgba(15, 17, 21, 0.9);
}

/* Side Panel (Chat & Participants) */
.side-panel {
  width: 340px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.side-tabs {
  display: flex;
  gap: 6px;
}

.side-tab {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}

.side-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.side-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

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

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 24px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
}

.chat-msg.own {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
}

.chat-bubble {
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.own .chat-bubble {
  background: var(--accent);
  color: #fff;
}

.chat-form {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.chat-form .input {
  height: 40px;
  font-size: 0.88rem;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.participants-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.participant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

.participant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.participant-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.participant-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.participant-icons .off {
  color: var(--danger);
}

.side-footer-invite {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.side-footer-invite .btn {
  width: 100%;
  height: 40px;
  font-size: 0.86rem;
}

/* Control Bar */
.control-bar-wrap {
  padding: 12px 16px 18px;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.control-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.ctrl-btn {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  color: var(--text);
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

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

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-btn.is-off {
  background: var(--danger-soft);
  color: var(--danger);
}

.ctrl-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.ctrl-btn.is-danger {
  width: 58px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
}

.ctrl-btn.is-danger:hover {
  background: var(--danger-hover);
}

.ctrl-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
}

.ctrl-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  animation: toastIn 200ms ease-out;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
@media (max-width: 860px) {
  .lobby-container {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 24px 16px;
  }

  .home-features {
    grid-template-columns: 1fr;
  }

  .video-stage[data-count="2"] {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .side-panel {
    position: fixed;
    inset: 56px 0 78px 0;
    width: auto;
    border-radius: 0;
    z-index: 50;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0 16px;
  }

  .join-row {
    flex-direction: column;
  }

  .control-bar {
    gap: 6px;
    padding: 6px 8px;
  }

  .ctrl-btn {
    width: 42px;
    height: 42px;
  }

  .ctrl-btn.is-danger {
    width: 50px;
  }

  .device-row {
    grid-template-columns: 1fr;
  }
}
