body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #2c3e50, #4a69bd);
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#game-container {
    width: 100%;
    max-width: 420px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    #game-container.scoreboard-active {
        max-width: 900px; /* Allow more space for the two-column layout */
    }
}

/* --- Header: Timer & Score --- */
#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 20px;
}

#timer-container, #score-container {
    display: flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 8px 16px;
    border-radius: 20px;
}

#timer {
    font-size: 1.5em;
    font-weight: 700;
    margin-left: 8px;
}

#score {
    font-size: 1.5em;
    font-weight: 700;
    margin-right: 8px;
}

#score-label {
    font-size: 0.9em;
}

#current-word-container {
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease-out;
    margin-bottom: 20px;
    position: relative;
}

#word-score-feedback {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.2em;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    pointer-events: none;
    animation: fade-up-and-out 1.2s ease-out forwards;
}

@keyframes fade-up-and-out {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px);
    }
}

#current-word {
    font-size: 2em;
    font-weight: 700;
    letter-spacing: 3px;
    color: #ffffff;
}

#game-board-container {
    margin-top: 0;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    position: relative;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1 / 1;
    touch-action: none;
}

.tile {
    color: white;
    background: linear-gradient(0deg, #345088, #192d52);
    box-shadow: 0px -4px 6px #ffffff61;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s ease-out, background-color 0.1s;
    position: relative;
}

.tile.selected {
    background: linear-gradient(0deg, #ec407a, #ec407a);
    box-shadow: none;
    transform: scale(1.1);
}

.tile-letter {
    font-size: 2.2em;
    font-weight: 700;
    line-height: 1;
}

.bonus {
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 0.7em;
    font-weight: 700;
    padding: 2px 4px;
    border-radius: 4px;
    color: white;
    line-height: 1;
}

.bonus.letter-2 { background-color: #66bb6a; }
.bonus.letter-3 { background-color: #9ccc65; }
.bonus.word-2 { background-color: #ffa726; }
.bonus.word-3 { background-color: #ef5350; }

.zoom-in { animation: zoom-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
.zoom-out { animation: zoom-out 0.5s cubic-bezier(0.36, 0, 0.66, -0.56) forwards; }
@keyframes zoom-in { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes zoom-out { from { transform: scale(1); opacity: 1; } to { transform: scale(0.5); opacity: 0; } }

#timer-container.ticking { animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }

.word-score-feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.2em;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    pointer-events: none;
    animation: fade-up-and-out 0.8s ease-out forwards;
}

@keyframes fade-up-and-out {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -150%);
    }
}



#scoreboard-overlay {
    width: 100%;
    max-width: 380px; /* Give it a max-width */
    background-color: rgba(44, 62, 80, 0.95);
    border-radius: 16px;
    padding: 20px;
    box-sizing: border-box;
    transform: translateX(-120%);
    opacity: 0;
}

#scoreboard-overlay.single-player-layout {
    display: flex;
    justify-content: center;
}

.personal-performance-container {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Increased gap */
    width: 100%;
}

.personal-performance-container h2 {
    margin: 0;
    font-size: 1.6em; /* Larger title */
    color: #ffffff;
    border-bottom: 2px solid #64b5f6;
    padding-bottom: 10px;
    text-align: center;
}

.round-stats-box {
    /* No background - will be inside the main container */
    padding: 0;
}

.main-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
}

.main-stats .stat-item {
    text-align: center;
}

.main-stats .stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #ffd700;
}

.main-stats .stat-label {
    font-size: 1.2em;
    font-weight: 600;
}

.secondary-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 1.2em;
}

.secondary-stats .stat-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-stats .stat-label {
    font-weight: 700;
}

.secondary-stats .stat-value {
    font-weight: 700;
    color: #66bb6a;
}

.missed-gems-container {
    /* No background */
    padding: 0;
}

.missed-gems-container h3 {
    margin: 0 0 10px 0;
    font-size: 1.4em;
    color: #ffffff;
    text-align: center;
}

.missed-gems-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.missed-gem {
    font-size: 1em;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    padding: 5px;
}

.missed-gem-score {
    font-size: 1em;
    color: #ffd700;
}

/* --- Found Words (Live Gameplay) --- */
#end-of-round-container {
    top: -200px;
    /* left: 0; */
    /* right: 0; */
    /* bottom: 0; */
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
    box-sizing: border-box;
    width: 100%;
    /* transform: translateY(-40px); */
}


#scoreboard-overlay {
    width: 100%;
    height: calc(100% - 50px);
    background-color: rgba(44, 62, 80, 0.95);
    border-radius: 16px;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transform: translateX(-120%);
    opacity: 0;
}

.fly-in-left { animation: fly-in-left 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards; }
@keyframes fly-in-left { from { transform: translateX(-120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

#scoreboard-timer-wrapper {
    width: 100%;
    margin-bottom: 25px;
    display: flex;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#scoreboard-timer-container {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: 700;
}

.next-round-text { margin-right: 10px; }

#new-timer-clone {
    display: flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 6px 12px;
    border-radius: 20px;
}

#scoreboard-timer-element {
    font-size: 1.2em;
    font-weight: 700;
    margin-left: 8px;
}

/* --- Professional Podium Styles --- */
#podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    height: 130px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.podium-place {
    width: 33.3%;
    padding: 5px;
    border-radius: 8px 8px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
}
.podium-place.place-1 { height: 100%; background-color: rgba(255, 215, 0, 0.2); order: 2; }
.podium-place.place-2 { height: 85%; background-color: rgba(192, 192, 192, 0.2); order: 1; }
.podium-place.place-3 { height: 70%; background-color: rgba(205, 127, 50, 0.2); order: 3; }

.podium-rank {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1.2em;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.5);
}

.podium-avatar { font-size: 2em; }
.podium-name { font-weight: 700; font-size: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 90%; margin-top: 5px; }
.podium-stats { font-size: 0.8em; color: rgba(255, 255, 255, 0.8); white-space: nowrap; }

/* --- Responsive Scoreboard Layout --- */
.scoreboard-content-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow-y: auto; /* Allow scrolling within the container */
}

/* On wider screens, use a two-column layout */
@media (min-width: 768px) {
    .scoreboard-content-wrapper.multiplayer {
        flex-direction: row;
        gap: 20px;
    }
    .personal-performance-container,
    #opponent-summary-container {
        flex: 1; /* Each takes up half the space */
        max-height: 100%;
        overflow-y: auto;
    }
}

#opponent-summary-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-top: 10px; /* Align title with personal summary */
}

#opponent-summary-container h2 {
    margin: 0;
    font-size: 1.6em;
    color: #ffffff;
    border-bottom: 2px solid #ffb74d; /* Different color for distinction */
    padding-bottom: 10px;
    text-align: center;
}

#podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    height: 150px; /* Increased height for better visuals */
    margin-bottom: 10px;
    padding: 0 10px;
    box-sizing: border-box;
}

.podium-place {
    width: 33.3%;
    padding: 10px 5px;
    border-radius: 8px 8px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    border-top: 2px solid;
}

.podium-place.place-1 { 
    height: 100%; 
    order: 2; 
    border-color: #ffd700;
}
.podium-place.place-2 { 
    height: 85%; 
    order: 1; 
    border-color: #c0c0c0;
}
.podium-place.place-3 { 
    height: 70%; 
    order: 3; 
    border-color: #cd7f32;
}

.podium-rank {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5em;
    font-weight: bold;
    color: #fff;
    background-color: rgba(0,0,0,0.4);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid;
}
.podium-place.place-1 .podium-rank { border-color: #ffd700; }
.podium-place.place-2 .podium-rank { border-color: #c0c0c0; }
.podium-place.place-3 .podium-rank { border-color: #cd7f32; }


.podium-avatar { 
    font-size: 2.5em; 
    font-weight: 700;
}
.podium-name { 
    font-weight: 700; 
    font-size: 1.1em; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    width: 100%; 
    margin-top: 5px; 
}
.podium-stats { 
    font-size: 1em; 
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
}

#other-players-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 10px; /* Add some padding */
}

.player-result-row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.player-rank { 
    font-size: 1.1em; 
    font-weight: bold; 
    margin-right: 15px; 
    color: rgba(255, 255, 255, 0.7);
    min-width: 30px; /* Align numbers */
    text-align: right;
}
.player-name { 
    font-size: 1.1em; 
    font-weight: bold; 
    flex-grow: 1; 
    text-align: left; 
}
.player-stats { 
    font-size: 1.1em; 
    font-weight: bold;
    color: #ffd700;
}


/* Single Player Styles */
#scoreboard-overlay h2 { margin: 5px 0; }
.single-player-summary {
    display: flex;
    justify-content: space-around;
    width: 100%;
    background-color: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}
.single-player-summary .player-stats, .single-player-summary .player-score {
    font-size: 1.3em;
}
.single-player-summary b {
    font-size: 1.5em;
    display: block;
}
.missed-words-list-single { width: 100%; height: 150px; overflow-y: auto; }
.missed-word-item { padding: 5px; font-size: 1.1em; }
.missed-word-score { font-weight: 400; }

/* Two-Column Word List */
#word-comparison-container {
    display: flex;
    justify-content: space-around;
    width: 100%;
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 10px;
    box-sizing: border-box;
}
.word-column { width: 48%; }
.word-column h3 { margin-top: 0; margin-bottom: 10px; font-size: 1.0em; white-space: nowrap; }
.word-item { padding: 4px 0; font-size: 1.1em; text-align: left; font-weight: 700; }
.missed-by-player { color: #999; text-decoration: line-through; opacity: 0.7; }

/* --- Found Words (Live Gameplay) --- */
#found-words-display-container { width: 100%; height: 120px; background-color: rgba(0, 0, 0, 0.2); border-radius: 12px; margin-top: 20px; padding: 10px; box-sizing: border-box; overflow-y: auto; transition: opacity 0.3s ease-out; }
#live-found-words { text-align: left; }
.found-word { display: inline-block; background-color: #5c6bc0; color: white; padding: 4px 10px; border-radius: 15px; margin: 4px; font-size: 1em; font-weight: 700; }
.hidden { display: none; }

/* --- Global Word Feed --- */
#global-feed-container { position: fixed; bottom: 10px; right: 10px; width: 250px; height: 300px; background-color: rgba(0, 0, 0, 0.4); border-radius: 10px; color: #fff; display: none; flex-direction: column; overflow: hidden; z-index: 100; }
#global-feed-header { background-color: rgba(0, 0, 0, 0.3); padding: 8px; text-align: center; font-weight: bold; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
#global-feed-content { flex-grow: 1; padding: 8px; display: flex; flex-direction: column; }
.global-feed-item { padding: 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); opacity: 0; transform: translateY(20px); transition: opacity 0.5s ease-out, transform 0.5s ease-out; }
.global-feed-item.visible { opacity: 1; transform: translateY(0); }
.feed-username { font-weight: bold; color: #64b5f6; }
.feed-word { font-weight: bold; color: #ffd700; }
#start-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 25px;
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(0deg, #7196bb, #cbd9ff);
    color: #000000;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 7px 7px 18px rgba(0, 0, 0, 0.8), 2px 2px 2px rgba(255, 255, 255, 0.7) inset, -2px -2px 2px rgba(255, 255, 255, 0.3) inset;
    transition: background-color 0.3s, transform 0.1s;
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    white-space: nowrap;
}
#start-button:hover {
    background-color: #45a049;
}

#start-button:active {
    transform: translate(-50%, -50%) scale(0.95);
}