/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F7;
    --bg-tertiary: #FAFAFA;
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --accent-primary: #007AFF;
    --accent-hover: #0051D5;
    --border-color: #D2D2D7;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
    --game-bg: #F5F5F7;
    --game-obstacle: #1C1C1E;
    --game-text: #1D1D1F;
    --game-text-secondary: #86868B;
}

[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --text-primary: #F5F5F7;
    --text-secondary: #98989D;
    --accent-primary: #0A84FF;
    --accent-hover: #409CFF;
    --border-color: #38383A;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.7);
    --game-bg: #1C1C1E;
    --game-obstacle: #F5F5F7;
    --game-text: #F5F5F7;
    --game-text-secondary: #98989D;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    font-size: 17px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== Header ===== */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.28, 0.11, 0.32, 1);
}

[data-theme="dark"] #header {
    background: rgba(28, 28, 30, 0.72);
}

.header-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.375rem;
    font-weight: 400;
    letter-spacing: -0.02em;
}

.logo-bold {
    font-weight: 600;
    color: var(--text-primary);
}

.logo-light {
    font-weight: 300;
    color: var(--text-secondary);
}

nav {
    display: flex;
    gap: 2rem;
}

nav a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 400;
    font-size: 0.875rem;
    transition: opacity 0.2s ease;
    opacity: 0.8;
}

nav a:hover {
    opacity: 1;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.125rem;
    margin-left: 1rem;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

/* ===== Sections ===== */
.section {
    min-height: 100vh;
    padding: 120px 2rem;
    display: flex;
    align-items: center;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s cubic-bezier(0.28, 0.11, 0.32, 1),
        transform 0.8s cubic-bezier(0.28, 0.11, 0.32, 1);
}

.section.visible {
    opacity: 1;
    transform: translateY(0);
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
}

.section-title {
    font-size: 3.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-align: center;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.section-subtitle {
    font-size: 1.375rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 5rem;
    font-weight: 400;
}

/* ===== Hero Section ===== */
.hero-section {
    background: var(--bg-primary);
}

.hero-content {
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
}

.hero-greeting {
    font-size: 4rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    letter-spacing: -0.04em;
    line-height: 1.1;
}

.hero-site-name {
    color: var(--accent-primary);
}

.cursor {
    display: inline-block;
    width: 2px;
    height: 3.5rem;
    background: var(--accent-primary);
    margin-left: 4px;
    animation: blink 1s step-end infinite;
    vertical-align: middle;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

.hero-subtitle {
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.hero-decoration {
    display: none;
}

/* ===== Downloads Section ===== */
.downloads-section {
    background: var(--bg-secondary);
}

.downloads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.5rem;
}

.download-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 2.5rem 2rem;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.28, 0.11, 0.32, 1);
    opacity: 0;
    transform: translateY(20px);
}

.download-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.download-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.download-icon {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
}

.download-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.download-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1rem;
    line-height: 1.5;
}

.download-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.75rem 1.75rem;
    border-radius: 980px;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.download-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

/* ===== Game Section ===== */
.game-section {
    background: var(--bg-primary);
}

.game-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 24px;
    padding: 3rem;
    box-shadow: var(--shadow-md);
}

.game-canvas-wrapper {
    background: #F5F5F7;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    position: relative;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
}

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

.game-info h3 {
    font-size: 1.75rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.game-info p {
    color: var(--text-secondary);
    font-size: 1.0625rem;
    line-height: 1.6;
    max-width: 600px;
    margin: 0 auto 1.5rem;
}

.game-controls {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-style: italic;
}

/* ===== AI Section ===== */
.ai-section {
    background: var(--bg-secondary);
}

.ai-container {
    max-width: 800px;
    margin: 0 auto;
}

.ai-chat {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.ai-messages {
    height: 450px;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--bg-tertiary);
}

.ai-message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.ai-message.user {
    flex-direction: row-reverse;
}

.message-content {
    background: var(--bg-primary);
    padding: 0.875rem 1.25rem;
    border-radius: 18px;
    max-width: 75%;
    font-size: 1rem;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.ai-message.user .message-content {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.ai-message.bot .message-content {
    background: var(--bg-secondary);
}

.ai-input-container {
    display: flex;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    gap: 1rem;
    background: var(--bg-primary);
}

.ai-input {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 980px;
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
}

.ai-input:focus {
    border-color: var(--accent-primary);
    background: var(--bg-primary);
}

.ai-send-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.75rem 1.75rem;
    border-radius: 980px;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ai-send-btn:hover {
    background: var(--accent-hover);
}

/* ===== Contact Section ===== */
.contact-section {
    background: var(--bg-primary);
}

.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.contact-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 3.5rem 2.5rem;
    text-align: center;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s cubic-bezier(0.28, 0.11, 0.32, 1);
}

.contact-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.contact-icon {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
}

.contact-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.contact-card p {
    color: var(--text-secondary);
    font-size: 1.0625rem;
}

/* ===== Footer ===== */
.footer {
    background: var(--bg-secondary);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 6px;
    border: 3px solid var(--bg-secondary);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    nav {
        gap: 1rem;
    }

    nav a {
        font-size: 0.8125rem;
    }

    .hero-greeting {
        font-size: 2.5rem;
    }

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

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

    .section-subtitle {
        font-size: 1.125rem;
        margin-bottom: 3rem;
    }

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

    .cursor {
        height: 2.5rem;
    }

    .game-container {
        padding: 2rem;
    }
}

/* ===== Game Library ===== */
.game-library-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.active-game-container {
    background: var(--bg-primary);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.game-canvas-wrapper {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 4/3;
    max-height: 600px;
}

.game-canvas-wrapper iframe {
    width: 100%;
    height: 100%;
    display: block;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.game-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.game-card:hover {
    transform: translateY(-2px);
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-md);
}

.game-card.active {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.game-card-icon {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.game-card h4 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.game-card.local-loader {
    border-style: dashed;
}

@media (max-width: 480px) {
    .header-content {
        padding: 1rem 1.25rem;
    }

    .section {
        padding: 100px 1.25rem;
    }

    .logo {
        font-size: 1.125rem;
    }

    nav {
        gap: 0.75rem;
    }

    nav a {
        font-size: 0.75rem;
    }

    .game-container {
        padding: 1.5rem;
    }
}