:root {
  --bg: #0b0d12;
  --bg-elev: #121723;
  --bg-elev-2: #171d2b;
  --panel: rgba(20, 26, 38, 0.92);
  --panel-strong: rgba(10, 14, 22, 0.96);
  --text: #f5f7fb;
  --muted: #aab3c5;
  --soft: #7e8798;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #e53935;
  --accent-2: #ff5a56;
  --success: #39d98a;
  --warning: #ffb020;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --radius-sm: 12px;
  --topbar-h: 68px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #0a0c11 0%, #0d1017 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100%;
}

body {
  min-height: 100vh;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

/* =========================================================
   APP SHELL
========================================================= */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: rgba(8, 11, 18, 0.84);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.topbar__logo-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.topbar__brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

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

.topbar__nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 999px;
  transition: 0.2s ease;
}

.topbar__nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.topbar__nav-item--active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

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

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.player-column {
  min-width: 0;
}

.chat-sidebar {
  min-width: 0;
  width: 100%;
}

/* =========================================================
   BUTTONS
========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 10px 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  transition: 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
}

.btn--primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: #fff;
}

.btn--primary:hover {
  filter: brightness(1.05);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.03);
}

.btn--sm {
  padding: 8px 12px;
  font-size: 0.92rem;
}

.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
}

/* =========================================================
   PLAYER
========================================================= */

.player-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.video,
.player-skeleton,
.buffering,
.error-overlay,
.controls {
  position: absolute;
  inset: 0;
}

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

/* =========================================================
   PLAYER OVERLAYS
========================================================= */

.overlay {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.overlay--top-left {
  top: 14px;
  left: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.overlay--top-right {
  top: 14px;
  right: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
}

.badge--live {
  color: #fff;
  background: rgba(229, 57, 53, 0.95);
}

.badge__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.08);
}

.viewer-pill,
.quality-badge,
.ws-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
}

.viewer-pill__icon {
  width: 16px;
  height: 16px;
}

.quality-badge {
  min-width: 48px;
  justify-content: center;
}

.ws-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.ws-status--connecting {
  color: var(--warning);
}

.ws-status--connected {
  color: var(--success);
}

.ws-status--disconnected {
  color: #ff6b6b;
}

/* =========================================================
   SKELETON / BUFFERING / ERROR
========================================================= */

.player-skeleton {
  z-index: 6;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.08), transparent 35%),
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.player-skeleton.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.player-skeleton__spinner,
.buffering__spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.14);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}

.buffering {
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.error-overlay {
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: rgba(4, 7, 12, 0.84);
  backdrop-filter: blur(8px);
}

.error-overlay__icon {
  width: 44px;
  height: 44px;
  color: #ff7d7d;
}

.error-overlay__title {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
}

.error-overlay__message {
  margin: 0;
  color: var(--muted);
  max-width: 420px;
  line-height: 1.5;
}

/* =========================================================
   CONTROLS
========================================================= */

.controls {
  z-index: 7;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 14px;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.04) 45%,
    rgba(0, 0, 0, 0.72) 100%
  );
}

.controls__progress-area {
  margin-bottom: 12px;
}

.progress-bar {
  position: relative;
  height: 6px;
  width: 100%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.progress-bar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.progress-bar__live-indicator {
  position: absolute;
  right: 0;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transform: translate(50%, -50%);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.18);
}

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

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

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  transition: 0.2s ease;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.ctrl-btn--text {
  width: 42px;
  padding: 0;
}

.ctrl-btn__icon {
  width: 20px;
  height: 20px;
}

.ctrl-btn__icon--pause,
.ctrl-btn__icon--vol-off,
.ctrl-btn__icon--shrink {
  display: none;
}

.player-wrapper.playing .ctrl-btn__icon--play {
  display: none;
}

.player-wrapper.playing .ctrl-btn__icon--pause {
  display: block;
}

.player-wrapper.muted .ctrl-btn__icon--vol-on {
  display: none;
}

.player-wrapper.muted .ctrl-btn__icon--vol-off {
  display: block;
}

.player-wrapper.fullscreen .ctrl-btn__icon--expand {
  display: none;
}

.player-wrapper.fullscreen .ctrl-btn__icon--shrink {
  display: block;
}

.volume-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.volume-slider-wrap {
  width: 90px;
}

.volume-slider {
  width: 100%;
  accent-color: var(--accent);
}

.time-display {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.quality-menu-wrap {
  position: relative;
}

.quality-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  min-width: 120px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.quality-menu__item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
}

.quality-menu__item:hover,
.quality-menu__item--active {
  background: rgba(255, 255, 255, 0.08);
}

/* =========================================================
   STREAM META
========================================================= */

.stream-meta {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(18, 23, 35, 0.78);
  backdrop-filter: blur(8px);
}

.stream-meta__header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.stream-meta__avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(180deg, #38445f, #202b40);
  color: #fff;
}

.stream-meta__info {
  min-width: 0;
  flex: 1 1 auto;
}

.stream-meta__title {
  margin: 0 0 6px;
  font-size: 1.45rem;
  line-height: 1.25;
}

.stream-meta__channel-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
}

.stream-meta__channel {
  font-weight: 700;
  color: var(--text);
}

.stream-meta__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.stream-meta__description {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.stream-meta__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.88rem;
}

/* =========================================================
   CHAT
========================================================= */

.chat-sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(18, 23, 35, 0.88);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

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

.chat-header__title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.chat-header__icon {
  width: 18px;
  height: 18px;
}

.chat-header__toggle {
  flex: 0 0 auto;
}

.chat-body {
  height: 420px;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  line-height: 1.45;
  word-break: break-word;
  color: var(--text);
}

.chat-msg__author {
  font-weight: 800;
}

.chat-msg__text {
  color: var(--text);
}

.chat-msg--system {
  color: var(--muted);
  font-style: italic;
}

.chat-footer {
  border-top: 1px solid var(--border);
  padding: 14px 16px 16px;
}

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

.chat-input,
.chat-name-input {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}

.chat-input::placeholder,
.chat-name-input::placeholder {
  color: var(--soft);
}

.chat-input:focus,
.chat-name-input:focus {
  border-color: rgba(255, 255, 255, 0.18);
}

.chat-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.chat-name-label {
  color: var(--muted);
  font-size: 0.92rem;
  flex: 0 0 auto;
}

/* =========================================================
   MOBILE FAB / TOASTS
========================================================= */

.mobile-chat-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 95;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  display: none;
  place-items: center;
  color: #fff;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: var(--shadow);
}

.mobile-chat-fab svg {
  width: 24px;
  height: 24px;
}

.mobile-chat-fab__badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  background: #fff;
  color: #000;
  font-size: 0.74rem;
  font-weight: 800;
}

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast--success {
  border-color: rgba(57, 217, 138, 0.3);
}

.toast--error {
  border-color: rgba(255, 107, 107, 0.3);
}

.toast.removing {
  animation: toast-out 0.18s ease forwards;
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 1100px) {
  .main {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

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

  .topbar__nav {
    display: none;
  }

  .main {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px;
  }

  .player-wrapper {
    border-radius: 16px;
  }

  .stream-meta {
    margin-top: 14px;
    padding: 14px;
  }

  .stream-meta__header {
    flex-wrap: wrap;
  }

  .stream-meta__actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-sidebar {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    width: min(92vw, 400px);
    max-width: 100%;
    border-radius: 18px 0 0 0;
    transform: translateX(100%);
    transition: transform 0.26s ease;
    z-index: 90;
  }

  .chat-sidebar.mobile-open {
    transform: translateX(0);
  }

  .chat-body {
    height: calc(100vh - var(--topbar-h) - 160px);
  }

  .mobile-chat-fab {
    display: grid;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 10px;
  }

  .topbar__brand {
    font-size: 0.98rem;
  }

  .topbar__actions .btn {
    padding: 8px 10px;
  }

  .player-wrapper {
    border-radius: 14px;
  }

  .overlay--top-left,
  .overlay--top-right {
    top: 10px;
  }

  .overlay--top-left {
    left: 10px;
    gap: 8px;
  }

  .overlay--top-right {
    right: 10px;
    gap: 8px;
  }

  .badge,
  .viewer-pill,
  .quality-badge,
  .ws-status {
    height: 30px;
    padding: 0 10px;
    font-size: 0.78rem;
  }

  .controls {
    padding: 10px;
  }

  .controls__row {
    gap: 8px;
  }

  .controls__group {
    gap: 8px;
  }

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

  .ctrl-btn__icon {
    width: 18px;
    height: 18px;
  }

  .volume-slider-wrap {
    width: 72px;
  }

  .time-display {
    font-size: 0.82rem;
  }

  .stream-meta__title {
    font-size: 1.18rem;
  }

  .stream-meta__avatar {
    width: 46px;
    height: 46px;
  }
}

/* =========================================================
   LANDSCAPE MOBILE = PLAYER FIRST
========================================================= */

@media (max-width: 932px) and (orientation: landscape) {
  .topbar {
    display: none;
  }

  .main {
    display: block;
    padding: 0;
    width: 100%;
    max-width: none;
  }

  .player-column {
    width: 100%;
  }

  .player-wrapper {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    border-radius: 0;
  }

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

  .stream-meta {
    display: none;
  }

  .chat-sidebar:not(.mobile-open) {
    display: none;
  }

  .chat-sidebar.mobile-open {
    top: 0;
    width: min(86vw, 380px);
    height: 100vh;
    border-radius: 18px 0 0 18px;
  }

  .chat-body {
    height: calc(100vh - 152px);
  }

  .mobile-chat-fab {
    bottom: 12px;
    right: 12px;
  }
}

/* =========================================================
   SCROLLBAR
========================================================= */

.chat-body::-webkit-scrollbar {
  width: 10px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

/* =========================================================
   ANIMATIONS
========================================================= */

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

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

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