/* ================================================================
   AI 数学动画播放器 - 电影级播放器样式
   全屏沉浸式 + 播放控制 + 场景切换
   ================================================================ */

/* ---------- CSS 变量 ---------- */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-panel: rgba(18, 18, 26, 0.95);
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0c0;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-pink: #ec4899;
    --accent-gold: #f59e0b;
    --accent-green: #10b981;
    --glow-cyan: rgba(0, 212, 255, 0.4);
    --glow-purple: rgba(168, 85, 247, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- 基础重置 ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

/* ---------- 主容器 ---------- */
.app {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ================================================================
   开场选择界面
   ================================================================ */
.intro-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
    z-index: 100;
}

.intro-content {
    text-align: center;
    max-width: 600px;
    padding: 40px;
    animation: fadeInUp 0.8s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.intro-title {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 800;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}

.gradient-text {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple), var(--accent-pink));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradient-shift 4s ease infinite;
}

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.intro-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 40px;
}

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

#topic-input {
    flex: 1;
    padding: 16px 24px;
    font-size: 1.05rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}

#topic-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 20px var(--glow-cyan);
}

#topic-input::placeholder {
    color: rgba(160, 160, 192, 0.5);
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 32px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--glow-purple);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1rem;
}

/* 预设主题 */
.preset-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 24px;
}

.preset-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    align-self: center;
}

.preset-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.preset-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.08);
}

/* API 配置 */
.api-config {
    margin-top: 16px;
}

.btn-text {
    padding: 8px 16px;
    font-size: 0.85rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-text:hover {
    color: var(--accent-gold);
}

.api-panel {
    margin-top: 12px;
    animation: fadeIn 0.3s ease;
}

.api-panel input {
    width: 100%;
    max-width: 360px;
    padding: 12px 16px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    outline: none;
}

.api-panel input:focus {
    border-color: var(--accent-gold);
}

.api-panel small {
    display: block;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ================================================================
   播放器界面
   ================================================================ */
.player-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

/* 渲染容器 */
.render-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
}

#canvas-2d {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#three-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#three-container canvas {
    display: block;
}

/* 叠加层 */
.overlay-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.formula-overlay {
    position: absolute;
    padding: 20px 30px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.formula-overlay.visible {
    opacity: 1;
}

.formula-overlay .katex {
    font-size: 1.8rem;
    color: var(--accent-cyan);
}

.formula-overlay.top-left { top: 40px; left: 40px; }
.formula-overlay.top-right { top: 40px; right: 40px; }
.formula-overlay.bottom-left { bottom: 100px; left: 40px; }
.formula-overlay.bottom-right { bottom: 100px; right: 40px; }
.formula-overlay.center { 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%);
}

.text-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    pointer-events: none;
}

.text-overlay-item {
    padding: 20px 40px;
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 800;
    text-align: center;
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.text-overlay-item.visible {
    opacity: 1;
}

.text-overlay-item.fade-in-scale {
    animation: fadeInScale 0.8s ease forwards;
}

.text-overlay-item.fade-in-up {
    animation: fadeInUp 0.8s ease forwards;
}

.text-overlay-item.glow-pulse {
    animation: glowPulse 2s ease-in-out infinite;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes glowPulse {
    0%, 100% { 
        text-shadow: 0 0 20px var(--glow-cyan), 0 0 40px var(--glow-purple);
        transform: scale(1);
    }
    50% { 
        text-shadow: 0 0 40px var(--glow-cyan), 0 0 80px var(--glow-purple);
        transform: scale(1.05);
    }
}

/* 字幕栏 */
.subtitle-bar {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80%;
    padding: 16px 32px;
    font-size: 1.2rem;
    line-height: 1.6;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 20;
}

.subtitle-bar.visible {
    opacity: 1;
}

/* 转场层 */
.transition-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
    background: transparent;
}

.transition-layer.fade-in {
    animation: transitionFadeIn 0.6s ease forwards;
}

.transition-layer.fade-out {
    animation: transitionFadeOut 0.6s ease forwards;
}

@keyframes transitionFadeIn {
    from { background: #000; }
    to { background: transparent; }
}

@keyframes transitionFadeOut {
    from { background: transparent; }
    to { background: #000; }
}

/* ================================================================
   控制栏
   ================================================================ */
.control-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-panel);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 50;
}

.control-left, .control-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-center {
    flex: 1;
}

.control-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-cyan);
}

.time-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 100px;
}

/* 进度条 */
.progress-bar {
    position: relative;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    cursor: pointer;
    transition: height 0.2s ease;
}

.progress-bar:hover {
    height: 8px;
}

.progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-purple));
    border-radius: 3px;
    transition: width 0.1s linear;
}

.progress-thumb {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: var(--accent-cyan);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s ease;
    box-shadow: 0 0 10px var(--glow-cyan);
}

.progress-bar:hover .progress-thumb {
    transform: translate(-50%, -50%) scale(1);
}

/* 场景标记 */
.scene-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.scene-marker {
    position: absolute;
    top: 50%;
    width: 3px;
    height: 12px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    transform: translate(-50%, -50%);
}

/* 速度选择 */
.speed-select {
    padding: 8px 12px;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
}

.speed-select:hover {
    border-color: var(--accent-cyan);
}

/* ================================================================
   场景侧边栏
   ================================================================ */
.scene-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: var(--bg-panel);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 60;
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.scene-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.scene-item {
    padding: 14px 16px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition);
}

.scene-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent-cyan);
}

.scene-item.active {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-cyan);
}

.scene-item-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.scene-item-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ================================================================
   加载遮罩
   ================================================================ */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 15, 0.9);
    z-index: 200;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto 20px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-content p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ================================================================
   错误提示
   ================================================================ */
.error-toast {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 28px;
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
    border-radius: var(--radius);
    font-weight: 600;
    z-index: 300;
    animation: toastIn 0.4s ease, toastOut 0.4s ease 3.5s forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ================================================================
   滚动条
   ================================================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ================================================================
   用户状态栏
   ================================================================ */
.user-bar {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
}

.user-logged-out .btn-login {
    padding: 10px 20px;
    font-size: 0.9rem;
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: var(--transition);
}

.user-logged-out .btn-login:hover {
    background: rgba(0, 212, 255, 0.1);
    box-shadow: 0 0 12px var(--glow-cyan);
}

.user-logged-in {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

.btn-text-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-text-small:hover {
    border-color: var(--accent-pink);
    color: var(--accent-pink);
}

/* ================================================================
   知识列表区域
   ================================================================ */
.knowledge-section {
    margin-top: 40px;
    width: 100%;
    max-width: 800px;
    animation: fadeInUp 0.6s ease;
}

.knowledge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.knowledge-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.knowledge-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.knowledge-card {
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.knowledge-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent-cyan);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.knowledge-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.knowledge-card-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.knowledge-card-duration {
    display: flex;
    align-items: center;
    gap: 4px;
}

.knowledge-card-scenes {
    display: flex;
    align-items: center;
    gap: 4px;
}

.knowledge-card-date {
    font-size: 0.8rem;
    color: rgba(160, 160, 192, 0.6);
    margin-top: 8px;
}

.knowledge-card-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: var(--transition);
}

.knowledge-card:hover .knowledge-card-actions {
    opacity: 1;
}

.btn-card-action {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

.btn-card-action:hover {
    background: rgba(239, 68, 68, 0.8);
    color: #fff;
}

.knowledge-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.knowledge-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.btn-page {
    padding: 8px 16px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-page:hover:not(:disabled) {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.btn-page:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ================================================================
   响应式调整
   ================================================================ */
@media (max-width: 768px) {
    .intro-content {
        padding: 20px;
    }

    .user-bar {
        top: 12px;
        right: 12px;
    }

    .knowledge-list {
        grid-template-columns: 1fr;
    }
}
