:root {
    --bg: #0f0e17;
    --panel: #1a1a2e;
    --panel-2: #16213e;
    --border: #2a2a4a;
    --text: #e0e0e0;
    --text-muted: #888;
    --red: #ff6b6b;
    --blue: #4dabf7;
    --yellow: #ffd43b;
    --green: #51cf66;
    --accent: #ffcc00;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    font-size: 2em;
    margin-bottom: 20px;
    color: var(--accent);
}

h2 {
    font-size: 1.3em;
    margin-bottom: 12px;
    color: var(--text);
}

h3 {
    font-size: 1em;
    margin-bottom: 8px;
    color: var(--text-muted);
}

/* ===== Home Page ===== */

.home {
    max-width: 900px;
    margin: 0 auto;
}

.section {
    background: var(--panel);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

#new-game-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-group select,
.form-group input {
    padding: 8px 10px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95em;
}

#new-game-form button {
    grid-column: 1 / -1;
    padding: 12px;
    background: var(--blue);
    color: var(--bg);
    border: none;
    border-radius: 6px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

#new-game-form button:hover {
    background: #5bb3ff;
}

.runs-table {
    width: 100%;
    border-collapse: collapse;
}

.runs-table th,
.runs-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9em;
}

.runs-table th {
    color: var(--text-muted);
    font-weight: normal;
    text-transform: uppercase;
    font-size: 0.75em;
    letter-spacing: 0.5px;
}

.runs-table tr:hover {
    background: var(--panel-2);
}

.delete-btn {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 4px;
}

.delete-btn:hover {
    color: #ff8888;
}

.empty {
    color: var(--text-muted);
    text-align: center;
    padding: 30px;
}

/* ===== Game Page ===== */

#game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

#board-container {
    position: relative;
}

#board {
    display: grid;
    gap: 1px;
    background: #333;
    border: 2px solid var(--border);
    border-radius: 4px;
}

.cell {
    width: 30px;
    height: 30px;
    background: #2a2a2a;
    transition: background 0.2s;
}

.cell.player-0 { background: #2a2a2a; }
.cell.player-1 { background: var(--red); }
.cell.player-2 { background: var(--blue); }
.cell.player-3 { background: var(--yellow); }
.cell.player-4 { background: var(--green); }

#placement-overlay {
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(100% - 4px);
    height: calc(100% - 4px);
    pointer-events: none;
}

.placement-cell {
    position: absolute;
    width: 30px;
    height: 30px;
    background: rgba(255, 204, 0, 0.25);
    border: 1px dashed rgba(255, 204, 0, 0.7);
    pointer-events: auto;
    cursor: pointer;
    box-sizing: border-box;
    border-radius: 2px;
}

.placement-cell:hover {
    background: rgba(255, 204, 0, 0.45);
}

#sidebar {
    width: 260px;
    background: var(--panel);
    border-radius: 10px;
    padding: 15px;
    overflow-y: auto;
    max-height: 80vh;
}

#player-info {
    margin-bottom: 15px;
}

.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.player-info:last-child {
    border-bottom: none;
}

.player-name {
    font-weight: bold;
    font-size: 0.95em;
}

.player-name.red { color: var(--red); }
.player-name.blue { color: var(--blue); }
.player-name.yellow { color: var(--yellow); }
.player-name.green { color: var(--green); }

.player-meta {
    display: flex;
    gap: 10px;
    font-size: 0.85em;
    color: var(--text-muted);
}

.player-meta .score {
    color: var(--text);
}

#pieces {
    margin-bottom: 15px;
}

#pieces h3 {
    margin-bottom: 10px;
}

.piece {
    display: inline-grid;
    gap: 1px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 3px;
    margin-bottom: 5px;
    transition: all 0.2s;
}

.piece:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.piece.selected {
    border: 2px solid var(--accent);
    background: var(--panel-2);
}

.piece-cell {
    width: 16px;
    height: 16px;
    background: transparent;
}

.piece-cell.filled {
    background: var(--red);
}

#controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#controls button,
#controls a {
    display: block;
    width: 100%;
    padding: 10px;
    text-align: center;
    background: var(--panel-2);
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.95em;
    transition: background 0.2s;
}

#controls button:hover,
#controls a:hover {
    background: var(--blue);
    color: var(--bg);
}

#status-bar {
    margin-top: 20px;
    padding: 12px 16px;
    background: var(--panel);
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.05em;
    min-height: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#status-save-btn {
    padding: 4px 12px;
    background: var(--blue);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
}

#status-save-btn:hover {
    background: #5bb3ff;
}

/* ===== Replay Page ===== */

#replay-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

#replay-sidebar {
    width: 320px;
}

#replay-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

#replay-controls button {
    padding: 6px 14px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s;
}

#replay-controls button:hover:not(:disabled) {
    background: var(--blue);
    color: var(--bg);
}

#replay-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#step-slider {
    width: 100%;
    margin: 10px 0;
    accent-color: var(--blue);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
}

.speed-control label {
    font-size: 0.85em;
    color: var(--text-muted);
}

.speed-control select {
    padding: 4px 8px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9em;
}

#move-list {
    max-height: 280px;
    overflow-y: auto;
    margin-bottom: 15px;
    background: var(--panel);
    border-radius: 8px;
    padding: 8px;
}

.move-entry {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    transition: background 0.2s;
}

.move-entry.played {
    color: var(--text-muted);
}

.move-entry.current {
    background: var(--panel-2);
    color: var(--text);
    font-weight: bold;
}

.move-num {
    color: var(--text-muted);
    width: 24px;
}

.move-player.red { color: var(--red); }
.move-player.blue { color: var(--blue); }
.move-player.yellow { color: var(--yellow); }
.move-player.green { color: var(--green); }

#statistics {
    background: var(--panel);
    border-radius: 8px;
    padding: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9em;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:first-child {
    color: var(--text-muted);
}

.stat-row span:last-child {
    color: var(--text);
    font-weight: bold;
}
