/* ===== 全局重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    /* P20华为浏览器：100vh 包含地址栏，用 JS 设置的 --vh 替代 */
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    background: #0a0a12;
    color: #fff;
    /* EMUI强制暗色模式时保证文字可见 */
    color-scheme: dark;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
    overflow: hidden;
    /* 华为浏览器：禁止长按选词/菜单 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    /* 华为浏览器：防止下拉刷新（老旧WebKit不支持时无害） */
    overscroll-behavior: none;
}

/* ----- 字幕列表容器 ----- */
#subtitle-list {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    padding: 0 12px;
    /* P20适配：安全区域（刘海屏） */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    background: #0a0a12;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 内部 ul 用于存放字幕，通过 transform 移动 */
#subtitle-list ul {
    width: 100%;
    max-width: 860px;
    margin: 0;
    padding: 0;
    list-style: none;
    transition: none;
    will-change: transform;
}

/* 字幕条目（左对齐） */
.subtitle-item {
    padding: 6px 16px;
    margin: 2px 0;
    font-size: calc(var(--base-font-size, 1.2rem) * 0.8);
    line-height: 1.6;
    color: #aab;
    text-align: left;
    border-radius: 8px;
    background: transparent;
    transition: background 0.25s, color 0.25s, transform 0.25s, box-shadow 0.25s, font-size 0.25s;
    word-break: break-word;
    /* P20华为浏览器：点击高亮完全透明（transparent比rgba更兼容） */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* 华为浏览器：字体抗锯齿 */
    -webkit-font-smoothing: antialiased;
}

/* 高亮字幕 */
.subtitle-item.active {
    font-size: calc(var(--base-font-size, 1.2rem) * 1.2);
    background: rgba(108, 92, 231, 0.35);
    color: #ffeaa7;
    border-left: 4px solid #6c5ce7;
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(108, 92, 231, 0.2);
    font-weight: 500;
}

/* 提示信息 */
.empty-message, .error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    /* P20兼容：clamp 不支持的旧浏览器用固定字号降级 */
    font-size: 1.4rem;
    font-size: clamp(1rem, 4vw, 1.8rem);
    text-align: center;
    padding: 20px;
}
.empty-message { color: #aab; opacity: 0.7; }
.error-message { color: #ff6b6b; }

/* ----- 齿轮按钮 ----- */
#toggle-controls {
    position: fixed;
    bottom: 24px;
    right: 24px;
    /* P20适配：避开刘海屏安全区域 */
    right: max(24px, env(safe-area-inset-right) + 8px);
    bottom: max(24px, env(safe-area-inset-bottom) + 8px);
    z-index: 1000;
    background: #6c5ce7;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.5);
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-touch-callout: none;
}
#toggle-controls:active { transform: scale(0.92); }

/* ----- 控制面板 ----- */
/* P20关键：避免 position:fixed + transform 渲染 Bug（EMUI 8-9常见）
   用 bottom 属性 + JS 精确控制面板位置 */
#control-panel {
    position: fixed;
    left: 0;
    width: 100%;
    max-height: 70vh;
    max-height: calc(var(--vh, 1vh) * 70);
    background: rgba(10, 10, 18, 0.98);  /* 先给纯色降级 */
    /* backdrop-filter 支持时覆盖 */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 2px solid rgba(255,255,255,0.06);
    padding: 16px 16px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 999;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.6);
    overscroll-behavior: contain;
}
/* backdrop-filter 降级：@supports 是留给较新浏览器的，
   P20 老旧 WebKit 不认识 @supports，会直接用上面的纯色背景 */
@supports (backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px)) {
    #control-panel {
        background: rgba(18, 18, 32, 0.96);
    }
}

.panel-inner {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}
.panel-inner h2 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 4px;
}
.panel-inner .sub-head {
    text-align: center;
    color: #b2bec3;
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.5;
}

/* 字号滑块 */
.font-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #1e1e32;
    padding: 8px 14px;
    border-radius: 30px;
    margin: 6px auto 10px;
    max-width: 320px;
}
.font-control label {
    font-size: 14px;
    color: #b2bec3;
    white-space: nowrap;
}
.font-control input[type="range"] {
    flex: 1;
    min-width: 80px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #6c5ce7;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}
.font-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #6c5ce7;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}
.font-control input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #6c5ce7;
    border: 2px solid #fff;
    cursor: pointer;
}
.font-control input[type="range"]::-ms-track {
    width: 100%;
    height: 6px;
    background: transparent;
    border-color: transparent;
    color: transparent;
}
.font-control input[type="range"]::-ms-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #6c5ce7;
    border: 2px solid #fff;
    cursor: pointer;
}
.font-control input[type="range"]::-ms-fill-lower {
    background: #6c5ce7;
    border-radius: 4px;
}
.font-control input[type="range"]::-ms-fill-upper {
    background: #3d3d5c;
    border-radius: 4px;
}
.font-control .font-size-display {
    min-width: 40px;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #ffeaa7;
}

/* 模式按钮 */
.mode-control {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 4px auto 10px;
    flex-wrap: wrap;
}
.mode-btn {
    background: transparent;
    color: #b2bec3;
    border: 2px solid #3d3d5c;
    border-radius: 30px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
}
.mode-btn:hover { border-color: #6c5ce7; color: #ddd; }
.mode-btn.active { background: #6c5ce7; border-color: #6c5ce7; color: #fff; box-shadow: 0 0 20px rgba(108, 92, 231, 0.3); }
.mode-btn:active { transform: scale(0.95); }
.mode-btn.pressed { background: rgba(108, 92, 231, 0.3); border-color: #6c5ce7; }

/* 文件计数 & 播放列表 */
.file-count {
    text-align: center;
    color: #b2bec3;
    font-size: 13px;
    padding: 6px 0;
    border-bottom: 1px solid #3d3d5c;
    margin-bottom: 8px;
}
#playlist {
    list-style: none;
    padding: 0;
    margin: 6px 0 12px;
    max-height: 180px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #1a1a2e;
    border-radius: 12px;
    overscroll-behavior: contain;
}
#playlist li {
    padding: 12px 14px;
    border-bottom: 1px solid #2d2d4a;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 44px;
}
#playlist li:active { background: #3d3d5c; }
/* P20兼容：:active 伪类不可靠，通过 JS 添加 .pressed 获得反馈 */
#playlist li.pressed { background: #3d3d5c; }
.mode-btn.pressed { background: rgba(108, 92, 231, 0.3); border-color: #6c5ce7; }
#toggle-controls.pressed { transform: scale(0.92); }

.active-song { background: #6c5ce7 !important; border-radius: 8px; }
.active-song .subtitle-badge { background: #fff; color: #6c5ce7; }

.subtitle-badge {
    font-size: 11px;
    background: #00b894;
    padding: 2px 12px;
    border-radius: 20px;
    color: #fff;
    font-weight: 500;
    white-space: nowrap;
}
.no-sub {
    font-size: 11px;
    background: #636e72;
    padding: 2px 12px;
    border-radius: 20px;
    color: #ddd;
    font-weight: 400;
    white-space: nowrap;
}

/* 音频播放器 */
audio {
    width: 100%;
    margin: 4px 0 2px;
    border-radius: 10px;
    display: block;
    background: #1a1a2e;
    height: 48px;
}

/* ===== 滚动条美化 ===== */
#subtitle-list::-webkit-scrollbar { width: 0; }
#playlist::-webkit-scrollbar { width: 3px; }
#playlist::-webkit-scrollbar-track { background: #1a1a2e; }
#playlist::-webkit-scrollbar-thumb { background: #6c5ce7; border-radius: 10px; }
#control-panel::-webkit-scrollbar { width: 3px; }
#control-panel::-webkit-scrollbar-track { background: transparent; }
#control-panel::-webkit-scrollbar-thumb { background: #6c5ce7; border-radius: 10px; }
#playlist::-webkit-scrollbar-button { display: none; }
#control-panel::-webkit-scrollbar-button { display: none; }

/* ===== 响应式断点 ===== */

/* 平板及手机 (小于 1024px) */
@media (max-width: 1024px) {
    .subtitle-item { font-size: calc(var(--base-font-size, 1.0rem) * 0.85); }
    .subtitle-item.active { font-size: calc(var(--base-font-size, 1.0rem) * 1.25); }
}

/* 手机 (小于 768px) - 含P20 */
@media (max-width: 768px) {
    #subtitle-list { padding: 0 8px; }
    .subtitle-item {
        padding: 5px 12px;
        margin: 1px 0;
        font-size: calc(var(--base-font-size, 0.9rem) * 0.85);
        line-height: 1.5;
    }
    .subtitle-item.active { font-size: calc(var(--base-font-size, 0.9rem) * 1.25); }

    #toggle-controls { width: 52px; height: 52px; font-size: 24px; bottom: 18px; right: 18px; }
    #control-panel { max-height: 80vh; max-height: calc(var(--vh, 1vh) * 80); padding: 14px 12px 18px; }
    .panel-inner h2 { font-size: 18px; }
    .panel-inner .sub-head { font-size: 12px; }

    .font-control { padding: 6px 12px; max-width: 100%; gap: 8px; }
    .font-control label { font-size: 13px; }
    .font-control input[type="range"] { min-width: 60px; height: 5px; }
    .font-control input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; }
    .font-control input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }

    .mode-btn { font-size: 13px; padding: 6px 12px; min-height: 40px; }
    #playlist { max-height: 150px; }
    #playlist li { font-size: 14px; padding: 10px 12px; min-height: 40px; }
    audio { height: 44px; }
}

/* 小屏手机 (小于 480px) */
@media (max-width: 480px) {
    .subtitle-item { padding: 4px 10px; font-size: calc(var(--base-font-size, 0.8rem) * 0.85); }
    .subtitle-item.active { font-size: calc(var(--base-font-size, 0.8rem) * 1.25); }
    #toggle-controls { width: 48px; height: 48px; font-size: 22px; bottom: 14px; right: 14px; }
    #control-panel { max-height: 85vh; max-height: calc(var(--vh, 1vh) * 85); padding: 12px 10px 16px; }
    .panel-inner h2 { font-size: 17px; }
    .panel-inner .sub-head { font-size: 11px; }
    .font-control { padding: 4px 10px; gap: 6px; }
    .font-control label { font-size: 12px; }
    .mode-btn { font-size: 12px; padding: 4px 10px; min-height: 36px; }
    #playlist li { font-size: 13px; padding: 8px 10px; min-height: 36px; }
    audio { height: 40px; }
}

/* 横屏优化 */
@media (max-height: 500px) and (orientation: landscape) {
    #subtitle-list { padding: 0 16px; }
    .subtitle-item { padding: 3px 12px; font-size: calc(var(--base-font-size, 0.8rem) * 0.8); }
    .subtitle-item.active { font-size: calc(var(--base-font-size, 0.8rem) * 1.15); }
    #control-panel { max-height: 60vh; max-height: calc(var(--vh, 1vh) * 60); padding: 10px 14px 14px; }
    #playlist { max-height: 100px; }
    #playlist li { font-size: 13px; padding: 6px 10px; min-height: 34px; }
    audio { height: 36px; }
    .mode-btn { font-size: 12px; padding: 4px 10px; min-height: 32px; }
}
