:root {
    --bg-color: #0f0c29;
    --darker-bg: #050414;
    --board-bg: #1b1b3a;
    --accent: #bb86fc;
    --fg-board: #24244a;
    --tile-color: #bb86fc;
    --preview-good: #2ecc71;
    --preview-bad: #e74c3c;
    --preview-clear: #821cff;
}

body {
    margin: 0;
    font-family: 'Arial', sans-serif;
    background-color: var(--bg-color);
    color: var(--accent);
    height: 100vh;
    overflow: hidden;
    width: 100%;
    position: fixed;
    touch-action: none;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--darker-bg);
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 1.2rem;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 10px;
    margin-top: 0;
}

#leaderboard-list {
    list-style: none;
    padding: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1rem;
}

#leaderboard-list li {
    margin-bottom: 8px;
}

/* Game Area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Use space-around to keep header, board, and hand 
       distributed vertically without overlapping */
    justify-content: space-around; 
    padding: 10px;
    height: 100vh;
    box-sizing: border-box;
}

.header {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.score-box {
    margin: auto;
    font-size: 2rem;
    font-weight: bold;
}

/* Board */
.board-container {
    position: relative;
    padding: 1vmin;
    background-color: var(--board-bg);
    border-radius: 8px;

    /* DYNAMIC SCALING:
       The board will be 70% of the screen's smaller dimension.
       This prevents overflow regardless of window orientation. */
    width: 70vmin;
    height: 70vmin;
    
    /* Center it */
    display: flex;
    align-items: center;
    justify-content: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    background-color: var(--fg-board);
    border: 2px solid var(--fg-board);
    
    /* Fill the container completely */
    width: 100%;
    height: 100%;
}

.cell {
    /* No fixed width/height needed; the grid and aspect-ratio handle it */
    background-color: var(--board-bg);
    transition: background-color 0.05s ease-out;
    will-change: background-color;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.cell.filled {
    background-color: var(--tile-color);
    box-shadow: inset 0 0 5px rgba(0,0,0,0.3);
}

/* Previews */
.cell.preview-good { background-color: var(--preview-good); }
.cell.preview-bad { background-color: var(--preview-bad); }
.cell.preview-clear { background-color: var(--preview-clear); }

/* Hand */
.hand-container {
    display: flex;
    gap: 2vmin;
    /* Scale the hand container height based on the window height */
    height: 15vh; 
    justify-content: center;
    align-items: center;
    width: 100%;
}

.hand-slot {
    /* Scale slots relative to window size */
    width: 18vmin;
    height: 18vmin;
    max-width: 120px;
    max-height: 120px;
    background-color: var(--board-bg);
    border: 2px solid var(--fg-board);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.mini-grid {
    display: grid;
    gap: 0;
    box-sizing: border-box;
    line-height: 0;
}

.hand-slot.selected {
    border-color: var(--accent);
    background-color: #2a2a5a;
}

.hand-slot .mini-row {
    display: flex;
}

.hand-slot .mini-cell {
    width: 20px;
    height: 20px;
    background-color: transparent;
    display: block;
    box-sizing: border-box;
}
.hand-slot .mini-cell.filled {
    background-color: var(--tile-color);
    border: 1px solid var(--fg-board);
}

/* Game Over Screen */
#game-over-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 12, 41, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.hidden { display: none !important; }

.replay-btn {
    background-color: var(--accent);
    color: var(--bg-color);
    font-size: 1.5rem;
    font-weight: bold;
    padding: 15px 40px;
    border: none;
    cursor: pointer;
    margin-top: 20px;
}

.replay-btn:hover {
    background-color: #d1adff;
}
