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

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #1a1a1a;
    font-family: Arial, sans-serif;
    overflow: auto;
    transition: background 0.5s;
    position: relative;
}

#backgroundGame {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.15;
    z-index: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

#menuScreen, #setupScreen, #coinFlipScreen, #gameContainer, #rulesScreen {
    position: relative;
    z-index: 1;
}

#menuScreen, #rulesScreen {
    display: none;
}

#menuScreen.active, #rulesScreen.active {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
}

.screen-with-bg {
    position: relative;
    z-index: 1;
}

.menu-container {
    text-align: center;
    background: rgba(42, 42, 42, 0.95);
    padding: 60px 80px;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.game-title {
    font-size: 72px;
    font-weight: bold;
    color: white;
    margin-bottom: 60px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    letter-spacing: 8px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.menu-btn {
    padding: 20px 60px;
    font-size: 24px;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    position: relative;
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.menu-btn.secondary {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
    font-size: 20px;
    padding: 15px 50px;
}

.menu-btn.secondary:hover {
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.6);
}

.menu-btn.disabled {
    background: #444;
    cursor: not-allowed;
    opacity: 0.5;
}

.menu-btn.disabled:hover {
    transform: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.coming-soon {
    display: block;
    font-size: 12px;
    margin-top: 5px;
    opacity: 0.7;
    font-weight: normal;
}

.rules-container {
    background: rgba(42, 42, 42, 0.95);
    padding: 40px;
    border-radius: 20px;
    max-width: 900px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.rules-container h1 {
    color: white;
    text-align: center;
    margin-bottom: 30px;
    font-size: 42px;
}

.rules-content {
    color: white;
    margin-bottom: 30px;
}

.rule-section {
    margin-bottom: 25px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.rule-section h2 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 24px;
}

.rule-section p {
    margin-bottom: 10px;
    line-height: 1.6;
    font-size: 16px;
}

.rule-section p:last-child {
    margin-bottom: 0;
}

.rule-section strong {
    color: #9C27B0;
}

body.game-active {
    background: var(--body-bg);
}

body.destroy-mode-active.player1-destroy {
    animation: pulsePlayer1 2s infinite;
}

body.destroy-mode-active.player2-destroy {
    animation: pulsePlayer2 2s infinite;
}

@keyframes pulsePlayer1 {
    0%, 100% { 
        filter: brightness(1) drop-shadow(0 0 0px var(--player1-color));
    }
    50% { 
        filter: brightness(1.3) drop-shadow(0 0 30px var(--player1-color));
    }
}

@keyframes pulsePlayer2 {
    0%, 100% { 
        filter: brightness(1) drop-shadow(0 0 0px var(--player2-color));
    }
    50% { 
        filter: brightness(1.3) drop-shadow(0 0 30px var(--player2-color));
    }
}

#setupScreen, #coinFlipScreen {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
    width: 100%;
}

#setupScreen.active, #coinFlipScreen.active {
    display: flex;
}

#gameContainer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    flex-direction: column;
    padding: 0;
    gap: 0;
    z-index: 100;
}

#gameContainer.active {
    display: flex;
}

.setup-form {
    background: #2a2a2a;
    padding: 30px;
    border-radius: 10px;
    width: 100%;
    max-width: 1000px;
}

.players-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 20px;
    width: 100%;
}

.players-container.solo-mode {
    grid-template-columns: 1fr;
    max-width: 500px;
    margin: 0 auto 20px auto;
}

.player-setup {
    background: #333;
    padding: 20px;
    border-radius: 8px;
    min-width: 0;
    transition: background 0.3s;
}

.player-setup.color-selected {
    background: var(--setup-bg-color);
}

.player-setup h2 {
    color: white;
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    color: white;
    display: block;
    margin-bottom: 5px;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    border: none;
    font-size: 16px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.color-option {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: white;
    transform: scale(1.15);
}

.color-option.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.setup-buttons {
    display: flex;
    gap: 15px;
}

.start-btn {
    padding: 15px 40px;
    font-size: 18px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
    flex: 1;
}

.start-btn:hover {
    background: #45a049;
}

.start-btn:disabled {
    background: #666;
    cursor: not-allowed;
}

.back-btn {
    padding: 15px 30px;
    font-size: 18px;
    background: #666;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.back-btn:hover {
    background: #777;
}

.back-btn.large {
    padding: 15px 50px;
    font-size: 20px;
    display: block;
    margin: 0 auto;
}

#coinFlipScreen {
    text-align: center;
}

#coin {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: var(--coin-color, #ffd700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    margin: 20px auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: transform 0.1s, box-shadow 0.3s;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#coin.flipping {
    animation: flip 1s ease-in-out;
}

#coin.winner {
    animation: coinGlow 1s ease-in-out infinite;
}

@keyframes coinGlow {
    0%, 100% { 
        box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 20px var(--coin-color);
    }
    50% { 
        box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 40px var(--coin-color), 0 0 60px var(--coin-color);
    }
}

@keyframes flip {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(1800deg); }
}

#coinFlipScreen h2 {
    color: white;
    font-size: 28px;
}

#coinFlipScreen p {
    color: #aaa;
    font-size: 18px;
}

#topBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.8);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

#bottomBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.8);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
}

.player-stats {
    display: flex;
    gap: 0px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 13px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.5);
    font-weight: bold;
    color: white;
}

.player-stats .stat-item:first-child {
    border-radius: 12px 0 0 12px;
}

.player-stats .stat-item:last-child {
    border-radius: 0 12px 12px 0;
}

.player-stats .stat-item:not(:first-child):not(:last-child) {
    border-radius: 0;
}

.stat-icon {
    font-size: 14px;
    display: flex;
    align-items: center;
}

.turn-info {
    text-align: center;
    color: white;
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 6px;
    color: white;
    font-size: 16px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
    border-radius: 15px;
}

#resetBtn {
    padding: 6px 16px;
    font-size: 13px;
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(102, 102, 102, 0.8);
    font-weight: bold;
}

#resetBtn:hover {
    background: rgba(102, 102, 102, 1);
    transform: scale(1.05);
}

#grid {
    display: grid;
    gap: 0px;
    background: #333;
    padding: 0px;
    border: 2px solid #555;
    transition: border-color 0.3s, box-shadow 0.3s;
    width: fit-content;
    height: fit-content;
    margin: auto;
}

#grid.destroy-mode-active {
    box-shadow: 0 0 20px currentColor;
}

.cell {
    background: #2a2a2a;
    cursor: pointer;
    transition: background 0.2s;
    min-width: 12px;
    min-height: 12px;
    position: relative;
}

.cell:not(.player1):not(.player2):not(.player1-base):not(.player2-base):not(.player1-territory):not(.player2-territory):not(.teleporter):not(.bonus)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 3px,
            rgba(255, 255, 255, 0.02) 3px,
            rgba(255, 255, 255, 0.02) 6px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent,
            transparent 3px,
            rgba(255, 255, 255, 0.02) 3px,
            rgba(255, 255, 255, 0.02) 6px
        );
    pointer-events: none;
    z-index: 0;
}

.cell:hover {
    background: #3a3a3a;
}

.cell.player1 {
    background: var(--player1-color);
    position: relative;
    box-shadow: inset -2px -2px 0px rgba(0, 0, 0, 0.3),
                inset 2px 2px 0px rgba(255, 255, 255, 0.3);
}

.cell.player1::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

.cell.player2 {
    background: var(--player2-color);
    position: relative;
    box-shadow: inset -2px -2px 0px rgba(0, 0, 0, 0.3),
                inset 2px 2px 0px rgba(255, 255, 255, 0.3);
}

.cell.player2::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

.cell.player1-base {
    background: var(--player1-dark);
    border: 2px solid var(--player1-darker);
    position: relative;
    box-shadow: inset -3px -3px 0px rgba(0, 0, 0, 0.4),
                inset 3px 3px 0px rgba(255, 255, 255, 0.4);
}

.cell.player1-base::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.cell.player2-base {
    background: var(--player2-dark);
    border: 2px solid var(--player2-darker);
    position: relative;
    box-shadow: inset -3px -3px 0px rgba(0, 0, 0, 0.4),
                inset 3px 3px 0px rgba(255, 255, 255, 0.4);
}

.cell.player2-base::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.cell.player1-territory {
    background: var(--player1-territory);
}

.cell.player2-territory {
    background: var(--player2-territory);
}

.cell.bonus {
    animation: pulse 1.5s infinite;
    position: relative;
}

.cell.bonus-bomb {
    background: #ff4444 !important;
}

.cell.bonus-bomb::after {
    content: '💣';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
}

.cell.bonus-speed {
    background: #ffaa00 !important;
}

.cell.bonus-speed::after {
    content: '🚀';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
}

.cell.bonus-reinforce {
    background: #666666 !important;
}

.cell.bonus-reinforce::after {
    content: '🛡️';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
}

.cell.player1.reinforced,
.cell.player2.reinforced {
    filter: brightness(0.6);
}

.cell.player1.reinforced::after,
.cell.player2.reinforced::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.5) 2px,
        rgba(0, 0, 0, 0.5) 4px
    );
    pointer-events: none;
    z-index: 1;
}

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

.cell.teleporter {
    background: linear-gradient(45deg, #00ffff, #ff00ff) !important;
    animation: teleporterPulse 2s infinite;
    border: 2px solid #ffffff;
    position: relative;
}

.cell.teleporter::after {
    content: '⚡';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
}

@keyframes teleporterPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 5px #00ffff; }
    50% { opacity: 0.7; box-shadow: 0 0 15px #ff00ff; }
}

.cell.possible-move {
    background: #9e9e9e !important;
    cursor: pointer;
}

.cell.possible-move:hover {
    background: #bdbdbd !important;
}

.cell.path-preview {
    opacity: 0.6;
}

.cell.destroy-move {
    background: #ff6b6b !important;
    cursor: pointer;
    position: relative;
}

.cell.destroy-move:hover {
    background: #ff8787 !important;
}

.cell.destroy-move::after {
    content: '💥';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
}

.cell.bonus-cost {
    position: relative;
}

.cell.bonus-cost::before {
    content: attr(data-cost);
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff9800;
    color: white;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 10;
    border: 1px solid white;
}

.cell.reinforce-target {
    background: rgba(102, 102, 102, 0.5) !important;
    cursor: pointer;
    position: relative;
}

.cell.reinforce-target:hover {
    background: rgba(102, 102, 102, 0.7) !important;
}

.cell.reinforce-target::after {
    content: '🛡️';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
}

.cell.speed-target {
    background: rgba(255, 170, 0, 0.3) !important;
}

#destroyBtn, #reinforceBtn, #speedBtn {
    padding: 6px 20px;
    font-size: 12px;
    color: white;
    border: 2px solid var(--player-color);
    cursor: pointer;
    transition: all 0.3s;
    background: var(--player-color-dim);
    min-width: 120px;
    font-weight: bold;
}

#destroyBtn {
    border-radius: 15px 0 0 15px;
    border-right: 1px solid var(--player-color);
}

#destroyBtn:hover {
    background: var(--player-color);
}

#reinforceBtn {
    border-radius: 0;
    border-left: 1px solid var(--player-color);
    border-right: 1px solid var(--player-color);
}

#reinforceBtn:hover {
    background: var(--player-color);
}

#speedBtn {
    border-radius: 0 15px 15px 0;
    border-left: 1px solid var(--player-color);
}

#speedBtn:hover {
    background: var(--player-color);
}

#destroyBtn:disabled, #reinforceBtn:disabled, #speedBtn:disabled {
    background: #444;
    border-color: #666;
    cursor: not-allowed;
    opacity: 0.5;
}

#destroyBtn.active {
    background: var(--player-color);
    box-shadow: 0 0 15px var(--player-color);
    transform: scale(1.05);
}

#reinforceBtn.active {
    background: var(--player-color);
    box-shadow: 0 0 15px var(--player-color);
    transform: scale(1.05);
}

#speedBtn.active {
    background: var(--player-color);
    box-shadow: 0 0 15px var(--player-color);
    transform: scale(1.05);
}

.button-container {
    display: flex;
    gap: 0px;
    flex-wrap: nowrap;
    justify-content: center;
}

.victory {
    color: #ffd700;
    font-size: 28px;
    animation: victory 0.5s ease-in-out;
}

@keyframes victory {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}