/* style.css */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    margin: 0;
}

/* Container for scoreboard and AI analysis */
#bottom-containers {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
    margin-left: 15px;
    margin-top: 20px;
}

/* Top containers for scoreboard and game rules */
#top-containers {
    display: flex;
    flex-direction: row;
    gap: 15px;
    align-items: flex-start;
}

/* Left column for scoreboard and its children */
#left-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
}

/* Shared panel base styles */
#game-container, #scoreboard, #computer-level-container, #game-rules-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    box-sizing: border-box;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 400px;
    min-width: 400px;
    max-width: 400px;
    margin-top: 20px;
}

h1 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 2em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    margin-top: 0;
}

.row {
    display: flex;
    margin: 10px 0;
    justify-content: center;
    min-height: 130px;
    align-items: center;
    position: relative;
}

.stick {
    width: 35px;
    height: 120px;
    background: 
        radial-gradient(ellipse at center top, #D2691E 0%, #CD853F 15%, #8B4513 30%, #A0522D 70%, #654321 100%);
    margin: 0 6px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    user-select: none;
    font-size: 22px;
    border-radius: 18px; /* Cylindrical shape */
    box-shadow: 
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    transform-style: preserve-3d;
}

.stick::before { /* Top cap */
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 35px;
    height: 8px;
    background: radial-gradient(ellipse, #D2691E 0%, #CD853F 30%, #8B4513 70%, #654321 100%);
    border-radius: 50%;
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    z-index: 2;
}

.stick::after { /* Wood texture */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            90deg,
            transparent 0px,
            transparent 2px,
            rgba(139, 69, 19, 0.1) 2px,
            rgba(139, 69, 19, 0.1) 3px
        ),
        repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 8px,
            rgba(160, 82, 45, 0.05) 8px,
            rgba(160, 82, 45, 0.05) 10px
        );
    border-radius: 18px;
    pointer-events: none;
    z-index: 1;
}

.stick:hover {
    transform: translateY(-8px) scale(1.05) rotateX(5deg);
    box-shadow: 
        0 8px 16px rgba(0, 0, 0, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.3),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3);
}

.stick.selected {
    background: 
        radial-gradient(ellipse at center top, #FF4444 0%, #FF2222 15%, #CC0000 30%, #AA0000 70%, #880000 100%);
    transform: translateY(-10px) scale(1.1) rotateX(3deg);
    box-shadow: 
        0 12px 24px rgba(255, 68, 68, 0.6),
        inset 0 2px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    animation: pulse 1s infinite;
}

.stick.computer-selected {
    background: 
        radial-gradient(ellipse at center top, #4488FF 0%, #2266FF 15%, #0044CC 30%, #0022AA 70%, #001188 100%);
    transform: translateY(-10px) scale(1.1) rotateX(3deg);
    box-shadow: 
        0 12px 24px rgba(68, 136, 255, 0.6),
        inset 0 2px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    animation: pulse 1s infinite;
}

.stick.removed {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: all 0.5s ease-out;
}

.stick.selected.removed,
.stick.computer-selected.removed {
    opacity: 0;
    transform: translateY(-10px) scale(0.8) rotateX(3deg);
    transition: all 0.5s ease;
}
@keyframes pulse {
    0%, 100% { 
        transform: translateY(-10px) scale(1.1) rotateX(3deg); 
    }
    50% { 
        transform: translateY(-10px) scale(1.15) rotateX(3deg); 
    }
}


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

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Add smooth animations for game elements */
#game-container { animation: fadeIn 0.8s ease-out; }

/* Responsive design */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        align-items: center;
    }
    
    #bottom-containers {
        margin-left: 0;
        margin-top: 20px;
        flex-direction: column;
        gap: 15px;
    }
    
    #top-containers {
        flex-direction: column;
        gap: 15px;
    }
    
    #left-column {
        width: 100%;
    }
    
    #game-container {
        margin-bottom: 0;
        width: 90%;
        max-width: 400px;
    }
    
    #scoreboard, #ai-thinking-container, #computer-level-container {
        width: 200px;
    }
    
    #game-rules-container {
        width: 320px;
    }
    
    .stick {
        width: 30px;
        height: 100px;
        margin: 0 4px;
        font-size: 18px;
        border-radius: 15px;
    }
    
    .row {
        min-height: 120px;
    }
    
}

/* Enhanced visual feedback */
.stick:active {
    transform: scale(0.95);
}

/* Loading animation for computer moves */
.computer-thinking { animation: pulse 0.5s infinite; }

/* Success/Error message animations */
.message-success {
    color: #27ae60;
    animation: fadeIn 0.5s ease-out;
}

.message-error {
    color: #e74c3c;
    animation: fadeIn 0.5s ease-out;
}

#scoreboard { width: 270px; min-width: 270px; max-width: 270px; }

/* AI Thinking Container */
#ai-thinking-container {
    background: linear-gradient(135deg, rgba(30, 30, 30, 0.95), rgba(50, 50, 50, 0.95));
    padding: 20px;
    border-radius: 15px;
    width: 270px;
    min-width: 270px;
    max-width: 270px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(100, 100, 100, 0.3);
    box-sizing: border-box;
}

.ai-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.ai-title {
    color: #00ff88;
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#ai-thinking-display {
    margin-bottom: 10px;
    min-height: 60px;
}

/* Matrix effect for AI calculations */
#ai-calculations {
    margin-bottom: 15px;
    min-height: 85px;
    font-family: 'Courier New', monospace;
    font-size: 0.65em;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

#ai-calculations::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 255, 136, 0.03) 2px,
            rgba(0, 255, 136, 0.03) 4px
        );
    pointer-events: none;
    z-index: 1;
}

.calc-line {
    color: #00ff88;
    margin: 4px 4px;
    padding: 2px 12px;
    background: rgba(0, 255, 136, 0.1);
    border-radius: 3px;
    border-left: 2px solid #00ff88;
    opacity: 0;
    transform: translateX(-20px);
    transition: all 0.3s ease-out;
    font-family: 'Courier New', monospace;
    position: relative;
    overflow: hidden;
    z-index: 2;
    width: calc(100% - 9px);
    box-sizing: border-box;
}

.calc-line.show {
    opacity: 1;
    transform: translateX(0);
}

.calc-line.show::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 255, 136, 0.4), transparent);
    animation: matrixScan 0.8s ease-out;
}

.calc-line.show::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        rgba(0, 255, 136, 0.1) 0%, 
        transparent 20%, 
        transparent 80%, 
        rgba(0, 255, 136, 0.1) 100%
    );
    animation: matrixGlow 2s ease-in-out infinite;
}

@keyframes matrixScan {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

@keyframes matrixGlow {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.8;
    }
}

.calc-line:nth-child(1) { animation-delay: 0.1s; }
.calc-line:nth-child(2) { animation-delay: 0.3s; }
.calc-line:nth-child(3) { animation-delay: 0.5s; }
.calc-line:nth-child(4) { animation-delay: 0.7s; }

/* Removed animated thinking lines */

.ai-status {
    color: #888;
    font-size: 0.75em;
    text-align: center;
    font-family: 'Courier New', monospace;
    min-height: 1em;
}

.ai-status.thinking {
    color: #00ff88;
    animation: statusBlink 1s infinite;
}

.ai-status.calculating {
    color: #ffaa00;
    animation: statusBlink 0.8s infinite;
}

.ai-status.optimizing {
    color: #ff6b6b;
    animation: statusBlink 0.6s infinite;
}

/* Removed thinkingFlow animation */

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#scoreboard h2 {
    margin-top: 0;
    color: #2c3e50;
    text-align: center;
    font-size: 1.5em;
    margin-bottom: 15px;
}

.score {
    margin: 10px 0;
    font-size: 1.1em;
    font-weight: 600;
    color: #34495e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(52, 73, 94, 0.05);
    border-radius: 8px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

#reset-button {
    background: linear-gradient(145deg, #e74c3c, #c0392b);
    color: #fff;
    width: 100%;
    margin-top: 15px;
}

#reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(231, 76, 60, 0.3);
}

#move-button {
    margin-top: 20px;
    background: linear-gradient(145deg, #27ae60, #229954);
    color: #fff;
    padding: 12px 24px;
    font-size: 1em;
}

#move-button:disabled {
    background: linear-gradient(145deg, #95a5a6, #7f8c8d);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#move-button:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(39, 174, 96, 0.3);
}

/* Reuse Move button as Start New Game with previous blue style */
#move-button.as-new-game {
    background: linear-gradient(145deg, #3498db, #2980b9);
    color: #fff;
}

#move-button.as-new-game:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(52, 152, 219, 0.3);
}

#start-message {
    margin-top: 10px;
    font-weight: bold;
    color: #2c3e50;
    font-size: 1em;
    text-align: center;
}

#message {
    margin-top: 15px;
    font-size: 0.9em;
    color: #2c3e50;
    text-align: center;
    min-height: 40px;
    font-weight: 400;
    padding: 12px;
    background: rgba(52, 73, 94, 0.05);
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Result banner overlay */
.board-fixed { height: 100%; }

#board-area {
    position: relative;
    width: 100%;
    min-height: 340px; /* keeps container height when banner shows */
}

.result-banner {
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 30%;
    border-radius: 12px;
    font-weight: 800;
    font-size: 2em;
    letter-spacing: 1px;
    box-sizing: border-box;
}

.result-banner.show { display: flex; }
.result-win { color: #1e7e34; border: 4px solid #1e7e34; background: rgba(30, 126, 52, 0.08); }
.result-lose { color: #c0392b; border: 4px solid #c0392b; background: rgba(192, 57, 43, 0.08); }

/* New Game Button Styles */
#new-game-button {
    margin-top: 15px;
    background: linear-gradient(145deg, #3498db, #2980b9);
    color: #fff;
    padding: 12px 24px;
    font-size: 1em;
    display: block;
    width: 100%;
}

#new-game-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(52, 152, 219, 0.3);
}

/* Footer Styles */
#game-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 0;
    font-size: 0.75em;
    text-align: center;
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
}

.footer-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.footer-content span {
    opacity: 0.8;
    font-weight: 400;
}

.footer-content span:not(:last-child) {
    margin-right: 4px;
}

/* Responsive footer */
@media (max-width: 768px) {
    #game-footer {
        font-size: 0.7em;
        padding: 6px 0;
    }
    
    .footer-content {
        gap: 6px;
    }
}

/* Computer Level Container */
#computer-level-container { width: 270px; min-width: 270px; max-width: 270px; }

/* Game Rules Container */
#game-rules-container { width: 340px; min-width: 340px; max-width: 340px; margin-bottom: 0; }

.rules-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.rules-title {
    color: #2c3e50;
    font-weight: 600;
    font-size: 1.5em;
    text-align: center;
}

.rules-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rule-item {
    color: #34495e;
    font-size: 0.85em;
    line-height: 1.4;
    padding: 8px;
    background: rgba(52, 73, 94, 0.05);
    border-radius: 6px;
    border-left: 3px solid #3498db;
    margin-bottom: 3px;
}

.rule-item strong {
    color: #2c3e50;
    font-weight: 600;
}

.level-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.level-title {
    color: #2c3e50;
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: nowrap;
}

.level-btn {
    background: rgba(52, 152, 219, 0.1);
    border: 2px solid #3498db;
    color: #3498db;
    padding: 6px 10px;
    border-radius: 8px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.72em; /* slightly smaller to fit three buttons */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-btn:hover {
    background: rgba(52, 152, 219, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.level-btn.active {
    background: #3498db;
    color: #fff;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.5);
}

.level-btn.active:hover {
    background: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(52, 152, 219, 0.7);
}

/* Game Result Display */

h1 {
    margin-top: 0px;
}