:root {
    --primary-color: #4ECDC4;
    --secondary-color: #FF6B6B;
    --accent-color: #FFE66D;
    --bg-color: #E0F7FA;
    --text-color: #2C3E50;
    --font-main: 'Comic Neue', cursive, sans-serif;
}

html {
    font-size: 14px; /* Compact default for better fit */
}

/* Responsive Font Scaling */
@media (max-width: 1400px) {
    html {
        font-size: 13px;
    }
}

@media (max-width: 1000px) {
    html {
        font-size: 12px;
    }
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    background-color: var(--bg-color);
    background-image: radial-gradient(#B2EBF2 20%, transparent 20%),
                      radial-gradient(#B2EBF2 20%, transparent 20%);
    background-size: 50px 50px;
    background-position: 0 0, 25px 25px;
    color: var(--text-color);
    height: 100vh; /* Fixed height to prevent scrolling */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Hide overflow */
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    padding: 0.5rem; /* Reduced padding */
    box-sizing: border-box;
}

/* Header */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    padding: 0.4rem 1rem; /* Compact padding */
    border-radius: 0.8rem;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
    margin-bottom: 0.5rem; /* Reduced margin */
    border: 2px solid #fff;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex-shrink: 0; /* Prevent shrinking */
}

.top-bar h1 {
    margin: 0;
    color: var(--secondary-color);
    font-size: 1.6rem; /* Reduced size */
    text-shadow: 2px 2px 0 #ffe66d;
}

.controls {
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    font-weight: bold;
    font-size: 0.9rem;
    color: #555;
}

select {
    padding: 0.5rem;
    border-radius: 0.5rem;
    border: 2px solid var(--primary-color);
    font-family: inherit;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    outline: none;
}

select:hover {
    background-color: #f0fdfc;
}

#new-game-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
    border-radius: 2rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: transform 0.1s;
    box-shadow: 0 4px 0 #c0392b;
    margin-bottom: 2px;
}

#new-game-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Main Content */
.game-content {
    flex: 1;
    display: flex;
    gap: 1rem;
    min-height: 0;
    /* Responsive layout handled by media queries below */
}

/* Panels */
.left-panel, .right-panel {
    background-color: white;
    padding: 0.5rem;
    border-radius: 1rem;
    box-shadow: 0 6px 0 rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 2px solid #fff;
    overflow-y: auto;
}

.left-panel {
    flex: 0 0 9rem; /* Flexible width based on rem */
    min-width: 100px;
}

.right-panel {
    flex: 0 0 15rem; /* Reduced width for 3 columns */
    min-width: 180px;
}

/* Center Panel Updates */
.center-panel {
    flex: 1;
    background-color: white;
    border-radius: 1rem;
    box-shadow: 0 6px 0 rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    justify-content: center; /* Center vertically */
    align-items: center;
    position: relative;
    border: 2px solid #fff;
    padding: 0.5rem;
    min-width: 0; /* Prevent flex overflow */
}

h2 {
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
    text-align: center;
}

/* Letter Grids */
.vowels-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.consonants-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Fixed 3 columns on desktop */
    gap: 0.5rem;
    width: 100%;
}

.letter-btn {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--accent-color);
    border: none;
    border-radius: 0.8rem;
    font-size: 2rem; /* Reduced from 2rem */
    font-weight: bold;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    box-shadow: 0 4px 0 #e1c950;
    font-family: var(--font-main);
    width: 100%; /* Fill grid cell */
}

/* ... existing hover states ... */

.letter-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background-color: #fff0a0;
}

.letter-btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #e1c950;
}

.letter-btn:disabled {
    background-color: #f0f0f0;
    color: #ccc;
    cursor: not-allowed;
    box-shadow: none;
    transform: translateY(4px);
}

.letter-btn.correct {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 0 #3bbcb3;
}

.letter-btn.wrong {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 0 #e74c3c;
}

/* Canvas */
.canvas-wrapper {
    background: #fdfdfd;
    border-radius: 1rem;
    padding: 0.2rem;
    border: 2px dashed #ddd;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
}

canvas {
    width: 100%;
    max-width: 400px; /* Reduced max-width */
    height: auto;
    max-height: 35vh; /* Reduced max-height for better fit */
    object-fit: contain;
}

/* Word Container moved to center */
.word-container {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.synonym-container {
    margin-top: 0.5rem;
    font-size: 1.1rem;
    color: var(--primary-color);
    font-style: italic;
    min-height: 1.5rem;
    text-align: center;
    width: 100%;
}

/* Bottom Control Panel */
.bottom-panel {
    margin-top: 0.8rem;
    padding: 1.2rem;
    background-color: white;
    border-radius: 1rem;
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    border: 2px solid #fff;
    flex-shrink: 0;
}

.action-btn {
    padding: 0.6rem 1.2rem; /* Increased padding */
    font-size: 1.1rem; /* Increased font */
    font-family: inherit;
    font-weight: bold;
    border: none;
    border-radius: 2rem;
    cursor: pointer;
    background-color: #f1f2f6;
    color: var(--text-color);
    box-shadow: 0 4px 0 #dfe4ea;
    transition: all 0.1s;
    white-space: nowrap;
}

/* ... button states ... */

.action-btn:hover:not(:disabled) {
    background-color: #e1e2e6;
    transform: translateY(-2px);
}

.action-btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: none;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: translateY(4px);
}

.hint-btn {
    background-color: var(--accent-color);
    color: var(--text-color);
    box-shadow: 0 4px 0 #e1c950;
}

.hint-btn:hover:not(:disabled) {
    background-color: #fff0a0;
}

.sound-btn.muted {
    background-color: #e0e0e0;
    color: #999;
    box-shadow: 0 4px 0 #ccc;
}

.hint-btn:active:not(:disabled) {
    box-shadow: 0 1px 0 #e1c950;
}

.pronounce-btn {
    background-color: #A0E7E5; /* Light teal/blue distinct from others */
    color: var(--text-color);
    box-shadow: 0 4px 0 #7ACBC8;
    min-width: 100px; /* Reduced min-width */
    text-align: center;
}

.pronounce-btn:hover:not(:disabled) {
    background-color: #B4F2F0;
}

.pronounce-btn:active:not(:disabled) {
    box-shadow: 0 1px 0 #7ACBC8;
}

.vowels-btn {
    background-color: #FFA07A; /* Light Salmon */
    color: var(--text-color);
    box-shadow: 0 4px 0 #E9967A;
}

.vowels-btn:hover:not(:disabled) {
    background-color: #FFB69B;
}

.vowels-btn:active:not(:disabled) {
    box-shadow: 0 1px 0 #E9967A;
}

/* Explain Button */
.explain-btn {
    background-color: #A66EFA; /* Medium Purple */
    color: white;
    box-shadow: 0 4px 0 #8A4ECA;
}

.explain-btn:hover:not(:disabled) {
    background-color: #B98EFF;
}

.explain-btn:active:not(:disabled) {
    box-shadow: 0 1px 0 #8A4ECA;
}

/* Synonym Button */
.synonym-btn {
    background-color: #2ECC71; /* Emerald Green */
    color: white;
    box-shadow: 0 4px 0 #27AE60;
}

.synonym-btn:hover:not(:disabled) {
    background-color: #58D68D;
}

.synonym-btn:active:not(:disabled) {
    box-shadow: 0 1px 0 #27AE60;
}

.letter-slot {
    font-size: 2rem; /* Reduced size */
    width: 2.5rem;
    height: 3.5rem;
    border-bottom: 3px solid var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    border-radius: 0.5rem 0.5rem 0 0;
    background: rgba(0,0,0,0.02);
}

.letter-slot.revealed {
    color: var(--text-color);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.letter-slot.missed {
    color: var(--secondary-color);
    opacity: 0.8;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Message */
#game-message {
    margin: 0.5rem 0;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    min-height: 2rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    width: 100%;
    box-sizing: border-box;
}

.hidden {
    visibility: hidden;
}

.win-msg { 
    color: var(--primary-color);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}
.lose-msg { 
    color: var(--secondary-color); 
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
    visibility: visible;
}

.modal.hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 1.5rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    position: relative;
    width: 90%;
    max-width: 600px;
    z-index: 1001;
    border: 4px solid var(--primary-color);
    max-height: 90vh;
    overflow-y: auto;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 0;
}

.close-btn:hover {
    color: var(--secondary-color);
}

#modal-word {
    text-align: center;
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-top: 0;
    margin-bottom: 1.5rem;
    text-transform: capitalize;
}

.modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.modal-text {
    width: 100%;
    text-align: left;
}

.modal-text h3 {
    color: var(--secondary-color);
    margin-top: 0;
    font-size: 1.4rem;
}

#modal-definition {
    font-size: 1.2rem;
    line-height: 1.6;
    color: #555;
}

/* --- Media Queries for Layout Adjustments --- */

/* Tablet / Smaller Desktop */
@media (max-width: 900px) {
    /* Allow scrolling on smaller screens where layout stacks */
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
        overflow-y: visible;
    }

    .game-content {
        flex-direction: column;
        align-items: center;
    }

    .left-panel, .right-panel, .center-panel {
        width: 100%;
        flex: 0 0 auto;
        order: 2; /* Put panels below game area by default */
    }

    .center-panel {
        order: 1; /* Game area first */
        margin-bottom: 1rem;
    }
    
    .left-panel {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

    .vowels-grid {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    .letter-btn {
        width: 3rem;
        height: 3rem;
        font-size: 1.5rem;
    }
    
    .consonants-grid {
        grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
    }
}

/* Mobile Portrait */
@media (max-width: 600px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .bottom-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .action-btn {
        width: 100%;
    }
    
    .letter-slot {
        width: 2rem;
        height: 3rem;
        font-size: 1.5rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
}
