:root {
  --bg: #0a0a0c;
  --surface: #131316;
  --elevated: #1c1c21;
  --border: #27272e;
  --text: #f4f4f6;
  --muted: #9ca3af;
  --live: #e11d48;
  --online: #22c55e;
}

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

:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

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

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--live);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.9rem;
}

.brand h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.btn-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-pill {
  cursor: pointer;
}

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

.edit-icon {
  color: var(--muted);
  font-size: 0.8rem;
}

.rename-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rename-form input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 0.85rem;
  width: 140px;
}

.btn-mini {
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-pill.online .dot {
  background: var(--online);
}

.status-pill.starting .dot {
  background: #f59e0b;
}

.status-pill.offline .dot {
  background: var(--live);
}

.banned-banner {
  background: rgba(225, 29, 72, 0.14);
  border: 1px solid var(--live);
  color: #fecdd3;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  font-weight: 500;
}

.reconnect-bar {
  margin-bottom: 12px;
}

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

.input-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.input-bar input {
  flex: 1;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

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

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--elevated);
}

.remote-feedback {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--online);
}

.remote-feedback.error {
  color: var(--live);
}

.saved-streams {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.saved-header {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.saved-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.saved-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px 6px 13px;
  font-size: 0.84rem;
  color: var(--text);
  cursor: pointer;
}

.saved-chip:hover {
  background: var(--elevated);
  border-color: var(--muted);
}

.saved-chip-title {
  font-weight: 600;
}

.saved-chip-id {
  font-size: 0.78rem;
  color: var(--muted);
}

.saved-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

.saved-chip-remove:hover {
  background: rgba(225, 29, 72, 0.2);
  color: #fecdd3;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 16px;
  align-items: start;
}

.workspace-grid.remote-only {
  grid-template-columns: 1fr;
}

.player-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.player-box.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  width: 100vw;
  height: 100dvh;
  aspect-ratio: auto;
  border-radius: 0;
  border: none;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(10, 10, 12, 0.90);
  padding: 24px;
  text-align: center;
  color: var(--text);
  font-size: 1rem;
  z-index: 10;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.buffer-progress-wrap {
  width: min(320px, 85%);
}

.buffer-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--elevated);
  border-radius: 999px;
  overflow: hidden;
}

.buffer-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--online);
  transition: width 0.35s ease;
}

.unmute-btn {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(10, 10, 12, 0.94);
  color: var(--text);
  border: 2px solid var(--live);
  border-radius: 999px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.unmute-btn:hover,
.unmute-btn:focus-visible {
  background: var(--live);
  color: #fff;
}

.player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(transparent, rgba(10, 10, 12, 0.92));
  transition: opacity 0.2s ease;
}

.player-controls.idle-hidden {
  opacity: 0;
  pointer-events: none;
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.live-pill {
  background: var(--live);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.ctrl-title {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.codec-badge {
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.ctrl-btn {
  background: rgba(28, 28, 33, 0.85);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

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

.ctrl-text-btn {
  font-size: 0.78rem;
  font-weight: 500;
}

.volume-slider {
  width: 72px;
  accent-color: var(--text);
  cursor: pointer;
}

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

.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.side-card-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.room-badge {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  background: var(--elevated);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
}

.qr-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.qr-box {
  background: #ffffff;
  padding: 8px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.qr-box svg {
  width: 96px;
  height: 96px;
  display: block;
}

.qr-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.paired-status {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
}

.paired-status.connected {
  color: var(--online);
}

.qr-hint {
  font-size: 0.76rem;
  color: var(--muted);
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}

.viewer-count {
  font-size: 0.78rem;
  color: var(--muted);
}

.chat-messages {
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.chat-msg {
  background: var(--elevated);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.84rem;
  line-height: 1.35;
}

.chat-msg-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.chat-msg-sender {
  font-weight: 600;
  color: var(--text);
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.85rem;
}

.btn-chat-send {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.btn-icon-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ctrl-text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.unmute-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.paired-devices-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.paired-device-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #86efac;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

.paired-empty {
  font-size: 0.82rem;
  color: var(--muted);
}

.chat-empty-hint {
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
  padding: 20px 10px;
}

.remote-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.remote-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.remote-tab.active {
  background: var(--elevated);
  color: var(--text);
  border-color: var(--live);
}

.remote-pad-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.remote-media-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.remote-media-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 10px;
  font-size: 0.86rem;
}

.pad-mode-switch {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.pad-mode-switch .btn-pill.active {
  background: var(--elevated);
  border-color: var(--live);
}

.dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(3, 68px);
  gap: 10px;
  justify-content: center;
  margin: 4px auto;
}

.dpad-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}

.dpad-btn:active {
  background: var(--elevated);
  border-color: var(--live);
}

.dpad-ok {
  background: var(--live);
  border-color: var(--live);
  color: #fff;
}

.touchpad-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.touchpad-surface {
  width: 100%;
  height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
}

.touchpad-click-btn {
  width: 100%;
  padding: 14px;
}

.virtual-cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2147483647;
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  transition: transform 35ms linear;
  will-change: transform;
}

#playerBox.cursor-hidden,
#playerBox.cursor-hidden video {
  cursor: none !important;
}

body.virtual-mouse-active,
body.virtual-mouse-active * {
  cursor: none !important;
}

.fs-upgrade-overlay {
  position: absolute;
  inset: 0;
  z-index: 95;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  padding: 0 20px 84px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  outline: none !important;
}

.fs-upgrade-overlay.hidden {
  display: none !important;
}

.fs-upgrade-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 10, 12, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #f4f4f6;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}

.fs-upgrade-overlay:focus-visible .fs-upgrade-pill {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35), 0 8px 28px rgba(0, 0, 0, 0.65);
}

.cursor-ring {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid #ffffff;
  opacity: 0;
  transform: scale(0.5);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.fs-only-btn {
  display: none;
}

.player-box:fullscreen .fs-only-btn,
.player-box:-webkit-full-screen .fs-only-btn,
.player-box.pseudo-fullscreen .fs-only-btn {
  display: inline-flex;
}

.ctrl-btn.off {
  opacity: 0.45;
  text-decoration: line-through;
}

.fs-chat-feed {
  display: none;
  position: absolute;
  left: 14px;
  bottom: 66px;
  z-index: 25;
  pointer-events: none;
  flex-direction: column;
  gap: 6px;
  max-width: min(360px, 75vw);
  opacity: 0;
  transition: opacity 0.8s ease;
}

.player-box:fullscreen .fs-chat-feed,
.player-box:-webkit-full-screen .fs-chat-feed,
.player-box.pseudo-fullscreen .fs-chat-feed {
  display: flex;
}

.fs-chat-feed.fs-chat-disabled {
  display: none !important;
}

.fs-chat-feed.visible {
  opacity: 1;
  transition: opacity 0.15s ease;
}

.fs-chat-pill {
  background: rgba(10, 10, 12, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.84rem;
  line-height: 1.3;
  word-break: break-word;
}

.fs-chat-compose {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 66px;
  z-index: 26;
  display: flex;
  gap: 8px;
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.fs-chat-compose input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.88rem;
}

.btn-fs-send {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 768px) {
  .app {
    padding: 14px 14px 28px;
  }

  #qrCard {
    display: none !important;
  }

  .saved-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .saved-chip {
    flex-shrink: 0;
  }

  .player-box {
    margin-left: -14px;
    margin-right: -14px;
    width: calc(100% + 28px);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .chat-card {
    display: none;
  }

  body.mobile-chat-open {
    overflow: hidden;
  }

  body.mobile-chat-open .app {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    padding: 0;
  }

  body.mobile-chat-open .topbar,
  body.mobile-chat-open #streamSection,
  body.mobile-chat-open #reconnectBar,
  body.mobile-chat-open #bannedBanner {
    display: none !important;
  }

  body.mobile-chat-open .main,
  body.mobile-chat-open .workspace-grid {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  body.mobile-chat-open .player-column {
    flex-shrink: 0;
  }

  body.mobile-chat-open .player-box {
    margin: 0;
    width: 100%;
  }

  body.mobile-chat-open .side-column {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.mobile-chat-open .chat-card {
    display: flex !important;
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border);
  }

  body.mobile-chat-open .chat-messages {
    flex: 1;
    height: auto;
  }

  body.mobile-chat-open .mobile-chat-close {
    display: inline-flex !important;
  }
}

.cursor-ring.flash {
  opacity: 1;
  transform: scale(1.4);
}

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

@media (max-width: 680px) {
  .volume-slider {
    display: none;
  }

  .ctrl-text-btn .btn-label {
    display: none;
  }

  .ctrl-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .ctrl-title {
    max-width: 90px;
  }
}

@media (max-width: 520px) {
  .ctrl-title {
    display: none;
  }

  .input-bar {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}
