/* AI Snake: Retro Revival - Retro-Modern Styling */

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

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
    background-attachment: fixed;
    color: #00ff41;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    /* Retro CRT scanline effect */
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 1000;
    opacity: 0.3;
}

.game-container {
    max-width: 800px;
    width: 100%;
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    border: 3px solid #00ff41;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 
        0 0 30px rgba(0, 255, 65, 0.3),
        inset 0 0 20px rgba(0, 255, 65, 0.05);
    position: relative;
    z-index: 1;
    /* Pixel-perfect rendering */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Smooth transitions */
    transition: box-shadow 0.3s ease;
}

.game-container.playing {
    border-color: #00ff41;
    box-shadow: 
        0 0 40px rgba(0, 255, 65, 0.5),
        inset 0 0 20px rgba(0, 255, 65, 0.1);
}

.game-container.paused {
    border-color: #ffaa00;
    box-shadow: 
        0 0 40px rgba(255, 170, 0, 0.5),
        inset 0 0 20px rgba(255, 170, 0, 0.1);
}

.game-container.game-over {
    border-color: #ff0066;
    box-shadow: 
        0 0 40px rgba(255, 0, 102, 0.5),
        inset 0 0 20px rgba(255, 0, 102, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 
        0 0 10px #00ff41,
        0 0 20px #00ff41,
        0 2px 0 #00cc33;
    animation: glow 2s ease-in-out infinite alternate;
    letter-spacing: 2px;
    /* Retro text effect */
    position: relative;
}

header p {
    color: #888;
    margin-bottom: 20px;
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@keyframes glow {
    from { 
        text-shadow: 
            0 0 10px #00ff41,
            0 0 20px #00ff41,
            0 2px 0 #00cc33;
    }
    to { 
        text-shadow: 
            0 0 20px #00ff41, 
            0 0 30px #00ff41,
            0 0 40px #00ff41,
            0 2px 0 #00cc33;
    }
}

.game-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 20px;
}

.score-board {
    background: rgba(0, 255, 65, 0.1);
    border: 2px solid #00ff41;
    border-radius: 5px;
    padding: 15px;
    flex: 1;
    box-shadow: 
        0 0 10px rgba(0, 255, 65, 0.2),
        inset 0 0 10px rgba(0, 255, 65, 0.05);
    transition: all 0.3s ease;
}

.score-board:hover {
    box-shadow: 
        0 0 15px rgba(0, 255, 65, 0.3),
        inset 0 0 15px rgba(0, 255, 65, 0.08);
}

.score-board div {
    margin: 8px 0;
    font-size: 1.1rem;
    text-shadow: 0 0 5px rgba(0, 255, 65, 0.5);
    transition: transform 0.2s ease;
}

.score-board div:hover {
    transform: scale(1.05);
}

.ai-panel {
    background: rgba(0, 100, 255, 0.1);
    border: 2px solid #0066ff;
    border-radius: 5px;
    padding: 15px;
    flex: 1;
    color: #66ccff;
    position: relative;
    transition: all 0.3s ease;
    box-shadow: 
        0 0 10px rgba(0, 102, 255, 0.2),
        inset 0 0 10px rgba(0, 102, 255, 0.05);
}

.ai-panel:hover {
    box-shadow: 
        0 0 15px rgba(0, 102, 255, 0.3),
        inset 0 0 15px rgba(0, 102, 255, 0.08);
}

.ai-panel h3 {
    margin-bottom: 10px;
    color: #0099ff;
    text-shadow: 0 0 8px rgba(0, 153, 255, 0.6);
    letter-spacing: 1px;
}

/* AI Adaptation Level Indicators */
.ai-panel.learning {
    border-color: #ffaa00;
    background: rgba(255, 170, 0, 0.1);
}

.ai-panel.learning h3::after {
    content: " 🌱";
    animation: pulse 1.5s ease-in-out infinite;
}

.ai-panel.adapting {
    border-color: #00aaff;
    background: rgba(0, 170, 255, 0.1);
}

.ai-panel.adapting h3::after {
    content: " 🧠";
    animation: pulse 1.2s ease-in-out infinite;
}

.ai-panel.adapted {
    border-color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
}

.ai-panel.adapted h3::after {
    content: " 🎯";
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#aiCommentary {
    min-height: 40px;
    margin-bottom: 10px;
    font-style: italic;
    animation: fadeIn 0.5s ease-in;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    border-left: 3px solid #0099ff;
    line-height: 1.4;
}

@keyframes fadeIn {
    from { 
        opacity: 0;
        transform: translateY(-5px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-stats div {
    margin: 5px 0;
    font-size: 0.9rem;
}

#gameCanvas {
    border: 4px solid #00ff41;
    border-radius: 5px;
    background: #000;
    margin: 20px 0;
    box-shadow: 
        0 0 20px rgba(0, 255, 65, 0.3),
        inset 0 0 30px rgba(0, 255, 65, 0.05);
    /* Pixel-perfect rendering for retro look */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Smooth animation */
    transition: all 0.3s ease;
}

#gameCanvas:focus {
    outline: none;
    box-shadow: 
        0 0 30px rgba(0, 255, 65, 0.5),
        inset 0 0 30px rgba(0, 255, 65, 0.08);
}

/* Canvas state animations */
.playing #gameCanvas {
    border-color: #00ff41;
    animation: canvasPulse 2s ease-in-out infinite;
}

.paused #gameCanvas {
    border-color: #ffaa00;
    opacity: 0.8;
}

.game-over #gameCanvas {
    border-color: #ff0066;
    animation: canvasShake 0.5s ease-in-out;
}

@keyframes canvasPulse {
    0%, 100% {
        box-shadow: 
            0 0 20px rgba(0, 255, 65, 0.3),
            inset 0 0 30px rgba(0, 255, 65, 0.05);
    }
    50% {
        box-shadow: 
            0 0 30px rgba(0, 255, 65, 0.5),
            inset 0 0 30px rgba(0, 255, 65, 0.08);
    }
}

@keyframes canvasShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.controls {
    margin: 20px 0;
}

.controls button {
    background: linear-gradient(45deg, #00ff41, #00cc33);
    border: 2px solid #00ff41;
    color: #000;
    padding: 12px 24px;
    margin: 0 10px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 
        0 4px 0 #00aa22,
        0 0 10px rgba(0, 255, 65, 0.3);
    position: relative;
    top: 0;
}

.controls button:hover {
    background: linear-gradient(45deg, #00ff55, #00dd44);
    box-shadow: 
        0 4px 0 #00aa22,
        0 0 20px rgba(0, 255, 65, 0.6);
    transform: translateY(-2px);
    top: -2px;
}

.controls button:active {
    transform: translateY(2px);
    top: 2px;
    box-shadow: 
        0 2px 0 #00aa22,
        0 0 10px rgba(0, 255, 65, 0.3);
}

.controls button:disabled {
    background: linear-gradient(45deg, #333, #222);
    border-color: #444;
    color: #666;
    cursor: not-allowed;
    transform: none;
    top: 0;
    box-shadow: 
        0 4px 0 #111,
        0 0 5px rgba(0, 0, 0, 0.3);
}

.controls button:disabled:hover {
    transform: none;
    top: 0;
}

.instructions {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #333;
    border-radius: 5px;
    padding: 15px;
    margin-top: 20px;
    text-align: left;
}

.instructions h3 {
    color: #00ff41;
    margin-bottom: 10px;
}

.instructions p {
    color: #ccc;
    line-height: 1.5;
    margin: 5px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .game-container {
        padding: 15px;
        border-width: 2px;
    }
    
    header h1 {
        font-size: 1.8rem;
        letter-spacing: 1px;
    }
    
    header p {
        font-size: 0.8rem;
    }
    
    .game-info {
        flex-direction: column;
        gap: 10px;
    }
    
    #gameCanvas {
        width: 100%;
        height: auto;
        max-width: 100%;
        border-width: 3px;
    }
    
    .controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    
    .controls button {
        padding: 10px 20px;
        margin: 0;
        font-size: 0.85rem;
        flex: 1 1 auto;
        min-width: 100px;
    }
    
    .instructions {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .game-container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .score-board,
    .ai-panel {
        padding: 10px;
    }
    
    .score-board div,
    .ai-stats div {
        font-size: 0.9rem;
        margin: 5px 0;
    }
    
    .controls button {
        padding: 8px 16px;
        font-size: 0.8rem;
        min-width: 80px;
    }
    
    .dpad {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(3, 50px);
    }
    
    .dpad-btn {
        font-size: 1.2rem;
    }
    
    .instructions {
        padding: 10px;
        font-size: 0.85rem;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .game-info {
        flex-direction: row;
        gap: 10px;
    }
    
    .mobile-controls {
        position: fixed;
        bottom: 10px;
        right: 10px;
        z-index: 100;
        background: rgba(0, 0, 0, 0.8);
        padding: 10px;
        border-radius: 10px;
        border: 2px solid #00ff41;
    }
    
    .dpad {
        grid-template-columns: repeat(3, 45px);
        grid-template-rows: repeat(3, 45px);
        gap: 3px;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    header h1 {
        font-size: 1.3rem;
    }
    
    .game-container {
        padding: 8px;
    }
    
    #gameCanvas {
        border-width: 2px;
    }
}

/* Large screens - optimize layout */
@media (min-width: 1200px) {
    .game-container {
        max-width: 900px;
    }
    
    header h1 {
        font-size: 3rem;
    }
    
    .game-info {
        gap: 30px;
    }
    
    .score-board,
    .ai-panel {
        padding: 20px;
    }
}

/* Accessibility */
.controls button:focus {
    outline: 3px solid #00ff41;
    outline-offset: 3px;
    animation: focusPulse 1s ease-in-out infinite;
}

#gameCanvas:focus {
    outline: none;
}

@keyframes focusPulse {
    0%, 100% { outline-color: #00ff41; }
    50% { outline-color: #00cc33; }
}

/* Score animation on update */
@keyframes scoreUpdate {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); color: #00ff88; }
    100% { transform: scale(1); }
}

.score-board div.updated {
    animation: scoreUpdate 0.3s ease-out;
}

/* AI Panel state transitions */
.ai-panel.learning {
    animation: learningPulse 2s ease-in-out infinite;
}

@keyframes learningPulse {
    0%, 100% {
        border-color: #ffaa00;
        box-shadow: 
            0 0 10px rgba(255, 170, 0, 0.2),
            inset 0 0 10px rgba(255, 170, 0, 0.05);
    }
    50% {
        border-color: #ffcc00;
        box-shadow: 
            0 0 20px rgba(255, 170, 0, 0.4),
            inset 0 0 15px rgba(255, 170, 0, 0.1);
    }
}

/* Loading animation for AI stats */
.ai-stats div span {
    display: inline-block;
    transition: all 0.3s ease;
}

.ai-stats div span.updating {
    animation: statUpdate 0.5s ease-out;
}

@keyframes statUpdate {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Retro pixel corners effect */
.game-container::before,
.game-container::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid #00ff41;
}

.game-container::before {
    top: -3px;
    left: -3px;
    border-right: none;
    border-bottom: none;
}

.game-container::after {
    bottom: -3px;
    right: -3px;
    border-left: none;
    border-top: none;
}

/* Additional corner decorations */
.score-board::before,
.ai-panel::before {
    content: '▸';
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 0.8rem;
    opacity: 0.5;
}

/* Smooth transitions for all interactive elements */
* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Mobile touch controls */
.mobile-controls {
    display: none;
    margin: 20px 0;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 5px;
    justify-content: center;
    margin: 0 auto;
    max-width: 200px;
}

.dpad-btn {
    background: linear-gradient(45deg, #00ff41, #00cc33);
    border: 2px solid #00ff41;
    color: #000;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    box-shadow: 
        0 4px 0 #00aa22,
        0 0 10px rgba(0, 255, 65, 0.3);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
    transform: translateY(2px);
    box-shadow: 
        0 2px 0 #00aa22,
        0 0 10px rgba(0, 255, 65, 0.3);
    background: linear-gradient(45deg, #00dd44, #00aa22);
}

.dpad-up {
    grid-column: 2;
    grid-row: 1;
}

.dpad-left {
    grid-column: 1;
    grid-row: 2;
}

.dpad-right {
    grid-column: 3;
    grid-row: 2;
}

.dpad-down {
    grid-column: 2;
    grid-row: 3;
}

.mobile-hint {
    display: none;
}

/* Show mobile controls on touch devices */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls {
        display: block;
    }
    
    .mobile-hint {
        display: block;
        color: #00ff41;
        font-weight: bold;
        margin-top: 10px;
    }
}

/* Enhanced keyboard navigation indicators */
button:focus-visible,
.dpad-btn:focus-visible {
    outline: 3px solid #00ff41;
    outline-offset: 3px;
    box-shadow: 
        0 4px 0 #00aa22,
        0 0 20px rgba(0, 255, 65, 0.6);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    body {
        background: #000;
    }
    
    .game-container {
        border-width: 4px;
    }
    
    .score-board,
    .ai-panel {
        border-width: 3px;
    }
}

/* 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;
    }
    
    body::before {
        display: none;
    }
}

/* Dark mode support (already dark, but ensure consistency) */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
    }
}