/* Critical CSS is inlined in HTML for faster first paint */

/* Extended CSS Variables */
:root {
    --focus-ring: 0 0 0 4px rgba(10, 132, 255, 0.25);
    --selection-bg: rgba(10, 132, 255, 0.2);
    --selection-text: #1d1d1f;
}

@media (prefers-color-scheme: dark) {
    :root {
        --focus-ring: 0 0 0 4px rgba(255, 92, 141, 0.25);
        --selection-bg: rgba(255, 92, 141, 0.3);
        --selection-text: #f5f5f7;
    }
}

html {
    scroll-behavior: smooth;
}

/* Custom Text Selection */
::selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

::-moz-selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

/* iOS Safe Area Support */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

@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;
    }
}

/* Extended body styles beyond critical CSS */
body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Focus Styles */
a:focus-visible,
button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 8px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

/* Remove tap highlight on all interactive elements */
a, button, input, textarea {
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 0 22px;
}

/* Hero Section - extends critical CSS */
.hero {
    padding: 40px 22px;
}

@supports (height: 100svh) {
    .hero {
        min-height: 100svh;
    }
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin-bottom: 24px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

@media (prefers-color-scheme: dark) {
    .avatar {
        box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
    }
}

.hero h1 {
    font-size: clamp(48px, 6vw, 64px);
    font-weight: 800;
    font-family: ui-monospace, 'SF Mono', Monaco, Menlo, Consolas, 'Courier New', monospace;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 12px;
    background: linear-gradient(180deg, #6e6e73 0%, #1d1d1f 50%, #6e6e73 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

@media (prefers-color-scheme: dark) {
    .hero h1 {
        background: linear-gradient(180deg, #86868b 0%, #f5f5f7 50%, #86868b 100%);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
}

.subtitle {
    font-size: 21px;
    color: var(--text-secondary);
    font-weight: 400;
    -webkit-user-select: none;
    user-select: none;
}

/* About Section */
.about {
    padding: clamp(60px, 10vh, 100px) 22px;
    background: var(--bg-secondary);
}

.lead {
    font-size: clamp(21px, 3vw, 28px);
    font-weight: 600;
    text-align: left;
    line-height: 1.5;
    color: var(--text);
    max-width: 760px;
    margin: 0 auto;
    letter-spacing: -0.01em;
}

/* Skills Section */
.skills {
    padding: clamp(80px, 12vh, 120px) 22px;
}

.skills h2 {
    font-size: 48px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 60px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.skills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    max-width: 980px;
    margin: 0 auto;
}

/* Card */
.skill-card,
.project-card,
.current-card {
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid var(--border);
    transition: all 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
    will-change: transform;
    /* Performance optimizations */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {

    .skill-card:hover,
    .project-card:hover {
        transform: scale(1.02);
        border-color: rgba(10, 132, 255, 0.3);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04), 0 8px 32px rgba(0, 0, 0, 0.04);
    }

    @media (prefers-color-scheme: dark) {

        .skill-card:hover,
        .project-card:hover {
            border-color: rgba(255, 92, 141, 0.4);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 8px 32px rgba(0, 0, 0, 0.2);
        }
    }
}

.skill-card {
    padding: 40px 32px;
    text-align: center;
}

.project-card {
    padding: 40px 32px;
}

.skill-icon {
    font-size: 48px;
    margin-bottom: 20px;
    -webkit-user-select: none;
    user-select: none;
}

.skill-card h3 {
    font-size: 21px;
    font-weight: 600;
    margin-bottom: 8px;
}

.skill-card p {
    font-size: 17px;
    color: var(--text-secondary);
}

/* Current Section */
.current {
    padding: clamp(80px, 12vh, 120px) 22px;
    background: var(--bg-secondary);
}

.current h2 {
    font-size: 48px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 60px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.current-card {
    padding: 48px 40px;
    max-width: 800px;
    margin: 0 auto;
}

.badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 20px;
    -webkit-user-select: none;
    user-select: none;
}

.current-card h3 {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.current-card p {
    font-size: 19px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Projects Section */
.projects {
    padding: clamp(80px, 12vh, 120px) 22px;
}

.projects h2 {
    font-size: 48px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 60px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    max-width: 980px;
    margin: 0 auto;
}

.project-number {
    font-size: 14px;
    font-weight: 600;
    font-family: ui-monospace, 'SF Mono', Monaco, Menlo, Consolas, 'Courier New', monospace;
    color: var(--text-secondary);
    margin-bottom: 20px;
    -webkit-user-select: none;
    user-select: none;
}

.project-card h3 {
    font-size: 24px;
    font-weight: 600;
    font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    margin-bottom: 12px;
}

.project-card p {
    font-size: 17px;
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.link {
    color: var(--accent);
    text-decoration: none;
    font-size: 17px;
    font-weight: 500;
    position: relative;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.link::after {
    content: '→';
    display: inline-block;
    margin-left: 4px;
    transition: transform 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
    -webkit-user-select: none;
    user-select: none;
}

@media (hover: hover) {
    .link:hover {
        opacity: 0.7;
    }

    .link:hover::after {
        transform: translateX(4px);
    }
}

/* Channels Section */
.channels {
    padding: clamp(80px, 12vh, 120px) 22px;
    background: var(--bg-secondary);
}

.channels h2 {
    font-size: 48px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.section-desc {
    text-align: center;
    font-size: 21px;
    color: var(--text-secondary);
    margin-bottom: 48px;
}

.social-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.social-links a,
.social-links button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    text-decoration: none;
    color: var(--text);
    min-height: 88px;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    transition: all 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
    will-change: transform;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .social-links a:hover,
    .social-links button:hover {
        background: var(--bg-secondary);
        transform: scale(1.03);
    }

    .social-links a:hover svg,
    .social-links button:hover svg {
        transform: scale(1.08);
        opacity: 1;
    }

    /* Platform-specific brand colors on hover */
    .social-links a[data-platform="github"]:hover svg {
        color: #181717;
    }

    .social-links a[data-platform="twitter"]:hover svg {
        color: #1DA1F2;
    }

    .social-links a[data-platform="youtube"]:hover svg {
        color: #FF0000;
    }

    .social-links a[data-platform="bilibili"]:hover svg {
        color: #FB7299;
    }

    .social-links a[data-platform="wechat"]:hover svg,
    .social-links button[data-platform="wechat"]:hover svg {
        color: #07C160;
    }

    .social-links a[data-platform="channels"]:hover svg,
    .social-links button[data-platform="channels"]:hover svg {
        color: #fa9d3b;
    }

    .social-links a[data-platform="blog"]:hover svg path {
        opacity: 1;
    }

    .social-links a[data-platform="blog"]:hover .blog-gradient {
        opacity: 1;
    }

    .social-links a[data-platform="blog"]:hover .blog-default {
        opacity: 0;
    }

    .social-links a[data-platform="email"]:hover svg {
        color: #EA4335;
    }
}

/* Blog gradient toggle - applies to all devices */
.social-links a[data-platform="blog"] .blog-gradient,
.social-links a[data-platform="blog"] .blog-default {
    transition: opacity 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.social-links a[data-platform="blog"] .blog-gradient {
    opacity: 0;
}

/* Dark mode adjustments for platform colors */
@media (prefers-color-scheme: dark) {
    @media (hover: hover) and (prefers-reduced-motion: no-preference) {
        .social-links a[data-platform="github"]:hover svg {
            color: #ffffff;
        }
    }
}

/* Touch feedback for mobile devices */
@media (hover: none) {
    .social-links a:active,
    .social-links button:active {
        transform: scale(0.97);
        opacity: 0.8;
    }

    .skill-card:active,
    .project-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .link:active {
        opacity: 0.6;
    }
}

.social-links svg {
    width: 28px;
    height: 28px;
    padding: 2px;
    color: var(--text);
    opacity: 0.7;
    overflow: visible;
    flex-shrink: 0;
    display: block;
    pointer-events: none;
    transition: all 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
    -webkit-user-select: none;
    user-select: none;
}

@media (prefers-color-scheme: dark) {
    .social-links svg {
        opacity: 0.8;
    }
}

.social-links span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    opacity: 0.75;
    transition: all 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
    -webkit-user-select: none;
    user-select: none;
}

/* Footer */
footer {
    padding: clamp(40px, 8vh, 80px) 22px;
    text-align: center;
}

footer p {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {

    .skills h2,
    .current h2,
    .projects h2,
    .channels h2 {
        font-size: 40px;
    }

    .skills,
    .current,
    .projects,
    .channels {
        padding: clamp(60px, 10vh, 100px) 22px;
    }

    .about {
        padding: clamp(50px, 8vh, 80px) 22px;
    }
}

@media (max-width: 768px) {
    .hero {
        min-height: auto;
        padding: clamp(80px, 18vh, 120px) 22px;
    }

    .avatar {
        width: 100px;
        height: 100px;
    }

    .hero h1 {
        font-size: 40px;
    }

    .subtitle {
        font-size: 17px;
    }

    .about {
        padding: clamp(40px, 8vh, 60px) 22px;
    }

    .lead {
        font-size: 21px;
        /* Improve readability on mobile */
        line-height: 1.5;
    }

    .skills,
    .current,
    .projects,
    .channels {
        padding: clamp(50px, 10vh, 80px) 22px;
    }

    .skills h2,
    .current h2,
    .projects h2,
    .channels h2 {
        font-size: 32px;
        margin-bottom: 40px;
    }

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

    .skill-card {
        padding: 32px 24px;
    }

    .current-card {
        padding: 32px 24px;
    }

    .current-card h3 {
        font-size: 24px;
    }

    .current-card p {
        font-size: 17px;
        line-height: 1.6;
    }

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

    .project-card {
        padding: 32px 24px;
    }

    .project-card p {
        line-height: 1.6;
    }

    .social-links {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .section-desc {
        font-size: 17px;
    }
}

@media (max-width: 480px) {
    .hero {
        padding: clamp(60px, 15vh, 100px) 20px;
    }

    .avatar {
        width: 90px;
        height: 90px;
        margin-bottom: 20px;
    }

    .hero h1 {
        font-size: 36px;
        margin-bottom: 10px;
    }

    .subtitle {
        font-size: 15px;
    }

    .about {
        padding: clamp(40px, 8vh, 60px) 18px;
    }

    .skills,
    .current,
    .projects,
    .channels {
        padding: clamp(40px, 8vh, 70px) 18px;
    }

    .skills h2,
    .current h2,
    .projects h2,
    .channels h2 {
        font-size: 28px;
        margin-bottom: 32px;
    }

    .lead {
        font-size: 19px;
        line-height: 1.55;
    }

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

    .skill-icon {
        font-size: 40px;
    }

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

    .current-card h3 {
        font-size: 22px;
    }

    .current-card p {
        line-height: 1.65;
    }

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

    .project-card p {
        line-height: 1.65;
    }

    .social-links {
        gap: 10px;
    }

    .social-links a,
    .social-links button {
        padding: 20px 12px;
        min-height: 84px;
    }
}

@media (min-width: 1440px) {
    .container {
        max-width: 1200px;
    }

    .skills-grid,
    .projects-grid {
        max-width: 1200px;
    }
}

@media (max-height: 700px) and (min-width: 769px) {
    .hero {
        min-height: auto;
        padding: clamp(60px, 12vh, 100px) 22px;
    }

    .about,
    .skills,
    .current,
    .projects,
    .channels {
        padding: clamp(60px, 10vh, 80px) 22px;
    }
}

@media (min-height: 900px) and (min-width: 769px) {
    .hero {
        padding: clamp(60px, 8vh, 100px) 22px;
    }

    .skills,
    .current,
    .projects,
    .channels {
        padding: clamp(100px, 15vh, 150px) 22px;
    }

    .about {
        padding: clamp(80px, 12vh, 120px) 22px;
    }
}

/* QR Code Modal - Apple Style */
.qr-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    align-items: center;
    justify-content: center;
}

.qr-modal.active {
    opacity: 1;
}

.qr-modal-content {
    position: relative;
    width: min(440px, 90vw);
    background: rgba(255, 255, 255, 0.98);
    border-radius: 24px;
    box-shadow:
        0 0 0 0.5px rgba(0, 0, 0, 0.04),
        0 30px 60px -15px rgba(0, 0, 0, 0.3),
        0 0 100px rgba(0, 0, 0, 0.15);
    transform: scale(0.94) translateY(20px);
    opacity: 0;
    transition: all 0.45s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.qr-modal.active .qr-modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

@media (prefers-color-scheme: dark) {
    .qr-modal-content {
        background: rgba(28, 28, 30, 0.98);
        box-shadow:
            0 0 0 0.5px rgba(255, 255, 255, 0.08),
            0 30px 60px -15px rgba(0, 0, 0, 0.6),
            0 0 100px rgba(0, 0, 0, 0.4);
    }
}

.qr-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(120, 120, 128, 0.12);
    color: #666;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
}

.qr-modal-close:hover {
    background: rgba(120, 120, 128, 0.2);
    transform: scale(1.08);
}

.qr-modal-close:active {
    transform: scale(0.96);
}

.qr-modal-close svg {
    width: 20px;
    height: 20px;
}

@media (prefers-color-scheme: dark) {
    .qr-modal-close {
        background: rgba(120, 120, 128, 0.2);
        color: #aaa;
    }

    .qr-modal-close:hover {
        background: rgba(120, 120, 128, 0.32);
        color: #fff;
    }
}

.qr-modal-header {
    padding: 32px 32px 20px;
    text-align: center;
}

.qr-modal-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0 0 8px;
}

.qr-modal-desc {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

.qr-image-wrapper {
    padding: 0 32px 32px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.qr-image {
    display: block;
    width: 100%;
    max-width: 320px;
    height: auto;
    border-radius: 16px;
    box-shadow:
        0 0 0 0.5px rgba(0, 0, 0, 0.04),
        0 8px 24px -8px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
    .qr-image {
        box-shadow:
            0 0 0 0.5px rgba(255, 255, 255, 0.08),
            0 8px 24px -8px rgba(0, 0, 0, 0.4);
    }
}

/* Mobile optimizations */
@media (max-width: 640px) {
    .qr-modal-content {
        width: min(380px, 88vw);
        border-radius: 20px;
    }

    .qr-modal-header {
        padding: 28px 24px 16px;
    }

    .qr-modal-title {
        font-size: 20px;
    }

    .qr-modal-desc {
        font-size: 14px;
    }

    .qr-image-wrapper {
        padding: 0 24px 28px;
    }

    .qr-image {
        max-width: 280px;
        border-radius: 14px;
    }

    .qr-modal-close {
        width: 32px;
        height: 32px;
        top: 12px;
        right: 12px;
    }

    .qr-modal-close svg {
        width: 18px;
        height: 18px;
    }
}