body {
    background: #f4f4f4;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 20px;
    overflow-x: hidden;
    box-sizing: border-box;
    width: 100vw;
}

*, *::before, *::after {
    box-sizing: border-box;
}

.game-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
}

#cardsContainer {
    display: contents; /* Makes children participate in parent grid */
}

.card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 20px 16px;
    min-width: 0;
    max-width: 100%;
    text-align: center;
    transition: transform 0.3s ease;
    cursor: pointer;
    position: relative;
}

.card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.card.flipped {
    transform: rotate(180deg);
}

.card h2 {
    margin-bottom: 18px;
    color: #333;
}

.flip-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 16px;
    opacity: 0.6;
    transition: opacity 0.2s;
    cursor: pointer;
    z-index: 10;
}

.flip-indicator:hover {
    opacity: 1;
}

.card-content {
    position: relative;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.player-name {
    background: transparent;
    border: none;
    font-size: 1.3em;
    font-weight: bold;
    color: #333;
    text-align: center;
    flex-grow: 1;
    padding: 5px;
    border-radius: 4px;
    transition: background-color 0.2s;
    min-width: 0;
    max-width: 100%;
}

.player-name:focus {
    background: #f8f9fa;
    outline: 2px solid #0078d4;
}

.remove-player-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.remove-player-btn:hover {
    background: #c82333;
}

.remove-player-btn.hidden {
    display: none;
}

.points {
    margin-bottom: 16px;
}

.point-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.center-btn {
    grid-column: 2;
    display: flex;
    justify-content: center;
}

.center-btn .point-btn {
    width: 100%;
}

.point-btn {
    background: #28a745;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    min-width: 0;
    width: 100%;
}

.point-btn:hover {
    background: #218838;
}

select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 16px;
}

button {
    background: #0078d4;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    margin: 8px 0;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: #005fa3;
}

.result {
    margin: 15px 0 8px 0;
    font-size: 18px;
    color: #222;
}

.total-input {
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 18px;
    font-weight: bold;
    color: #222;
    width: 80px;
    text-align: center;
    margin-left: 5px;
}

.total-input:focus {
    outline: 2px solid #0078d4;
    border-color: #0078d4;
}

.action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 10px;
}

.undo-btn {
    background: #fd7e14;
    font-size: 13px;
    padding: 6px 12px;
}

.undo-btn:hover {
    background: #e36209;
}

.undo-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.card.hidden {
    display: none;
}

.add-player-container {
    grid-column: 1 / -1;
    text-align: center;
    margin: 10px 0;
}

.add-player-container {
    text-align: center;
    margin: 20px auto;
    max-width: 300px;
}

.add-player-btn {
    background: #6c757d;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.add-player-btn:hover {
    background: #5a6268;
}

.add-player-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Template card should be hidden */
.card-template {
    display: none !important;
}

@media (max-width: 600px) {
    body {
        padding: 15px;
    }
    
    .game-container {
        gap: 20px;
        padding: 10px;
        max-width: 100%;
    }
    
    /* Mobile: 1 card per row only when 2 or fewer players */
    .game-container.mobile-single {
        grid-template-columns: 1fr !important;
    }
    
    /* Mobile: 2 cards per row when 3 or more players */
    .game-container.mobile-double {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px;
    }
    
    .card {
        padding: 16px 12px;
        min-width: 0;
    }
    
    .card-header {
        margin-bottom: 12px;
    }
    
    .player-name {
        font-size: 1em;
        padding: 4px;
        max-width: calc(100% - 30px);
    }
    
    .point-btn {
        padding: 8px 4px;
        font-size: 12px;
        min-width: 0;
    }
    
    .result {
        font-size: 15px;
        margin: 12px 0 8px 0;
    }
    
    .total-input {
        font-size: 15px;
        width: 55px;
    }
    
    .action-buttons {
        gap: 6px;
    }
    
    .undo-btn, .resetBtn {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .remove-player-btn {
        width: 20px;
        height: 20px;
        font-size: 12px;
        margin-left: 6px;
    }
    
    .flip-indicator {
        font-size: 14px;
        top: 6px;
        right: 6px;
    }
}

@media (max-width: 450px) {
    body {
        padding: 10px;
    }
    
    .game-container {
        gap: 15px;
        padding: 5px;
    }
    
    /* Small mobile: 1 card per row when 2 or fewer players */
    .game-container.mobile-single {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }
    
    /* Small mobile: 2 cards per row when 3 or more players */
    .game-container.mobile-double {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    .card {
        padding: 14px 10px;
        min-width: 0;
        border-radius: 8px;
    }
    
    .card-header {
        margin-bottom: 10px;
    }
    
    .player-name {
        font-size: 0.95em;
        padding: 3px;
        max-width: calc(100% - 28px);
    }
    
    .points p {
        font-size: 12px;
        margin-bottom: 8px;
    }
    
    .point-buttons {
        gap: 5px;
    }
    
    .point-btn {
        padding: 6px 3px;
        font-size: 11px;
        min-width: 0;
        border-radius: 4px;
    }
    
    .result {
        font-size: 13px;
        margin: 10px 0 6px 0;
    }
    
    .result p {
        margin: 0;
    }
    
    .total-input {
        font-size: 13px;
        width: 45px;
        padding: 2px 4px;
    }
    
    .action-buttons {
        gap: 4px;
        margin-top: 8px;
    }
    
    .undo-btn, .resetBtn {
        font-size: 10px;
        padding: 5px 6px;
        border-radius: 4px;
    }
    
    .remove-player-btn {
        width: 18px;
        height: 18px;
        font-size: 11px;
        margin-left: 4px;
    }
    
    .add-player-container {
        margin: 8px 0;
    }
    
    .add-player-btn {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    .flip-indicator {
        font-size: 12px;
        top: 4px;
        right: 4px;
    }
}
