/* ================================
   CSS Variables & Themes
   ================================ */

:root {
    --player-color: #667eea;
    --ai-color: #00d9ff;
    
    --bg-gradient: #1a1a2e;
    --container-bg: #1e1e3f;
    --text-color: #e0e0ff;
    --text-muted: #b0b0dd;
    --dot-color: #a0a0ff;
    --line-inactive: rgba(120, 120, 170, 0.5);
    --border-color: rgba(138, 43, 226, 0.3);
    --button-color: #8a2be2;
    --input-bg: rgba(30, 30, 63, 0.8);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
}

.game-container {
    text-align: center;
    background: var(--container-bg);
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
    max-width: 520px;
    width: 100%;
    border: 2px solid var(--border-color);
    position: relative;
}

h1 {
    color: var(--text-color);
    margin-bottom: 18px;
    font-size: 2em;
    letter-spacing: 1px;
}

/* ================================
   Stats Bar
   ================================ */

.stats-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 15px;
}

.stat-item {
    background: var(--input-bg);
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-label {
    font-size: 0.7em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
}

/* ================================
   Scores
   ================================ */

.info-panel {
    margin-bottom: 15px;
}

.scores {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.score-box {
    background: #0a0a15;
    padding: 12px 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    min-width: 90px;
}

.score-box.player-active {
    border-color: var(--player-color);
    box-shadow: 0 0 15px var(--player-color);
}

.score-box.ai-active {
    border-color: var(--ai-color);
    box-shadow: 0 0 15px var(--ai-color);
}

.score-label {
    font-size: 0.85em;
    font-weight: bold;
    color: var(--text-muted);
}

.score-box.player-active .score-label,
.score-box.ai-active .score-label {
    color: white;
}

.score-value {
    font-size: 1.8em;
    font-weight: bold;
    color: #888;
}

.score-box.player-active .score-value {
    color: var(--player-color) !important;
}

.score-box.ai-active .score-value {
    color: var(--ai-color) !important;
}

.turn-indicator {
    font-size: 1em;
    font-weight: bold;
    padding: 10px 20px;
    background: var(--button-color);
    border-radius: 20px;
    color: white;
    min-width: 110px;
}

.move-counter {
    margin-top: 10px;
    font-size: 0.9em;
    color: var(--text-muted);
}

/* ================================
   Board - Fixed Positioning
   ================================ */

.board-wrapper {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    padding: 20px;
    background: rgba(20, 20, 40, 0.5);
    border-radius: 12px;
    overflow: auto;
}

#board {
    position: relative;
}

.grid-container {
    position: relative;
    display: inline-block;
}

/* Dots - centered on grid intersections */
.dot {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--dot-color);
    border-radius: 50%;
    z-index: 10;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px rgba(138, 43, 226, 0.5);
}

/* Line slots - positioned between dots */
.line-slot {
    position: absolute;
    z-index: 5;
    cursor: pointer;
}

.line-slot.horizontal {
    height: 26px;
    transform: translateY(-50%);
}

.line-slot.vertical {
    width: 26px;
    transform: translateX(-50%);
}

/* The actual line visual */
.line-visual {
    position: absolute;
    background: var(--line-inactive);
    transition: background 0.15s;
}

.line-slot.horizontal .line-visual {
    width: 100%;
    height: 5px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    border-radius: 3px;
}

.line-slot.vertical .line-visual {
    width: 5px;
    height: 100%;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 3px;
}

.line-slot:hover:not(.active) .line-visual {
    background: var(--player-color);
    opacity: 0.6;
}

.line-slot.active {
    cursor: default;
}

.line-slot.active.player .line-visual {
    background: var(--player-color);
    box-shadow: 0 0 12px var(--player-color);
}

.line-slot.active.ai .line-visual {
    background: var(--ai-color);
    box-shadow: 0 0 12px var(--ai-color);
}

/* Last move glow */
.line-slot.last-move .line-visual {
    animation: lastPulse 0.6s ease-in-out 2;
}

@keyframes lastPulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.5); }
}

/* Completed boxes */
.box-overlay {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.6em;
    font-weight: bold;
    z-index: 1;
    opacity: 0.25;
}

.box-overlay.player {
    color: var(--player-color);
    background: color-mix(in srgb, var(--player-color) 20%, transparent);
}

.box-overlay.ai {
    color: var(--ai-color);
    background: color-mix(in srgb, var(--ai-color) 20%, transparent);
}

/* ================================
   Controls
   ================================ */

.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.restart-btn, .settings-btn {
    background: var(--button-color);
    color: white;
    border: none;
    padding: 12px 28px;
    font-size: 0.95em;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.settings-btn {
    background: #555577;
    padding: 12px 20px;
}

/* ================================
   Combo Badge
   ================================ */

#comboContainer {
    position: relative;
    height: 0;
}

.combo-badge {
    position: absolute;
    left: 50%;
    top: 10px;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--player-color), var(--ai-color));
    color: white;
    padding: 6px 16px;
    border-radius: 15px;
    font-weight: bold;
    font-size: 1em;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
}

/* ================================
   Modals
   ================================ */

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

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: var(--container-bg);
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    border: 2px solid var(--border-color);
    max-width: 90vw;
    width: 380px;
}

.modal-content h2 {
    color: var(--text-color);
    margin-bottom: 12px;
    font-size: 1.8em;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 1.1em;
}

/* Settings */
.settings-content {
    width: 400px;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    text-align: left;
    margin-bottom: 20px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-group label {
    color: var(--text-muted);
    font-size: 0.85em;
    font-weight: 600;
}

input[type="color"] {
    width: 45px;
    height: 38px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    cursor: pointer;
}

select {
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9em;
}

.settings-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.secondary-btn {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
}

/* ================================
   AI Thinking
   ================================ */

.ai-thinking {
    opacity: 0.7;
    pointer-events: none;
}

/* ================================
   Confetti
   ================================ */

.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 999;
}

/* ================================
   Responsive
   ================================ */

@media (max-width: 500px) {
    body { padding: 8px; }
    .game-container { padding: 18px 12px; border-radius: 12px; }
    h1 { font-size: 1.6em; }
    .stat-item { padding: 5px 10px; }
    .score-box { padding: 10px 14px; min-width: 75px; }
    .turn-indicator { padding: 8px 14px; min-width: 90px; font-size: 0.9em; }
    .board-wrapper { padding: 12px; margin: 12px 0; }
    .line-slot.horizontal { height: 30px; }
    .line-slot.vertical { width: 30px; }
    .settings-grid { grid-template-columns: 1fr; }
}
