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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f4f8;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* Main container */
.game-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1); /* Softer shadow */
    padding: 32px;
    max-width: 1400px; /* Wider to accommodate two columns */
    display: grid;
    grid-template-columns: 370px 1fr; /* Two column layout */
    gap: 40px;
    align-items: end;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 2.5em;
}

/* Game mode selector */
.game-mode-selector {
    display: flex;
    flex-direction: column; /* Stack vertically */
    gap: 8px;
}

.mode-btn {
    width: auto;
    padding: 12px 16px;
    text-align: left; /* Left align text */
    background: #f7fafc;
    color: #4a5568;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-weight: 500;
}

.mode-btn.active {
    background: #38a169; /* Green background */
    color: white;
    border-color: #38a169;
}

/* Bot difficulty selector */
#bot-difficulty-selector {
    margin: 15px 0;
    text-align: center;
}

#bot-difficulty-selector label {
    font-weight: bold;
    margin-right: 10px;
}

#bot-difficulty-selector select {
    padding: 5px 10px;
    font-size: 1em;
    border-radius: 5px;
    border: 2px solid #ddd;
}

/* Multiplayer connection panel */
.connection-panel {
    background: #fef5e7; /* Light orange background */
    border: 1px solid #f6ad55;
    border-radius: 8px;
    padding: 12px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #c05621; /* Orange text */
    font-weight: 500;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545;
}

.status-indicator.connected {
    background: #28a745;
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(40, 167, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0); }
}

.room-controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.room-controls input {
    flex: 1;
    padding: 4px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
}

.matchmaking-controls {
    margin-top: 15px;
}

#find-match-btn {
    width: 100%;
    padding: 15px;
    font-size: 1.2em;
}

#searching-display {
    text-align: center;
    padding: 15px;
    background: #e3f2fd;
    border-radius: 8px;
    margin-top: 10px;
}

#searching-display > div:first-child {
    font-size: 1.2em;
    margin-bottom: 10px;
}

#search-timer {
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
    margin: 10px 0;
}

#cancel-matchmaking-btn {
    margin-top: 10px;
}

.divider {
    text-align: center;
    margin: 20px 0;
    color: #999;
}

.player-info {
    background: #e3f2fd;
    padding: 10px;
    border-radius: 5px;
    margin-top: 15px;
    text-align: center;
    font-weight: bold;
}

.player-info.black {
    background: #333;
    color: white;
}

.player-info.white {
    background: #f5f5f5;
    border: 2px solid #333;
}

/* Game info section */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0; /* Remove background */
    background: none;
}

/* Timer bar */
.timer-container {
    width: 100%;
    max-width: 700px;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    margin: 0 auto 16px auto;
    overflow: hidden;
    opacity: 1;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    border-radius: 4px;
    transform-origin: left center;
    transition: none;
}

.timer-bar.opponent-turn {
    background: linear-gradient(90deg, #9e9e9e, #757575);
    opacity: 0.6;
}

.timer-bar.running {
    animation: timerCountdown 30s linear forwards;
}

.timer-bar.warning {
    background: linear-gradient(90deg, #ff9800, #ff5722);
}

.timer-bar.danger {
    background: linear-gradient(90deg, #f44336, #d32f2f);
}

@keyframes timerCountdown {
    0% {
        transform: scaleX(1);
    }
    100% {
        transform: scaleX(0);
    }
}


.score {
    display: flex;
    gap: 30px;
    align-items: center;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2em;
    font-weight: bold;
}

.score-disc {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #333;
}

.score-disc.black {
    background: #333;
}

.score-disc.white {
    background: white;
}

.current-player {
    background: #e6fffa; /* Light green background */
    color: #234e52;
    padding: 8px 24px;
    border-radius: 20px;
    font-weight: 600;
}

/* Game board */
.board {
    /* responsive width: up to 700px but at most 92% of viewport width */
    width: min(700px, 92vw);
    max-width: 700px; /* Larger board */
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    background: #333;
    padding: 2px;
    border-radius: 10px;
    margin-bottom: 20px;
    aspect-ratio: 1;
    box-sizing: border-box;
    /* prevent cells from overflowing the rounded corners */
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    background-clip: padding-box;
}

.cell {
    background: #2d7a2d;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: background 0.3s;
    /* allow grid cells to size responsively; remove fixed width */
    width: 100%;
    min-width: 0; /* allow shrinking in flex/grid */
    box-sizing: border-box;
    /* avoid painting beyond parent's rounded corners */
    border-radius: 0;
}

.cell:hover.valid-move {
    background: #3d9a3d;
}

.cell.valid-move::after {
    content: '';
    position: absolute;
    width: 20%;
    height: 20%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 0.3; }
    100% { transform: scale(1); opacity: 0.5; }
}

.disc {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    border: 2px solid #333;
    transition: all 0.3s ease;
}

.disc.black {
    background: radial-gradient(circle at 30% 30%, #555, #000);
}

.disc.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ccc);
}

.disc.flip {
    animation: flip 0.5s ease;
}

@keyframes flip {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}

/* Controls - Desktop version (inside sidebar) */
.controls {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: flex-start;
    margin-bottom: 17px;
}

/* Hide mobile controls by default */
.mobile-controls {
    display: none;
}

/* Show desktop controls by default */
.desktop-controls {
    display: flex;
}

.controls button#new-game-btn,
.controls button#new-game-btn-mobile {
    background: #1fa2ff;
    color: #fff;
}

.controls button#undo-move-btn,
.controls button#undo-move-btn-mobile {
    background: #e53935;
    color: #fff;
}

button {
    padding: 12px 24px;
    font-size: 1em;
    width: auto;
    flex: 1; 
    font-weight: bold;
    color: white;
    background: #38a169;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
    animation: modalSlideIn 0.3s ease;
}

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

.modal h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.4em;
}

.modal p {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
}

.modal button {
    background: #38a169;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: block;
    margin: 0 auto; /* Keskittää napin */
}

.modal button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.modal .icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.modal .icon.info {
    color: #667eea;
}

.modal .icon.warning {
    color: #f39c12;
}

.modal .icon.error {
    color: #e74c3c;
}

.modal .icon.success {
    color: #27ae60;
}

.sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.sidebar-top {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Responsive design */
@media (max-width: 1024px) {
    .game-container {
        padding: 0px;
        grid-template-columns: 1fr; /* stack into single column */
        gap: 14px;
        align-items: stretch;
        /* make the container fixed to the top with some padding on mobile */
        position: fixed;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100vw - 24px);
        max-width: 960px;
        max-height: calc(100vh - 24px);
        overflow: auto;
        z-index: 2000;
        border-radius: 12px;
        box-shadow: 0 12px 30px rgba(0,0,0,0.18);
        touch-action: pan-y;
    }

    .sidebar {
        position: relative;
        width: 100%;
        order: 1;
        background: white;
        border-radius: 12px;
        box-shadow: 0 6px 18px rgba(0,0,0,0.08);
        padding: 3px;
        margin-bottom: 10px;
        transition: max-height 0.25s ease, opacity 0.2s ease;
    }

    /* Ensure game-area follows below the sidebar */
    .game-area {
        grid-column: 1 / -1;
        order: 2;
        width: 100%;
    }
    
    /* Hide desktop controls, show mobile controls */
    .desktop-controls {
        display: none !important;
    }
    
    .mobile-controls {
        display: flex !important;
        order: 3;
        width: 100%;
        gap: 10px;
        padding: 10px 4px;
    }

    /* Show mobile toggle button */
    .sidebar-toggle { display: block; }

    /* When collapsed, hide the sidebar (mobile only) - BUT NOT THE CONTROLS */
    .game-container.sidebar-collapsed .sidebar {
        display: none;
        opacity: 0;
        max-height: 0;
        padding: 0 16px;
        margin-bottom: 0;
        pointer-events: none;
    }


    /* Tiiviimpi pakkaus */
    .divider {
    text-align: center;
    margin: 10px 0;
    color: #999;
}   
    .sidebar-top {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

    button {
        padding: 12px 4px;
    }

    .game-info {
    margin-left: 10px;
    margin-right: 10px;

    .current-player {
    padding: 8px 10px;

    #cancel-matchmaking-btn {
    padding: 10px;
}

}

}
}

    .game-container.game-active .connection-panel {
        display: none !important;
    }



/* Make mode selector horizontal and show only icons on small screens */
@media (max-width: 1024px) {
    .game-mode-selector {
        display: flex;
        flex-direction: row;
        gap: 8px;
        justify-content: center;
        align-items: center;
        margin-top: 6px;
    }

    .mode-btn {
        padding: 8px 10px;
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    /* show short text on small screens, hide full text */
    .mode-text-full { display: none; }
    .mode-text-short { display: inline; font-size: 0.95rem; color: inherit; }
    .mode-icon { font-size: 1.2rem; }
}

/* Desktop: show full text, hide short labels */
@media (min-width: 1001px) {
    .mode-text-short { display: none; }
    .mode-text-full { display: inline; }
}

@media (max-width: 720px) {
    .board { gap: 1px; padding: 1px; }
    .disc { width: 90%; height: 86%; }
    .score { gap: 5px;
            padding: 2px; }
}

@media (max-width: 420px) {
    .board { gap: 1px; padding: 1px; width: min(92vw, 360px); }
    .disc { width: 90%; height: 86%; }
    .mode-btn { padding: 8px 10px; font-size: 0.9rem; }
}