/* CSS Variables - Dark Theme (default) */
:root,
[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6a6a7a;

    --red-primary: #e63946;
    --red-light: #ff6b6b;
    --red-glow: rgba(230, 57, 70, 0.4);

    --blue-primary: #4361ee;
    --blue-light: #4cc9f0;
    --blue-glow: rgba(67, 97, 238, 0.4);

    --cell-empty: #2a2a4a;
    --cell-hover: #3a3a5a;
    --cell-border: #404060;

    --sidebar-bg: #1a1a2e;
    --topbar-bg: #1a1a2e;

    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-glow-red: 0 0 20px var(--red-glow);
    --shadow-glow-blue: 0 0 20px var(--blue-glow);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8ed;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a5a;
    --text-muted: #7a7a8a;

    --cell-empty: #d8d8e8;
    --cell-hover: #c8c8d8;
    --cell-border: #b0b0c0;

    --sidebar-bg: #ffffff;
    --topbar-bg: #ffffff;

    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    transition: background var(--transition-normal), color var(--transition-normal);
}

/* Game container - CSS Grid layout */
.game-container {
    display: grid;
    grid-template-columns: 200px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar board";
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Top Bar */
.top-bar {
    grid-area: topbar;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--cell-border);
    z-index: 10;
}

.game-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.3rem;
    background: linear-gradient(135deg, var(--red-light) 0%, var(--blue-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.top-bar-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--cell-border);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--cell-hover);
    transform: translateY(-1px);
}

.icon-btn .icon {
    width: 20px;
    height: 20px;
}

/* Theme toggle icon visibility */
[data-theme="dark"] .icon-sun {
    display: block;
}
[data-theme="dark"] .icon-moon {
    display: none;
}
[data-theme="light"] .icon-sun {
    display: none;
}
[data-theme="light"] .icon-moon {
    display: block;
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.25rem;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--cell-border);
    overflow-y: auto;
}

.btn-new-game {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 0.95rem;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    color: var(--text-muted);
}

/* Turn Indicator */
.turn-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.current-player-stone {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--red-light) 0%, var(--red-primary) 100%);
    box-shadow: var(--shadow-glow-red);
    transition: all var(--transition-normal);
    flex-shrink: 0;
}

.current-player-stone.blue {
    background: linear-gradient(135deg, var(--blue-light) 0%, var(--blue-primary) 100%);
    box-shadow: var(--shadow-glow-blue);
}

.current-player-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Player Indicators */
.player-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.player-stone {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-stone.red {
    background: linear-gradient(135deg, var(--red-light) 0%, var(--red-primary) 100%);
    box-shadow: var(--shadow-glow-red);
}

.player-stone.blue {
    background: linear-gradient(135deg, var(--blue-light) 0%, var(--blue-primary) 100%);
    box-shadow: var(--shadow-glow-blue);
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.player-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.player-goal {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Board Size Select */
.board-size-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--cell-border);
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.board-size-select:hover {
    border-color: var(--text-muted);
}

.board-size-select:focus {
    outline: none;
    border-color: var(--blue-primary);
}

/* Board Area */
.board-area {
    grid-area: board;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    overflow: hidden;
    background: var(--bg-primary);
}

.board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Corner labels */
.corner-label {
    position: absolute;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    opacity: 0.7;
    pointer-events: none;
}

.corner-label.top-left,
.corner-label.bottom-right {
    color: var(--red-light);
}

.corner-label.top-right,
.corner-label.bottom-left {
    color: var(--blue-light);
}

.corner-label.top-left {
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
}

.corner-label.bottom-right {
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
}

.corner-label.top-right {
    right: -40px;
    top: 50%;
    transform: translateY(-50%) rotate(90deg);
}

.corner-label.bottom-left {
    left: -40px;
    top: 50%;
    transform: translateY(-50%) rotate(-90deg);
}

/* SVG Board */
.hex-board {
    display: block;
    filter: drop-shadow(0 10px 40px rgba(0, 0, 0, 0.3));
}

/* Hexagon cells */
.hex-cell {
    cursor: pointer;
    transition: all var(--transition-fast);
}

.hex-cell polygon {
    fill: var(--cell-empty);
    stroke: var(--cell-border);
    stroke-width: 2;
    transition: all var(--transition-fast);
}

.hex-cell:hover polygon {
    fill: var(--cell-hover);
    stroke: var(--text-muted);
}

.hex-cell.red polygon {
    fill: url(#red-gradient);
    stroke: var(--red-light);
    stroke-width: 2;
}

.hex-cell.blue polygon {
    fill: url(#blue-gradient);
    stroke: var(--blue-light);
    stroke-width: 2;
}

.hex-cell.red,
.hex-cell.blue {
    cursor: default;
}

.hex-cell.red:hover polygon {
    fill: url(#red-gradient);
}

.hex-cell.blue:hover polygon {
    fill: url(#blue-gradient);
}

/* Winning path highlight */
.hex-cell.winning polygon {
    stroke-width: 3;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Border edges */
.board-edge {
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    opacity: 0.6;
}

.board-edge.red {
    stroke: var(--red-primary);
}

.board-edge.blue {
    stroke: var(--blue-primary);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    border: 1px solid var(--cell-border);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--cell-hover) 0%, var(--bg-tertiary) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 2rem 2.5rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    animation: modalIn 0.3s ease;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-info {
    text-align: left;
    max-width: 500px;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--cell-hover);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    background: linear-gradient(135deg, var(--red-light) 0%, var(--blue-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Info Modal Content */
.info-content {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.info-content section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.info-content section p {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.info-content section ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.info-content section li {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-secondary);
    padding-left: 1rem;
    position: relative;
}

.info-content section li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--text-muted);
}

.red-text {
    color: var(--red-light);
    font-weight: 600;
}

.blue-text {
    color: var(--blue-light);
    font-weight: 600;
}

/* Responsive - smaller screens get a collapsible sidebar */
@media (max-width: 768px) {
    .game-container {
        grid-template-columns: 160px 1fr;
    }

    .sidebar {
        padding: 1rem;
        gap: 1rem;
    }

    .game-title {
        font-size: 1.5rem;
    }

    .corner-label {
        display: none;
    }
}

@media (max-width: 600px) {
    .game-container {
        grid-template-columns: 140px 1fr;
    }

    .sidebar {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .section-title {
        font-size: 0.6rem;
    }

    .player-label {
        font-size: 0.7rem;
    }

    .player-goal {
        font-size: 0.6rem;
    }

    .btn-new-game {
        padding: 0.625rem 0.75rem;
        font-size: 0.8rem;
    }

    .current-player-stone {
        width: 26px;
        height: 26px;
    }

    .player-stone {
        width: 20px;
        height: 20px;
    }
}
