/* --- ÁREA DE JUEGO (Game Board) --- */
#game-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    /* Distribute card and keyboard vertically */
    align-items: center;
    position: relative;
    padding: 10vh 2vw 2vh 2vw;
    gap: 3vh;
    /* Ensure top bar space */
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

#game-card {
    text-align: center;
    background: var(--card-bg);
    padding: 2vh 3vw;
    /* Give more space to text */
    border-radius: 4vh;
    /* Proportional rounding */
    box-shadow: 0 2vh 5vh rgba(0, 0, 0, 0.1);
    width: 80vw;
    /* Strict proportional width */
    max-width: 1200px;
    /* Optional safety limit for huge screens */
    height: 40vh;
    /* Strict, prevents pushing keyboard down */
    display: block;
    /* Changed from flex to block to allow safe overflow scrolling */
    text-align: center;
    transition: transform 0.3s, background-color 0.3s;
    color: var(--text-main);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#game-card::-webkit-scrollbar {
    width: 6px;
}

#game-card::-webkit-scrollbar-track {
    background: transparent;
}

#game-card::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

html.dark-mode #game-card::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

/* Floating Controls */
#sound-toggle,
#theme-toggle,
#keyboard-toggle,
#case-toggle {
    position: absolute;
    top: 20px;
    z-index: 20;
    background: var(--button-bg);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
    color: var(--text-main);
}

#sound-toggle {
    right: 20px;
}

#theme-toggle {
    right: 75px;
}

#keyboard-toggle {
    right: 130px;
}

#case-toggle {
    right: 185px;
    /* Moved further left just in case */
    font-weight: bold;
    font-size: 0.9rem;
}

#sound-toggle:hover,
#theme-toggle:hover,
#keyboard-toggle:hover,
#case-toggle:hover {
    transform: scale(1.1);
}

#case-toggle.inactive {
    opacity: 0.5;
    background: #ccc;
    color: #666;
}

html.dark-mode #case-toggle.inactive {
    background: #334155;
    color: #64748b;
}

#sound-toggle.muted {
    opacity: 0.6;
    background: #eee;
}

/* Stats Indicators */
.stats-top {
    position: absolute;
    top: 25px;
    right: 35px;
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--secondary);
    background: rgba(0, 0, 0, 0.05);
    padding: 6px 16px;
    border-radius: 30px;
    transition: all 0.3s;
    /* MOVED TO TOP BAR in HTML */
}

html.dark-mode .stats-top {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary);
}

.stats-top-center-fixed {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    font-size: min(2vw, 2.5vh);
    /* Scales smoothly and won't overflow */
    font-weight: bold;
    color: #e67e22;
    background: var(--button-bg);
    padding: 0.8vh 1.5vw;
    border-radius: 50px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: none;
    align-items: center;
    transition: all 0.2s;
    width: max-content;
    max-width: 95vw;
}

html.dark-mode .stats-top-center-fixed {
    color: #ff9f43;
}

.stats-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9rem;
    color: #888;
    background: rgba(0, 0, 0, 0.02);
    padding: 4px 14px;
    border-radius: 20px;
    /* MOVED TO TOP BAR in HTML */
}

#letter-display {
    font-size: min(15vw, 20vh);
    color: var(--text-main);
    margin: 0;
    padding: 2vh 0 20vh 0;
    /* Virtual bottom space allows last lines to center smoothly */
    user-select: none;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100%;
    /* Will be as tall as game-card or taller */
    justify-content: center;
    align-items: center;
    align-content: center;
    gap: 1vh;
}

.game-line {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    justify-content: center;
    align-items: center;
    gap: 1vw;
}

.word-chunk {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
}

#letter-display.word-mode {
    font-size: min(6vw, 10vh);
    /* Smaller scaling boundary */
    line-height: 1.2;
    padding: 0;
}

#letter-display.word-mode:has(.space) {
    font-size: min(5vw, 8vh);
}

#letter-display.paragraph-mode {
    font-size: min(2.5vw, 4vh);
    /* Smaller to fit large texts inside 40vh box */
    text-align: left;
    padding: 2vh;
    gap: 0.8vh; /* Vertical gap between lines */
}

#letter-display.paragraph-mode .game-line {
    justify-content: flex-start !important;
    gap: 0 !important; /* Remove horizontal gap between chunks in code/paragraph mode */
}

/* Font Overrides (Some custom fonts are drawn smaller by default) */
#letter-display.font-caveat {
    font-size: min(18vw, 24vh);
}

#letter-display.word-mode.font-caveat {
    font-size: min(8vw, 13vh);
}

#letter-display.word-mode.font-caveat:has(.space) {
    font-size: min(6vw, 9vh);
}

#letter-display.paragraph-mode.font-caveat {
    font-size: min(3.5vw, 5vh);
}

#letter-display.font-patrick {
    font-size: min(17vw, 22vh);
}

#letter-display.word-mode.font-patrick {
    font-size: min(7vw, 12vh);
}

#letter-display.word-mode.font-patrick:has(.space) {
    font-size: min(5.5vw, 8.5vh);
}

#letter-display.paragraph-mode.font-patrick {
    font-size: min(3vw, 4.5vh);
}

/* Visual Feedback for Single Letter Mode */
#letter-display.correct {
    color: #27ae60;
    transform: scale(1.1);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#letter-display.incorrect {
    color: #c0392b;
    animation: shake 0.4s;
}

/* Characters */
.char {
    display: inline-block;
    transition: all 0.2s;
    border-bottom: 4px solid transparent;
    min-width: 0.3em;
    font-family: inherit;
    white-space: pre !important;
}

.char.space {
    min-width: 0.5em;
    opacity: 0.25;
    transition: opacity 0.2s, color 0.2s;
}

.char.space.current {
    opacity: 0.8;
}

.char.space.correct {
    color: #27ae60;
    opacity: 0.4;
}

.char.space.incorrect {
    color: #c0392b;
    opacity: 0.85;
}

.char.newline {
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: 2px;
    margin-right: 2px;
}

.flex-break {
    flex-basis: 100%;
    width: 0;
    height: 0;
    overflow: hidden;
}

.char:not(.space):not(.correct):not(.incorrect) {
    color: var(--text-main);
}

.char.current {
    border-bottom-color: var(--primary);
}

.char.correct {
    color: #27ae60;
}

.char.incorrect {
    color: #c0392b;
    animation: shake 0.2s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

#status {
    font-size: 4vh;
    /* Proportional status text */
    font-weight: bold;
    color: var(--text-muted);
    min-height: 5vh;
    margin-top: 2vh;
}

/* Countdown Overlay */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    pointer-events: none;
}

html.dark-mode .countdown-overlay {
    background: rgba(15, 23, 42, 0.6);
}

#countdown-number {
    font-size: 30vw;
    font-weight: 900;
    color: var(--accent-color);
    text-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: scale(0.5);
    font-family: 'Lexend', sans-serif;
}

.animate-countdown {
    animation: countdownPulse 0.9s ease-out forwards;
}

@keyframes countdownPulse {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    50% {
        opacity: 1;
        transform: scale(1.2);
    }

    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

/* Start Button */
.start-pulsing-btn {
    background: #27ae60;
    color: white;
    font-size: 1.8rem;
    font-weight: bold;
    padding: 20px 60px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(39, 174, 96, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    animation: pulse 2s infinite;
}

.start-pulsing-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(39, 174, 96, 0.6);
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.7);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(39, 174, 96, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0);
    }
}

/* Feedback Classes */
.correct {
    color: #27ae60 !important;
}

.incorrect {
    color: #c0392b !important;
}

.bg-correct {
    background-color: #d4efdf !important;
}

.bg-incorrect {
    background-color: #fadbd8 !important;
}

html.dark-mode.bg-correct {
    background-color: #064e3b !important;
}

html.dark-mode.bg-incorrect {
    background-color: #7f1d1d !important;
}

/* Report Button */
.report-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: 2px solid var(--border-color);
}

.report-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
    background: var(--text-color);
}

html.dark-mode .report-btn {
    background: #2c3e50;
    border-color: #34495e;
}

html.dark-mode .report-btn:hover {
    background: #34495e;
}

/* --- COLOREADO DE SINTAXIS (Syntax Highlighting) --- */
:root {
    --syntax-keyword: #007acc;
    --syntax-string: #098658;
    --syntax-number: #098658;
    --syntax-comment: #008000;
}

:root.dark-mode, :root.theme-neon, :root.theme-sunset, :root.theme-matrix, :root.theme-forest, :root.theme-lavender, :root.theme-ocean {
    --syntax-keyword: #4fc1ff;
    --syntax-string: #ce9178;
    --syntax-number: #b5cea8;
    --syntax-comment: #6a9955;
}

.char.syntax-keyword:not(.space):not(.correct):not(.incorrect) {
    color: var(--syntax-keyword) !important;
}

.char.syntax-string:not(.space):not(.correct):not(.incorrect) {
    color: var(--syntax-string) !important;
}

.char.syntax-number:not(.space):not(.correct):not(.incorrect) {
    color: var(--syntax-number) !important;
}

.char.syntax-comment:not(.space):not(.correct):not(.incorrect) {
    color: var(--syntax-comment) !important;
}