body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #fff9e6; /* Creamy background */
    
    /* Mobile Viewport Fixes */
    height: 100dvh; 
    width: 100vw;
    display: flex;
    justify-content: center;
    overflow: hidden; /* Prevent body scroll */
}

.game-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    position: relative;
}

/* --- HEADER (Fixed Top) --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f0f8ff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative; /* Anchor for settings panel */
    gap: 8px;
    z-index: 50;
    
    /* Prevent header from shrinking on small screens */
    flex-shrink: 0; 
}

.back-btn {
    text-decoration: none;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Dropdowns */
.pack-selector, .mode-selector {
    background: #fff;
    border: 2px solid #3eb8b0;
    border-radius: 15px;
    padding: 8px 5px;
    font-size: 1rem;
    font-weight: bold;
    color: #444;
    cursor: pointer;
    flex-grow: 1; /* evenly space */
}

/* Settings Button */
.icon-btn {
    background: white;
    border: 2px solid #ccc;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.icon-btn:hover {
    background: #f0f0f0;
}

/* Settings Panel Popup */
.settings-panel {
    position: absolute;
    top: 60px;
    right: 10px;
    background: white;
    border: 3px solid #3eb8b0;
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    z-index: 100;
    min-width: 220px;
    max-width: 280px;
    animation: popIn 0.2s ease-out;
}
.settings-panel.hidden {
    display: none;
}
.settings-panel label {
    font-weight: bold;
    color: #555;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
}

/* Settings Sections */
.settings-section {
    border-top: 2px solid #e0e0e0;
    padding-top: 12px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.settings-section.hidden {
    display: none;
}
.section-header {
    font-weight: bold;
    font-size: 0.8rem;
    color: #3eb8b0;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    display: block !important;
}
.preview-text {
    font-size: 0.75rem;
    color: #888;
    text-align: center;
    font-weight: normal;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal !important;
}
.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3eb8b0;
}
.checkbox-label span {
    font-weight: normal;
}

/* Speed Slider */
input[type=range] {
    width: 100%;
    accent-color: #3eb8b0;
    cursor: pointer;
}

@keyframes popIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Win Message */
.message {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #4ade80;
    font-size: 1.2rem;
    font-weight: bold;
    color: #2e7d32;
    pointer-events: none;
    white-space: nowrap;
    z-index: 40;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.message.hidden {
    opacity: 0;
    transform: translate(-50%, -10px);
    transition: opacity 0.3s, transform 0.3s;
}

/* --- IMAGE AREA (Word Mode Only) --- */
.image-area {
    background-color: #f8f9fa;
    border-bottom: 2px solid #ddd;
    flex-shrink: 0;
    height: 20dvh;
    max-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.image-area.hidden {
    display: none;
}
.image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.word-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.word-image.hidden {
    display: none;
}
.image-fallback {
    font-size: 5rem;
    opacity: 0.6;
    text-align: center;
}

/* --- WORD PROGRESS BAR --- */
.word-progress-bar {
    background-color: #fff;
    border-bottom: 2px solid #ddd;
    padding: 12px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
}
.word-progress-bar.hidden {
    display: none;
}

.letter-bubble {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 42px;
    padding: 0 6px;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: bold;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

/* Letter bubble states */
.letter-bubble.completed {
    background-color: #d4edda;
    border: 2px solid #28a745;
    color: #155724;
}
.letter-bubble.active {
    background-color: #cfe2ff;
    border: 3px solid #0d6efd;
    color: #084298;
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}
.letter-bubble.pending {
    background-color: #f8f9fa;
    border: 2px solid #dee2e6;
    color: #6c757d;
}

/* Status indicators */
.letter-bubble .status-icon {
    font-size: 1rem;
    margin-left: 2px;
}

/* --- CANVAS AREA (Flexible Middle) --- */
.canvas-wrapper {
    position: relative;
    background-color: #fff;
    touch-action: none; /* Prevents scrolling while drawing */
    
    /* FLEX TRICK: Forces canvas to fit available space without pushing boundaries */
    flex-grow: 1;
    height: 0; 
    min-height: 0;
    
    display: flex;
    align-items: center;
    justify-content: center;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    object-fit: contain; /* Ensures geometry doesn't stretch */
}

.hint-icon {
    position: absolute;
    font-size: 2rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

/* --- LETTER GRID (Fixed Bottom) --- */
.letter-grid {
    padding: 10px;
    background-color: #f8f9fa;
    border-top: 1px solid #ddd;
    
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    
    /* Constrain height for mobile, allow scroll */
    max-height: 30dvh; 
    overflow-y: auto;
    
    /* Prevent grid from shrinking */
    flex-shrink: 0;
}

.letter-btn {
    aspect-ratio: 1;
    border: 2px solid #ddd;
    background: white;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
}

/* Word buttons (for word mode) */
.letter-btn.word-btn {
    aspect-ratio: auto;
    min-height: 50px;
    padding: 8px 12px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.letter-btn.active {
    background-color: #e3f2fd;
    border-color: #2196f3;
    color: #1565c0;
    transform: scale(1.05);
}

.letter-btn:hover {
    background-color: #f0f0f0;
}