/* Import Google Fonts for a modern look */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    color: #fff;
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Glassmorphism Panels */
.glass-panel {
    background: rgba(255, 255, 255, 0.05);
    /* Very transparent white */
    backdrop-filter: blur(12px);
    /* The frosted glass effect */
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    border-radius: 16px;
    padding: 20px;
}

.play-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.play-header {
    background: transparent;
    border: none;
    box-shadow: none;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.play-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    background: -webkit-linear-gradient(45deg, #00d2ff 0%, #3a7bd5 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.play-content {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
    align-items: stretch;
}

.history-panel {
    width: 320px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    /* Height is constrained by the board height via align-items:stretch */
    overflow: hidden;
    min-height: 0;
}

/* Setup View */
.setup-overlay {
    max-width: 600px;
    margin: 40px auto;
    text-align: center;
}

.setup-overlay .panel-header {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.config-grid {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.config-grid .config-section {
    flex: 1;
    margin-bottom: 0;
}

/* Configurations */
.config-section {
    margin-bottom: 25px;
}

.config-section h3 {
    font-size: 1.1rem;
    color: #e0e0e0;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.config-select {
    width: 100%;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease;
}

.config-select:focus {
    border-color: #3a7bd5;
}

/* Range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    margin: 8px 0;
    padding: 8px 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d2ff, #3a7bd5);
    box-shadow: 0 0 6px rgba(58, 123, 213, 0.6);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d2ff, #3a7bd5);
    box-shadow: 0 0 6px rgba(58, 123, 213, 0.6);
    cursor: pointer;
}

.config-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 30px;
}

.btn-large {
    padding: 15px;
    font-size: 1.2rem;
    width: 100%;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
}

.game-status-box {
    margin-top: 30px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    text-align: center;
}

.game-status-box h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #aaa;
    text-transform: uppercase;
}

.status-neutral {
    color: #a0a0a0;
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.status-badge.status-neutral {
    color: #a0a0a0;
}

.status-badge.status-red {
    color: #ff5252;
    border-color: rgba(255, 82, 82, 0.4);
    background: rgba(255, 82, 82, 0.1);
}

.status-badge.status-yellow {
    color: #ffd740;
    border-color: rgba(255, 215, 64, 0.4);
    background: rgba(255, 215, 64, 0.1);
}

.status-badge.status-win {
    color: #69f0ae;
    border-color: rgba(105, 240, 174, 0.4);
    background: rgba(105, 240, 174, 0.1);
    animation: pulse 1.5s infinite;
}

.status-red {
    color: #ff5252;
    font-weight: bold;
}

.status-yellow {
    color: #ffd740;
    font-weight: bold;
}

.status-win {
    color: #69f0ae;
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
        text-shadow: 0 0 10px rgba(105, 240, 174, 0.5);
    }

    50% {
        opacity: 0.7;
        text-shadow: 0 0 20px rgba(105, 240, 174, 1);
    }

    100% {
        opacity: 1;
        text-shadow: 0 0 10px rgba(105, 240, 174, 0.5);
    }
}

/* The Board Area */
.play-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding-top: 10px;
    /* CSS Variables for responsive board */
    --max-cell-w: calc((100vw - 420px) / 9);
    --max-cell-h: calc((100vh - 320px) / 9);
    --cell-size: clamp(20px, min(var(--max-cell-w), var(--max-cell-h)), 80px);
    --board-padding: calc(var(--cell-size) * 0.1);
    --token-size: calc(var(--cell-size) * 0.8);
    --token-offset: calc(var(--cell-size) * 0.1);
}

@media (max-width: 1000px) {
    .play-area {
        --max-cell-w: calc(95vw / 9);
        --max-cell-h: calc(60vh / 9);
    }

    .play-content {
        flex-direction: column;
        align-items: center;
    }

    .history-panel {
        width: 100%;
        max-width: calc(var(--cell-size) * 9);
        min-height: 300px;
    }

    .history-list {
        max-height: 250px;
    }
}

@media (max-width: 600px) {
    .play-header h1 {
        font-size: 1.8rem;
    }

    .play-container {
        padding: 5px;
    }

    .glass-panel {
        padding: 10px;
    }

    .config-grid {
        flex-direction: column;
        gap: 15px;
    }

    .turn-indicator {
        gap: 8px;
    }

    .player-turn {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .win-overlay h2 {
        font-size: 2rem;
    }
}

.turn-indicator {
    display: flex;
    width: 100%;
    justify-content: center;
    margin-bottom: 20px;
    gap: 20px;
}

.player-turn {
    padding: 10px 30px;
    border-radius: 20px;
    font-weight: bold;
    opacity: 0.3;
    transition: all 0.3s ease;
    transform: scale(0.9);
}

.player-turn.active {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.red-turn.active {
    background: linear-gradient(135deg, #ff5252, #c62828);
    box-shadow: 0 0 20px rgba(255, 82, 82, 0.5);
}

.yellow-turn.active {
    background: linear-gradient(135deg, #ffd740, #ff8f00);
    box-shadow: 0 0 20px rgba(255, 215, 64, 0.5);
    color: #333;
    /* Dark text for contrast on yellow */
}

/* HTML Board Structure */
.html-board-wrapper {
    position: relative;
    width: calc(var(--cell-size) * 9);
    /* 9 cols */
    height: calc(var(--cell-size) * 9);
    /* 9 rows */
    margin-bottom: 60px;
    /* Increased to ensure bottom is visible when scrolled */
    flex-shrink: 0;
    /* Empêche le wrapper de se réduire */
}

.html-board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(9, var(--cell-size));
    background-color: #1976D2;
    /* Classic Connect 4 Blue */
    width: 100%;
    height: 100%;
    box-shadow:
        10px 10px 30px rgba(0, 0, 0, 0.5),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: var(--board-padding);
    box-sizing: content-box;
    /* To accommodate the padding outside the size */
    transform: translateX(calc(-1 * var(--board-padding))) translateY(calc(-1 * var(--board-padding)));
    /* Offset for the padding */
    gap: 0;

    /* Using CSS Masks to create the holes */
    mask-image: radial-gradient(circle at 50% 50%, transparent 40%, black 41%);
    mask-size: var(--cell-size) var(--cell-size);
    mask-position: var(--board-padding) var(--board-padding);
    /* Align holes with grid cells inside padding */
    -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 40%, black 41%);
    -webkit-mask-size: var(--cell-size) var(--cell-size);
    -webkit-mask-position: var(--board-padding) var(--board-padding);

    z-index: 10;
    position: relative;
}

/* Layer behind the board for the tokens */
.board-tokens-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    background-color: rgba(0, 0, 0, 0.2);
    /* Dark background behind holes */
    border-radius: 12px;
}

/* Click detectors */
.click-columns {
    display: flex;
    position: absolute;
    top: calc(-1 * var(--cell-size));
    /* Extend above the board so user can click dropping area */
    left: 0;
    width: 100%;
    height: calc(100% + var(--cell-size));
    z-index: 20;
}

.col-click {
    flex: 1;
    height: 100%;
    cursor: pointer;
    position: relative;
}

.col-click::after {
    content: '';
    position: absolute;
    top: calc(var(--cell-size) - var(--board-padding));
    left: 0;
    right: 0;
    height: calc(100% - var(--cell-size) + 2 * var(--board-padding));
    transition: background-color 0.2s ease;
    border-radius: 4px;
}

.col-click:hover::after {
    background-color: rgba(255, 255, 255, 0.1);
}

.col-click.disabled {
    cursor: not-allowed;
}

.col-click.disabled:hover::after {
    background-color: transparent;
}

/* Column Numbers */
.column-numbers {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    position: absolute;
    bottom: -45px;
    left: 0;
    width: 100%;
    z-index: 15;
    pointer-events: none;
    margin: 0;
    padding: 0;
}

.column-numbers span {
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.4);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}


/* Tokens */
.token {
    position: absolute;
    width: var(--token-size);
    height: var(--token-size);
    border-radius: 50%;
    margin-left: var(--token-offset);
    /* Center in cell */
    margin-top: var(--token-offset);
    /* Center in cell */
    box-shadow:
        inset -5px -5px 15px rgba(0, 0, 0, 0.4),
        inset 5px 5px 15px rgba(255, 255, 255, 0.4);
}

.token.red {
    background: radial-gradient(circle at 30% 30%, #ff5252, #c62828);
}

.token.yellow {
    background: radial-gradient(circle at 30% 30%, #ffd740, #ff8f00);
}

/* Falling animation */
@keyframes dropToken {
    0% {
        transform: translateY(var(--drop-from, 0));
    }

    /* Start at top of board */
    60% {
        transform: translateY(0);
    }

    /* Hit bottom */
    80% {
        transform: translateY(calc(-0.15 * var(--cell-size)));
    }

    /* Bounce up */
    100% {
        transform: translateY(0);
    }

    /* Settle */
}

.token.falling {
    animation: dropToken 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Winning token highlight */
@keyframes winGlow {
    0% {
        box-shadow: 0 0 10px white, inset -5px -5px 15px rgba(0, 0, 0, 0.4);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 30px white, 0 0 20px rgba(255, 255, 255, 0.8), inset -5px -5px 15px rgba(0, 0, 0, 0.4);
        transform: scale(1.1);
        z-index: 25;
    }

    100% {
        box-shadow: 0 0 10px white, inset -5px -5px 15px rgba(0, 0, 0, 0.4);
        transform: scale(1);
    }
}

.token.winning {
    animation: winGlow 1s ease-in-out infinite;
}

.token.dimmed {
    opacity: 0.3;
}

/* Win Overlay */
.win-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;
    min-width: 300px;
    height: auto;
    padding: 30px;
    background: transparent;
    z-index: 30;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.win-overlay.show {
    opacity: 1;
}

.win-overlay.hidden {
    display: none;
}

.win-overlay h2 {
    font-size: 3rem;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}

/* History */
.history-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 20px;
}

/* Scrollbar styling for history */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

.move-entry {
    background: rgba(0, 0, 0, 0.2);
    margin-bottom: 8px;
    padding: 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    border-left: 4px solid #555;
}

.move-entry.red {
    border-left-color: #ff5252;
}

.move-entry.yellow {
    border-left-color: #ffd740;
}

.move-num {
    margin-right: 10px;
    font-weight: bold;
    color: #aaa;
    width: 25px;
}

.thinking-text {
    font-style: italic;
    color: #4fc3f7;
    animation: flash 1s infinite alternate;
}

@keyframes flash {
    from {
        opacity: 0.5;
    }

    to {
        opacity: 1;
    }
}

.weight-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.weight-score.positive {
    color: #69f0ae;
}

.weight-score.negative {
    color: #ff5252;
}

.weight-score.neutral {
    color: #aaa;
}