:root {
  --bg: #0b0b0f;
  --bg-elev: #14141b;
  --bg-card: #1a1a24;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f4f7;
  --muted: #9a9aab;
  --accent: #e11d48;
  --accent-soft: rgba(225, 29, 72, 0.18);
  --live: #22c55e;
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

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

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

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

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

img {
  display: block;
  max-width: 100%;
}

.view {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ——— Login ——— */
.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(225, 29, 72, 0.28), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(34, 197, 94, 0.12), transparent 50%),
    linear-gradient(160deg, #0b0b0f 0%, #151520 50%, #0b0b0f 100%);
}

.login-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M0 60V0h60' fill='none' stroke='rgba(255,255,255,0.03)' stroke-width='1'/%3E%3C/svg%3E");
  opacity: 0.9;
}

.login-card {
  position: relative;
  width: min(400px, 100%);
  padding: 36px 32px;
  background: rgba(20, 20, 27, 0.85);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.brand {
  text-align: center;
  margin-bottom: 8px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #fb7185);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.04em;
  box-shadow: 0 10px 28px rgba(225, 29, 72, 0.4);
}

.brand-mark.sm {
  width: 36px;
  height: 36px;
  margin: 0;
  border-radius: 10px;
  font-size: 0.8rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand h1 em {
  font-style: normal;
  color: var(--accent);
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.field span {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  border-color: rgba(225, 29, 72, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-error {
  margin: 0;
  color: #fb7185;
  font-size: 0.85rem;
  text-align: center;
}

.btn-primary {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), #fb7185);
  color: #fff;
  font-weight: 700;
  padding: 13px 18px;
  border-radius: 12px;
  transition: transform 0.15s, filter 0.15s;
}

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

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

.btn-primary.sm {
  padding: 10px 16px;
  font-size: 0.9rem;
}

.btn-ghost {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.btn-ghost.sm {
  padding: 4px 10px;
  font-size: 1.1rem;
}

/* ——— Home ——— */
.home-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(11, 11, 15, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-left strong {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--muted);
}

.search-wrap input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--text);
}

.home-main {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.cats {
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 65px;
  align-self: start;
  max-height: calc(100dvh - 65px);
  overflow: auto;
}

.cat-btn {
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.cat-btn:hover,
.cat-btn.active {
  background: var(--accent-soft);
  color: #fff;
}

.content {
  padding: 20px 24px 40px;
  overflow: auto;
  min-height: 0;
  height: 100%;
}

.content-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}

.content-head h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.status-bar {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac;
  font-size: 0.9rem;
}

.status-bar.error {
  background: rgba(225, 29, 72, 0.12);
  border-color: rgba(225, 29, 72, 0.3);
  color: #fda4af;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.channel-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  animation: rise 0.4s ease both;
}

.channel-card:hover {
  transform: translateY(-4px);
  border-color: rgba(225, 29, 72, 0.45);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.channel-thumb {
  aspect-ratio: 16 / 10;
  background: #0e0e14;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.channel-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.channel-thumb .fallback {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, #2a2a38, #1a1a24);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--muted);
}

.card-live {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 6px;
}

.card-viewers {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #e8e8ef;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
}

.card-viewers svg {
  flex-shrink: 0;
  opacity: 0.9;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: live-blink 1.4s ease-in-out infinite;
}

@keyframes live-blink {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  }
  50% {
    opacity: 0.35;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
}

.channel-meta {
  padding: 12px;
}

.channel-meta strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

.channel-meta .card-src {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  color: #6ee7b7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ——— Player ——— */
.player-view {
  background: #000;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.player-shell {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.player-stage {
  position: relative;
  background: #000;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.stream-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  z-index: 1;
}

.player-chrome {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  pointer-events: none;
}

.player-chrome .ctrl-btn,
.player-chrome .back-btn {
  pointer-events: auto;
}

.player-chrome .back-btn {
  position: static;
  margin-right: auto;
}

.chrome-mid {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.chrome-np {
  pointer-events: none;
  min-width: 0;
}

.https-gate {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(229, 9, 20, 0.25), transparent 55%),
    #0b0b0f;
}

.https-card {
  width: min(420px, 100%);
  text-align: center;
  padding: 36px 28px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(20, 20, 27, 0.9);
}

.https-card h1 {
  margin: 12px 0 8px;
  font-size: 2rem;
  font-weight: 800;
}

.https-card h1 em {
  font-style: normal;
  color: var(--accent);
}

.https-card p {
  color: var(--muted);
  margin-bottom: 10px;
}

.https-card .btn-primary {
  display: inline-flex;
  margin-top: 16px;
  text-decoration: none;
}

.player-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.55) 0%,
    transparent 28%,
    transparent 62%,
    rgba(0, 0, 0, 0.75) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.player-stage.show-controls .player-overlay,
.player-stage.is-loading .player-overlay,
.player-stage.has-error .player-overlay {
  opacity: 1;
  pointer-events: auto;
}

.live-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  pointer-events: none;
}

.live-badge .viewer-sep {
  opacity: 0.45;
  letter-spacing: 0;
}

.live-badge .viewer-count {
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: #d4d4dd;
}

.live-badge .live-dot {
  width: 10px;
  height: 10px;
}

.overlay-top {
  display: flex;
  justify-content: flex-end;
}

.back-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--line);
  font-size: 1.2rem;
}

.center-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: auto 0;
}

.ctrl-btn {
  color: #fff;
  padding: 8px;
  border-radius: 10px;
  transition: background 0.15s, transform 0.15s;
}

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

.ctrl-btn.round {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 1.1rem;
}

.ctrl-btn.round.play {
  width: 68px;
  height: 68px;
  background: rgba(225, 29, 72, 0.9);
  border-color: transparent;
  font-size: 1.35rem;
  box-shadow: 0 8px 24px rgba(225, 29, 72, 0.4);
}

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.now-playing img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: #1a1a24;
}

.now-playing strong {
  display: block;
  font-size: 1rem;
}

.bottom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.volume {
  width: 90px;
  accent-color: var(--accent);
}

.player-loading,
.player-error {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 12px;
  justify-items: center;
  background: rgba(0, 0, 0, 0.55);
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.player-error {
  pointer-events: auto;
}

.player-error .btn-primary,
.player-error .btn-ghost {
  pointer-events: auto;
}

.unmute-fab {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: auto;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.player-error-url {
  max-width: 90%;
  font-size: 0.72rem;
  word-break: break-all;
  color: #a1a1aa;
  margin: 0;
}

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

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

.up-next {
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  padding: 16px 12px;
  overflow: auto;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.up-next h3 {
  margin: 0 8px 12px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.up-next-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.up-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  text-align: left;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.up-item:hover,
.up-item.active {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.up-item.active {
  border-color: rgba(225, 29, 72, 0.45);
  background: var(--accent-soft);
}

.up-item img,
.up-fallback {
  width: 48px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  background: #0e0e14;
  flex-shrink: 0;
}

.up-fallback {
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.up-item strong {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.up-item .up-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.up-item .up-viewers {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.68rem;
  color: #a3e635;
  font-weight: 600;
  white-space: nowrap;
}

.up-item span {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ——— Responsive ——— */
@media (max-width: 900px) {
  .home-main {
    grid-template-columns: 1fr;
  }

  .cats {
    position: static;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding: 12px 16px;
    gap: 6px;
  }

  .cat-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .player-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 38dvh;
    height: 100dvh;
  }

  .player-stage {
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
  }

  .up-next {
    border-left: 0;
    border-top: 1px solid var(--line);
    height: 100%;
    max-height: none;
  }

  .ctrl-btn.round {
    width: 44px;
    height: 44px;
  }

  .ctrl-btn.round.play {
    width: 56px;
    height: 56px;
  }

  .bottom-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
  }

  .search-wrap {
    order: 3;
    max-width: none;
    width: 100%;
  }

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

  .volume {
    width: 60px;
  }

  .content {
    padding: 16px;
  }
}
