/* ========================================
   响应式适配 — PC端 / 平板 / 手机端
   配合 style.css 和 project.css 使用
   ======================================== */

/* ========================================
   全局移动端基础优化
   ======================================== */

/* 消除移动端点击高亮 */
* {
    -webkit-tap-highlight-color: transparent;
}

/* 平滑触摸滚动 */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-overflow-scrolling: touch;
    text-size-adjust: 100%;
}

/* 防止移动端回弹滚动 */
body {
    overscroll-behavior-y: contain;
    /* 安全区域留白 */
    padding-top: env(safe-area-inset-top);
}

/* 所有可点击元素最小触控区域 44px（Apple HIG） */
.nav-link,
.filter-btn,
.btn,
.share-btn,
.footer-social a,
.carousel-btn,
.carousel-dot,
.lightbox-nav,
.lightbox-close,
.lightbox-dot,
.video-play,
.back-to-top,
.theme-toggle,
.lang-toggle,
.nav-toggle {
    min-height: 44px;
    min-width: 44px;
}

/* ========================================
   安全区域适配（iPhone X+ 刘海/底部条）
   ======================================== */
/* 导航栏安全区域适配 */
.navbar {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
    height: calc(var(--nav-height) + env(safe-area-inset-top));
}

.navbar.scrolled {
    height: calc(64px + env(safe-area-inset-top));
}

.back-to-top {
    bottom: max(30px, calc(env(safe-area-inset-bottom) + 20px));
    right: max(20px, env(safe-area-inset-right));
}

.footer {
    padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 20px));
}

.scroll-progress {
    top: env(safe-area-inset-top);
}

/* 导航菜单安全区域 - 仅在 mobile 模式下由 style.css 内的 @media (max-width:768px) 处理 */

/* ========================================
   平板端适配 (769px ~ 1024px)
   ======================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 900px;
        padding: 0 20px;
    }

    .about-content {
        grid-template-columns: 1fr 1.2fr;
        gap: 40px;
    }

    .avatar-ring {
        width: 240px;
        height: 240px;
    }

    .hobbies-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .highlights-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .blog-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .videos-grid {
        grid-template-columns: 1fr;
        max-width: 600px;
        margin: 0 auto;
    }

    .friends-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .project-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .related-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .hobby-card {
        padding: 32px 28px;
    }

    .section {
        padding: 80px 0;
    }

    .hero-emoji {
        font-size: 60px;
    }
}

/* ========================================
   小平板 / 大手机横屏 (481px ~ 768px)
   ======================================== */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 0 20px;
    }

    /* 作品集和博客改为两列 */
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .blog-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .friends-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 视频单列居中 */
    .videos-grid {
        grid-template-columns: 1fr;
        max-width: 500px;
        margin: 0 auto;
    }
}

/* ========================================
   手机端适配 (≤ 768px) — 触屏优化
   ======================================== */
@media (max-width: 768px) and (pointer: coarse) {
    /* 触屏设备：轮播按钮常驻显示 */
    .carousel-btn {
        opacity: 0.85;
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .carousel-btn:hover {
        opacity: 1;
        transform: translateY(-50%) scale(1.05);
    }

    /* 触屏设备：卡片悬浮效果改为按压效果 */
    .hobby-card:hover,
    .portfolio-card:hover,
    .blog-card:hover,
    .video-card:hover,
    .friend-card:hover {
        transform: translateY(-4px);
    }

    /* 触屏设备：取消hover缩放，改为active按压 */
    .portfolio-card:active .portfolio-emoji,
    .hobby-card:active .hobby-icon {
        transform: scale(1.1);
    }

    /* 触屏设备：作品集遮罩常驻半透明 */
    .portfolio-overlay {
        opacity: 0;
    }

    .portfolio-card:active .portfolio-overlay {
        opacity: 1;
    }
}

/* ========================================
   手机端适配 (≤ 768px) — 完整布局
   ======================================== */
@media (max-width: 768px) {
    /* 导航栏优化 */
    .nav-container {
        padding: 0 16px;
    }

    .nav-logo {
        font-size: 17px;
    }

    .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    /* 移动端菜单遮罩 */
    .nav-menu-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .nav-menu-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    .nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: min(300px, 80vw);
        height: 100vh;
        height: 100dvh;
        background: rgba(11, 16, 32, 0.98);
        backdrop-filter: blur(20px);
        flex-direction: column;
        padding: max(80px, env(safe-area-inset-top)) 20px env(safe-area-inset-bottom);
        gap: 4px;
        transition: right 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
        z-index: 1001;
        overflow-y: auto;
        border-left: 1px solid rgba(255, 255, 255, 0.06);
    }

    [data-theme="dark"] .nav-menu {
        background: rgba(5, 8, 22, 0.98);
    }

    .nav-menu.active {
        right: 0;
    }

    .nav-link {
        color: rgba(255, 255, 255, 0.85) !important;
        font-size: 16px;
        padding: 14px 20px;
        border-radius: 10px;
        display: block;
        width: 100%;
    }

    .nav-link::after {
        display: none;
    }

    .nav-link:hover,
    .nav-link.active {
        background: rgba(99, 102, 241, 0.15);
        color: #fff !important;
    }

    .nav-toggle {
        display: flex;
        z-index: 1002;
    }

    /* Section间距 */
    .section {
        padding: 60px 0;
    }

    .section-header {
        margin-bottom: 40px;
    }

    /* Hero区域 */
    .hero {
        min-height: 100vh;
        min-height: 100dvh;
        padding-bottom: 110px;   /* 移动端确保按钮与底部 scroll-indicator 不会重叠 */
    }

    .hero-content {
        padding: 20px 20px 0;
    }

    .hero-emoji {
        font-size: 52px;
        margin-bottom: 16px;
    }

    .hero-buttons {
        flex-direction: column;
        width: 100%;
        max-width: 280px;
        margin: 0 auto 24px;
        gap: 12px;
    }

    .btn {
        width: 100%;
        padding: 12px 28px;
        font-size: 15px;
    }

    .scroll-indicator {
        bottom: max(30px, env(safe-area-inset-bottom));
    }

    /* 减小blob尺寸防止溢出 */
    .blob-1 {
        width: 300px;
        height: 300px;
    }

    .blob-2 {
        width: 250px;
        height: 250px;
    }

    .blob-3 {
        width: 280px;
        height: 280px;
    }

    /* 关于我 */
    .about-content {
        grid-template-columns: 1fr;
        gap: 32px;
        text-align: center;
    }

    .about-avatar {
        order: -1;
    }

    .avatar-ring {
        width: 180px;
        height: 180px;
    }

    .avatar-placeholder {
        font-size: 64px;
    }

    .badge-floating {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .about-text h3 {
        font-size: 1.4rem;
    }

    .about-text p {
        font-size: 0.95rem;
    }

    .skills {
        justify-content: center;
        gap: 8px;
    }

    .skill-tag {
        padding: 6px 16px;
        font-size: 13px;
    }

    .about-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .stat-num {
        font-size: 1.6rem;
    }

    .skill-bars {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* 时间线 */
    .timeline {
        padding-left: 28px;
        max-width: 100%;
    }

    .timeline-dot {
        left: -30px;
        width: 14px;
        height: 14px;
    }

    .timeline-date {
        font-size: 12px;
    }

    .timeline-title {
        font-size: 1rem;
    }

    .timeline-desc {
        font-size: 0.85rem;
    }

    /* 爱好卡片 */
    .hobbies-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .highlights-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .highlight-card {
        padding: 28px 20px;
    }

    .hobby-card {
        padding: 28px 24px;
    }

    .hobby-icon {
        width: 56px;
        height: 56px;
        font-size: 28px;
        margin-bottom: 16px;
    }

    .hobby-card h3 {
        font-size: 1.2rem;
    }

    .hobby-card p {
        font-size: 0.9rem;
    }

    .hobby-gallery {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    /* 作品集 */
    .portfolio-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .portfolio-filters {
        gap: 6px;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 8px;
        flex-wrap: nowrap;
        white-space: nowrap;
    }

    .portfolio-filters::-webkit-scrollbar {
        display: none;
    }

    .filter-btn {
        padding: 8px 16px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .portfolio-info {
        padding: 20px;
    }

    .portfolio-info h3 {
        font-size: 1.1rem;
    }

    .portfolio-info p {
        font-size: 0.88rem;
    }

    .portfolio-emoji {
        font-size: 52px;
    }

    /* 视频区 */
    .videos-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .video-emoji {
        font-size: 52px;
    }

    .video-play {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }

    .video-info {
        padding: 20px;
    }

    /* 视频弹窗 */
    .video-modal {
        padding: 0;
    }

    .video-modal-content {
        max-width: 100%;
    }

    .video-modal-content iframe,
    .video-modal-content video {
        border-radius: 0;
        width: 100vw;
    }

    .video-modal-content h3 {
        font-size: 1.1rem;
        padding: 0 16px;
    }

    .video-modal-close {
        top: max(12px, env(safe-area-inset-top));
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    /* 博客 */
    .blog-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .blog-emoji {
        font-size: 44px;
    }

    .blog-content {
        padding: 20px;
    }

    .blog-content h3 {
        font-size: 1.05rem;
    }

    .blog-content p {
        font-size: 0.88rem;
    }

    /* 联系区 */
    .contact-wrapper {
        grid-template-columns: 1fr;
        gap: 32px;
    }

    .contact-form {
        padding: 24px 20px;
    }

    /* 表单输入框 font-size ≥ 16px 防止 iOS 自动缩放 */
    .form-group input,
    .form-group textarea {
        font-size: 16px;
        padding: 12px 16px;
    }

    .contact-item {
        padding: 14px 16px;
        gap: 12px;
    }

    .contact-icon {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }

    /* 友链 */
    .friends-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .friend-card {
        padding: 16px 20px;
    }

    .friend-avatar {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    /* 页脚 */
    .footer {
        padding: 40px 0 max(30px, env(safe-area-inset-bottom));
    }

    .footer-brand {
        font-size: 22px;
    }

    .footer-text {
        font-size: 0.9rem;
    }

    .footer-social {
        gap: 12px;
    }

    .footer-social a {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* 回到顶部按钮 */
    .back-to-top {
        width: 44px;
        height: 44px;
        font-size: 20px;
        bottom: max(20px, env(safe-area-inset-bottom));
        right: 16px;
    }

    /* 主题切换按钮 */
    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* 语言切换按钮 - 超小屏紧凑模式 */
    .lang-toggle {
        height: 36px;
        padding: 0 10px;
        font-size: 12px;
        gap: 4px;
    }
    .lang-toggle .lang-icon {
        font-size: 14px;
    }

    /* Lightbox 全屏查看器 */
    .lightbox-container {
        padding: 40px 8px;
    }

    .lightbox-content img {
        max-width: 95vw;
        max-height: 70vh;
    }

    .lightbox-content iframe,
    .lightbox-content video {
        width: 95vw;
    }

    .lightbox-nav {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .lightbox-prev {
        left: 4px;
    }

    .lightbox-next {
        right: 4px;
    }

    .lightbox-close {
        top: max(12px, env(safe-area-inset-top));
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .lightbox-caption {
        bottom: 40px;
        font-size: 13px;
        max-width: 90vw;
    }

    .lightbox-dots {
        bottom: max(16px, env(safe-area-inset-bottom));
    }

    /* 作品详情页 */
    .project-navbar {
        padding: 12px 16px;
    }

    .project-hero {
        min-height: 50vh;
        padding: 100px 0 50px;
    }

    .project-hero-content {
        padding: 0 20px;
    }

    .project-hero-title {
        font-size: clamp(1.5rem, 5vw, 2.2rem);
    }

    .project-hero-desc {
        font-size: 1rem;
    }

    .project-body {
        padding: 40px 0;
    }

    .project-section {
        margin-bottom: 32px;
    }

    .project-section-title {
        font-size: 1.3rem;
    }

    .project-detail-desc p {
        font-size: 0.95rem;
    }

    .project-gallery {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .related-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .related-projects {
        padding: 50px 0;
    }

    .related-title {
        font-size: 1.5rem;
    }

    /* 社交分享 */
    .share-buttons {
        gap: 8px;
    }

    .share-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* 滚动动画简化（移动端性能优化） */
    .reveal {
        transition: opacity 0.5s ease;
    }

    /* 粒子动画减少 */
    .particle {
        display: none;
    }

    /* blob 动画减慢（省电） */
    .blob {
        animation-duration: 30s;
    }
}

/* ========================================
   超小屏幕 (≤ 375px) — iPhone SE 等
   ======================================== */
@media (max-width: 375px) {
    .container {
        padding: 0 14px;
    }

    .section {
        padding: 48px 0;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .section-tag {
        font-size: 11px;
        letter-spacing: 2px;
    }

    .hero-emoji {
        font-size: 44px;
    }

    .hero-title {
        font-size: clamp(1.8rem, 8vw, 2.2rem);
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .hero-desc {
        font-size: 0.85rem;
    }

    .avatar-ring {
        width: 150px;
        height: 150px;
    }

    .avatar-placeholder {
        font-size: 54px;
    }

    .badge-floating {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .hobby-card {
        padding: 24px 18px;
    }

    .hobby-icon {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }

    .portfolio-info,
    .video-info,
    .blog-content {
        padding: 16px;
    }

    .contact-form {
        padding: 20px 16px;
    }

    .friend-card {
        padding: 14px 16px;
    }

    .footer-social a {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .btn {
        padding: 12px 20px;
        font-size: 14px;
    }
}

/* ========================================
   横屏手机适配
   ======================================== */
@media (max-width: 968px) and (orientation: landscape) and (max-height: 500px) {
    .hero {
        min-height: 100vh;
        min-height: 100dvh;
        padding-top: 80px;
        padding-bottom: 40px;
    }

    .hero-emoji {
        font-size: 40px;
        margin-bottom: 8px;
    }

    .hero-buttons {
        flex-direction: row;
        max-width: none;
    }

    .btn {
        width: auto;
    }

    .nav-menu {
        height: 100vh;
        height: 100dvh;
    }
}

/* ========================================
   大屏PC端优化 (≥ 1400px)
   ======================================== */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }

    .nav-container {
        max-width: 1320px;
    }

    .section {
        padding: 120px 0;
    }

    .hero-emoji {
        font-size: 84px;
    }

    .hobbies-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 32px;
    }

    .portfolio-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 32px;
    }

    .blog-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 32px;
    }

    .avatar-ring {
        width: 320px;
        height: 320px;
    }
}

/* ========================================
   超大屏 (≥ 1920px)
   ======================================== */
@media (min-width: 1920px) {
    .container {
        max-width: 1500px;
    }

    .nav-container {
        max-width: 1500px;
    }

    body {
        font-size: 17px;
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .navbar,
    .nav-toggle,
    .back-to-top,
    .theme-toggle,
    .scroll-progress,
    .scroll-indicator,
    .hero-particles,
    .blob,
    .video-modal,
    .lightbox-overlay,
    .preloader,
    .share-buttons,
    .contact-form,
    .footer-social {
        display: none !important;
    }

    body {
        color: #000;
        background: #fff;
    }

    .section {
        padding: 20px 0;
        page-break-inside: avoid;
    }

    .hobby-card,
    .portfolio-card,
    .blog-card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }

    .reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ========================================
   暗黑模式 — 移动端导航菜单适配
   ======================================== */
[data-theme="dark"] .nav-menu {
    background: rgba(5, 8, 22, 0.98);
}

[data-theme="dark"] .nav-link {
    color: rgba(241, 245, 249, 0.85) !important;
}

[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-link.active {
    background: rgba(99, 102, 241, 0.2);
    color: #fff !important;
}

/* ========================================
   动画偏好 — 尊重 prefers-reduced-motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .blob,
    .particle,
    .hero-emoji {
        animation: none !important;
    }

    .reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}
