/* ==================== 基础样式 ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ==================== 主容器布局 ==================== */
#app-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column; /* 移动端：竖向堆叠 */
  overflow: hidden;
}

/* 播放器区域 */
#player-section {
  position: relative;
  width: 100%;
  flex: 0 0 auto; /* 移动端：固定高度 */
  height: 0;
  padding-bottom: 56.25%; /* 16:9 宽高比 */
  background: #000;
  overflow: hidden;
  min-height: 200px;
  max-height: 60vh; /* 移动端最多占60%屏幕高度 */
}

/* DPlayer 容器 */
#dplayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  background: #000;
}

/* 强制 DPlayer 内部元素填充 */
#dplayer .dplayer-video-wrap {
  width: 100% !important;
  height: 100% !important;
}

#dplayer video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

#freeze-canvas {
  position: absolute;
  inset: 0;
  z-index: 9999;
  display: none;
  width: 100%;
  height: 100%;
  background: #000;
  cursor: default;
  pointer-events: auto;
}

#player-section.is-frozen #freeze-canvas {
  display: block;
}

/* 自定义弹幕覆盖层 */
#danmaku-overlay {
  position: absolute;
  inset: 0;
  z-index: 10000;
  overflow: hidden;
  pointer-events: none;
}

.custom-danmaku {
  position: absolute;
  right: 12px;
  display: inline-block;
  max-width: 70%;
  color: #fff;
  font-size: clamp(18px, 2.2vw, 30px);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow:
    1px 1px 2px rgba(0, 0, 0, 0.9),
    -1px -1px 2px rgba(0, 0, 0, 0.75),
    0 0 4px rgba(0, 0, 0, 0.8);
  will-change: transform;
  animation-name: danmakuMove;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes danmakuMove {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(-100vw - 100% - 24px));
  }
}

/* 右上角实时时钟 */
#live-clock {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  z-index: 10001;
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: clamp(13px, 1.5vw, 20px);
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#player-section.is-frozen #live-clock {
  background: rgba(0, 0, 0, 0.72);
}

/* 状态覆盖层 */
#status-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

#status-overlay.hidden {
  display: none;
}

#status-text {
  color: #fff;
  font-size: 24px;
  text-align: center;
  padding: 20px;
}

/* ==================== 移动端弹幕输入（已废弃，使用聊天区域输入） ==================== */
#mobile-danmaku-entry {
  display: none; /* 移动端也使用聊天区域的输入框 */
}

#danmaku-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: none;
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(24, 144, 255, 0.92);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  transition: transform 0.2s;
}

#danmaku-toggle-btn:active {
  transform: scale(0.95);
}

.danmaku-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 13px;
}

.danmaku-toggle-text {
  white-space: nowrap;
}

#danmaku-panel {
  width: min(560px, 100%);
}

#danmaku-panel.hidden {
  display: none;
}

#danmaku-form {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: rgba(8, 14, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
}

#danmaku-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  background: rgba(255, 255, 255, 0.96);
}

#danmaku-send-btn {
  min-width: 72px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  background: #1890ff;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

#danmaku-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#danmaku-feedback {
  min-height: 20px;
  margin-top: 8px;
  padding: 0 8px;
  color: #fff;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

#danmaku-feedback.error {
  color: #ffb3b3;
}

#danmaku-feedback.success {
  color: #d9f7be;
}

/* ==================== 聊天区域 ==================== */
#chat-section {
  display: flex; /* 移动端也显示 */
  flex-direction: column;
  flex: 1; /* 移动端占据剩余空间（约40%） */
  min-height: 0;
  background: #18181b;
  border-top: 1px solid #2d2d30; /* 移动端上边框 */
  overflow: hidden; /* 防止内容溢出 */
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #1f1f23;
  border-bottom: 1px solid #2d2d30;
  flex-shrink: 0;
}

#chat-header h2 {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

#viewer-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #a0a0a0;
  font-size: 14px;
}

.viewer-icon {
  font-size: 16px;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* 聊天消息项 */
.chat-message {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: slideIn 0.3s ease-out;
}

.chat-message.own {
  background: rgba(24, 144, 255, 0.15);
  color: #69c0ff;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 滚动条样式 */
#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* 桌面端输入区域 */
#chat-input-area {
  padding: 16px;
  background: #1f1f23;
  border-top: 1px solid #2d2d30;
  flex-shrink: 0;
}

#desktop-danmaku-form {
  display: flex;
  gap: 8px;
}

#desktop-danmaku-input {
  flex: 1;
  min-height: 40px;
  border: 1px solid #3d3d40;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  background: #2d2d30;
  color: #fff;
  transition: border-color 0.2s;
}

#desktop-danmaku-input:focus {
  border-color: #1890ff;
}

#desktop-danmaku-send-btn {
  min-width: 64px;
  min-height: 40px;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  background: #1890ff;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#desktop-danmaku-send-btn:hover {
  background: #40a9ff;
}

#desktop-danmaku-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#desktop-danmaku-feedback {
  min-height: 18px;
  margin-top: 8px;
  color: #a0a0a0;
  font-size: 12px;
}

#desktop-danmaku-feedback.error {
  color: #ff7875;
}

#desktop-danmaku-feedback.success {
  color: #95de64;
}

/* ==================== 动画效果 ==================== */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes slideUp {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
}

/* ==================== 桌面端布局（横屏） ==================== */
@media (min-width: 768px) {
  #app-container {
    flex-direction: row; /* 桌面端：横向分栏 */
  }

  /* 桌面端：播放器占据剩余空间 */
  #player-section {
    flex: 1;
    min-height: 0;
    width: calc(100% - 360px); /* 减去聊天室宽度 */
    position: relative;
  }

  #dplayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    background: #000;
  }

  #chat-section {
    width: 360px;
    flex: none;
    border-top: none;
    border-left: 1px solid #2d2d30; /* 桌面端左边框 */
  }
}

/* 大屏优化 */
@media (min-width: 1440px) {
  #player-section {
    width: calc(100% - 420px); /* 减去大屏聊天室宽度 */
  }

  #chat-section {
    width: 420px;
  }

  #chat-header h2 {
    font-size: 18px;
  }

  .chat-message {
    font-size: 15px;
  }
}

/* 小屏优化 */
@media (max-width: 640px) {
  #status-text {
    font-size: 20px;
  }

  .custom-danmaku {
    max-width: 82%;
    font-size: 18px;
  }

  #live-clock {
    padding: 5px 8px;
    font-size: 13px;
  }

  #mobile-danmaku-entry {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  #danmaku-toggle-btn {
    min-height: 42px;
    padding: 0 12px;
    font-size: 13px;
  }

  .danmaku-toggle-icon {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  #danmaku-panel {
    width: 100%;
  }

  #danmaku-form {
    gap: 8px;
    padding: 8px;
  }

  #danmaku-send-btn {
    min-width: 64px;
  }

  #danmaku-input,
  #danmaku-send-btn {
    font-size: 14px;
  }
}

/* ==================== xgplayer 样式覆盖 ==================== */
/* 隐藏 xgplayer 默认弹幕输入框（使用自定义） */
.xgplayer-danmu-input {
  display: none !important;
}

/* 隐藏 DPlayer 弹幕发送控件 */
.dplayer-comment {
  display: none !important;
}

.dplayer-icons-right .dplayer-comment-icon {
  display: none !important;
}

/* 全屏时调整弹幕样式 */
.xgplayer-is-fullscreen .xgplayer-danmu {
  font-size: 28px !important;
}

/* 移动端弹幕字体 */
@media (max-width: 640px) {
  .xgplayer-danmu {
    font-size: 18px !important;
  }
}

/* 强制xgplayer容器填充 */
.xgplayer {
  width: 100% !important;
  height: 100% !important;
}

.xgplayer-video-wrap {
  width: 100% !important;
  height: 100% !important;
}
