/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    transition: all 0.3s ease;
    overflow-x: hidden;
}

/* CSS Variables for theming */
:root {
    /* Light theme */
    --bg-color: #ffffff;
    --text-color: #333333;
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --accent-color: #06d6a0;
    --card-bg: #f8fafc;
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --nav-bg: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] {
    /* Dark theme */
    --bg-color: #0f172a;
    --text-color: #e2e8f0;
    --primary-color: #818cf8;
    --secondary-color: #a78bfa;
    --accent-color: #34d399;
    --card-bg: #1e293b;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --nav-bg: rgba(15, 23, 42, 0.95);
}

/* Navigation Styles */
.main-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    transition: all 0.3s ease;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 4rem;
}

.nav-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
    margin: 0;
}

.nav-link {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    transition: color 0.3s ease;
    position: relative;
}

.nav-link:hover,
.nav-link:focus {
    color: var(--primary-color);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
}

.nav-link:hover::after,
.nav-link:focus::after {
    width: 100%;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    color: var(--text-color);
}

.control-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover,
.control-btn:focus {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

#language-select {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

/* Main Content */
.main-content {
    margin-top: 4rem;
    min-height: calc(100vh - 4rem);
}

/* Hero Section */
.hero-section {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    position: relative;
    overflow: hidden;
}

.hero-content {
    max-width: 800px;
    padding: 2rem;
    z-index: 2;
    position: relative;
}

.hero-title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(45deg, #ffffff, #e2e8f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.hero-visual {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
    z-index: 1;
}

#hero-canvas {
    width: 100%;
    height: 100%;
}

/* Showcase Sections */
.showcase-section {
    padding: 4rem 0;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.section-header {
    text-align: center;
    margin-bottom: 3rem;
}

.section-header h2 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.section-header p {
    font-size: 1.125rem;
    color: var(--text-color);
    opacity: 0.8;
}

/* Demo Grid */
.demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.demo-card {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px var(--shadow-color);
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.demo-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px var(--shadow-color);
}

.demo-card h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-align: center;
}

.demo-container {
    background: #000;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    position: relative;
    min-height: 300px;
    overflow: hidden;
}

.demo-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Controls */
.demo-controls,
.game-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.demo-controls input[type="range"] {
    flex: 1;
    min-width: 150px;
}

.demo-controls select,
.demo-controls button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
}

.game-controls button {
    background: var(--primary-color);
    color: white;
    border: none;
}

.score {
    font-weight: 600;
    color: var(--accent-color);
}

/* Memory Game Grid */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-width: 300px;
    margin: 0 auto;
}

.memory-card {
    aspect-ratio: 1;
    background: var(--primary-color);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}

.memory-card.flipped {
    background: var(--accent-color);
    transform: rotateY(180deg);
}

.memory-card.matched {
    background: var(--secondary-color);
    cursor: default;
}

/* Synth Interface */
.synth-keys {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    padding: 1rem;
}

.key {
    background: white;
    border: 2px solid #333;
    border-radius: 0.25rem;
    width: 40px;
    height: 120px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.1s ease;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.5rem;
}

.key:hover {
    background: var(--primary-color);
    color: white;
}

.key:active {
    transform: translateY(2px);
}

/* About Section */
.about-content {
    max-width: 800px;
    margin: 0 auto;
}

.about-text h3 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin: 2rem 0 1rem 0;
}

.about-text ul {
    padding-left: 2rem;
    margin: 1rem 0;
}

.about-text li {
    margin: 0.5rem 0;
    color: var(--text-color);
}

.article-preview {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    margin-top: 2rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.article-link {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    text-decoration: none;
    margin-top: 1rem;
    transition: all 0.3s ease;
}

.article-link:hover,
.article-link:focus {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

/* Footer */
.main-footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    text-align: center;
    margin-top: 4rem;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.footer-content p {
    color: var(--text-color);
    opacity: 0.8;
    margin: 0.25rem 0;
}

/* Accessibility Focus Styles */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow-color: rgba(0, 0, 0, 0.8);
    }
}

/* Reduced Motion Support */
@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;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        height: auto;
        padding: 1rem;
        gap: 1rem;
    }
    
    .nav-menu {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .nav-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .main-content {
        margin-top: 8rem;
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .section-header h2 {
        font-size: 2rem;
    }
    
    .demo-grid {
        grid-template-columns: 1fr;
    }
    
    .demo-card {
        min-width: unset;
    }
    
    .demo-container {
        min-height: 250px;
    }
}

@media (max-width: 480px) {
    .nav-container {
        padding: 0.5rem;
    }
    
    .hero-title {
        font-size: 1.75rem;
    }
    
    .demo-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .demo-card {
        padding: 1rem;
    }
    
    .demo-controls,
    .game-controls {
        flex-direction: column;
        align-items: stretch;
    }
}