/* General Body and HTML Styles */
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh; 
    overflow-x: hidden; 
    font-family: -apple-system, BlinkMacMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    color: white;
    -webkit-tap-highlight-color: transparent;
}

/* Setup and Game Over Pages */
.setup-page, .gameover-page {
    display: flex;
    flex-direction: column;
    justify-content: flex-start; 
    align-items: center;
    width: 100%;
    min-height: 100vh; 
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    background: #2c3e50;
    overflow-y: auto; 
}

.setup-page h1, .gameover-page h1 { margin-top: 20px; margin-bottom: 20px; } 
.setup-page p, .gameover-page p { margin-bottom: 15px; }

.setup-page form, .gameover-page form {
    width: 100%;
    max-width: 90vw; 
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.setup-page input[type="text"], .setup-page input[type="number"], .setup-page select {
    padding: 12px 18px;
    margin: 8px 0;
    border-radius: 8px;
    font-size: 1em;
    box-sizing: border-box;
    width: 100%;
    min-width: 400px;
    background-color: #34495e;
    color: white;
    border: 1px solid #567086;
}

.setup-page input[type="text"]::placeholder { color: #bdc3c7; }

.setup-page .player-input-group {
    display: flex;
    margin-bottom: 8px;
    width: 100%;
}

.setup-page .player-input-group input {
    flex-grow: 1;
    margin-right: 5px;
    margin-bottom: 0;
}

.setup-page .remove-player-btn {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 12px 15px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 8px;
    transition: transform 0.2s ease, filter 0.2s ease;
    width: auto; /* Adjusted from 20% */
    min-width: 40px; /* Adjusted */
}

.setup-page .remove-player-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.setup-page button, .gameover-page button, .action-buttons button {
    padding: 15px 20px;
    margin: 10px 0; 
    border-radius: 8px;
    border: none;
    font-size: 1.2em; 
    box-sizing: border-box;
    width: 100%; 
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s ease, filter 0.2s ease, background-color 0.2s ease;
}

.setup-page button:hover, .gameover-page button:hover, .action-buttons button:hover:not(:disabled) {
    transform: scale(1.03);
    filter: brightness(1.1);
}

.setup-page .add-player-btn { background-color: #27ae60; color: white; margin-bottom: 20px; }
.setup-page .start-game-btn, .gameover-page .play-again-btn { background-color: #3498db; color: white; }
.gameover-page .new-game-btn { background-color: #f39c12; color: white; }


/* Advanced Settings Styles */
.advanced-settings-toggle-btn {
    background-color: #8e44ad;
    color: white;
    margin-top: 15px;
    margin-bottom: 10px;
}

.advanced-settings-container {
    background-color: #34495e;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 90vw;
    box-sizing: border-box;
    border: 1px solid #567086;
}

.advanced-settings-container h3 {
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #567086;
    padding-bottom: 10px;
}

.settings-group {
    margin-bottom: 20px;
}

.settings-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    font-size: 0.95em;
    color: #ecf0f1;
}

.settings-group input[type="number"], .settings-group input[type="text"], .settings-group select {
    width: 100%; 
    padding: 10px;
    font-size: 1em;
    margin-bottom: 5px; 
}

.category-setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #4a6074;
}
.category-setting:last-child {
    border-bottom: none;
}

.category-setting .category-name {
    flex-basis: 45%;
    font-size: 0.9em;
    overflow-wrap: break-word;
    padding-right: 5px;
}

.category-setting .category-enable {
    flex-basis: 15%;
    text-align: center;
}
.category-setting .category-enable input[type="checkbox"] {
    transform: scale(1.3);
    margin: 0;
}

.category-setting .category-weight {
    flex-basis: 35%;
}
.category-setting .category-weight input[type="number"] {
    width: 100%;
    padding: 8px;
    font-size: 0.9em;
    margin: 0;
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap; 
    gap: 10px; 
    justify-content: center; 
    margin-bottom: 15px;
}

.preset-btn {
    background-color: #16a085;
    color: white;
    padding: 10px 15px; 
    font-size: 0.9em;
    width: auto; 
    min-width: 120px; 
    flex-grow: 1; 
    max-width: calc(50% - 5px); 
}


/* Game Page */
.game-page {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 100vh; 
    padding: 15px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.game-page::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--game-background, #333);
    z-index: 1;
    transition: background 0.7s ease-in-out;
}

.background-icons-container {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden;
    z-index: 2;
}

.background-icons-container i {
    position: absolute;
    font-size: clamp(10vw, 15vmin, 20vw); /* Responsive font size */
    animation: floatIcon 30s infinite linear alternate;
    color: var(--icon-color, rgba(255, 255, 255, 0.1));
    will-change: transform, opacity;
    opacity: 0;
    user-select: none;
    pointer-events: none;
}

@keyframes floatIcon {
    0% { transform: translate(0, 0) rotate(0deg) scale(0.8); opacity: 0; }
    10% { opacity: var(--icon-opacity, 0.1); }
    25% { transform: translate(-25vw, 20vh) rotate(90deg) scale(1.1); }
    50% { transform: translate(20vw, -25vh) rotate(180deg) scale(0.9); }
    75% { transform: translate(15vw, 15vh) rotate(270deg) scale(1.2); }
    90% { opacity: var(--icon-opacity, 0.1); }
    100% { transform: translate(0, 0) rotate(360deg) scale(0.8); opacity: 0; }
}

/* Game UI Elements Positioning */
.category-display, .round-player-info, .question-container, .action-buttons, .top-right-ui-container {
    position: relative;
    z-index: 5;
}

.category-display, .round-player-info {
    position: absolute;
    top: 10px;
    font-size: clamp(0.7em, 2.5vw, 0.9em);
    background-color: rgba(0,0,0,0.4);
    padding: 5px 10px;
    border-radius: 5px;
    white-space: nowrap;
}

.category-display { left: 10px; }
.round-player-info { right: 10px; text-align: right; }

/* Question Container */
.question-container {
    text-align: center;
    margin-top: 5vh;
    margin-bottom: 2vh;
    padding: 15px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 10px;
    max-width: 90%;
    width: 100%;
    overflow-y: auto;
    max-height: 55vh;
    box-sizing: border-box;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.current-player-name {
    font-size: clamp(1.5em, 5vw, 2em);
    font-weight: bold;
    margin-bottom: 10px;
    color: #f1c40f;
}

.question-text {
    font-size: clamp(2em, 4vw, 2em);
    line-height: 1.4;
    min-height: 80px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.deferred-messages {
    margin-top: 15px;
    font-size: clamp(0.8em, 2.5vw, 1em);
    font-style: italic;
    background-color: rgba(255,255,255,0.1);
    padding: 10px;
    border-radius: 5px;
    border-left: 4px solid #f0ad4e;
    text-align: left;
}

.deferred-messages strong { display: block; margin-bottom: 5px; }

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 90vw; 
    margin: 0 auto 30px auto;
    padding-bottom: 10px; /* Space for home bar on iOS */
}

.action-buttons button {
    padding: 18px; 
    font-size: clamp(1.1em, 4vw, 1.3em); /* Adjusted font size */
    font-weight: 500;
}

.action-buttons button:active:not(:disabled) { transform: scale(0.97); }


/* Specific button colors */
.btn-skip { background-color: #e67e22; color: white; }
.btn-skip:disabled { background-color: #7f8c8d; color: #bdc3c7; cursor: not-allowed; opacity: 0.7; }
.btn-done { background-color: #2ecc71; color: white; }
.btn-quit { background-color: #e74c3c; color: white; }
.btn-go-back { background-color: #9b59b6; color: white; }
.btn-go-back:disabled { background-color: #7f8c8d; color: #bdc3c7; cursor: not-allowed; opacity: 0.7; }

/* Timer and TTS Styles */
.top-right-ui-container {
    position: absolute;
    top: 60px;
    right: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.timer-container {
    position: relative;
    width: clamp(50px, 12vw, 80px);
    height: clamp(50px, 12vw, 80px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: clamp(1.2em, 5vw, 2em);
    color: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.tts-btn {
    width: clamp(40px, 10vw, 60px);
    height: clamp(40px, 10vw, 60px);
    border-radius: 50%;
    border: none;
    background-color: #3498db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1em, 4vw, 1.5em);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0,0,0,0.4);
    transition: transform 0.2s ease, filter 0.2s ease;
}
.tts-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.timer-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.5); 
    border: 3px solid transparent;
    box-sizing: border-box;
    transition: background-color 0.5s ease;
}

.timer-reading .timer-circle {
    background-color: #2ecc71; 
    border-color: #27ae60;
}

.timer-main .timer-circle {
    background-color: #e74c3c; 
    border-color: #c0392b;
}

@media (max-height: 650px) { /* More aggressive scaling for shorter screens */
    .question-container { margin-top: 2vh; max-height: 48vh; }
    .current-player-name { font-size: clamp(1.3em, 4.5vw, 1.8em); margin-bottom: 5px; }
    .question-text { font-size: clamp(1.9em, 3.5vw, 1.9em); min-height: 60px; margin-bottom: 10px;}
    .action-buttons button { padding: 12px; font-size: clamp(1em, 3.8vw, 1.2em); margin: 5px 0; }
    .action-buttons { gap: 5px; }
    .top-right-ui-container { top: 45px; }
    .timer-container { width: clamp(40px, 10vw, 60px); height: clamp(40px, 10vw, 60px); font-size: clamp(1em, 4vw, 1.5em); }
    .tts-btn { width: clamp(35px, 9vw, 50px); height: clamp(35px, 9vw, 50px); font-size: clamp(0.9em, 3.5vw, 1.3em); }
    .category-display, .round-player-info { top: 5px; }
}

@media (max-width: 400px) {
    .preset-btn { max-width: 100%; } 
    .category-setting { flex-direction: column; align-items: flex-start; }
    .category-setting .category-name,
    .category-setting .category-enable,
    .category-setting .category-weight { flex-basis: auto; width: 100%; text-align: left; }
    .category-setting .category-enable { margin: 5px 0; }
    .category-setting .category-enable input[type="checkbox"] { margin-left: 0; }

    .setup-page .remove-player-btn { padding: 10px; }
    .action-buttons button { padding: 14px; } /* Slightly more padding for very narrow screens */

}
