:root {
  --bg: #0b0b0d;
  --surface: rgba(15, 15, 18, 0.4);
  --surface-raised: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.05);
  --border-hover: rgba(255, 255, 255, 0.1);
  --accent: #e2a654;
  --accent-hover: #f0bd7a;
  --accent-subtle: rgba(226, 166, 84, 0.1);
  --live: #e85d75;
  --text-primary: #fafafa;
  --text-secondary: #9a9aa0;
  --text-muted: #56565c;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 260px;
  --header-h: 60px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ───────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ── Sidebar ──────────────────────────── */

.sidebar {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.sidebar-top {
  padding: 24px 20px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  user-select: none;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(232, 93, 117, 0.15);
  animation: brand-pulse 2s ease-in-out infinite;
}

@keyframes brand-pulse {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(232, 93, 117, 0.15);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(232, 93, 117, 0.04);
  }
}

.brand-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: block;
}

.sidebar-channels {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-channels::-webkit-scrollbar {
  width: 6px;
}

.sidebar-channels::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-channels::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
  transition: background 0.15s var(--ease);
}

.sidebar-channels::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

.channel-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.12s var(--ease), opacity 0.6s var(--ease);
  margin-bottom: 4px;
  position: relative;
  animation: channel-fade-in 0.32s var(--ease) backwards;
}

@keyframes channel-fade-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.channel-card:hover {
  background: var(--surface-raised);
}

.channel-card:active {
  transform: scale(0.98);
}

.channel-card:focus {
  outline: none;
}

.channel-card:focus-visible {
  background: var(--surface-raised);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.channel-card.is-active {
  background: var(--accent-subtle);
}

/* 正在播放：左侧 3px 胶囊状竖条，带柔光，标识"this one is live for you" */
.channel-card.is-active::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(226, 166, 84, 0.45);
}

.channel-card.is-active .channel-info .name {
  color: var(--accent);
  font-weight: 700;
}

.channel-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  position: relative;
}

.channel-info {
  min-width: 0;
}

.channel-info .name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-info .uid {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Status Indicator ─────────────────── */

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  position: absolute;
  right: -2px;
  bottom: -2px;
  border: 2px solid var(--bg);
  /* 颜色平滑过渡，避免轮询时的跳变 */
  transition: background-color 0.6s var(--ease), opacity 0.6s var(--ease);
}

.status-indicator.is-online {
  background: #4ade80;
  animation: status-breath 3s ease-in-out infinite;
}

@keyframes status-breath {
  0%, 100% { opacity: 0.82; }
  50% { opacity: 1; }
}

.status-indicator.is-offline {
  background: var(--text-muted);
  opacity: 0.6;
}

/* 检测中：仅在首次加载时出现，柔和的呼吸效果 */
.status-indicator.is-checking {
  background: var(--accent);
  animation: status-checking 1.6s ease-in-out infinite;
}

@keyframes status-checking {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* 离线频道整体置灰，过渡平滑 */
.channel-card.is-offline {
  opacity: 0.5;
}

.channel-card.is-offline:hover {
  opacity: 0.85;
}

.channel-card.is-offline .channel-avatar {
  filter: grayscale(0.6);
  transition: filter 0.6s var(--ease);
}

.channel-card .channel-avatar {
  transition: filter 0.6s var(--ease);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
}

/* ── Main ─────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

/* ── Header ───────────────────────────── */

.header {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 12px;
  gap: 16px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger {
  display: none;
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
}

.hamburger svg {
  width: 20px;
  height: 20px;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.search-bar {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 0 16px;
  font-family: inherit;
  min-width: 0;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.btn-clear {
  display: none;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 4px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.btn-clear svg {
  width: 14px;
  height: 14px;
}

.btn-clear:hover {
  background: var(--surface-raised);
  color: var(--text-secondary);
}

.btn-clear.is-visible {
  display: flex;
}

.btn-play {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #0b0b0d;
  border: none;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn-play:hover {
  background: var(--accent-hover);
}

.btn-play:active {
  transform: scale(0.96);
}

.btn-play svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.header-right {
  flex-shrink: 0;
}

/* ── Player ────────────────────────────── */

.player-area {
  flex: 1;
  margin: 0 12px 12px;
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}

#dplayer {
  width: 100% !important;
  height: 100% !important;
  transition: filter 0.3s var(--ease);
}

.player-area.is-switching #dplayer {
  filter: brightness(0.4) blur(6px);
}

/* ── Portal ────────────────────────────── */

.portal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
  transition: opacity 0.5s var(--ease), visibility 0.5s var(--ease);
}

.portal.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.portal-inner {
  text-align: center;
  max-width: 380px;
  padding: 0 24px;
}

.portal-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 0 60px rgba(226, 166, 84, 0.18), 0 0 0 1px rgba(226, 166, 84, 0.12);
}

.portal-icon svg {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.portal h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.portal p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

.portal .error-detail {
  color: var(--live);
}

.portal .error-tip {
  display: block;
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.portal-quicks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}

.portal-quick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease);
}

.portal-quick:hover {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.portal-quick:active {
  transform: scale(0.96);
}

.portal-quick-emoji {
  font-size: 0.95rem;
}

/* ── DPlayer Overrides ─────────────────── */

.dplayer-controller {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent) !important;
}

.dplayer-bar-wrap .dplayer-bar {
  height: 3px !important;
  border-radius: 0 !important;
  transition: height 0.15s var(--ease);
}

.dplayer-bar-wrap:hover .dplayer-bar {
  height: 5px !important;
}

/* ── Sidebar Overlay (mobile) ──────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), visibility 0.3s var(--ease);
}

.sidebar-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Responsive ────────────────────────── */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: 280px;
    z-index: 1000;
    transition: left 0.3s var(--ease);
  }

  .sidebar.is-open {
    left: 0;
  }

  .sidebar-overlay {
    display: block;
  }

  .hamburger {
    display: flex;
    background: transparent;
    border: none;
    padding: 0;
  }

  .header {
    padding: 0 8px;
  }

  .player-area {
    margin: 0 8px 8px;
  }
}

@media (max-width: 600px) {
  .header {
    padding: 0 8px;
    gap: 10px;
  }

  .search {
    justify-content: flex-end;
  }

  .btn-play span {
    display: none;
  }

  .btn-play {
    padding: 9px 12px;
  }

  .player-area {
    margin: 0 0 8px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .header {
    position: fixed;
    top: 0;
    left: 0;
    height: 0;
    padding: 0;
    z-index: 200;
  }

  .player-area {
    margin: 0;
    border-radius: 0;
    border: none;
  }

  .search,
  .header-right {
    display: none;
  }

  .hamburger {
    display: flex;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 36px;
    height: 36px;
    background: rgba(15, 15, 18, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-primary);
  }

  .hamburger svg {
    width: 18px;
    height: 18px;
  }
}

#toast {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 20, 25, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  padding: 16px 32px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s var(--ease);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}

#toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

#toast.is-loading::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid rgba(226, 166, 84, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: toast-spin 0.8s linear infinite;
}

@keyframes toast-spin {
  to { transform: rotate(360deg); }
}

/* ── Unmute Hint ─────────────────────── */

.unmute-hint {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px 9px 12px;
  background: rgba(15, 15, 18, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-hover);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), visibility 0.3s var(--ease), background 0.15s var(--ease);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.unmute-hint.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.unmute-hint:hover {
  background: rgba(25, 25, 30, 0.92);
  border-color: var(--accent);
}

.unmute-hint:active {
  transform: translateY(0) scale(0.96);
}

.unmute-hint svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

#toast strong {
  color: var(--accent);
  font-size: 1.1rem;
  display: block;
  font-weight: 700;
}
