/**
 * TCBCDC 500 Card Game Styles
 */

:root {
    --primary: #2c5282;
    --primary-light: #4299e1;
    --secondary: #718096;
    --success: #38a169;
    --danger: #e53e3e;
    --warning: #d69e2e;
    --bg: #f7fafc;
    --card-bg: #ffffff;
    --text: #2d3748;
    --text-light: #718096;
    --border: #e2e8f0;
    --felt: #1a472a;
    --felt-light: #2d5a3d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--felt);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Game Container */
.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.game-header h1 {
    color: white;
    font-size: 1.5rem;
}

.back-link {
    color: var(--primary-light);
    text-decoration: none;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* Table Layout */
.table {
    flex: 1;
    display: grid;
    grid-template-areas:
        ".     north  ."
        "west  play   east"
        ".     south  .";
    grid-template-columns: 250px 1fr 250px;
    grid-template-rows: 250px 1fr 280px;
    gap: 0.5rem;
    background: linear-gradient(145deg, var(--felt) 0%, var(--felt-light) 100%);
    border-radius: 16px;
    padding: 1rem;
    border: 8px solid #0d2818;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.3);
}

/* Player Areas */
.player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
}

.player-area.north { grid-area: north; }
.player-area.south { grid-area: south; }
.player-area.west {
    grid-area: west;
    justify-content: center;
}
.player-area.east {
    grid-area: east;
    justify-content: center;
}

.player-label {
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dealer-chip {
    display: none;
    background: var(--warning);
    color: #000;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: bold;
    text-align: center;
    line-height: 20px;
}

.dealer-chip.active {
    display: inline-block;
}

.player-bid {
    color: #ffd700;
    font-size: 2.5rem;
    font-weight: bold;
    min-height: 1.2em;
    margin-top: 0.25rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Player Hands */
.player-hand {
    display: flex;
    justify-content: center;
    min-height: 196px;
}

.player-area.west .player-hand,
.player-area.east .player-hand {
    flex-direction: column;
    min-height: auto;
    min-width: 140px;
}

/* Playing Cards */
.card {
    width: 140px;
    height: 196px;
    background: white;
    border-radius: 10px;
    border: 2px solid #ccc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
    font-weight: bold;
    cursor: default;
    position: relative;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
}

.card.red { color: #e53e3e; }
.card.black { color: #1a202c; }

/* Card rank - top left corner */
.card .card-rank {
    position: absolute;
    top: 8px;
    left: 10px;
    font-size: 2rem;
    font-weight: bold;
    line-height: 1;
}

/* Card suit - bottom left corner */
.card .card-suit {
    position: absolute;
    bottom: 8px;
    left: 10px;
    font-size: 2.5rem;
    line-height: 1;
}

/* Card back */
.card.back {
    background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
    border-color: #1a365d;
}

.card.back::after {
    content: "500";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.3);
    font-size: 1.8rem;
    font-weight: bold;
}

/* Joker card */
.card.joker {
    background: linear-gradient(135deg, #faf089 0%, #f6e05e 100%);
}

.card.joker .suit {
    font-size: 4rem;
}

/* Human player's clickable cards */
.player-area.south .card:not(.back) {
    cursor: pointer;
}

.player-area.south .card:not(.back):hover {
    transform: translateY(-10px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.player-area.south .card.selected {
    transform: translateY(-15px);
    box-shadow: 0 8px 16px rgba(66, 153, 225, 0.5);
    border-color: var(--primary-light);
}

.player-area.south .card.invalid {
    opacity: 0.5;
    cursor: not-allowed;
}

.player-area.south .card.invalid:hover {
    transform: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Card overlap in hands - show rank and suit in corners */
.player-hand .card:not(:first-child) {
    margin-left: -70px;
}

.player-area.west .player-hand .card:not(:first-child),
.player-area.east .player-hand .card:not(:first-child) {
    margin-left: 0;
    margin-top: -130px;
}

/* Play Area */
.play-area {
    grid-area: play;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Current Trick */
.trick {
    position: relative;
    width: 380px;
    height: 380px;
}

.trick-card {
    position: absolute;
    width: 140px;
    height: 196px;
}

.trick-card.north {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.trick-card.south {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.trick-card.west {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.trick-card.east {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

/* Kitty Display */
.kitty {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.kitty .card {
    transform: scale(0.9);
}

/* Game Message */
.message {
    color: white;
    font-size: 1rem;
    text-align: center;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    margin-top: 0.5rem;
    min-height: 2em;
}

.message:empty {
    display: none;
}

/* Score Panel */
.score-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.score-team {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.team-label {
    color: var(--text-light);
    font-size: 0.9rem;
}

.score-value {
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
}

.score-value.positive { color: var(--success); }
.score-value.negative { color: var(--danger); }

.tricks-display {
    color: white;
    font-size: 0.9rem;
}

.current-contract {
    color: #ffd700;
    font-size: 0.9rem;
    min-width: 150px;
    text-align: center;
}

/* Buttons */
.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--primary-light);
}

.btn:disabled {
    background: var(--secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Modal Dialogs */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: var(--primary);
    margin-bottom: 1rem;
    text-align: center;
}

/* Bidding Dialog */
.current-bid-display {
    text-align: center;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.bid-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.bid-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bid-tricks {
    width: 30px;
    font-weight: 600;
    color: var(--text-light);
}

.bid-btn {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.2s;
}

.bid-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--bg);
}

.bid-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.bid-btn[data-suit="S"],
.bid-btn[data-suit="C"] {
    color: #1a202c;
}

.bid-btn[data-suit="D"],
.bid-btn[data-suit="H"] {
    color: #e53e3e;
}

.bid-btn[data-suit="NT"] {
    font-size: 0.8rem;
    color: var(--text);
}

.special-bids {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.bid-btn.misere {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.bid-btn.open-misere {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border-color: transparent;
}

.pass-btn {
    width: 100%;
    background: var(--secondary);
}

.pass-btn:hover {
    background: #5a6a7a;
}

/* Discard Dialog */
.discard-count {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.discard-hand {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.discard-hand .card {
    cursor: pointer;
}

.discard-hand .card:hover {
    transform: translateY(-5px);
}

.discard-hand .card.selected {
    transform: translateY(-10px);
    box-shadow: 0 8px 16px rgba(229, 62, 62, 0.5);
    border-color: var(--danger);
}

#confirm-discard-btn {
    width: 100%;
}

/* Round/Game End Dialogs */
.round-summary,
.game-summary {
    text-align: center;
    padding: 1rem;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 1rem;
}

.round-summary .result,
.game-summary .result {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.round-summary .result.win,
.game-summary .result.win {
    color: var(--success);
}

.round-summary .result.loss,
.game-summary .result.loss {
    color: var(--danger);
}

.round-summary .details,
.game-summary .details {
    color: var(--text-light);
}

#next-hand-btn,
#new-game-end-btn {
    width: 100%;
}

/* Card animations */
@keyframes dealCard {
    from {
        opacity: 0;
        transform: translateY(-50px) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotate(0);
    }
}

.card.dealing {
    animation: dealCard 0.3s ease-out forwards;
}

@keyframes playCard {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.trick-card .card {
    animation: playCard 0.2s ease-out;
}

/* Responsive */
@media (max-width: 1400px) {
    .table {
        grid-template-columns: 180px 1fr 180px;
        grid-template-rows: 200px 1fr 220px;
    }

    .card {
        width: 100px;
        height: 140px;
    }

    .card .card-rank {
        font-size: 1.5rem;
        top: 6px;
        left: 8px;
    }

    .card .card-suit {
        font-size: 1.8rem;
        bottom: 6px;
        left: 8px;
    }

    .player-hand .card:not(:first-child) {
        margin-left: -50px;
    }

    .player-area.west .player-hand .card:not(:first-child),
    .player-area.east .player-hand .card:not(:first-child) {
        margin-top: -90px;
    }

    .trick {
        width: 280px;
        height: 280px;
    }

    .trick-card {
        width: 100px;
        height: 140px;
    }
}

@media (max-width: 1000px) {
    .table {
        grid-template-columns: 140px 1fr 140px;
        grid-template-rows: 160px 1fr 180px;
    }

    .card {
        width: 80px;
        height: 112px;
    }

    .card .card-rank {
        font-size: 1.2rem;
        top: 4px;
        left: 6px;
    }

    .card .card-suit {
        font-size: 1.4rem;
        bottom: 4px;
        left: 6px;
    }

    .player-hand .card:not(:first-child) {
        margin-left: -40px;
    }

    .player-area.west .player-hand .card:not(:first-child),
    .player-area.east .player-hand .card:not(:first-child) {
        margin-top: -70px;
    }

    .trick {
        width: 220px;
        height: 220px;
    }

    .trick-card {
        width: 80px;
        height: 112px;
    }

    .game-header h1 {
        font-size: 1.2rem;
    }

    .score-panel {
        gap: 1rem;
    }

    .score-value {
        font-size: 1.2rem;
    }

    .modal-content {
        padding: 1rem;
    }

    .bid-btn {
        padding: 0.4rem;
        font-size: 1rem;
    }
}
