/**
 * Responsive Styles
 * Austin's Portfolio Site
 * 断点：1400px / 1200px / 991px / 768px / 576px / 400px
 */

/* ========== 全局防溢出修复 ========== */
/* 此规则必须在最前面以确保优先级 */
*, *::before, *::after {
    box-sizing: border-box;
}

/* ========== Large Desktops (1400px+) ========== */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }
}

/* ========== Medium Desktops (1200px+) ========== */
@media (min-width: 1200px) {
    .hero-bg {
        background-attachment: fixed;
    }
}

/* ========== Tablets and Small Desktops (<1200px) ========== */
@media (max-width: 1199px) {
    /* 防止横向滚动 */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    body {
        overscroll-behavior-x: none;
    }

    /* 确保所有主要容器不会溢出 */
    #main,
    .section,
    .container,
    #hero,
    .hero-content {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* ========== AOS 移动端回退 ========== */
    /* 当 AOS 在移动端禁用时，确保所有带 data-aos 属性的元素正常显示 */
    [data-aos] {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
        pointer-events: auto !important;
        visibility: visible !important;
    }

    /* ========== 隐藏桌面端侧边栏 ========== */
    #header {
        display: none !important;
    }

    /* ========== 显示移动端导航 ========== */
    .mobile-header {
        display: flex !important;
        align-items: center !important;
    }

    .mobile-nav-toggle {
        display: block !important;
    }

    .mobile-nav-menu {
        display: block !important;
    }

    /* 主内容区域 */
    #main {
        margin-left: 0 !important;
        padding-top: 60px; /* 为移动端顶部栏留出空间 */
    }

    /* Hero 区域调整 */
    #hero {
        min-height: calc(100vh - 60px);
        min-height: calc(100dvh - 60px);
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Footer */
    #footer {
        position: static;
        width: 100% !important;
        padding: 20px 15px;
        margin-left: 0 !important;
    }

    /* 移动端导航激活时禁止滚动 */
    body.mobile-nav-active {
        overflow: hidden !important;
    }

    /* 忽略桌面端的collapsed状态 */
    body.sidebar-collapsed #main,
    body.sidebar-collapsed #footer {
        margin-left: 0 !important;
    }

    /* Container Padding */
    .container {
        padding-left: 15px;
        padding-right: 15px;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* Resume */
    .resume-content {
        grid-template-columns: 1fr;
    }

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

    .resume-grid {
        grid-template-columns: 1fr;
    }

    /* Contact */
    .contact-content {
        grid-template-columns: 1fr;
    }
}

/* ========== Tablets (<992px) ========== */
@media (max-width: 991px) {
    /* About */
    .about-content {
        grid-template-columns: 1fr;
    }

    .about-image {
        text-align: center;
    }

    .about-image img {
        max-width: 400px;
        margin: 0 auto;
    }

    /* Skills */
    .skills-content {
        grid-template-columns: 1fr;
    }

    /* Why Me */
    .why-me-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Contact */
    .contact-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Section Title */
    .section-title h2::after {
        left: 50%;
        transform: translateX(-50%);
    }

    .section-title {
        text-align: center;
    }

    .why-me-subtitle {
        margin: 0 auto;
        text-align: center;
    }
}

/* ========== 中等平板 (600-768px) ========== */
@media (max-width: 768px) and (min-width: 601px) {
    .contact-cards-row {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-sm);
    }

    .contact-card {
        padding: var(--space-md);
    }

    .contact-card-icon {
        width: 40px;
        height: 40px;
    }

    .contact-card-icon i {
        font-size: 18px;
    }

    .contact-card h4 {
        font-size: 0.65rem;
    }

    .contact-card p {
        font-size: var(--fs-xs);
        word-break: break-all;
    }
}

/* ========== Small Tablets and Large Phones (<768px) ========== */
@media (max-width: 768px) {
    /* Hero - 修复 iOS Safari 100vh 问题 */
    #hero {
        min-height: 100vh;
        min-height: -webkit-fill-available;
        min-height: 100dvh; /* 动态视口高度 */
        padding: 60px 0 40px;
    }

    .hero-content {
        padding: var(--space-md);
    }

    .hero-card {
        padding: var(--space-lg);
    }

    .hero-card h1 {
        font-size: 1.6rem;
        line-height: 1.3;
    }

    .hero-title {
        font-size: var(--fs-sm);
        padding: var(--space-xs) var(--space-md);
    }

    /* Hero Highlights 响应式优化 */
    .hero-highlights {
        gap: var(--space-xs);
        margin-bottom: var(--space-lg);
    }

    .highlight-item {
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-sm);
    }

    .highlight-item i {
        font-size: var(--fs-base);
        min-width: 20px;
    }

    .highlight-item span {
        font-size: var(--fs-xs);
        line-height: 1.4;
    }

    .hero-avatar {
        width: 80px;
        height: 80px;
    }

    .hero-cta {
        padding: var(--space-sm) var(--space-lg);
        font-size: var(--fs-xs);
    }

    /* Resume Stats */
    .resume-stats {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .stat-item {
        padding: var(--space-md);
        min-width: calc(50% - var(--space-sm));
        max-width: calc(50% - var(--space-sm));
    }

    .stat-number {
        font-size: var(--fs-xl);
    }

    .stat-icon {
        font-size: 20px;
    }

    /* Section */
    .section {
        padding: 40px 0;
    }

    /* About Details */
    .about-details {
        grid-template-columns: 1fr;
    }

    .about-subheading2 {
        font-size: var(--fs-xs) !important;
        letter-spacing: 1px;
        padding: var(--space-xs);
    }

    /* Why Me */
    .why-me-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .why-me-item {
        padding: var(--space-lg);
    }

    /* Contact */
    .contact {
        padding-bottom: 60px;
    }

    .contact-cards-row {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-sm);
    }

    .wechat-content {
        flex-direction: column;
        text-align: center;
    }

    .wechat-info {
        text-align: center;
    }

    .wechat-icon {
        margin: 0 auto var(--space-md);
    }

    .contact-wechat-full .wechat-qr-code {
        width: 150px;
        height: 150px;
    }

    .contact-card {
        padding: var(--space-md);
    }

    .contact-card-icon {
        width: 44px;
        height: 44px;
    }

    .contact-card-icon i {
        font-size: 20px;
    }

    .contact-card h4 {
        font-size: 0.7rem;
    }

    .contact-card p {
        font-size: var(--fs-sm);
    }

    /* Back to Top */
    .back-to-top {
        bottom: 70px;
    }
}

/* ========== Phones (<576px) ========== */
@media (max-width: 576px) {
    /* Typography */
    :root {
        --fs-2xl: 1.5rem;
        --fs-xl: 1.25rem;
        --fs-lg: 1rem;
    }

    /* Hero */
    .hero-content {
        padding: var(--space-sm);
    }

    .hero-card {
        padding: var(--space-md);
        border-radius: 20px;
    }

    .hero-card h1 {
        font-size: 1.4rem;
        letter-spacing: 1px;
    }

    .hero-title {
        font-size: var(--fs-xs);
        padding: 6px 12px;
        margin-bottom: var(--space-lg);
    }

    .hero-avatar {
        width: 70px;
        height: 70px;
        margin-bottom: var(--space-md);
    }

    .hero-highlights {
        margin-bottom: var(--space-md);
    }

    .highlight-item {
        padding: 8px 12px;
        border-radius: 6px;
    }

    .highlight-item i {
        font-size: 14px;
        min-width: 18px;
    }

    .highlight-item span {
        font-size: 11px;
    }

    .hero-cta {
        padding: 10px 20px;
        font-size: 12px;
    }

    /* Section Title */
    .section-title h2 {
        font-size: var(--fs-lg);
    }

    /* Resume Stats */
    .stat-item {
        min-width: 100%;
        max-width: 100%;
    }

    /* Resume */
    .resume-item {
        padding: var(--space-sm);
        padding-left: var(--space-lg);
    }

    .resume-item h4 {
        font-size: var(--fs-sm);
    }

    .resume-item h5 {
        font-size: var(--fs-xs);
    }

    /* Contact Cards - 垂直堆叠 */
    .contact-cards-row {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .contact-card {
        padding: var(--space-lg);
    }

    .contact-card-icon {
        width: 50px;
        height: 50px;
    }

    .contact-card-icon i {
        font-size: 24px;
    }

    .contact-card h4 {
        font-size: var(--fs-xs);
    }

    .contact-card p {
        font-size: var(--fs-base);
    }

    .wechat-id {
        font-size: var(--fs-lg);
    }

    .contact-wechat-full .wechat-qr-code {
        width: 130px;
        height: 130px;
    }

    /* Why Me */
    .why-me-item {
        text-align: center;
        padding: var(--space-md);
    }

    .why-me-item .icon {
        margin: 0 auto var(--space-md);
        width: 50px;
        height: 50px;
    }

    .why-me-item .icon i {
        font-size: 24px;
    }

    .why-me-item .content h4 {
        font-size: var(--fs-base);
    }

    .why-me-item .content p {
        font-size: var(--fs-xs);
    }

    /* Contact */
    .contact-grid {
        grid-template-columns: 1fr;
    }

    /* Info Item */
    .info-item i {
        float: none;
        margin: 0 auto var(--space-sm);
    }

    .info-item h4,
    .info-item p {
        padding-left: 0;
        text-align: center;
    }

    /* Buttons */
    .btn {
        width: 100%;
        justify-content: center;
    }

    /* About Section */
    .about-image img {
        max-width: 280px;
    }
}

/* ========== Extra Small Phones (<400px) ========== */
@media (max-width: 400px) {
    .hero-card {
        padding: var(--space-sm);
    }

    .hero-card h1 {
        font-size: 1.2rem;
    }

    .hero-avatar {
        width: 60px;
        height: 60px;
    }

    .highlight-item {
        padding: 6px 10px;
    }

    .highlight-item span {
        font-size: 10px;
    }

    .hero-cta {
        padding: 8px 16px;
        font-size: 11px;
    }

    /* Section */
    .section {
        padding: 30px 0;
    }

    .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Contact */
    .contact-wechat-full {
        padding: var(--space-md);
    }

    .contact-wechat-full .wechat-qr-code {
        width: 120px;
        height: 120px;
    }

    /* 小屏幕移动端导航适配 */
    .mobile-nav-content {
        padding: 80px 16px 40px;
    }

    .mobile-nav-profile {
        margin-bottom: 24px;
    }

    .mobile-profile-avatar {
        width: 65px;
        height: 65px;
    }

    .mobile-profile-name {
        font-size: 1.2rem;
    }

    .mobile-nav-links {
        max-width: 280px;
        gap: 10px;
    }

    .mobile-nav-link {
        padding: 14px 18px;
        gap: 12px;
        font-size: 0.95rem;
    }

    .mobile-nav-link .nav-icon {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
        border-radius: 12px;
    }

    .mobile-lang-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .mobile-social-links a {
        width: 46px;
        height: 46px;
        font-size: 1.3rem;
    }
}

/* ========== Print Styles ========== */
@media print {
    #header,
    #footer,
    .mobile-nav-toggle,
    .back-to-top,
    .language-switcher {
        display: none !important;
    }

    #main {
        margin-left: 0;
    }

    #hero {
        min-height: auto;
        padding: 40px 0;
    }

    .hero-bg::before {
        background: none;
    }

    .hero-card h1 {
        color: var(--color-dark);
    }

    .section {
        page-break-inside: avoid;
    }

    a {
        text-decoration: underline;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: var(--text-muted);
    }
}

/* ========== High Contrast Mode ========== */
@media (prefers-contrast: high) {
    :root {
        --color-primary: #0066cc;
        --text-primary: #000000;
        --text-muted: #333333;
    }

    .nav-menu a,
    #footer {
        border: 1px solid currentColor;
    }
}

/* ========== Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }

    .skill-progress {
        transition: none;
    }
}

/* ========== 触摸设备优化 ========== */
@media (hover: none) and (pointer: coarse) {
    /* 移除 hover 效果的 transform，避免触摸时闪烁 */
    .resume-item.clickable:hover {
        transform: none;
    }

    .why-me-item:hover {
        transform: none;
    }

    .contact-card:hover {
        transform: none;
    }

    .highlight-item:hover {
        transform: none;
    }

    /* 增大触摸目标 */
    .nav-menu a {
        padding: 14px 15px;
        min-height: 48px;
    }

    .lang-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .back-to-top {
        width: 48px;
        height: 48px;
    }

    /* 移动端导航触摸优化 */
    .mobile-nav-link {
        min-height: 56px;
    }

    .mobile-nav-link:active {
        transform: scale(0.98);
        background: rgba(20, 157, 221, 0.2);
    }

    .mobile-lang-btn {
        min-height: 44px;
    }

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

    .mobile-social-links a {
        min-width: 52px;
        min-height: 52px;
    }

    .mobile-social-links a:active {
        transform: scale(0.9);
    }
}

/* ========== 横屏手机优化 ========== */
@media (max-height: 500px) and (orientation: landscape) {
    #hero {
        min-height: auto;
        padding: 30px 0;
    }

    .hero-card {
        padding: var(--space-md);
    }

    .hero-avatar {
        width: 50px;
        height: 50px;
        margin-bottom: var(--space-sm);
    }

    .hero-card h1 {
        font-size: 1.2rem;
        margin-bottom: var(--space-xs);
    }

    .hero-highlights {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-xs);
        margin-bottom: var(--space-md);
    }

    /* 横屏模式下的移动端导航优化 */
    .mobile-nav-content {
        padding: 70px 24px 30px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 24px;
    }

    .mobile-nav-profile {
        flex-direction: row;
        margin-bottom: 0;
        gap: 16px;
    }

    .mobile-profile-avatar {
        width: 50px;
        height: 50px;
        margin-bottom: 0;
    }

    .mobile-profile-name {
        font-size: 1.1rem;
    }

    .mobile-nav-links {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        max-width: none;
        gap: 8px;
        margin-bottom: 0;
    }

    .mobile-nav-link {
        width: auto;
        padding: 12px 20px;
    }

    .mobile-nav-link .nav-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .mobile-nav-link .nav-text {
        font-size: 0.9rem;
    }

    .mobile-nav-footer {
        flex-direction: row;
        margin-top: 16px;
        padding-top: 16px;
        gap: 24px;
    }

    .highlight-item {
        flex: 0 1 auto;
        max-width: 45%;
    }

    .hero-title {
        margin-bottom: var(--space-md);
    }
}

/* ========== Dark Mode 系统偏好 (已是深色主题，保持一致) ========== */
@media (prefers-color-scheme: dark) {
    /* 网站已经是深色主题，无需额外调整 */
}

/* ========== Safe Area (iPhone X+ 刘海屏) ========== */
@supports (padding: max(0px)) {
    #header {
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
    }

    /* mobile-header 已经用 padding 处理安全区域，不需要给按钮单独设置 */
    .mobile-header {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }

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

    #footer {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}