/* ============================================ */
/* GLOBAL RESET & BASE STYLES                   */
/* ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

body {
    font-family: Arial, sans-serif;
    padding: 20px;
    background: #f0f0f0;
    transition: background-color 0.3s;
}

/* ============================================ */
/* PLAYER TURN BODY BACKGROUNDS                 */
/* ============================================ */

body.red-turn {
    background: #d32f2f;
}

body.blue-turn {
    background: #1976d2;
}

/* Disable zone click interactions when round is ending (but allow drag-and-drop) */
body.round-ending .zone {
    cursor: not-allowed !important;
    /* Don't disable pointer-events to allow drag-and-drop */
}

body.round-ending .zone:hover {
    background: none !important;
}

body.round-ending .outer-zone {
    cursor: not-allowed !important;
    /* Don't disable pointer-events to allow drag-and-drop */
}

body.round-ending .outer-zone:hover {
    background: none !important;
}

/* Keep POKs draggable during round ending */
body.round-ending .pok {
    cursor: grab !important;
    pointer-events: auto !important;
}

body.round-ending .pok:active {
    cursor: grabbing !important;
}

/* ============================================ */
/* MAIN CONTAINER & LAYOUT                      */
/* ============================================ */

.container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-height: 95vh;
}

.top-section {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    flex: 1;
}

/* ============================================ */
/* LEFT PANEL: Scores & History                */
/* ============================================ */

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}


/* Rounds History Section */
.rounds-history {
    background: #fafafa;
    border-radius: 8px;
    padding: 15px;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.history-table-container {
    overflow-y: auto;
    flex: 1;
}

/* Rounds History Table */
#roundsHistoryTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#roundsHistoryTable thead {
    position: sticky;
    top: 0;
    background: #fafafa;
    z-index: 1;
}

#roundsHistoryTable th {
    padding: 8px 4px;
    text-align: center;
    font-weight: bold;
    border-bottom: 2px solid #ddd;
    color: #666;
}

#roundsHistoryTable td {
    padding: 6px 4px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

#roundsHistoryTable tbody tr:hover {
    background: #f5f5f5;
}

/* Round Row Color Coding */
#roundsHistoryTable .red-round-row {
    background-color: rgba(211, 47, 47, 0.08);
}

#roundsHistoryTable .red-round-row:hover {
    background-color: rgba(211, 47, 47, 0.15);
}

#roundsHistoryTable .blue-round-row {
    background-color: rgba(25, 118, 210, 0.08);
}

#roundsHistoryTable .blue-round-row:hover {
    background-color: rgba(25, 118, 210, 0.15);
}

#roundsHistoryTable .round-row-current {
    background-color: rgba(255, 193, 7, 0.1);
    font-style: italic;
}

#roundsHistoryTable .round-row-current:hover {
    background-color: rgba(255, 193, 7, 0.2);
}

/* Table Cell Styling */
#roundsHistoryTable .round-number {
    font-weight: bold;
    color: #666;
}

#roundsHistoryTable .red-winner {
    color: #d32f2f;
    font-weight: bold;
}

#roundsHistoryTable .blue-winner {
    color: #1976d2;
    font-weight: bold;
}

#roundsHistoryTable .winner-tie {
    color: #666;
    font-style: italic;
}

#roundsHistoryTable .winner-current {
    color: #999;
    font-style: italic;
}

/* ============================================ */
/* RIGHT PANEL: Game Board                     */
/* ============================================ */

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    justify-content: center;
    position: relative;
}

/* Flip Table Button (Top Left Corner) */
.flip-table-button {
    position: absolute;
    top: 0;
    left: 0;
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
    background: #4caf50;
    color: white;
    border-radius: 6px;
    margin: 0;
    z-index: 100;
}

.flip-table-button:hover {
    background: #429444;
}

.save-game-button {
    position: absolute;
    top: 0;
    right: 100px;
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
    background: #ff9800;
    color: white;
    border-radius: 6px;
    margin: 0;
    z-index: 100;
}

.save-game-button:hover {
    background: #f57c00;
}

.show-history-button {
    position: absolute;
    top: 0;
    left: 120px;
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
    background: #9c27b0;
    color: white;
    border-radius: 6px;
    margin: 0;
    z-index: 100;
    display: none;
}

.show-history-button:hover {
    background: #7b1fa2;
}

/* Game Board Container */
.table-container {
    background: #c9985a;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    /* Enable pointer events on container */
    pointer-events: auto;
    width: 75%;
    margin: auto;
    transition: transform 0.3s ease;
    cursor: pointer;
}

/* Flipped Table */
.table-container.flipped {
    transform: scaleX(-1);
}

/* Counter-flip text elements to keep them readable when table is flipped */
.table-container.flipped .zone-label {
    transform: scaleX(-1);
}

.table-container.flipped .center-circle {
    transform: translateY(-50%) scaleX(-1);
}

/* Adjust POK positioning and counter-flip text when table is flipped */
.table-container.flipped .pok {
    transform: translate(-50%, -50%) scaleX(-1);
}

/* Counter-flip player turn notification to keep it readable when table is flipped */
.table-container.flipped .player-turn-notification {
    transform: translate(-50%, -50%) scaleX(-1);
}

/* Outer Play Area (outside scoring zones) */
.outer-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 0;
}

.outer-zone:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Next Player Turn Indicator */
.next-player-indicator {
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
}

.next-player-indicator.red-bg {
    background-color: #d32f2f;
}

.next-player-indicator.blue-bg {
    background-color: #1976d2;
}

/* ============================================ */
/* GAME TABLE & ZONES                          */
/* ============================================ */

/* Main Game Table */
.table {
    background: #e4c9a0;
    border: 3px solid #2c1810;
    position: relative;
    aspect-ratio: 1.5/1;
    width: 92%;
    max-width: 800px;
    z-index: 1;
    cursor: pointer;
}

.table-inner {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
}

/* Table Sides (Left/Right) */
.side {
    flex: 1;
    position: relative;
    display: flex;
}

/* Center POK Logo Circle */
.center-circle {
    width: 20%;
    max-width: 160px;
    aspect-ratio: 1;
    border: 3px solid #2c1810;
    border-radius: 50%;
    position: absolute;
    right: 2.5%;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.center-circle svg,
.center-circle img {
    width: 100%;
    height: 100%;
}

/* Scoring Zone Columns */
.column {
    flex: 1;
    border-right: 3px solid #2c1810;
    display: flex;
    flex-direction: column;
    position: relative;
}

.column.zero-column {
    flex: 2;
}

.column:last-child {
    border-right: none;
}

.side.right .column {
    border-left: 3px solid #2c1810;
    border-right: none;
}

.side.right .column:first-child {
    border-left: none;
}

/* Scoring Zones (Rectangle zones 0-3) */
.zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

.zone:hover {
    background: #d4b890;
}

.zone.boundary-highlight {
    border: 3px dashed #ffd700;
    background: rgba(255, 215, 0, 0.15);
    animation: boundary-pulse 0.8s ease-in-out infinite;
}

.zone-label {
    font-size: 48px;
    font-weight: normal;
    color: #2c1810;
}

/* Circle Scoring Zones (zones 4 & 5) */
.circle-zone {
    position: absolute;
    width: 60%;
    min-width: 45px;
    aspect-ratio: 1/1;
    border: 3px solid #2c1810;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: #e4c9a0;
    transition: background-color 0.2s;
}

.circle-zone .zone-label {
    font-size: clamp(12px, 3vw, 20px);
}

.circle-zone:hover {
    background: #d4b890;
}

.circle-zone.boundary-highlight {
    border: 3px dashed #ffd700;
    background: rgba(255, 215, 0, 0.15);
    animation: boundary-pulse 0.8s ease-in-out infinite;
}

.circle-zone.top {
    top: 10%;
}

.circle-zone.bottom {
    bottom: 10%;
}

.side.left .circle-zone {
    left: 50%;
    transform: translateX(-50%);
}

.side.right .circle-zone {
    left: 10%;
}

/* ============================================ */
/* POK PIECES (Game Tokens)                    */
/* ============================================ */

.pok {
    position: absolute;
    /* Use viewport-based sizing that scales with the table */
    width: clamp(20px, 2vw, 30px);
    height: clamp(20px, 2vw, 30px);
    border-radius: 50%;
    border: 2px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(8px, 1.2vw, 12px);
    font-weight: bold;
    color: white;
    z-index: 100;
    cursor: grab;
    touch-action: none;
    transform: translate(-50%, -50%);
}

.pok:active {
    cursor: grabbing;
}

.pok.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* Red Player POK */
.pok.red {
    background: #d32f2f;
}

/* Blue Player POK */
.pok.blue {
    background: #1976d2;
}

/* Low Score POK (Half-filled gradient) */
.pok.low-score.red {
    background: linear-gradient(135deg, #d32f2f 50%, #888 50%);
}

.pok.low-score.blue {
    background: linear-gradient(135deg, #1976d2 50%, #888 50%);
}

/* Last Placed POK - Animated Dashed Border */
.pok.last-placed {
    border: 3px solid #333;
    animation: pok-breathe 1.3s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6), 0 0 20px rgba(255, 215, 0, 0.3);
}

/* Use flipped animation when table is flipped */
.table-container.flipped .pok.last-placed {
    animation: pok-breathe-flipped 1.3s ease-in-out infinite !important;
}

/* Historical POK Fade Transitions */
.pok.historical-fade-out {
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.pok.historical-fade-in {
    animation: pok-fade-in 0.8s ease-in forwards;
}

/* POKs that need to start invisible before fading in */
.pok.fade-ready {
    opacity: 0;
}

@keyframes pok-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pok-breathe {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1) scaleX(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.15) scaleX(1);
    }
}

@keyframes pok-breathe-flipped {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1) scaleX(-1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.15) scaleX(-1);
    }
}

@keyframes boundary-pulse {
    0%, 100% {
        border-color: #ffd700;
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5), inset 0 0 5px rgba(255, 215, 0, 0.3);
    }
    50% {
        border-color: #ffed4e;
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.8), inset 0 0 10px rgba(255, 215, 0, 0.5);
    }
}

/* ============================================ */
/* CURRENT ROUND SCORE DISPLAY                 */
/* ============================================ */

.current-round-score-container {
    position: relative;
    text-align: center;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    min-height: 120px;
}

.current-round-score {
    text-align: center;
    padding: 15px 20px;
    border-radius: 12px;
    transition: background-color 0.3s;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.current-round-score.red-leading {
    background-color: rgba(211, 47, 47, 0.15);
}

.current-round-score.blue-leading {
    background-color: rgba(25, 118, 210, 0.15);
}

.current-round-score.tied {
    background-color: #fafafa;
}

.current-round-score .score-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 8px;
    position: relative;
}

/* Score Circle (Shows current round points per player) */
.score-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: bold;
    color: white;
}

.score-circle.red-circle {
    background-color: #d32f2f;
}

.score-circle.blue-circle {
    background-color: #1976d2;
}

/* Score Difference Indicator */
.score-difference {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: white;
    background-color: #999;
}


/* ============================================ */
/* GAME START SELECTOR                         */
/* ============================================ */

.start-selector {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.95;
    z-index: 2000;
    display: flex;
    flex-wrap: wrap;
}

.start-selector.hidden {
    display: none;
}

/* Container for action buttons at top of start screen */
.start-selector-buttons {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    z-index: 2001;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 90%;
}

.continue-game-top-button,
.save-latest-game-button,
.import-match-button {
    padding: 15px 30px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.2s;
    white-space: nowrap;
    border: none;
}

.continue-game-top-button {
    background: #4caf50;
    display: none;
}

.continue-game-top-button.show {
    display: block;
}

.continue-game-top-button:hover {
    background: #45a049;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.save-latest-game-button {
    background: #ff9800;
    display: none;
}

.save-latest-game-button.show {
    display: block;
}

.save-latest-game-button:hover {
    background: #f57c00;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.import-match-button {
    background: #2196f3;
}

.import-match-button:hover {
    background: #1976d2;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.start-half {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.3s;
    font-size: 64px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.start-half:hover {
    opacity: 0.9;
}

.start-half.red {
    background: #d32f2f;
}

.start-half.blue {
    background: #1976d2;
}

/* Player Name Input */
.start-half {
    flex-direction: column;
    gap: 20px;
}

.player-name-input {
    width: 80%;
    max-width: 300px;
    padding: 15px 20px;
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    outline: none;
    transition: border-color 0.3s, background-color 0.3s;
}

.player-name-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.player-name-input:focus {
    border-color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.3);
}

.start-label {
    font-size: 20px;
    font-weight: normal;
    opacity: 0.8;
    letter-spacing: 2px;
}

/* ============================================ */
/* ROUND END MODAL                             */
/* ============================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.3s;
}

.modal.show {
    display: flex;
}

/* Modal Background Colors */
.modal.red-bg {
    background: #d32f2f;
}

.modal.blue-bg {
    background: #1976d2;
}

.modal.tie-bg {
    background: #666;
}

/* Modal Content */
.modal-content {
    text-align: center;
    color: white;
    width: 100%;
    padding: 40px;
}

.modal-round-number {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 20px;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.modal-content .winner {
    font-size: 96px;
    font-weight: bold;
    margin-bottom: 40px;
    color: white;
}

/* Modal Score Display - reusing score-circle styles */
.modal-score-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    margin: 40px 0;
}

.modal-score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 64px;
    font-weight: bold;
    color: white;
    border: 4px solid rgba(255, 255, 255, 0.3);
}

.modal-score-circle.red-circle {
    background-color: #d32f2f;
}

.modal-score-circle.blue-circle {
    background-color: #1976d2;
}

.modal-score-difference {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    color: white;
    background-color: rgba(255, 255, 255, 0.35);
    border: 4px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.modal-content .total-scores {
    font-size: 36px;
    margin-top: 40px;
    color: rgba(255, 255, 255, 0.9);
}

.modal-content .continue-hint {
    font-size: 24px;
    margin-top: 60px;
    color: rgba(255, 255, 255, 0.7);
}

/* Modal Score Visualizer */
.modal-score-visualizer-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    padding: 20px 30px;
    background: rgba(44, 24, 16, 0.6);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    margin: 40px auto 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.modal-score-visualizer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.modal-center-pok-marker {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-center-pok-marker .pok-svg {
    width: 100%;
    height: 100%;
}

.modal-center-pok-score {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 200;
}

/* ============================================ */
/* HISTORY MODAL (Mobile)                      */
/* ============================================ */

.history-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.history-modal.show {
    display: flex;
}

.history-modal-content {
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.close-history-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #d32f2f;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    z-index: 1;
}

.close-history-button:hover {
    background: #b71c1c;
}

.history-modal-content h2 {
    margin-bottom: 15px;
    padding-right: 50px;
}

.history-modal-table-container {
    overflow-y: auto;
    flex: 1;
}

#historyModalTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#historyModalTable thead {
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

#historyModalTable th {
    padding: 8px 4px;
    text-align: center;
    font-weight: bold;
    border-bottom: 2px solid #ddd;
    color: #666;
}

#historyModalTable td {
    padding: 6px 4px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

#historyModalTable tbody tr:hover {
    background: #f5f5f5;
}

/* Round Row Color Coding for History Modal */
#historyModalTable .red-round-row {
    background-color: rgba(211, 47, 47, 0.08);
}

#historyModalTable .red-round-row:hover {
    background-color: rgba(211, 47, 47, 0.15);
}

#historyModalTable .blue-round-row {
    background-color: rgba(25, 118, 210, 0.08);
}

#historyModalTable .blue-round-row:hover {
    background-color: rgba(25, 118, 210, 0.15);
}

#historyModalTable .round-row-current {
    background-color: rgba(255, 193, 7, 0.1);
    font-style: italic;
}

#historyModalTable .round-row-current:hover {
    background-color: rgba(255, 193, 7, 0.2);
}

/* Table Cell Styling for History Modal */
#historyModalTable .round-number {
    font-weight: bold;
    color: #666;
}

#historyModalTable .red-winner {
    color: #d32f2f;
    font-weight: bold;
}

#historyModalTable .blue-winner {
    color: #1976d2;
    font-weight: bold;
}

#historyModalTable .winner-tie {
    color: #666;
    font-style: italic;
}

#historyModalTable .winner-current {
    color: #999;
    font-style: italic;
}

/* ============================================ */
/* TYPOGRAPHY                                  */
/* ============================================ */

h1 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 5px;
}

h2 {
    text-align: center;
    font-size: 16px;
    margin-bottom: 10px;
    color: #333;
}

/* ============================================ */
/* PLAYER TURN NOTIFICATION                    */
/* ============================================ */

.player-turn-notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    z-index: 150;
    pointer-events: none;
    opacity: 0;
    color: #ffffff;
    padding: 20px 40px;
    border-radius: 12px;
    transition: opacity 0.3s ease-in;
    white-space: nowrap;
}

.player-turn-notification.red-player {
    background: #d32f2f;
}

.player-turn-notification.blue-player {
    background: #1976d2;
}

.player-turn-notification.show {
    opacity: 1;
}

.player-turn-notification.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* Round End Loading Bar */
.round-end-loading-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 10px;
    background: transparent;
    opacity: 0;
    transition: opacity 0.3s ease-in;
    overflow: hidden;
    z-index: 160;
    border-radius: 5px 5px 0 0;
}

.round-end-loading-bar.show {
    opacity: 1;
}

.loading-bar-fill {
    height: 100%;
    width: 0%;
    background: transparent;
    transition: width linear;
}

.loading-bar-fill.red-winner {
    background: #d32f2f;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.4);
}

.loading-bar-fill.blue-winner {
    background: #1976d2;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.4);
}

.loading-bar-fill.tie-game {
    background: #757575;
    box-shadow: 0 2px 8px rgba(117, 117, 117, 0.4);
}

/* End Round Button (shown during countdown) */
.end-round-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    text-transform: uppercase;
    color: white;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, background 0.2s ease;
    z-index: 170;
}

.end-round-button.show {
    opacity: 1;
    visibility: visible;
}

.end-round-button:hover {
    background: rgba(0, 0, 0, 0.85);
    border-color: rgba(255, 255, 255, 0.5);
}

.end-round-button:active {
    transform: translate(-50%, -50%) scale(0.95);
}

/* Edit Board Button (in round end modal) */
.edit-board-button {
    display: none;
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.edit-board-button.show {
    display: inline-block;
}

.edit-board-button:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.5);
}

.edit-board-button:active {
    transform: scale(0.95);
}

/* Hide edit board button for game winner modal */
.modal.game-winner .edit-board-button {
    display: none !important;
}

/* Save Game Button (in champion modal) */
.save-game-button {
    display: none;
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(76, 175, 80, 0.5);
    border: 2px solid rgba(76, 175, 80, 0.7);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.save-game-button.show {
    display: inline-block;
}

.save-game-button:hover {
    background: rgba(76, 175, 80, 0.7);
    border-color: rgba(76, 175, 80, 0.9);
}

.save-game-button:active {
    transform: scale(0.95);
}

/* ============================================ */
/* SCORE VISUALIZER (21 Ball Scoreboard)      */
/* ============================================ */

.score-visualizer-container {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto;
    align-items: center;
    padding: 10px 15px;
    background: #2c1810;
    border-radius: 8px;
    width: 100%;
    margin: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Margins for 5-column symmetry */
.score-visualizer-container > .end-pok-indicator.red {
    margin-left: 10px;
    margin-right: 15px;
}

.score-visualizer-container > .red-visualizer {
    margin-right: 15px;
}

.score-visualizer-container > .current-round-score {
    margin-left: 0;
    margin-right: 0;
}

.score-visualizer-container > .blue-visualizer {
    margin-left: 15px;
}

.score-visualizer-container > .end-pok-indicator.blue {
    margin-left: 15px;
    margin-right: 10px;
}

.score-visualizer {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.score-bar {
    position: relative;
    width: 100%;
    height: 20px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    box-sizing: border-box;
}

.score-track {
    position: absolute;
    left: 10px;
    right: 10px;
    width: calc(100% - 20px);
    height: 4px;
    background: linear-gradient(to bottom, #8b7355, #6b5644);
    border-radius: 2px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}

.score-markers {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.score-marker {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid #5a4a3a;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 -1px 1px rgba(0,0,0,0.3);
    transition: left 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                background 0.3s ease,
                border-color 0.3s ease;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

/* Red marbles - default gray, turn red when scored */
.red-visualizer .score-marker {
    background: radial-gradient(circle at 30% 30%, #c9c9c9, #888);
}

.red-visualizer .score-marker.scored {
    background: radial-gradient(circle at 30% 30%, #ff6b6b, #d32f2f);
    border-color: #b71c1c;
}

/* Blue marbles - default gray, turn blue when scored */
.blue-visualizer .score-marker {
    background: radial-gradient(circle at 30% 30%, #c9c9c9, #888);
}

.blue-visualizer .score-marker.scored {
    background: radial-gradient(circle at 30% 30%, #4dabf7, #1976d2);
    border-color: #0d47a1;
}

/* End POK Indicators (show total score at ends of marble tracks) */
.end-pok-indicator {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    align-self: center;
    justify-self: center;
}

.end-pok-indicator.red {
    background: #d32f2f;
}

.end-pok-indicator.blue {
    background: #1976d2;
}

/* Center POK Marker */
.center-pok-marker {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.center-pok-marker .pok-svg {
    width: 100%;
    height: 100%;
}

.center-pok-score {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 200;
}

/* POK-styled numbers in center marker */
.pok-style-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.pok-style-number.red {
    background: #d32f2f;
}

.pok-style-number.blue {
    background: #1976d2;
}

/* ============================================ */
/* BUTTONS                                     */
/* ============================================ */

button {
    padding: 12px 24px;
    margin: 10px 0;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 4px;
    background: #333;
    color: white;
    transition: background 0.2s;
    width: 100%;
}

button:hover {
    background: #555;
}

button:active {
    transform: scale(0.98);
}

/* New Game Button (Top Right Corner) */
.new-game-button {
    position: absolute;
    top: 0px;
    right: 0px;
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
    background: #4caf50;
    color: white;
    border-radius: 6px;
    margin: 0;
    z-index: 100;
}

.new-game-button:hover {
    background: #429444;
}

/* ============================================ */
/* GAME WINNER CELEBRATION                     */
/* ============================================ */

/* Winner modal with gold celebration theme */
.modal.game-winner {
    background: linear-gradient(135deg, #ffd700 0%, #ffb347 50%, #ffd700 100%);
}

/* Confetti canvas styling - confetti is rendered via JS */
.confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Trophy icon styling */
.winner-trophy {
    font-size: 120px;
    animation: trophy-bounce 1s ease-in-out infinite;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 215, 0, 0.4);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

@keyframes trophy-bounce {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-15px) scale(1.1);
    }
}

/* Champion title with glow */
.modal.game-winner .winner {
    font-size: 72px;
    color: #2c1810;
    text-shadow:
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 255, 255, 0.6),
        0 0 30px rgba(255, 215, 0, 0.4);
    animation: champion-pulse 1.5s ease-in-out infinite;
}

@keyframes champion-pulse {
    0%, 100% {
        transform: scale(1);
        text-shadow:
            0 0 10px rgba(255, 255, 255, 0.8),
            0 0 20px rgba(255, 255, 255, 0.6),
            0 0 30px rgba(255, 215, 0, 0.4);
    }
    50% {
        transform: scale(1.05);
        text-shadow:
            0 0 20px rgba(255, 255, 255, 1),
            0 0 40px rgba(255, 255, 255, 0.8),
            0 0 60px rgba(255, 215, 0, 0.6);
    }
}

/* Game over header styling */
.modal.game-winner .modal-round-number {
    font-size: 28px;
    color: #2c1810;
    text-transform: uppercase;
    letter-spacing: 8px;
    opacity: 0.9;
}

/* Winner announcement text */
.winner-announcement {
    font-size: 24px;
    color: #2c1810;
    margin-bottom: 20px;
    letter-spacing: 2px;
    opacity: 0.9;
}

/* Final score display in winner modal */
.modal.game-winner .modal-score-circle {
    border: 4px solid rgba(44, 24, 16, 0.5);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal.game-winner .modal-score-difference {
    background-color: rgba(44, 24, 16, 0.3);
    border: 4px solid rgba(44, 24, 16, 0.5);
}

/* Winner modal content needs higher z-index to be above confetti */
.modal.game-winner .modal-content {
    position: relative;
    z-index: 10;
}

/* Final score banner */
.final-score-banner {
    background: rgba(44, 24, 16, 0.2);
    border-radius: 12px;
    padding: 15px 30px;
    margin: 20px auto;
    display: inline-block;
}

.final-score-text {
    font-size: 36px;
    font-weight: bold;
    color: #2c1810;
}

.final-score-text .score-red {
    color: #d32f2f;
}

.final-score-text .score-blue {
    color: #1976d2;
}

/* Click to play again hint */
.modal.game-winner .continue-hint {
    color: #2c1810;
    opacity: 0.8;
    font-size: 20px;
    animation: hint-pulse 2s ease-in-out infinite;
}

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

/* Responsive adjustments for winner modal */
@media (max-width: 768px) {
    .winner-trophy {
        font-size: 80px;
    }

    .modal.game-winner .winner {
        font-size: 48px;
    }

    .modal.game-winner .modal-round-number {
        font-size: 20px;
        letter-spacing: 4px;
    }

    .final-score-text {
        font-size: 28px;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .winner-trophy {
        font-size: 60px;
    }

    .modal.game-winner .winner {
        font-size: 36px;
    }

    .modal.game-winner .modal-round-number {
        font-size: 16px;
        letter-spacing: 3px;
    }

    .final-score-text {
        font-size: 24px;
    }

    .final-score-banner {
        padding: 10px 20px;
        margin: 10px auto;
    }
}

/* ============================================ */
/* LEGACY/UNUSED STYLES                        */
/* (Kept for backwards compatibility)          */
/* ============================================ */

.scoreboard {
    text-align: center;
    padding: 20px;
    border-radius: 8px;
    background: #fafafa;
}

.main-score {
    font-size: 72px;
    font-weight: bold;
    margin-bottom: 15px;
}

.main-score .red {
    color: #d32f2f;
}

.main-score .blue {
    color: #1976d2;
}

/* ============================================ */
/* RESPONSIVE DESIGN                           */
/* ============================================ */

/* Hide left panel on smaller screens */
@media (max-width: 1024px) {
    .top-section {
        grid-template-columns: 1fr;
    }

    .left-panel {
        display: none;
    }

    .table-container {
        width: 90%;
    }

    .show-history-button {
        display: block;
    }
}

/* Mobile optimizations - fit everything vertically */
@media (max-width: 1024px) and (max-height: 500px),
       (max-width: 768px) {
    body {
        padding: 5px;
        overflow-x: hidden;
    }

    .container {
        padding: 10px;
        min-height: auto;
        height: auto;
    }

    .top-section {
        gap: 10px;
    }

    .right-panel {
        gap: 8px;
        justify-content: flex-start;
    }

    /* Make table container more compact */
    .table-container {
        padding: 15px;
        width: 100%;
        margin: 0;
    }

    /* Scale down buttons */
    .flip-table-button,
    .show-history-button,
    .save-game-button,
    .new-game-button {
        padding: 6px 12px;
        font-size: 12px;
    }

    .show-history-button {
        left: 90px;
    }

    .save-game-button {
        right: 80px;
    }

    .current-round-score {
        padding: 8px 10px;
    }

    .score-circle {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .score-difference {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }

    .current-round-score .score-row {
        gap: 10px;
        margin-bottom: 5px;
    }

    /* Player turn notification - more compact */
    .player-turn-notification {
        font-size: 24px;
        padding: 12px 20px;
    }

    /* Start selector buttons - smaller on mobile */
    .continue-game-top-button,
    .save-latest-game-button,
    .import-match-button {
        width: 70%;
        padding: 20px 30px;
        font-size: 20px;
    }

    .start-half {
        font-size: 48px;
    }

    .player-name-input {
        padding: 12px 15px;
        font-size: 20px;
    }

    .start-label {
        font-size: 16px;
    }

    /* Modal content - more compact */
    .modal-content {
        padding: 20px;
    }

    .modal-round-number {
        font-size: 20px;
        margin-bottom: 15px;
    }

    .modal-content .winner {
        font-size: 56px;
        margin-bottom: 20px;
    }

    .modal-score-display {
        gap: 15px;
        margin: 20px 0;
    }

    .modal-score-circle {
        width: 70px;
        height: 70px;
        font-size: 36px;
    }

    .modal-score-difference {
        width: 50px;
        height: 50px;
        font-size: 28px;
    }

    .modal-content .total-scores {
        font-size: 24px;
        margin-top: 20px;
    }

    .modal-score-visualizer-container {
        padding: 10px 15px;
        gap: 10px;
        margin-top: 20px;
    }

    .modal-center-pok-marker {
        width: 60px;
        height: 60px;
    }

    .modal-score-visualizer {
        padding: 4px;
    }

    .pok-style-number {
        width: 22px;
        height: 22px;
        font-size: 11px;
    }

    .modal-center-pok-score {
        gap: 6px;
    }

    .end-pok-indicator {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }


    .score-bar {
        padding: 0 8px;
    }

    .score-track {
        left: 8px;
        right: 8px;
        width: calc(100% - 16px);
    }
}

/* Landscape mobile - prioritize vertical space */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 2px;
        overflow-x: hidden;
    }

    .container {
        padding: 3px;
        min-height: auto;
        height: auto;
        overflow: visible;
    }

    .top-section {
        gap: 3px;
        height: 100%;
    }

    .right-panel {
        gap: 3px;
        justify-content: center;
    }

    .table-container {
        padding: 5px;
        width: 100%;
        max-width: 100%;
    }

    /* Make table smaller to fit */
    .table {
        width: 70%;
        max-width: 500px;
    }

    .flip-table-button,
    .show-history-button,
    .save-game-button,
    .new-game-button {
        padding: 3px 8px;
        font-size: 10px;
    }

    .show-history-button {
        left: 65px;
    }

    .save-game-button {
        right: 70px;
    }

    .current-round-score {
        padding: 3px 5px;
    }

    .score-circle {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }

    .score-difference {
        width: 22px;
        height: 22px;
        font-size: 11px;
    }

    .current-round-score .score-row {
        gap: 5px;
        margin-bottom: 2px;
    }

    .player-turn-notification {
        font-size: 16px;
        padding: 8px 12px;
    }

    /* Smaller zone labels */
    .zone-label {
        font-size: 32px;
    }

    /* Smaller POK pieces on landscape mobile */
    .pok {
        width: clamp(15px, 2vw, 25px);
        height: clamp(15px, 2vw, 25px);
        font-size: clamp(6px, 1vw, 10px);
    }

    /* Score visualizer - ultra compact for landscape */
    .score-visualizer-container {
        padding: 5px 8px;
        grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto;
    }

    .score-visualizer-container > .end-pok-indicator.red {
        margin-left: 5px;
        margin-right: 8px;
    }

    .score-visualizer-container > .red-visualizer {
        margin-right: 8px;
    }

    .score-visualizer-container > .current-round-score {
        margin-left: 0;
        margin-right: 0;
    }

    .score-visualizer-container > .blue-visualizer {
        margin-left: 8px;
    }

    .score-visualizer-container > .end-pok-indicator.blue {
        margin-left: 8px;
        margin-right: 5px;
    }

    .score-bar {
        height: 15px;
    }

    .score-marker {
        width: 8px;
        height: 8px;
    }

    .score-track {
        height: 3px;
    }

    .center-pok-marker {
        width: 50px;
        height: 50px;
    }

    .center-pok-score {
        gap: 5px;
    }

    .pok-style-number {
        width: 18px;
        height: 18px;
        font-size: 9px;
        border-width: 1.5px;
    }

    .modal-score-visualizer-container {
        padding: 8px 12px;
        gap: 8px;
        margin-top: 15px;
    }

    .modal-center-pok-marker {
        width: 50px;
        height: 50px;
    }

    .modal-center-pok-score {
        gap: 5px;
    }

    .end-pok-indicator {
        width: 22px;
        height: 22px;
        font-size: 11px;
    }

    .score-bar {
        height: 15px;
        padding: 0 8px;
    }

    .score-track {
        left: 8px;
        right: 8px;
        width: calc(100% - 16px);
    }
}

/* Extra small mobile devices - ultra compact */
@media (max-width: 480px) {
    body {
        padding: 2px;
        overflow-x: hidden;
    }

    .container {
        padding: 5px;
        min-height: auto;
        height: auto;
    }

    .table-container {
        padding: 10px;
    }

    .flip-table-button,
    .show-history-button,
    .save-game-button,
    .new-game-button {
        padding: 4px 8px;
        font-size: 10px;
    }

    .show-history-button {
        left: 70px;
    }

    /* Stack start selector buttons on mobile */
    .start-selector-buttons {
        flex-direction: column;
        gap: 10px;
        width: 90%;
        max-width: 300px;
    }

    .continue-game-top-button,
    .save-latest-game-button,
    .import-match-button {
        width: 100%;
        padding: 12px 20px;
        font-size: 16px;
    }

    .save-game-button {
        right: 75px;
    }

    .score-circle {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .score-difference {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    /* Score visualizer - compact for mobile */
    .score-visualizer-container {
        padding: 8px 10px;
        grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto;
    }

    .score-visualizer-container > .end-pok-indicator.red {
        margin-left: 5px;
        margin-right: 10px;
    }

    .score-visualizer-container > .red-visualizer {
        margin-right: 10px;
    }

    .score-visualizer-container > .current-round-score {
        margin-left: 0;
        margin-right: 0;
    }

    .score-visualizer-container > .blue-visualizer {
        margin-left: 10px;
    }

    .score-visualizer-container > .end-pok-indicator.blue {
        margin-left: 10px;
        margin-right: 5px;
    }


    .score-marker {
        width: 8px;
        height: 8px;
    }

    .score-bar {
        height: 15px;
    }

    .center-pok-marker {
        width: 60px;
        height: 60px;
    }

    .center-pok-score {
        gap: 6px;
    }

    .pok-style-number {
        width: 20px;
        height: 20px;
        font-size: 10px;
        border-width: 1.5px;
    }

    .modal-score-visualizer-container {
        padding: 10px 15px;
        gap: 12px;
        margin-top: 20px;
    }

    .modal-center-pok-marker {
        width: 60px;
        height: 60px;
    }

    .modal-center-pok-score {
        gap: 6px;
    }

    .end-pok-indicator {
        width: 25px;
        height: 25px;
        font-size: 12px;
    }

    .score-bar {
        padding: 0 8px;
    }

    .score-track {
        left: 8px;
        right: 8px;
        width: calc(100% - 16px);
    }
}
