/* Copyright (c) 2024-2026 Jericho Crosby (Chalwk). All Rights Reserved. */

.panel {
    background: var(--light);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 2rem;
}

.panel-head h1 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* mode + settings */
#mode-selection {
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
}

#game-settings {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    align-items: center;
}

#game-settings label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    color: var(--dark);
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
}

#game-settings select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    background: white;
    color: var(--dark);
    font-family: var(--font-primary);
    min-width: 140px;
}

#difficulty-label.hidden {
    display: none !important;
}

/* rules legend */
#difficulty-legend {
    max-width: 560px;
    margin: 0 auto 1.5rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    font-size: 0.8rem;
    line-height: 1.4;
}

#difficulty-legend .legend-row {
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
}

#difficulty-legend .legend-row+.legend-row {
    margin-top: 0.35rem;
}

#difficulty-legend dt {
    flex: 0 0 5rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.7rem;
}

#difficulty-legend dd {
    margin: 0;
    color: var(--dark);
}

/* main game area */
#game-container {
    position: relative;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    background: var(--darker);
    border-radius: var(--radius);
    padding: 1rem 0.75rem;
}

.game-stats {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "p1 status p2";
    align-items: center;
    width: 100%;
    gap: 0.5rem 0.75rem;
    padding: 0.25rem 0.5rem;
}

.stat-block {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    line-height: 1.1;
}

.stat-block.player1 {
    grid-area: p1;
    align-items: flex-start;
}

.stat-block.player2 {
    grid-area: p2;
    align-items: flex-end;
}

.stat-block strong {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-block .score {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.2rem;
}

.score-player-1 {
    color: #ef4444;
}

.score-player-2 {
    color: #4ade80;
}

.status-block {
    grid-area: status;
    justify-self: center;
    min-width: 0;
}

#status {
    font-weight: bold;
    font-size: 0.95rem;
    text-align: center;
    color: #fff;
    white-space: nowrap;
}

/* board */
.board-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 6px;
    width: 100%;
    max-width: 520px;
    aspect-ratio: 1 / 1;
    background-color: rgba(0, 0, 0, 0.35);
    padding: 6px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.small-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-gap: 2px;
    background-color: rgba(255, 255, 255, 0.04);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
    aspect-ratio: 1 / 1;
    min-width: 0;
    min-height: 0;
}

.small-board.active {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.35);
}

.small-board.won-X {
    background-color: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.55);
}

.small-board.won-O {
    background-color: rgba(74, 222, 128, 0.18);
    border-color: rgba(74, 222, 128, 0.55);
}

.small-board.won-tie {
    background-color: rgba(148, 163, 184, 0.16);
    border-color: rgba(148, 163, 184, 0.4);
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, color 0.15s ease;
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(0.55rem, 1.6vw, 1rem);
    line-height: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.small-board.won-X .cell,
.small-board.won-O .cell,
.small-board.won-tie .cell {
    cursor: not-allowed;
    opacity: 0.85;
}

.small-board:not(.won-X):not(.won-O):not(.won-tie) .cell:hover:not(.taken) {
    background-color: rgba(255, 255, 255, 0.14);
    transform: scale(1.05);
}

.cell.taken {
    cursor: not-allowed;
    opacity: 0.95;
}

.cell.player-X {
    color: #ef4444;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.cell.player-O {
    color: #4ade80;
    text-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

#winning-line {
    position: absolute;
    height: 8px;
    background: linear-gradient(90deg, var(--warning), #ffed4e);
    border-radius: 4px;
    display: none;
    transform-origin: 0 0;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.8);
    z-index: 10;
    pointer-events: none;
}

/* game over overlay */
.game-over-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    border-radius: var(--radius);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
    text-align: center;
    padding: 1rem;
    z-index: 20;
}

.game-over-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.game-over-content {
    animation: celebrate 0.5s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.game-over-message {
    color: #fff;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.game-over-score {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 0.5rem;
}

.win-message {
    color: var(--warning);
    font-size: 1.05rem;
}

.tie-message {
    color: var(--gray);
    font-size: 1.05rem;
}

@keyframes celebrate {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

/* responsive */
@media (max-width: 768px) {
    #game-settings {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem 1.25rem;
    }

    .cell {
        font-size: clamp(0.5rem, 1.6vw, 0.9rem);
    }
}

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

    #game-settings {
        gap: 0.5rem 0.75rem;
    }

    #game-settings select {
        min-width: 0;
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
    }

    #difficulty-legend {
        font-size: 0.75rem;
        padding: 0.65rem 0.85rem;
    }

    #difficulty-legend dt {
        flex-basis: 4rem;
    }

    #game-board {
        grid-gap: 4px;
        padding: 4px;
    }

    .small-board {
        grid-gap: 1px;
        padding: 2px;
    }

    #winning-line {
        height: 6px;
    }
}

@media (max-width: 420px) {
    .game-stats {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "p1 p2"
            "status status";
    }

    .status-block {
        margin-top: 0.15rem;
    }

    #status {
        font-size: 0.85rem;
        white-space: normal;
    }

    .game-over-message {
        font-size: 1.25rem;
    }

    #difficulty-legend .legend-row {
        flex-direction: column;
        gap: 0.1rem;
    }

    #difficulty-legend dt {
        flex: none;
    }
}