* {
    box-sizing: border-box;
}

/* Contenedor Principal */
#app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    /* Fixed height for game */
    position: relative;
    overflow: hidden;
}

/* --- BARRA LATERAL (SIDEBAR) --- */
#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    padding: 20px 45px 20px 20px;
    box-sizing: border-box;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    z-index: 10;
    color: var(--text-main);
    margin-left: 0;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
}

#sidebar.closed>* {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s;
}

#sidebar::-webkit-scrollbar {
    width: 8px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

body.dark-mode #sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

#sidebar.closed {
    margin-left: calc(var(--sidebar-width) * -1);
}

h3 {
    margin: 0 0 10px 0;
    color: var(--secondary);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 5px;
}

.control-group {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    margin: 0;
    /* Force zero margin */
}

h4 {
    margin: 10px 0 5px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.submenu .control-group {
    gap: 8px;
    /* Restore gap for inner lists */
    margin-bottom: 15px;
    /* Keep consistent bottom margin */
}

.submenu .control-group:last-child {
    margin-bottom: 0;
}

/* --- MENÚ DESPLEGABLE (ACCORDION) --- */
.menu-toggle {
    background: none;
    border: none;


    width: 100%;
    margin: 0;
    /* Override main.css default button margin */
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 8px 10px;
    /* Added padding for better hover area */
    border-radius: 8px;
    /* Rounded corners */
    transition: all 0.2s ease;
}

.menu-toggle:hover {
    background-color: rgba(0, 0, 0, 0.08);
    /* Darker for visibility in light mode */
    transform: translateX(5px);
    /* Subtle movement */
}

body.dark-mode .menu-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* 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;
}

.menu-toggle:hover h3 {
    color: var(--primary);
}

.menu-toggle h3 {
    border-bottom: none;
    margin-bottom: 0;
}

.submenu {
    max-height: 1500px;
    overflow: visible;
    /* Allow tooltips to show */
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out, margin-top 0.4s ease, overflow 0s 0.4s;
    /* Delay visible overflow */
    opacity: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 10px;
    padding-left: 15px;
    border-left: 2px solid var(--border-color);
}

.submenu .submenu {
    border-left: 1px dashed var(--border-color);
    margin-top: 5px;
    gap: 8px;
}

.submenu .menu-toggle h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.submenu.collapsed {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    pointer-events: none;
    display: none !important;
    transition: max-height 0.3s cubic-bezier(0, 1, 0, 1), opacity 0.3s, margin-top 0.3s, overflow 0s 0s;
    /* Immediate hide */
}

#sidebar.closed .submenu {
    visibility: hidden;
    transition: none;
}

.arrow-icon {
    transition: transform 0.3s;
    color: #888;
}

.menu-toggle.active .arrow-icon {
    transform: rotate(180deg);
}

/* --- BOTÓN TOGGLE (Side) --- */
#sidebar-toggle {
    position: absolute;
    left: calc(var(--sidebar-width));
    transform: translateY(-50%);
    top: 50%;
    z-index: 900;
    background: var(--accent-color);
    border: 2px solid var(--border-color);
    border-left: none;
    padding: 15px 5px;
    border-radius: 0 10px 10px 0;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    font-weight: bold;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease, background 0.2s, color 0.2s;
    outline: none;
    width: 30px;
    height: 60px;
}

#sidebar-toggle:hover {
    color: var(--primary);
    background: var(--bg-color);
}

#sidebar-toggle span {
    display: block;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.closed+#sidebar-toggle {
    left: 0;
}

#sidebar.closed+#sidebar-toggle span {
    transform: rotate(180deg);
}

/* --- BOTONES FLOTANTES --- */
#sound-toggle,
#theme-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;
}

#case-toggle {
    right: 130px;
    font-weight: bold;
    font-size: 0.9rem;
}

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

/* --- TOOLTIPS --- */


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

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

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

/* --- ÁREA DE JUEGO --- */
#game-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
}

#game-card {
    text-align: center;
    background: var(--card-bg);
    padding: 60px;
    border-radius: 40px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.1);
    min-width: 400px;
    max-width: 90%;
    transition: transform 0.3s, background-color 0.3s;
    color: var(--text-main);
    position: relative;
    overflow: hidden;
}

.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;
}

.stats-top-center-fixed {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    font-size: 1.5rem;
    font-weight: bold;
    color: #e67e22;
    background: var(--button-bg);
    padding: 10px 20px;
    border-radius: 50px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

body.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;
}

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

#letter-display {
    font-size: 14rem;
    line-height: 1;
    color: var(--text-main);
    margin: 15px 0;
    user-select: none;
    min-height: 220px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

#letter-display.word-mode {
    font-size: 6rem;
    min-height: 100px;
    line-height: 1.2;
    padding: 0 20px;
}

#letter-display.word-mode:has(.space) {
    font-size: 3.5rem;
}

#letter-display.paragraph-mode {
    font-size: 2.2rem;
    text-align: left;
    justify-content: flex-start;
    padding: 20px 40px;
    gap: 2px 8px;
}

.char {
    display: inline-block;
    transition: all 0.2s;
    border-bottom: 4px solid transparent;
    min-width: 0.3em;
    font-family: inherit;
}

.char.space {
    min-width: 0.5em;
}

.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: 1.5rem;
    font-weight: bold;
    color: var(--text-muted);
    min-height: 1.5rem;
    margin-top: 45px;
}

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

.incorrect {
    color: #c0392b !important;
}

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

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

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

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

/* Fuentes */
.font-sans {
    font-family: 'Segoe UI', sans-serif;
}

.font-serif {
    font-family: 'Times New Roman', serif;
}

.font-mono {
    font-family: 'Courier New', monospace;
}

.font-comic {
    font-family: 'Comic Sans MS', 'Chalkboard SE', sans-serif;
}

.font-impact {
    font-family: 'Impact', sans-serif;
    letter-spacing: 2px;
}

.font-lexend {
    font-family: 'Lexend', sans-serif;
}

.font-atkinson {
    font-family: 'Atkinson Hyperlegible', sans-serif;
}

.font-roboto-mono {
    font-family: 'Roboto Mono', monospace;
}

.font-patrick {
    font-family: 'Patrick Hand', cursive;
}

.font-caveat {
    font-family: 'Caveat', cursive;
}

/* Responsive Mobile */
@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 80%;
        max-width: 300px;
    }

    #sidebar.closed {
        transform: translateX(-100%);
        margin-left: 0;
    }

    #sidebar-toggle {
        left: 80%;
        top: 20px;
    }

    #sidebar.closed+#sidebar-toggle {
        left: 0;
        background: rgba(255, 255, 255, 0.8);
        border: 1px solid #ddd;
        border-radius: 0 10px 10px 0;
    }
}

/* Auth Helpers on Index */
#auth-controls-sidebar {
    padding: 20px;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

#profile-section .button-link {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#profile-section .button-link:hover {
    background: var(--primary) !important;
    color: white !important;
    transform: scale(1.02);
}

#auth-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    text-align: center;
}

#auth-btn,
#logout-btn,
.button-link {
    padding: 10px 18px;
    border-radius: 15px;
    border: none;
    background: var(--accent-color);
    color: white;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, background 0.3s;
}

#auth-btn:hover,
#logout-btn:hover,
.button-link:hover {
    transform: scale(1.02);
    filter: brightness(1.1);
}

#user-display {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
    word-break: break-all;
}

/* Custom Text UI */
.add-custom-text {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

#new-custom-text {
    width: 100%;
    height: 80px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
    resize: none;
    background: var(--bg-color);
    color: var(--text-color);
}

#new-custom-type {
    padding: 8px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: var(--bg-color);
    color: var(--text-color);
}

.custom-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

/* Start Screen */
.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 15px rgba(39, 174, 96, 0);
    }

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

/* Session Modal */
/* Session Modal uses global .modal-overlay and .modal-content from main.css */

.session-options {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 30px 0;
}

.session-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--primary);
    background: white;
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.session-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.cancel-btn {
    background: none;
    border: none;
    color: #888;
    text-decoration: underline;
    cursor: pointer;
    font-size: 1rem;
}

.delete-btn {
    background: none;
    border: none;

    color: var(--incorrect-color);
    cursor: pointer;
    font-size: 1.1rem;
}

.word-chunk {
    display: inline-flex;
    white-space: nowrap;
}

/* Welcome Message */
.welcome-container {
    text-align: center;
    color: var(--text-muted);
    margin-top: 50px;
    max-width: 600px;
    padding: 0 20px;
}

.welcome-title {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--primary);
}

.welcome-text {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 30px;
}

.features-grid {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.feature-tag {
    background: white;
    padding: 8px 15px;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    font-weight: bold;
    color: var(--secondary);
    border: 1px solid var(--border-color);
}

body.dark-mode .feature-tag {
    background: var(--card-bg);
}

.cta-text {
    font-weight: bold;
    color: var(--accent-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.8;
    }

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

    100% {
        opacity: 0.8;
    }
}