/* ===== CSS Reset & Variables ===== */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #1e293b;
    --accent-color: #22d3ee;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s ease;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===== Header ===== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

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

.nav-list {
    display: flex;
    list-style: none;
    gap: 30px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    padding: 8px 0;
    position: relative;
}

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

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-color);
    transition: var(--transition);
}

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

.mobile-menu-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
}

.mobile-menu-btn span {
    width: 25px;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

/* ===== Main ===== */
.main {
    padding: 40px 0;
}

.game-wrapper {
    display: grid;
    grid-template-columns: auto 280px;
    gap: 30px;
    justify-content: center;
    align-items: start;
}

/* ===== Game Section ===== */
.game-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.game-container {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 15px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

#gameCanvas {
    display: block;
    background: #000;
    border-radius: var(--radius-sm);
}

.game-overlay {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 10;
}

.game-overlay.hidden {
    display: none;
}

.overlay-content {
    padding: 30px;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-content p {
    color: var(--text-secondary);
    margin-bottom: 25px;
}

/* ===== Mobile Controls ===== */
.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 300px;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.control-btn {
    width: 60px;
    height: 60px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.control-btn:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(0.95);
}

.control-btn svg {
    width: 28px;
    height: 28px;
}

.control-btn.wide {
    width: 130px;
}

.control-btn.wide svg {
    width: 24px;
    height: 24px;
}

/* ===== Side Panel ===== */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.panel-title {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

#nextCanvas {
    display: block;
    margin: 0 auto;
    background: #000;
    border-radius: var(--radius-sm);
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.score-item:last-child {
    border-bottom: none;
}

.score-item.highlight {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(34, 211, 238, 0.1));
    margin: 10px -20px -20px;
    padding: 15px 20px;
    border-radius: 0 0 var(--radius) var(--radius);
    border-bottom: none;
}

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

.score-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-color);
}

.score-item.highlight .score-value {
    color: var(--warning);
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-align: center;
    width: 100%;
    margin-bottom: 10px;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ===== Controls List ===== */
.controls-list {
    list-style: none;
}

.controls-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

kbd {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    min-width: 30px;
    text-align: center;
}

/* ===== Content Section ===== */
.content-section {
    margin-top: 60px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px;
    border: 1px solid var(--border-color);
}

.content-section h2 {
    font-size: 1.75rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.content-section h3 {
    font-size: 1.25rem;
    margin: 30px 0 15px;
    color: var(--accent-color);
}

.content-section p {
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.8;
}

.feature-list {
    list-style: none;
    margin: 15px 0;
}

.feature-list li {
    padding: 10px 0 10px 25px;
    position: relative;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.feature-list li:last-child {
    border-bottom: none;
}

.feature-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--primary-color);
}

.feature-list li strong {
    color: var(--text-primary);
}

/* ===== Footer ===== */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 50px 0 20px;
    margin-top: 60px;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 40px;
    margin-bottom: 40px;
}

.footer-section h4 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 1rem;
}

.footer-section p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 10px;
}

.footer-section ul a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: var(--transition);
}

.footer-section ul a:hover {
    color: var(--primary-color);
}

.footer-bottom {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ===== Page Specific Styles ===== */
.page-header {
    text-align: center;
    padding: 60px 0;
    background: linear-gradient(135deg, var(--surface), var(--background));
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-color);
}

.page-header h1 {
    font-size: 2.5rem;
    margin-bottom: 15px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    max-width: 600px;
    margin: 0 auto;
}

.page-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px;
    border: 1px solid var(--border-color);
    margin-bottom: 40px;
}

.page-content h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin: 30px 0 15px;
}

.page-content h2:first-child {
    margin-top: 0;
}

.page-content p {
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.8;
}

.page-content ul,
.page-content ol {
    margin: 15px 0;
    padding-left: 25px;
    color: var(--text-secondary);
}

.page-content li {
    margin-bottom: 10px;
}

/* ===== Block Colors Display ===== */
.block-colors {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.block-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: var(--background);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.block-preview {
    width: 40px;
    height: 40px;
    border-radius: 4px;
}

.block-preview.i-block { background: #00f0f0; }
.block-preview.o-block { background: #f0f000; }
.block-preview.t-block { background: #a000f0; }
.block-preview.s-block { background: #00f000; }
.block-preview.z-block { background: #f00000; }
.block-preview.j-block { background: #0000f0; }
.block-preview.l-block { background: #f0a000; }

.block-name {
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Responsive Design ===== */
@media (max-width: 900px) {
    .game-wrapper {
        grid-template-columns: 1fr;
        max-width: 350px;
        margin: 0 auto;
    }

    .side-panel {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .side-panel .panel-card:first-child {
        grid-column: 1 / -1;
    }

    .mobile-controls {
        display: flex;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 30px;
    }
}

@media (max-width: 600px) {
    .header .container {
        height: 60px;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .nav-list {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--surface);
        flex-direction: column;
        padding: 20px;
        gap: 15px;
        border-bottom: 1px solid var(--border-color);
    }

    .nav-list.active {
        display: flex;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .main {
        padding: 20px 0;
    }

    #gameCanvas {
        width: 100%;
        max-width: 280px;
        height: auto;
        aspect-ratio: 1 / 2;
    }

    .game-container {
        padding: 10px;
    }

    .side-panel {
        grid-template-columns: 1fr;
    }

    .side-panel .panel-card:first-child {
        grid-column: 1;
    }

    .content-section,
    .page-content {
        padding: 25px;
    }

    .content-section h2,
    .page-header h1 {
        font-size: 1.5rem;
    }

    .page-header {
        padding: 40px 0;
    }

    .control-btn {
        width: 55px;
        height: 55px;
    }

    .control-btn.wide {
        width: 120px;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.game-section,
.side-panel,
.content-section {
    animation: fadeIn 0.5s ease-out;
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===== Print Styles ===== */
@media print {
    .header,
    .game-section,
    .mobile-controls,
    .footer {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    .content-section,
    .page-content {
        background: white;
        border: 1px solid #ccc;
    }
}
