body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 15px;
    padding: 0 15px;
    background-color: #f4f4f9;
    color: #333;
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
}

h1 {
    margin-bottom: 15px;
    font-size: 2.2em;
    color: #2c3e50;
    text-align: center;
}

/* --- Game Mode Selection --- */
#game-mode-selection {
    margin-bottom: 20px;
    text-align: center;
}
#game-mode-selection h2 {
    margin-bottom: 10px;
    font-size: 1.4em;
    color: #343a40;
}
.mode-button {
    padding: 10px 20px;
    margin: 0 10px;
    font-size: 1em;
    cursor: pointer;
    border: 1px solid #6c757d;
    background-color: #f8f9fa;
    color: #495057;
    border-radius: 5px;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.mode-button:hover {
    background-color: #e9ecef;
}
.mode-button.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}


#toggle-config-button {
    padding: 8px 15px;
    margin-bottom: 15px;
    cursor: pointer;
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 0.9em;
    transition: background-color 0.2s;
}
#toggle-config-button:hover {
    background-color: #5a6268;
}

.player-setup-container {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 780px; /* Can be adjusted if 6 AI options make it too wide */
    overflow: hidden;
    max-height: 1200px; 
    opacity: 1;
    transition: max-height 0.4s ease-in-out, opacity 0.3s 0.1s ease-in-out, margin-bottom 0.4s ease-in-out, padding 0.4s ease-in-out;
    padding-top: 10px;
    padding-bottom: 10px;
}
.player-setup-container.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* Collapsing Game Mode Selection */
#game-mode-selection {
    overflow: hidden; 
    max-height: 200px; 
    opacity: 1;
    transition: max-height 0.4s ease-in-out, opacity 0.3s ease-in-out, margin-bottom 0.4s ease-in-out, padding 0.4s ease-in-out;
    padding-top: 10px; 
    padding-bottom: 10px; 
    margin-bottom: 20px; 
}
#game-mode-selection.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0; 
    padding-top: 0;  
    padding-bottom: 0;
}


.player-setup {
    border: 1px solid #dee2e6;
    padding: 20px;
    width: 350px; /* This width might need to be adjusted if AI options container gets too wide */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}
.player-setup h2 {
    margin-top: 0;
    margin-bottom: 10px;
    text-align: center;
    color: #495057;
    font-size: 1.3em;
}
.player-name-input {
    width: calc(100% - 16px); /* Account for padding if any directly on input */
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1em;
}
.player-setup .image-controls,
.player-setup .sound-controls {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background-color: #f8f9fa;
}
.player-setup label {
    font-weight: bold;
    color: #495057;
    margin-bottom: 5px;
}

.image-controls .image-input-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    width: 100%;
    box-sizing: border-box;
}
.image-input-options .image-input {
    flex-grow: 1;
    flex-shrink: 1;
    min-width: 0;
}
.image-input-options span {
    font-style: italic;
    color: #6c757d;
    flex-shrink: 0;
    margin: 0 4px;
}
.image-input-options .take-photo-btn {
    padding: 6px 10px;
    font-size: 0.9em;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background-color: #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.image-input-options .take-photo-btn:hover {
    background-color: #dee2e6;
}

.record-button, .stop-record-button {
    padding: 8px 12px;
    font-size: 0.9em;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background-color: #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}
.record-button:hover, .stop-record-button:hover {
    background-color: #dee2e6;
}
.stop-record-button {
    background-color: #f8d7da;
    border-color: #f5c6cb;
}
.stop-record-button:hover {
    background-color: #f1b0b7;
}

.preview-img {
    max-width: 80px;
    max-height: 80px;
    border: 1px solid #dee2e6;
    object-fit: cover;
    align-self: center;
    margin-top: 5px;
    display: block;
    background-color: #e9ecef;
    border-radius: 4px;
}
.preview-img[src=""], .preview-img:not([src]), .preview-img[src="#"] {
    display: none;
}
.record-status {
    font-style: italic;
    font-size: 0.9em;
    color: #6c757d;
    margin-top: 5px;
    text-align: center;
    min-height: 1.2em;
}
.playback-audio {
    margin-top: 8px;
    width: 100%;
    height: 40px;
}
.playback-audio:not([src]) {
    display: none;
}

/* AI Opponent Selection Specifics */
#ai-opponent-selection-area {
    align-items: center;
}
.ai-options-container {
    display: flex;
    justify-content: space-around; /* This will spread them out, might go to 3 per row if parent is wide enough */
    gap: 10px; /* Reduced gap slightly */
    width: 100%;
    flex-wrap: wrap; /* Essential for multiple rows */
}
.ai-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px; /* Reduced padding slightly */
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
    background-color: #f8f9fa;
    min-width: 90px; /* Reduced min-width slightly */
    flex-basis: calc(33.333% - 10px); /* Aim for 3 per row, adjust gap in calc if gap changes */
    box-sizing: border-box;
    text-align: center;
}
.ai-option:hover {
    border-color: #007bff;
    transform: translateY(-3px);
}
.ai-option.selected {
    border-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
}
.ai-image-preview {
    width: 50px; /* Reduced size slightly */
    height: 50px;
    object-fit: cover;
    border-radius: 50%;
    margin-bottom: 6px;
    border: 1px solid #dee2e6;
    background-color: #e9ecef;
}
.ai-option span {
    font-weight: bold;
    font-size: 0.9em; /* Slightly smaller AI name text */
}
/* Text like (Easy), (Medium), (Hard) */
.ai-option span + br + *:not(img), .ai-option > *:not(img):not(span) {
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 2px;
}


/* Modal Styles */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.6); justify-content: center; align-items: center; padding: 15px; box-sizing: border-box; }
.modal-content { background-color: #fefefe; margin: auto; padding: 25px; border: 1px solid #888; width: 90%; max-width: 500px; border-radius: 8px; position: relative; text-align: center; box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.close-camera-btn { color: #aaa; position: absolute; top: 10px; right: 15px; font-size: 32px; font-weight: bold; line-height: 1; cursor: pointer; }
.close-camera-btn:hover, .close-camera-btn:focus { color: black; text-decoration: none; }
#camera-video-stream { width: 100%; max-height: 300px; border: 1px solid #ccc; margin-bottom: 15px; background-color: #333; border-radius: 4px; display: block; }
#capture-image-btn { padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; transition: background-color 0.2s; }
#capture-image-btn:disabled { background-color: #ccc; cursor: not-allowed; }
#capture-image-btn:hover:not(:disabled) { background-color: #218838; }
.camera-error-msg { margin-top: 10px; font-size: 0.9em; color: #dc3545; }

/* Main Game Layout */
#main-game-layout { display: flex; flex-direction: row; justify-content: center; align-items: flex-start; gap: 25px; width: 100%; max-width: 850px; margin-top: 20px; padding: 0 10px; box-sizing: border-box; }
#game-area { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
#status-message { margin-bottom: 15px; font-size: 1.3em; font-weight: bold; color: #2c3e50; text-align: center; min-height: 1.5em; transition: font-size 0.3s ease-in-out; width: 100%; max-width: 330px; }
#game-board { display: grid; grid-template-columns: repeat(3, 100px); grid-template-rows: repeat(3, 100px); gap: 5px; border: 3px solid #555; background-color: #e9ecef; padding: 5px; border-radius: 8px; margin-bottom: 20px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); transition: all 0.3s ease-in-out; }
.cell { width: 100%; height: 100%; background-color: #fff; border: 1px solid #ced4da; display: flex; justify-content: center; align-items: center; cursor: pointer; overflow: hidden; border-radius: 4px; transition: background-color 0.2s; }
.cell:hover { background-color: #f0f0f0; }
.cell img { max-width: 90%; max-height: 90%; object-fit: contain; border-radius: 4px; }
#reset-button { padding: 12px 28px; font-size: 1em; font-weight: bold; cursor: pointer; background-color: #007bff; color: white; border: none; border-radius: 5px; transition: background-color 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
#reset-button:hover { background-color: #0056b3; }
#scoreboard-area { width: 200px; padding: 15px; background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); align-self: flex-start; flex-shrink: 0; }
#scoreboard-area h3 { text-align: center; margin-top: 0; margin-bottom: 15px; color: #343a40; }
#scoreboard-area div { margin-bottom: 8px; font-size: 1.05em; word-break: break-word; }
#scoreboard-area span[id^="score-player"] { font-weight: bold; }
#scoreboard-area span[id$="-value"] { color: #007bff; margin-left: 5px; }

/* Win Message Animation Styles */
#win-message-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); display: none; justify-content: center; align-items: center; z-index: 2000; opacity: 0; pointer-events: none; transition: opacity 0.5s ease-in-out; }
#win-message-overlay.visible { opacity: 1; pointer-events: auto; }
#win-text { font-size: clamp(30px, 8vw, 100px); font-weight: bold; text-align: center; color: transparent; background: linear-gradient(45deg, #ff00ff, #00ff00, #ffff00, #00ffff, #ff0000, #ff00ff); background-size: 400% 400%; -webkit-background-clip: text; background-clip: text; text-shadow: 0 0 5px rgba(255,255,255,0.7), 0 0 10px rgba(255,0,255,0.5), 0 0 15px rgba(0,255,255,0.5), 0 0 20px rgba(255,255,0,0.5); opacity: 0; }
@keyframes fireworks-text-animation { 0% { opacity: 0; transform: scale(0.3) translateY(60px) rotateZ(-45deg); letter-spacing: -0.1em; } 20% { opacity: 1; transform: scale(1.1) translateY(0px) rotateZ(5deg); letter-spacing: 0.05em; background-position: 0% 50%; text-shadow: 0 0 8px rgba(255,255,255,0.8), 0 0 15px rgba(255,0,255,0.7), 0 0 25px rgba(0,255,255,0.7), 0 0 35px rgba(255,255,0,0.7); } 25% { transform: scale(1) rotateZ(-2deg); letter-spacing: 0em; } 35% { transform: scale(1.03) rotateZ(2deg) skewX(-3deg); background-position: 50% 100%; text-shadow: 0 0 6px rgba(255,255,255,0.7), 0 0 12px rgba(0,255,0,0.6), 0 0 20px rgba(255,0,0,0.6), 0 0 30px rgba(0,0,255,0.6); } 50% { transform: scale(0.97) rotateZ(-2deg) skewX(3deg); background-position: 100% 50%; } 65% { transform: scale(1.02) rotateZ(1deg) skewX(-2deg); background-position: 50% 0%; text-shadow: 0 0 8px rgba(255,255,255,0.8), 0 0 15px rgba(255,165,0,0.7), 0 0 25px rgba(128,0,128,0.7), 0 0 35px rgba(0,255,0,0.7); } 80% { opacity: 1; transform: scale(1) rotateZ(0deg) skewX(0deg); background-position: 0% 50%; letter-spacing: 0em; } 100% { opacity: 0; transform: scale(0.7) translateY(-60px) rotateZ(45deg); letter-spacing: 0.1em; } }

/* Collapsed Config State */
body.config-collapsed #game-board { grid-template-columns: repeat(3, min(25vw, 130px)); grid-template-rows: repeat(3, min(25vw, 130px)); gap: 7px; }
body.config-collapsed #status-message { font-size: 1.4em; max-width: calc(3 * min(25vw, 130px) + 2 * 7px + 6px); }
body.config-collapsed #main-game-layout { margin-top: max(3vh, 15px); }

/* Responsive Adjustments */
@media (max-width: 768px) { #main-game-layout { flex-direction: column; align-items: center; gap: 20px; } #scoreboard-area { width: 90%; max-width: 350px; align-self: center; } .player-setup { width: 90%; max-width: 400px; } h1 { font-size: 1.8em; } body.config-collapsed #game-board { grid-template-columns: repeat(3, min(28vw, 110px)); grid-template-rows: repeat(3, min(28vw, 110px)); } body.config-collapsed #status-message { max-width: calc(3 * min(28vw, 110px) + 2 * 7px + 6px); } }
@media (max-width: 480px) { #game-board { grid-template-columns: repeat(3, 75px); grid-template-rows: repeat(3, 75px); } #status-message { max-width: calc(3 * 75px + 2 * 5px + 6px); } body.config-collapsed #game-board { grid-template-columns: repeat(3, min(28vw, 90px)); grid-template-rows: repeat(3, min(28vw, 90px)); } body.config-collapsed #status-message { max-width: calc(3 * min(28vw, 90px) + 2 * 7px + 6px); } .player-setup h2 { font-size: 1.2em; } #reset-button { padding: 10px 20px; } #main-game-layout { max-width: 100%; } }