/* ==========================================================================
   WenBook HeroUI Design System & Motion Engine (Animations & Transitions)
   - 24px Border Radius (rounded-3xl / rounded-[24px])
   - No Emojis (FontAwesome 6 only)
   - Modern Cross-Document View Transitions API
   - Hardware-Accelerated 3D Physics Flip for Flashcards
   - Canvas Scratchpad Smooth Dynamic Expansion
   - Staggered Card Entrances & Bubble Animations
   - Mobile Bottom-Sheet & Desktop Modal Motion
   ========================================================================== */

:root {
    --primary-color: #2196F3;
    --primary-rgb: 33, 150, 243;
    --primary-hover: #1e88e5;
    --primary-active: #1976d2;
    --primary-light: rgba(33, 150, 243, 0.12);
    --wb-radius: 24px;
    --wb-radius-sm: 16px;
    --wb-radius-lg: 32px;
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --spring-easing: cubic-bezier(0.16, 1, 0.3, 1);
    --bounce-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==========================================================================
   1. 页面级平滑导航过渡 (View Transitions API & CSS Fallback)
   ========================================================================== */
@view-transition {
    navigation: auto;
}

/* 导航栏锁定为独立 view-transition 元素，页面跳转时完全静止不闪烁 */
.mobile-tab-bar {
    view-transition-name: mobile-navigation-dock;
}

::view-transition-group(mobile-navigation-dock) {
    animation-duration: 0s !important;
}

::view-transition-old(root) {
    animation: 0.15s cubic-bezier(0.4, 0, 1, 1) both page-fade-out;
}

::view-transition-new(root) {
    animation: 0.22s cubic-bezier(0, 0, 0.2, 1) both page-fade-in;
}

@keyframes page-fade-out {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-6px) scale(0.99);
    }
}

@keyframes page-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 页面主体内容进场动画 (降级与首次加载) */
.page-content-enter {
    animation: content-enter 0.28s var(--spring-easing) forwards;
}

@keyframes content-enter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: none; /* 关键：清除 transform，防止为 position: fixed 创建包含块隔离 */
    }
}

/* ==========================================================================
   2. 基础重置与排版
   ========================================================================== */
html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-left: var(--sal);
    padding-right: var(--sar);
}

/* 强制 24px 大圆角 */
.rounded-wb {
    border-radius: 24px !important;
}

.rounded-wb-sm {
    border-radius: 16px !important;
}

.rounded-wb-lg {
    border-radius: 32px !important;
}

/* ==========================================================================
   3. HeroUI 毛玻璃卡片与动效
   ========================================================================== */
.hero-card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(226, 232, 240, 0.85);
    border-radius: 24px;
    box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.04), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
    transition: transform 0.22s var(--spring-easing), box-shadow 0.22s var(--spring-easing), border-color 0.22s ease;
}

.dark .hero-card {
    background: rgba(24, 24, 27, 0.85);
    border-color: rgba(63, 63, 70, 0.6);
    box-shadow: 0 4px 24px -2px rgba(0, 0, 0, 0.3);
}

.hero-card:hover {
    box-shadow: 0 10px 30px -4px rgba(0, 0, 0, 0.08), 0 4px 12px -2px rgba(0, 0, 0, 0.04);
}

.dark .hero-card:hover {
    box-shadow: 0 10px 30px -4px rgba(0, 0, 0, 0.5);
}

/* 卡片流瀑布阶梯式进场动画 (Staggered Animation) */
.stagger-item {
    animation: card-spring-in 0.38s var(--spring-easing) both;
}

@keyframes card-spring-in {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.stagger-item:nth-child(1) { animation-delay: 0.02s; }
.stagger-item:nth-child(2) { animation-delay: 0.05s; }
.stagger-item:nth-child(3) { animation-delay: 0.08s; }
.stagger-item:nth-child(4) { animation-delay: 0.11s; }
.stagger-item:nth-child(5) { animation-delay: 0.14s; }
.stagger-item:nth-child(6) { animation-delay: 0.17s; }
.stagger-item:nth-child(7) { animation-delay: 0.20s; }
.stagger-item:nth-child(8) { animation-delay: 0.23s; }

/* 按钮通用触感微动效 */
.hero-btn {
    min-height: 40px;
    border-radius: 20px;
    font-weight: 600;
    transition: transform 0.18s var(--spring-easing), background-color 0.18s ease, box-shadow 0.18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

@media (pointer: coarse) {
    .hero-btn {
        min-height: 44px;
    }
}

.hero-btn:active {
    transform: scale(0.95);
}

/* PRO 极简专属风格：#2196F3 主题色 + 科技蓝光 Glow 效果 */
.pro-glow {
    border-color: #2196F3 !important;
    box-shadow: 0 0 16px -2px rgba(33, 150, 243, 0.45), 0 0 6px 0px rgba(33, 150, 243, 0.25) !important;
}

.pro-badge {
    background-color: #2196F3 !important;
    color: #ffffff !important;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.pro-pill {
    background: rgba(33, 150, 243, 0.12) !important;
    color: #2196F3 !important;
    border: 1px solid rgba(33, 150, 243, 0.4) !important;
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.25);
}

.dark .pro-pill {
    background: rgba(33, 150, 243, 0.18) !important;
    color: #64b5f6 !important;
    border-color: rgba(33, 150, 243, 0.5) !important;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.35);
}

/* ==========================================================================
   4. 自绘组件微动效 (Scratchpad Canvas & Tools)
   ========================================================================== */
/* 画板容器平滑拉伸动画 */
.scratchpad-box {
    transition: height 0.32s var(--spring-easing), opacity 0.24s ease;
}

/* 画笔颜色选择器微交互 */
.brush-color-pill {
    transition: transform 0.2s var(--bounce-easing), box-shadow 0.2s ease;
}

.brush-color-pill:hover,
.brush-color-pill.active {
    transform: scale(1.22);
}

/* 画板清空震颤动效 */
.canvas-clear-flash {
    animation: canvas-flash 0.3s ease-out;
}

@keyframes canvas-flash {
    0% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* ==========================================================================
   5. 闪记卡 3D 拟真物理翻转动效 (3D Physics Card Flip)
   ========================================================================== */
.flip-card-wrapper {
    perspective: 1400px;
    transform-style: preserve-3d;
}

.flip-card-body {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.55s var(--bounce-easing), box-shadow 0.55s ease;
    transform-style: preserve-3d;
}

.flip-card-body.is-flipped {
    transform: rotateY(180deg);
}

.flip-card-face {
    position: relative;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform-style: preserve-3d;
}

.flip-card-back-face {
    position: absolute;
    inset: 0;
    transform: rotateY(180deg);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* ==========================================================================
   6. AI 答疑对话气泡动效
   ========================================================================== */
.chat-bubble-enter {
    animation: bubble-pop-in 0.28s var(--spring-easing) both;
}

@keyframes bubble-pop-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   iOS Safari 状态栏与刘海屏安全区顶栏适配 (Safe Area Inset Top)
   ========================================================================== */
header.sticky {
    padding-top: env(safe-area-inset-top, 0px);
}

@supports (padding-top: env(safe-area-inset-top)) {
    header.sticky {
        padding-top: env(safe-area-inset-top, 0px);
    }
}

/* ==========================================================================
   7. 移动端 iOS SwiftUI 浮动导航栏
   ========================================================================== */
.mobile-tab-bar {
    position: fixed;
    bottom: max(12px, calc(var(--sab) + 8px));
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    width: calc(100% - max(32px, calc(var(--sal) + var(--sar) + 24px)));
    max-width: 480px;
    height: 64px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-radius: 32px;
    box-shadow: 0 12px 36px -4px rgba(0, 0, 0, 0.14), 0 4px 12px -2px rgba(0, 0, 0, 0.06);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 8px;
    /* 取消每次跳页面的 translateY(120%) 弹跳动画，确保页面切换时底部导航栏纹丝不动 */
    transform: translateZ(0);
    will-change: transform;
}

.dark .mobile-tab-bar {
    background: rgba(24, 24, 27, 0.88);
    border-color: rgba(63, 63, 70, 0.6);
    box-shadow: 0 12px 36px -4px rgba(0, 0, 0, 0.6);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: #64748b;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 16px;
    touch-action: manipulation;
    padding: 4px 0;
    gap: 3px;
}

.dark .tab-item {
    color: #a1a1aa;
}

.tab-item.active {
    color: #2196F3;
    font-weight: 700;
}

.dark .tab-item.active {
    color: #64b5f6;
}

.tab-item i {
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s var(--bounce-easing);
}

.tab-item span {
    font-size: 10px;
    line-height: 1;
}

.tab-item.active i {
    transform: scale(1.15);
}

.tab-camera-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2196F3 0%, #1565c0 100%);
    color: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(33, 150, 243, 0.45);
    margin-top: -12px;
    transition: transform 0.22s var(--bounce-easing), box-shadow 0.22s ease;
}

.tab-camera-btn i {
    font-size: 18px;
    color: white !important;
}

.tab-camera-btn:active {
    transform: scale(0.92);
}

.mobile-bottom-spacer {
    height: calc(88px + var(--sab));
}

@media (min-width: 768px) {
    .mobile-tab-bar,
    .mobile-bottom-spacer {
        display: none !important;
    }
}

/* ==========================================================================
   8. 弹窗与抽屉动效 (Modals & Bottom Sheets)
   ========================================================================== */
[data-modal] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 99999 !important;
    background-color: rgba(15, 23, 42, 0.65) !important;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: opacity 0.24s ease, backdrop-filter 0.24s ease;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box !important;
}

[data-modal].hidden {
    display: none !important;
}

[data-modal].flex {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* 桌面端弹窗动效与自适应居中 */
@media (min-width: 640px) {
    [data-modal] {
        padding: 1.5rem !important;
    }

    [data-modal] .hero-card {
        margin: auto !important;
        max-height: calc(100vh - 3rem);
        max-height: calc(100dvh - 3rem);
        overflow-y: auto;
        animation: modal-zoom-in 0.26s var(--spring-easing) forwards;
    }

    @keyframes modal-zoom-in {
        from {
            opacity: 0;
            transform: translateY(-12px) scale(0.95);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
}

/* 移动端 iOS 底部抽屉动效 */
@media (max-width: 639px) {
    [data-modal] {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    [data-modal] .hero-card {
        width: 100% !important;
        max-width: 100% !important;
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        border-top-left-radius: 28px !important;
        border-top-right-radius: 28px !important;
        padding-bottom: calc(1.5rem + var(--sab)) !important;
        max-height: 85vh;
        max-height: 85dvh;
        overflow-y: auto;
        position: relative;
        margin: 0 !important;
        animation: sheet-slide-up 0.28s var(--spring-easing) forwards;
    }

    [data-modal] .hero-card::before {
        content: '';
        display: block;
        width: 38px;
        height: 4px;
        border-radius: 2px;
        background-color: rgba(148, 163, 184, 0.5);
        margin: -6px auto 16px auto;
    }

    @keyframes sheet-slide-up {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}

/* ==========================================================================
   9. 移动端/iPad 触控裁切点 (Cropper.js)
   ========================================================================== */
@media (pointer: coarse) {
    .cropper-point {
        width: 18px !important;
        height: 18px !important;
        opacity: 0.88 !important;
    }
    .cropper-point.point-se,
    .cropper-point.point-sw,
    .cropper-point.point-ne,
    .cropper-point.point-nw {
        width: 24px !important;
        height: 24px !important;
    }
    .cropper-line {
        background-color: #38bdf8 !important;
    }
}

/* ==========================================================================
   10. 数学公式与 Toast
   ========================================================================== */
.latex-content {
    line-height: 1.75;
    font-size: 15px;
    word-break: break-word;
}

.latex-content p {
    margin-bottom: 10px;
}

.latex-content ul, .latex-content ol {
    margin-left: 20px;
    margin-bottom: 10px;
}

.latex-content pre {
    background: #f1f5f9;
    padding: 12px;
    border-radius: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 12px;
}

.dark .latex-content pre {
    background: #27272a;
}

.latex-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    background: rgba(148, 163, 184, 0.15);
    padding: 2px 6px;
    border-radius: 6px;
}

.katex-display {
    margin: 12px 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 6px 0;
    -webkit-overflow-scrolling: touch;
}

#wb-toast-container {
    position: fixed;
    top: max(20px, calc(var(--sat) + 12px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.wb-toast {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    padding: 12px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25);
    animation: toast-spring-in 0.32s var(--spring-easing) forwards;
}

.dark .wb-toast {
    background: rgba(39, 39, 42, 0.95);
    border: 1px solid rgba(63, 63, 70, 0.5);
}

@keyframes toast-spring-in {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   HeroUI 风格统一下拉选择器控件 (替代原生浏览器默认 select)
   ========================================================================== */
select, .hero-select {
    appearance: none !important;
    -webkit-appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 1rem 1rem !important;
    padding-right: 2.25rem !important;
    border-radius: 0.875rem !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
    cursor: pointer !important;
}

.dark select, .dark .hero-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2371717a'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
}

select:hover, .hero-select:hover {
    border-color: #38bdf8 !important;
}

select:focus, .hero-select:focus {
    outline: none !important;
    border-color: #0284c7 !important;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2) !important;
}

/* ==========================================================================
   11. iOS 沉浸式信息大排版容器 (移动端非卡片化、全屏自然舒展与大字距)
   ========================================================================== */
@media (max-width: 639px) {
    /* 移动端去卡片化，自然平铺全屏沉浸 */
    .ios-mobile-sheet {
        margin-left: -1rem !important;
        margin-right: -1rem !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .ios-mobile-card {
        margin-left: -1rem !important;
        margin-right: -1rem !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-top-width: 1px !important;
        border-bottom-width: 1px !important;
        box-shadow: none !important;
        padding: 1.25rem 1rem !important;
    }
}

/* ==========================================================================
   12. 移动端拍照全屏取景器与叠加控制层 (仅移动端生效，桌面端完全保持原样)
   ========================================================================== */
@media (max-width: 639px) {
    /* 1. iOS Safari 沉浸式背景与全景适配 (穿透顶栏状态栏与底栏工具栏) */
    html:has(body.mobile-camera-open),
    body.mobile-camera-open {
        background-color: #000000 !important;
        overflow: hidden !important;
        touch-action: manipulation;
        height: 100% !important;
        min-height: 100% !important;
    }

    body.mobile-camera-open main {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
        height: 100% !important;
    }

    body.mobile-camera-open header {
        display: none !important;
    }

    body.mobile-camera-open .mobile-tab-bar,
    body.mobile-camera-open .mobile-bottom-spacer {
        display: none !important;
    }

    /* 2. 移动端相机视口：使用 100% 与 100lvh / -webkit-fill-available，物理边缘全屏贴合 */
    .camera-viewport-container.mobile-camera-active {
        position: fixed !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        width: 100vw !important;
        height: 100% !important;
        height: 100lvh !important;
        min-height: 100% !important;
        min-height: 100lvh !important;
        min-height: -webkit-fill-available !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 60 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        background-color: #000000 !important;
        box-shadow: none !important;
    }

    /* 3. 摄像头视频流：绝对贴满物理屏幕边缘，穿透 Safari 毛玻璃顶底栏 */
    .camera-viewport-container.mobile-camera-active video#camera-preview {
        position: absolute !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        min-width: 100% !important;
        min-height: 100% !important;
        min-height: 100lvh !important;
        min-height: -webkit-fill-available !important;
        object-fit: cover !important;
        z-index: 0 !important;
    }
}

@media (min-width: 640px) {
    .camera-viewport-container.mobile-camera-active {
        position: relative !important;
        aspect-ratio: 4 / 3 !important;
        max-width: 48rem !important;
        border-radius: 1.5rem !important;
        border: 1px solid rgba(30, 41, 59, 0.8) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* 纯圆极简模式切换胶囊 */
.pill-capsule-bar {
    border-radius: 9999px !important;
}
.pill-capsule-bar button,
.pill-capsule-bar a {
    border-radius: 9999px !important;
}

