:root {
    --bg-color: #f0f2f5;
    --text-color: #333;
    --board-bg: #111;
    --board-grid: #222;
    --modal-bg: #fff;
    --modal-shadow: rgba(0, 0, 0, 0.2);
    --top-bar-bg: #fff;
    --top-bar-border: #ddd;
    --highlight: #4a90e2;
    --btn-hover: #f5f5f5;
    --panel-bg: #fff;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --board-bg: #000;
    --board-grid: #1a1a1a;
    --modal-bg: #2d2d2d;
    --modal-shadow: rgba(0, 0, 0, 0.5);
    --top-bar-bg: #2d2d2d;
    --top-bar-border: #444;
    --highlight: #64b5f6;
    --btn-hover: #3d3d3d;
    --panel-bg: #2d2d2d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Top Bar */
.top-bar {
    height: 50px;
    background-color: var(--top-bar-bg);
    border-bottom: 1px solid var(--top-bar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    flex-shrink: 0;
    z-index: 10;
}

.app-title {
    font-weight: bold;
    font-size: 1.2rem;
    width: 100px;
    text-align: left;
}

.score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.score-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.7;
}

#score {
    font-weight: bold;
    font-size: 1.2rem;
}

.right-controls {
    display: flex;
    gap: 0.5rem;
    width: 100px;
    justify-content: flex-end;
}

button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

button:hover {
    background-color: var(--btn-hover);
}

.icon {
    width: 24px;
    height: 24px;
}

/* Toggle Logic for Sun/Moon */
.sun-icon { display: block; }
.moon-icon { display: none; }

[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* Game Layout */
.game-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    width: 100%;
}

.game-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.board-wrapper {
    position: relative;
    padding: 4px;
    background-color: var(--text-color); /* Border color essentially */
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

canvas#tetris-board {
    display: block;
    background-color: var(--board-bg);
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 100px;
}

.next-piece-box {
    background-color: var(--panel-bg);
    padding: 0.5rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 2px 8px var(--modal-shadow);
}

.stats-box {
    background-color: var(--panel-bg);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--modal-shadow);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stat-row {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-bottom: 2px;
}

.value {
    font-size: 1.2rem;
    font-weight: bold;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 1.5rem;
    border-radius: 8px;
    width: 90%;
    max-width: 350px;
    box-shadow: 0 10px 25px var(--modal-shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header.center-header {
    justify-content: center;
}

.close-btn {
    font-size: 1.5rem;
    padding: 0.2rem;
    line-height: 1;
}

.setting-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group.toggle {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

select {
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #ccc;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
}

.primary-btn {
    width: 100%;
    background-color: var(--highlight);
    color: #fff;
    border-radius: 4px;
    font-weight: 600;
    margin-top: 1rem;
    padding: 0.8rem;
}

.primary-btn:hover {
    filter: brightness(1.1);
    background-color: var(--highlight);
}

.text-center { text-align: center; }
.winner-msg { font-size: 2rem; font-weight: bold; color: var(--highlight); }
.final-score-label { opacity: 0.8; margin-bottom: 0.5rem; }
