/* ===== 变量与基础 ===== */
:root {
  --bg: #0f0f12;
  --surface: #18181c;
  --surface-elevated: #1f1f24;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 8px;
  --radius-sm: 6px;
  --font-sans: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  --safe-right: env(safe-area-inset-right, 0);
}

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

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== 主布局：上播放器 + 下评论（手机优先） ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100vh;
  overflow: hidden;
}

.page-header {
  flex-shrink: 0;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.page-header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.02em;
}

/* 上半部分：播放器 */
.player-section {
  flex: 4.5 1 0;
  min-height: 0;
  width: 100%;
  padding: 0 8px 8px;
  background: var(--bg);
  display: flex;
}

.player-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.player-wrap .video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.room-preview {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 12px 34px;
  background: rgba(0, 0, 0, 0.58);
}

.room-preview.hidden {
  display: none !important;
}

.room-preview-card {
  position: relative;
  width: min(92%, 420px);
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(147, 197, 253, 0.5);
  background: radial-gradient(circle at 20% 15%, #1f2937 0%, #0f172a 60%, #020617 100%);
  box-shadow: 0 12px 26px rgba(2, 6, 23, 0.45);
}

.room-preview-card.no-image {
  display: flex;
  align-items: center;
  justify-content: center;
}

.room-preview-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-preview-image.hidden {
  display: none !important;
}

.room-preview-text-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.78) 30%, rgba(0, 0, 0, 0.88));
}

.room-preview-card.no-image .room-preview-text-wrap {
  position: static;
  padding: 14px;
  background: transparent;
}

.room-preview-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: #f1f5f9;
  word-break: break-word;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.room-preview-card.no-image .room-preview-text {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: #e2e8f0;
  text-shadow: none;
}

/* 全屏时播放器占满屏幕 */
.player-wrap:fullscreen {
  max-height: none;
  aspect-ratio: auto;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

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

.player-wrap:-webkit-full-screen {
  max-height: none;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

/* 全屏按钮 */
.btn-fullscreen,
.btn-exit-fullscreen {
  position: absolute;
  bottom: 6px;
  right: 8px;
  z-index: 6;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-fullscreen:hover,
.btn-exit-fullscreen:hover {
  background: rgba(0, 0, 0, 0.75);
}

.btn-fullscreen .icon-fullscreen,
.btn-exit-fullscreen .icon-exit-fullscreen {
  width: 17px;
  height: 17px;
}

.btn-exit-fullscreen.hidden {
  display: none !important;
}

.player-wrap:fullscreen .btn-fullscreen,
.player-wrap:-webkit-full-screen .btn-fullscreen {
  display: none;
}

.player-wrap:fullscreen .btn-exit-fullscreen,
.player-wrap:-webkit-full-screen .btn-exit-fullscreen {
  display: flex !important;
  bottom: 8px;
  right: 8px;
}

.audio-controls {
  position: absolute;
  right: 48px;
  bottom: 6px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
}

.audio-controls.hidden {
  display: none !important;
}

.btn-audio-toggle {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 999px;
  min-width: 56px;
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
  line-height: 24px;
  cursor: pointer;
}

.btn-audio-toggle:hover {
  background: rgba(255, 255, 255, 0.26);
}

.audio-volume-range {
  width: 86px;
  accent-color: #60a5fa;
  cursor: pointer;
}

.audio-volume-range:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 520px) {
  .audio-volume-range {
    width: 72px;
  }
}

/* 伪全屏兜底（不支持原生全屏时） */
body.pseudo-fullscreen-active {
  overflow: hidden;
}

body.pseudo-fullscreen-active .page-header,
body.pseudo-fullscreen-active .comment-section,
body.pseudo-fullscreen-active .player-meta {
  display: none !important;
}

body.pseudo-fullscreen-active .player-section {
  padding: 0 !important;
}

body.pseudo-fullscreen-active .player-wrap {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  aspect-ratio: auto !important;
  border-radius: 0 !important;
  z-index: 9999 !important;
}

body.pseudo-fullscreen-active .player-wrap .video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 播放器下方：地址栏（紧凑） */
.player-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.stream-url {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

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

.stream-url:focus {
  border-color: var(--primary);
}

/* 保存到本地（图标按钮） */
.btn-add-to-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-add-to-home-header {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
}

.btn-add-to-home:hover {
  border-color: var(--primary);
  background: var(--surface-elevated);
}

.icon-add-to-home {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-add-to-home-label {
  white-space: nowrap;
}

@media (max-width: 400px) {
  .btn-add-to-home-label {
    display: none;
  }
  .btn-add-to-home {
    padding: 8px 10px;
  }
}

/* 保存到桌面弹层 */
.add-to-home-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
}

.add-to-home-modal.hidden {
  display: none !important;
}

.add-to-home-modal-content {
  width: 100%;
  max-width: 340px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.add-to-home-message {
  margin: 0 0 16px 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.add-to-home-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== 按钮 ===== */
.btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

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

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

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

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

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

/* ===== 遮罩（加载中） ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.overlay-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== 错误框 ===== */
.error-box {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.85);
  z-index: 3;
}

.error-box.hidden {
  display: none;
}

.error-text {
  margin: 0;
  font-size: 13px;
  color: #fca5a5;
  text-align: center;
  max-width: 100%;
}

/* ===== 状态栏 ===== */
.status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 48px 6px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  z-index: 1;
}

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

.status-text.error {
  color: var(--danger);
}

.latency-text {
  opacity: 0.9;
}

.online-count-wrap {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.online-count-text {
  font-weight: 600;
  color: var(--text);
}

.online-count-label {
  font-size: 10px;
  color: var(--text-muted);
}

/* ===== 下半部分：评论区 ===== */
.comment-section {
  flex: 5.5 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: var(--safe-bottom);
}

.comment-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.comment-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.nickname-label {
  font-size: 12px;
  color: var(--text-muted);
}

.user-huaming {
  font-size: 12px;
  color: var(--primary);
  margin-right: auto;
}

.comment-item .comment-time {
  color: var(--text-muted);
  font-weight: normal;
  margin-left: 4px;
}

.comment-count {
  font-size: 12px;
  color: var(--text-muted);
}

.comment-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
}

.comment-empty {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
}

.comment-announcement {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid #7c2d12;
  border-radius: var(--radius-sm);
  background: rgba(251, 146, 60, 0.15);
  color: #fed7aa;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
}

.comment-announcement.hidden {
  display: none !important;
}

.comment-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.45;
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-item .comment-user {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.comment-item.comment-item-admin .comment-user {
  color: #fbbf24;
  font-weight: 600;
}

.comment-item .comment-body {
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

.comment-form-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.comment-rate-limit-tip {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
  text-align: center;
}

.comment-rate-limit-tip.hidden {
  display: none !important;
}

.comment-rate-limit-count {
  display: inline-block;
  min-width: 1.2em;
  text-align: center;
  font-weight: 700;
}

.comment-rate-limit-count-pop {
  animation: comment-count-pop 0.35s ease-out;
}

@keyframes comment-count-pop {
  0% {
    transform: scale(1.4);
    opacity: 0.9;
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.comment-form-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.comment-send-state {
  margin: 2px 2px 0;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
  transition: opacity 0.2s ease;
}

.comment-send-state.hidden {
  opacity: 0;
}

.comment-send-state.pending {
  color: #93c5fd;
}

.comment-send-state.success {
  color: #86efac;
}

.comment-send-state.error {
  color: #fca5a5;
}

.comment-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

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

.comment-input:focus {
  border-color: var(--primary);
}

.btn-send {
  flex-shrink: 0;
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 14px;
}

.btn-send:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-send:disabled {
  opacity: 0.5;
}

/* ===== 工具类 ===== */
.hidden {
  display: none !important;
}

/* 桌面端：限制最大宽度，保持比例 */
@media (min-width: 600px) {
  body {
    padding: 0;
  }

  .app {
    max-width: 480px;
    margin: 0 auto;
    max-height: 90vh;
    height: 90vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  }

  .player-section {
    padding: 10px 10px 8px;
  }

  .player-wrap {
    min-height: 0;
  }

  .comment-section {
    border-radius: 0 0 var(--radius) var(--radius);
  }
}

@media (max-width: 520px) {
  .room-preview-card {
    width: min(94%, 380px);
  }
  .room-preview-card.no-image .room-preview-text {
    font-size: 16px;
  }
}
