/* ============================================================
 * 直播间样式（H5 移动端优先）：深色主题
 * 布局：顶部视频 → 标题 → 聊天流 → 底部固定输入栏
 * ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg: #12151c;
    --panel: #1b202b;
    --border: #2a3140;
    --text: #e8ecf2;
    --text-dim: #8b94a7;
    --accent: #ff4d6a;
    --accent-2: #3b82f6;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; }

body {
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

/* ============ H5 整体布局：竖屏单列 ============ */
.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    max-width: 100%;
}

/* ============ 视频区 ============ */
.player-area {
    flex-shrink: 0;
    background: #0c0e13;
}

.video-wrap {
    position: relative;
    background: #000;
    aspect-ratio: 16 / 9;
    max-height: 45vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.video-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.live-badge {
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.live-badge .dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
    margin-right: 5px;
    animation: blink 1.2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.online-count {
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 4px;
}

/* 错误遮罩 */
.stream-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(12, 14, 19, 0.92);
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

.stream-error code {
    color: var(--accent-2);
    background: rgba(59, 130, 246, 0.12);
    padding: 1px 6px;
    border-radius: 4px;
}

.stream-error .err-tip { font-size: 11px; color: #6b7280; }

.stream-error .err-detail {
    font-size: 12px;
    color: #fca5a5;
    max-width: 90%;
    text-align: center;
    word-break: break-all;
}

.stream-error #btnRetry {
    margin-top: 4px;
    padding: 8px 22px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
}

.stream-error #btnRetry:active { opacity: 0.85; }

/* 标题 */
.video-meta {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.video-meta h1 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.video-meta p { font-size: 12px; color: var(--text-dim); }

/* ============ 聊天区 ============ */
.chat-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-online { font-size: 12px; color: var(--text-dim); font-weight: 400; }

.chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* 单条消息 */
.msg {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    animation: fadeIn 0.2s ease;
}

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

.msg .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.msg-body { min-width: 0; flex: 1; }

.msg-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 2px; }
.msg-head .name { font-size: 12px; font-weight: 600; }
.msg-head .time { font-size: 10px; color: var(--text-dim); }

.msg-text { font-size: 14px; line-height: 1.5; word-break: break-word; }

.msg-img {
    max-width: 160px;
    max-height: 160px;
    border-radius: 8px;
    cursor: zoom-in;
    border: 1px solid var(--border);
    display: block;
}

/* 系统消息 */
.msg.system {
    justify-content: center;
    font-size: 11px;
    color: var(--text-dim);
    background: rgba(139, 148, 167, 0.08);
    border-radius: 6px;
    padding: 4px 8px;
    align-self: center;
    max-width: 92%;
}

.msg.system .sys-tag { color: var(--accent-2); font-weight: 600; margin-right: 2px; }
.msg.system .time { margin-left: 6px; }

/* ============ 底部输入区（固定） ============ */
.chat-toolbar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px 4px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-toolbar button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
}

.chat-toolbar button:active { background: rgba(255, 255, 255, 0.1); }

.chat-toolbar button.active {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.emoji-panel {
    position: absolute;
    bottom: 50px;
    left: 10px;
    width: min(300px, calc(100% - 20px));
    max-height: 220px;
    overflow-y: auto;
    background: #232a38;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    display: none; /* 默认收起，用 .show 展开（hidden 属性会被 display 覆盖，故不用） */
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.emoji-panel.show { display: grid; }

.emoji-item {
    width: 32px;
    height: 32px;
    font-size: 20px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
}

.emoji-item:active { background: rgba(255, 255, 255, 0.12); }

.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 6px 10px calc(10px + var(--safe-bottom));
    flex-shrink: 0;
}

.chat-input-row input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 21px;
    background: #141925;
    color: var(--text);
    font-size: 16px; /* ≥16px 防止 iOS Safari 聚焦时页面自动放大 */
    outline: none;
}

.chat-input-row input:focus { border-color: var(--accent-2); }
.chat-input-row input::placeholder { color: var(--text-dim); }

.chat-input-row button {
    flex-shrink: 0;
    height: 42px;
    padding: 0 20px;
    border: none;
    border-radius: 21px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.chat-input-row button:active { transform: scale(0.96); }

/* ============ 图片全屏预览遮罩（H5） ============ */
#imgPreview {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.92);
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
}

#imgPreview img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    object-fit: contain;
}

/* ============ 宽屏（桌面/平板）保留左右布局 ============ */
@media (min-width: 768px) {
    .app { flex-direction: row; }

    .player-area {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    .video-wrap { max-height: none; }

    .chat-area {
        width: 380px;
        border-left: 1px solid var(--border);
    }

    .msg-img { max-width: 180px; max-height: 180px; }
}

/* ============ 横屏手机（窄屏 + 横屏） ============ */
@media (max-width: 767px) and (orientation: landscape) {
    .video-wrap { max-height: 28vh; }
    .video-meta { display: none; }
    .emoji-panel { max-height: 40vh; }
}

/* ============ 超小屏（<360px） ============ */
@media (max-width: 359px) {
    .emoji-panel { grid-template-columns: repeat(6, 1fr); }
    .msg-img { max-width: 120px; max-height: 120px; }
    .chat-toolbar button { width: 36px; height: 36px; }
}

/* ============ 昵称弹层（进入直播间前） ============ */
/* z-index 必须低于微信拦截遮罩 #wx-mask(999999)，保证微信提示永远在最上层 */
.nick-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
}

.nick-modal.show { display: flex; }

.nick-card {
    width: min(320px, calc(100% - 48px));
    background: #1c2333;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 20px 20px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.nick-card h3 {
    margin: 0 0 6px;
    font-size: 18px;
    color: #fff;
}

.nick-card p {
    margin: 0 0 16px;
    font-size: 13px;
    color: #8a94a8;
}

.nick-card input {
    width: 100%;
    box-sizing: border-box;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: #141925;
    color: #fff;
    font-size: 16px;
    text-align: center;
    outline: none;
}

.nick-card input:focus { border-color: #3b82f6; }

.nick-card button {
    width: 100%;
    height: 44px;
    margin-top: 14px;
    border: none;
    border-radius: 22px;
    background: #3b82f6;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.nick-card button:active { background: #2f6ad0; }
