/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'VT323', monospace;
    background: linear-gradient(135deg, #1E1B4B 0%, #312E81 50%, #4C1D95 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #EEF2FF;
    overflow-y: auto;
    position: relative;
}

/* CRT Scanlines effect */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    z-index: 1000;
    animation: scanline 8s linear infinite;
}

@keyframes scanline {
    0% { transform: translateY(0); }
    100% { transform: translateY(10px); }
}

/* Container */
.container {
    text-align: center;
    padding: 1.5rem 1rem 1rem;
    max-width: 1400px;
    width: 100%;
    position: relative;
    z-index: 1;
}

/* Game Layout */
.game-layout {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(800px, 1fr);
    grid-template-rows: auto auto;
    column-gap: 2.5rem;
    row-gap: 0.55rem;
    align-items: stretch;
    justify-content: center;
    margin-top: 1.5rem;
}

.left-panel {
    grid-column: 1;
    grid-row: 1;
    align-self: stretch;
}

.game-frame {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.game-footer {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: min(100%, 800px);
    justify-self: center;
    margin-top: -0.25rem;
}

/* Game Title */
.game-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    color: #F97316;
    text-shadow:
        0 0 10px #F97316,
        0 0 20px #F97316,
        0 0 30px #F97316,
        3px 3px 0 #4F46E5;
    margin-bottom: 2rem;
    letter-spacing: 2px;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow:
            0 0 10px #F97316,
            0 0 20px #F97316,
            0 0 30px #F97316,
            3px 3px 0 #4F46E5;
    }
    to {
        text-shadow:
            0 0 20px #F97316,
            0 0 30px #F97316,
            0 0 40px #F97316,
            3px 3px 0 #4F46E5;
    }
}

/* Game Wrapper */
.game-wrapper {
    position: relative;
    display: inline-block;
    width: min(100%, 800px);
    border: 8px solid #4F46E5;
    border-radius: 12px;
    box-shadow:
        0 0 30px rgba(79, 70, 229, 0.6),
        0 0 60px rgba(79, 70, 229, 0.3),
        inset 0 0 20px rgba(79, 70, 229, 0.4);
    background: #000;
    margin-bottom: 0.25rem;
}

.back-link-panel {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-top: 1rem;
    padding: 0.45rem 0.7rem;
    background: rgba(15, 23, 42, 0.75);
    border: 2px solid #6366F1;
    border-radius: 6px;
    font-size: 0.7rem;
    width: fit-content;
    align-self: center;
}

/* Canvas */
#gameCanvas {
    display: block;
    background: linear-gradient(180deg, #87CEEB 0%, #E0F2FE 100%);
    width: 100%;
    height: auto;
    max-width: 800px;
    border-radius: 4px;
}

/* Overlay Screens */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 2rem;
    border-radius: 4px;
    transition: opacity 0.3s ease;
}

.overlay-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Screen Title */
.screen-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(1.5rem, 4vw, 2rem);
    color: #818CF8;
    text-shadow:
        0 0 10px #818CF8,
        0 0 20px #818CF8;
    letter-spacing: 2px;
}

.game-over-title {
    color: #F97316;
    text-shadow:
        0 0 10px #F97316,
        0 0 20px #F97316;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Screen Text */
.screen-text {
    font-size: clamp(0.875rem, 2.5vw, 1.125rem);
    color: #EEF2FF;
    letter-spacing: 1px;
}

/* Score Display */
.score-display {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: rgba(79, 70, 229, 0.2);
    border: 2px solid #4F46E5;
    border-radius: 4px;
    padding: 1rem 2rem;
    box-shadow: 0 0 10px rgba(79, 70, 229, 0.5);
}

.final-score,
.best-score {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.875rem, 2.5vw, 1.125rem);
    color: #EEF2FF;
    letter-spacing: 1px;
}

.final-score span,
.best-score span {
    color: #F97316;
    text-shadow: 0 0 10px #F97316;
}

/* Game Button */
.game-button {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.75rem, 2vw, 1rem);
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
    color: #FFF;
    border: 3px solid #C2410C;
    border-radius: 8px;
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow:
        0 4px 0 #9A3412,
        0 0 20px rgba(249, 115, 22, 0.5);
    transition: all 0.15s ease;
    position: relative;
    top: 0;
}

.game-button:hover {
    background: linear-gradient(135deg, #FB923C 0%, #F97316 100%);
    box-shadow:
        0 4px 0 #9A3412,
        0 0 30px rgba(249, 115, 22, 0.7);
    transform: translateY(-2px);
}

.game-button:active {
    transform: translateY(2px);
    box-shadow:
        0 2px 0 #9A3412,
        0 0 20px rgba(249, 115, 22, 0.5);
}

/* Score Board */
.score-board {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.85rem, 2.5vw, 1.2rem);
    color: #EEF2FF;
    background: rgba(79, 70, 229, 0.3);
    border: 3px solid #4F46E5;
    border-radius: 8px;
    padding: 0.55rem 1.1rem;
    display: inline-flex;
    gap: 1.5rem;
    align-items: center;
    box-shadow:
        0 0 20px rgba(79, 70, 229, 0.5),
        inset 0 0 10px rgba(79, 70, 229, 0.2);
    margin-bottom: 0;
    transition: opacity 0.3s ease;
}

.score-board.hidden {
    opacity: 0;
    pointer-events: none;
}

.score-value {
    color: #F97316;
    text-shadow: 0 0 10px #F97316;
}

/* Side Panels */
.side-panel {
    text-align: left;
    padding: 1.25rem;
    background: linear-gradient(180deg, #1e1b4b 0%, #0f172a 100%);
    border: 4px solid #4F46E5;
    border-radius: 8px;
    box-shadow:
        0 0 20px rgba(79, 70, 229, 0.4),
        inset 0 0 15px rgba(79, 70, 229, 0.2);
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.side-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px 4px 0 0;
}

.panel-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.9rem;
    color: #818CF8;
    letter-spacing: 2px;
    margin-bottom: 1.25rem;
    text-align: center;
    text-shadow: 0 0 10px rgba(129, 140, 248, 0.8);
}

.panel-title-spaced {
    margin-top: auto;
    padding-top: 1.5rem;
}

.panel-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.4rem;
    border-bottom: 1px dashed rgba(148, 163, 184, 0.35);
    font-size: 0.85rem;
    color: #E0E7FF;
}

.panel-stat:last-child {
    border-bottom: none;
}

.panel-label {
    color: #A5B4FC;
    letter-spacing: 1px;
}

.panel-value {
    color: #FDE68A;
    text-shadow: 0 0 8px rgba(253, 230, 138, 0.5);
}

.panel-card {
    background: rgba(30, 27, 75, 0.7);
    border: 1px solid rgba(129, 140, 248, 0.5);
    border-radius: 10px;
    padding: 0.8rem 0.9rem;
    margin-bottom: 0.9rem;
    box-shadow: inset 0 0 10px rgba(129, 140, 248, 0.15);
}

.panel-card-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.75rem;
    color: #F472B6;
    letter-spacing: 1px;
    margin-bottom: 0.45rem;
}

.panel-card-text {
    font-size: 0.9rem;
    color: #E0E7FF;
    line-height: 1.4;
}

.spark-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #FDE68A;
}

.spark-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #FDE047;
    box-shadow: 0 0 10px rgba(253, 224, 71, 0.9);
}

.marquee-card {
    text-align: center;
    position: relative;
    overflow: hidden;
}

.marquee-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.85rem;
    color: #34D399;
    text-shadow: 0 0 10px rgba(52, 211, 153, 0.7);
    letter-spacing: 2px;
}

.marquee-subtitle {
    margin-top: 0.4rem;
    color: #C7D2FE;
    font-size: 0.85rem;
}

.marquee-lights {
    margin-top: 0.7rem;
    height: 10px;
    border-radius: 999px;
    background: repeating-linear-gradient(
        90deg,
        rgba(251, 146, 60, 0.9) 0 10px,
        rgba(249, 115, 22, 0.2) 10px 20px
    );
    box-shadow: 0 0 12px rgba(249, 115, 22, 0.7);
}

/* Status Board */
.status-board {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.65rem, 1.8vw, 0.8rem);
    color: #EEF2FF;
    background: rgba(15, 23, 42, 0.6);
    border: 2px solid #6366F1;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    flex-wrap: nowrap;
    align-items: center;
    box-shadow:
        0 0 12px rgba(99, 102, 241, 0.5),
        inset 0 0 8px rgba(99, 102, 241, 0.2);
    margin-top: -8px;
    margin-bottom: 0.25rem;
    width: 100%;
    max-width: 800px;
    transition: opacity 0.3s ease;
}

.status-board.hidden {
    opacity: 0;
    pointer-events: none;
}

.status-value {
    color: #E0E7FF;
    text-shadow: 0 0 8px rgba(224, 231, 255, 0.6);
}

.status-value.on {
    color: #34D399;
    text-shadow: 0 0 10px #34D399;
}

/* Footer Row */
.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1.5rem;
    width: 100%;
    margin-top: -0.1rem;
}

/* Instructions */
.instructions {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 1.25rem;
    flex-wrap: wrap;
    margin-top: 0;
    text-align: right;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: clamp(0.75rem, 2.2vw, 0.95rem);
    color: #C7D2FE;
    letter-spacing: 1px;
}

.icon {
    width: 18px;
    height: 18px;
    color: #818CF8;
    filter: drop-shadow(0 0 5px #818CF8);
}

.instruction-note {
    margin-top: 0.35rem;
    font-size: clamp(0.65rem, 2vw, 0.9rem);
    color: #FDE68A;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(253, 230, 138, 0.6);
}

/* Responsive */
@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        row-gap: 1.25rem;
        column-gap: 0;
    }

    .side-panel {
        text-align: center;
    }

    .panel-stat {
        justify-content: center;
        gap: 0.75rem;
    }

    .left-panel,
    .game-frame,
    .game-footer {
        grid-column: 1;
    }

    .game-frame {
        grid-row: 2;
    }

    .game-footer {
        grid-row: 3;
    }

    .footer-row {
        flex-direction: column;
        align-items: center;
    }

    .instructions {
        justify-content: center;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }

    .game-layout {
        gap: 1rem;
    }

    .game-wrapper {
        border-width: 3px;
    }

    .game-title {
        margin-bottom: 1rem;
    }

    .score-board {
        padding: 0.45rem 0.85rem;
        gap: 0.6rem;
    }

    .status-board {
        padding: 0.35rem 0.6rem;
        gap: 0.45rem;
    }

    .instructions {
        gap: 0.75rem;
    }

    .instruction-item {
        font-size: 0.7rem;
    }

    .instruction-note {
        font-size: 0.7rem;
    }

    .icon {
        width: 16px;
        height: 16px;
    }
}

/* Back Link */
.back-link {
    display: inline-block;
    margin-top: 1.5rem;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.75rem;
    color: #818CF8;
    text-decoration: none;
    transition: color 0.2s ease;
    letter-spacing: 1px;
}

.back-link:hover {
    color: #F97316;
    text-shadow: 0 0 10px #F97316;
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .scanlines {
        animation: none;
    }

    .game-title {
        animation: none;
    }

    .game-over-title {
        animation: none;
    }

    .game-button {
        transition: none;
    }

    .overlay-screen {
        transition: none;
    }

    .score-board {
        transition: none;
    }

    .back-link {
        transition: none;
    }
}
