/* General body styling, fonts, and base colors */
html, body {
    width: 100%; /* Ensures full width coverage */
    height: 100%; /* Ensures full height coverage */
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Open Sans', sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #333;
    overflow-x: hidden; /* Crucial to prevent horizontal scroll */
}

h1, h2, h3 {
    font-family: 'Fredoka One', cursive;
    color: #4CAF50; /* Green color for headings */
    margin-bottom: 20px;
}

/* --- Core Hidden Rule --- */
.hidden {
    display: none !important; /* Crucial for dynamic show/hide of elements */
}

/* --- Modal Styling --- */
.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    z-index: 1001; /* High z-index to show above other content */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    overflow: auto;
}

.modal-content {
    background-color: #fff;
    margin: auto;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    text-align: left; /* CHANGED: Aligns all text content to the left by default */
    position: relative;
}

.modal-content h2 {
    color: #FFC107;
    margin-bottom: 15px;
}

.modal-content p {
    line-height: 1.6;
    margin-bottom: 20px;
}

/* Justify text for paragraphs within the credits modal */
/* Removed max-width, margin, padding here as they are handled by .modal-content or would conflict */
#creditsModal .modal-content p {
    text-align: justify;
}

.modal-content h2 {
    color: #FFC107;
    margin-bottom: 15px;
    text-align: center; /* ADD THIS LINE to center h2 titles */
}
}


/* Specific rule for the disclaimer paragraph if you want it justified and others in creditsModal not */
/* If you want all paragraphs in #creditsModal justified, you can remove this rule */
#disclaimerParagraph {
    text-align: justify;
}

/* NEW CLASS: For centering groups of buttons within modals */
.modal-button-group {
    display: flex;
    justify-content: center; /* Centers the buttons horizontally */
    gap: 15px; /* Space between buttons */
    margin-top: 20px; /* Space above the button group */
    flex-wrap: wrap; /* Allows buttons to wrap to the next line on smaller screens */
}


.modal-content ul {
    list-style: none;
    padding: 0;
    margin-bottom: 20px;
}

.modal-content ul li {
    background-color: #e8f5e9;
    margin: 8px 0;
    padding: 10px;
    border-radius: 8px;
}

/* Specific styling for notification modal content */
.notification-content h2 {
    color: #E91E63;
}

/* --- Winner Splash Screen Modal --- */

#winnerSplashScreenModal .modal-content {
    background-color: #4CAF50; /* Green background for winner content */
    color: white; /* White text for winner content */
    padding: 15px; /* Reduced from 20px to 15px for top/bottom padding */
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 600px; /* Standardized max-width */
    width: 90%;
    display: flex; /* Use flexbox for internal content alignment */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px; /* Reduced from 15px to 10px */
    max-height: 90vh; /* Ensures the content box doesn't exceed 90% of viewport height */
    overflow-y: auto; /* Adds a scrollbar if content is still too tall */
    text-align: center; /* Keep this modal's content centered */
}

/* When the modal is active, make it visible */
#winnerSplashScreenModal:not(.hidden) {
    opacity: 1;
}

#winnerSplashScreenModal h2 {
    color: #FFC107; /* Gold color for winner name */
    font-size: 3em; /* Very large font for winner name */
    margin-bottom: 0; /* No bottom margin */
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.winner-trophy-img {
    max-width: 150px; /* Adjusted smaller size for the trophy to allow space for score */
    height: auto;
    animation: bounceIn 1s ease-out forwards; /* Add a bounce-in animation */
    margin-bottom: 5px; /* Reduced space below trophy */
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.winner-game-summary {
    width: 90%; /* Take up more width for better readability */
    background-color: #e0e0e0; /* A slightly darker grey background for the summary section */
    padding: 15px;
    border-radius: 8px;
    margin-top: 5px; /* Reduced space above summary */
    margin-bottom: 5px; /* Reduced from 10px to 5px */
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.winner-game-summary h3 {
    color: #333; /* Darker text color for "Game Summary:" */
    font-size: 1.5em;
    margin-bottom: 10px;
    text-shadow: none; /* Remove any previous green text shadow */
    background-color: transparent; /* Ensure no green background */
}

/* New container for the game summary table on winner screen */
.game-summary-table-container {
    width: 100%;
    overflow-x: auto; /* Adds horizontal scroll if table is too wide */
    display: block; /* Changed from 'table' for better overflow-x behavior */
    margin-left: auto;
    margin-right: auto;
}

/* Apply ranking table styles to the winner game summary table */
#gameSummaryTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box; /* Added for responsiveness */
}

#gameSummaryTable th,
#gameSummaryTable td {
    border: 1px solid #ccc; /* Slightly lighter border for inner table */
    padding: 5px; /* Reduced padding for more vertical and horizontal compaction */
    text-align: left; /* Default text align, overridden for headers and numeric data */
    color: #333; /* Ensure dark text */
    box-sizing: border-box; /* Added for responsiveness */
}

#gameSummaryTable th {
    background-color: #66BB6A; /* Slightly lighter green for summary table header */
    color: white;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center; /* ALL HEADERS ARE NOW CENTERED */
}

/* No specific nth-child centering needed for headers anymore */

#gameSummaryTable tbody tr:nth-child(even) {
    background-color: #f9f9f9; /* Lighter zebra for summary */
}

#gameSummaryTable tbody tr:hover {
    background-color: #e0ffe0; /* Light green hover effect */
}

/* Right-align numeric data columns for better readability in game summary table.
    ONLY applies to td elements now, allowing th to be centered. */
#gameSummaryTable td:nth-child(2), /* Correct data */
#gameSummaryTable td:nth-child(3), /* Wrong data */
#gameSummaryTable td:nth-child(4) { /* Accuracy data */
    text-align: right;
}

/* Ensure the player name column also has consistent, compact padding */
#gameSummaryTable td:first-child {
    padding: 5px;
}


.winner-buttons {
    display: flex;
    gap: 15px; /* Space between buttons */
    justify-content: center;
    width: 100%;
    margin-top: 10px; /* Control margin for buttons below summary */
}


/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-family: 'Fredoka One', cursive;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 5px; /* Kept margin for general btn, but the new .modal-button-group will use gap */
}

.primary-btn {
    background-color: #4CAF50;
    color: white;
}

.primary-btn:hover {
    background-color: #388E3C;
    transform: translateY(-2px);
}

.secondary-btn {
    background-color: #FFC107;
    color: #333;
}

.secondary-btn:hover {
    background-color: #FFA000;
    transform: translateY(-2px);
}

.btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* --- Game Container and Setup Box --- */
.game-container {
    background-color: #ffffff;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    padding: 20px;
    width: 90%;
    max-width: 930px;
    margin: 20px auto;
    text-align: center; /* Kept center for game setup elements like h1, input, etc. */
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.game-box {
    padding: 20px;
}

/* --- Player Input Section (Add Player) --- */
.player-input-section {
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#newPlayerName {
    padding: 10px 15px;
    border: 2px solid #ccc;
    border-radius: 8px;
    font-size: 1em;
    width: 250px;
    max-width: 80%;
}

.warning-text {
    color: #E91E63;
    font-weight: bold;
    margin-top: 10px;
}

.player-list {
    margin: 20px 0;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px;
    min-height: 50px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.player-item {
    background-color: #f1f8e9;
    border: 1px solid #c8e6c9;
    padding: 8px 15px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    color: #2E7D32;
}

.remove-player-btn {
    background-color: #E91E63;
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-size: 0.8em;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.remove-player-btn:hover {
    background-color: #C2185B;
}

/* --- Game Area Layout --- */
.game-area {
    display: flex;
    flex-direction: column; /* This now stacks the main game area (board + right panel) content */
    align-items: center;
    gap: 15px;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 10px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    box-sizing: border-box;
}

/* New wrapper for board and the combined right-side panel */
.board-and-right-panel-wrapper { /* Renamed from board-and-sidebar-wrapper */
    display: flex;
    flex-direction: row; /* Board on left, right-panel on right */
    gap: 20px; /* Space between board and right panel */
    justify-content: center; /* Center the board and right panel horizontally */
    align-items: flex-start; /* Align elements to the top */
    width: 100%;
    flex-wrap: wrap; /* Allows wrapping on smaller screens */
    box-sizing: border-box;
}

/* New container for the right-side elements (current player/dice + sidebar) */
.right-panel {
    display: flex;
    flex-direction: column; /* Stacks current player/dice above sidebar */
    gap: 15px; /* Space between current player/dice area and sidebar */
    flex-shrink: 0;
    width: 250px; /* Fixed width for the right panel */
    max-width: 100%; /* Allows it to shrink if needed */
    box-sizing: border-box;
}

/* NEW wrapper for current player info and dice, replacing the old game-header's primary role */
.current-player-dice-wrapper {
    background-color: #e0f2f1;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column; /* Stack info above actions within this wrapper */
    gap: 10px;
    justify-content: center; /* Center content vertically */
    align-items: center; /* Center content horizontally */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    width: 100%; /* Takes full width of its parent (.right-panel) */
    box-sizing: border-box;
}

.current-player-info {
    text-align: center; /* Center text within this block */
    display: flex;
    flex-direction: column;
    align-items: center; /* Center items (h2, player-identity, position) */
    flex-grow: 1; /* Allow it to grow */
    min-width: unset; /* Remove previous min-width constraint */
}

.current-player-info h2 {
    margin-top: 0;
    margin-bottom: 5px;
    font-size: 1.2em;
    color: #00796B;
}

.player-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center; /* Center the token and name */
}

.current-player-token {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

/* Player token colors */
.red-token { background-color: #D32F2F; }
.pink-token { background-color: #F8BBD0; }
.green-token { background-color: #8BC34A; }
.yellow-token { background-color: #FFEB3B; }
.blue-token { background-color: #2196F3; }
.black-token { background-color: #212121; }

.current-player-info span {
    font-size: 1.1em;
    font-weight: bold;
    color: #444;
}

.game-actions {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
    justify-content: center; /* Center dice and button */
    width: 100%; /* Take full width of parent */
}

.dice-image {
    width: 60px;
    height: 60px;
    border: 3px solid #00796B;
    border-radius: 10px;
    background-color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Game board styling */
.game-board {
    position: relative;
    width: 550px; /* Base size */
    aspect-ratio: 1 / 1;
    max-width: 100%;
    margin: 0;
    flex-shrink: 0;
    box-sizing: border-box;
}

.board-image {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.player-token {
    position: absolute;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -50%);
    transition: left 0.5s ease-in-out, top 0.5s ease-in-out;
    z-index: 10;
}

/* Sidebar for player status/score */
.sidebar {
    background-color: #e3f2fd;
    border-radius: 10px;
    padding: 10px;
    width: 100%; /* Takes full width of its parent (.right-panel) */
    flex-shrink: 0;
    max-height: 700px; /* Allows scrolling if many players */
    overflow-y: auto;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

.sidebar h3 {
    color: #00796B;
    margin-top: 0;
    margin-bottom: 10px;
}

#playersStatusList {
    list-style: none;
    padding: 0;
    margin: 0;
}

#playersStatusList li {
    display: flex;
    align-items: center;
    background-color: #e1f5fe;
    border: 1px solid #bbdefb;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    font-weight: bold;
    color: #333;
    gap: 10px;
    flex-wrap: wrap;
}

/* New class for tokens in the sidebar status list */
.player-token-sidebar {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

/* Highlight for current player in sidebar */
#playersStatusList li.current-player-highlight {
    background-color: #fff9c4;
    border-color: #ffeb3b;
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.5);
}

/* --- Responsive Adjustments for Smaller Screens (e.g., tablets and phones) --- */
@media (max-width: 930px) {
    .game-area {
        gap: 10px;
        padding: 10px;
    }

    .board-and-right-panel-wrapper { /* This wrapper will stack vertically */
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .right-panel { /* The right panel will take full width and still stack its contents */
        width: 100%;
        gap: 10px; /* Adjust gap when stacked */
    }

    .current-player-dice-wrapper {
        padding: 8px; /* Slightly less padding */
        gap: 8px; /* Adjust internal gap */
    }

    .sidebar {
        max-height: 250px; /* Limit height when stacked */
        padding: 8px;
    }

    .game-board {
        width: 100%; /* Board takes full width when stacked */
    }

    .player-token {
        width: 25px; /* Smaller tokens on smaller screens */
        height: 25px;
    }

    #winnerSplashScreenModal .modal-content {
        padding: 15px; /* Adjust padding for smaller screens too */
        font-size: 0.8em;
    }

    #winnerSplashScreenModal h2 {
        font-size: 2em;
    }
}

/* --- Responsive Adjustments for Very Small Screens (e.g., small phones) --- */
@media (max-width: 500px) {
    .game-container {
        padding: 10px;
        margin: 10px auto;
    }

    .game-area {
        padding: 8px;
        gap: 8px;
    }

    .current-player-dice-wrapper {
        padding: 5px;
        gap: 5px;
    }

    .sidebar {
        padding: 5px;
    }
}

/* --- Question Modal Specifics --- */
/* Styles for Images inside Questions */
.question-image {
    max-width: 80%; /* Ensures the image doesn't overflow the question modal */
    height: auto;  /* Maintains the image's aspect ratio */
    display: block; /* Makes the image take up its own line, separating it from text */
    margin: 15px auto; /* Adds 15px space above and below, and centers the image horizontally */
    border-radius: 8px; /* Optional: Gives the image slightly rounded corners */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Optional: Adds a subtle shadow for a nicer look */
}

/* Optional: If you might have smaller images that you want to stand out less */
/* .question-image.small {
    max-width: 50%;
} */

.options-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    text-align: left;
}

.option-label {
    display: flex;
    align-items: center;
    padding: 12px;
    background-color: #f0f4c3;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.option-label:hover {
    background-color: #e6ee9c;
}

.option-label input[type="radio"] {
    margin-right: 10px;
    transform: scale(1.2);
}

.option-text {
    flex-grow: 1;
}

.remark {
    font-weight: bold;
    margin-top: 15px;
    padding: 10px;
    border-radius: 8px;
}

.remark.correct {
    background-color: #e8f5e9;
    color: #2E7D32;
}

.remark.incorrect {
    background-color: #ffebee;
    color: #C62828;
}

/* --- Ranking Table Styling (Overall Ranking) --- */
.ranking-table-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 20px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 0.95em;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.ranking-table th,
.ranking-table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
    box-sizing: border-box;
}

/* Center table headers in the overall ranking table */
.ranking-table th {
    background-color: #4CAF50;
    color: white;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.ranking-table tbody tr:nth-child(even) {
    background-color: #f2f2f2;
}

.ranking-table tbody tr:hover {
    background-color: #e6ffe6;
    cursor: default;
}

/* Center text in Position column for overall ranking table */
.ranking-table th:first-child,
.ranking-table td:first-child {
    text-align: center;
}

/* Right-align numeric columns for better readability in overall ranking table.
    Removed 'th' from this selector to allow all 'th' to be centered. */
.ranking-table td:nth-child(3), /* Correct */
.ranking-table td:nth-child(4), /* Wrong */
.ranking-table td:nth-child(5) { /* Accuracy */
    text-align: right;
}

.ranking-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

/* Adjust general modal content padding if needed to fit table */
.modal-content {
    padding: 20px 30px;
}

/* --- Corner Logos --- */
.corner-logo {
    position: fixed;
    height: 50px;
    width: auto;
    z-index: 1000;
    padding: 5px;
}

.top-left-logo {
    top: 0;
    left: 0;
}

.top-right-logo {
    top: 0;
    right: 0;
}

@media (max-width: 768px) {
    .corner-logo {
        height: 35px;
        padding: 5px;
    }
}

@media (max-width: 480px) {
    .corner-logo {
        height: 25px;
        padding: 3px;
    }
}

/* Responsive styling for the splash screen logo stripe */
.logo-stripe {
    width: 100%;
    max-width: 600px;
    height: auto;
    display: block;
    margin: 20px auto 0;
}

@media (max-width: 600px) {
    .logo-stripe {
        max-width: 90%;
    }
}