:root {
    /* --- Light Mode Defaults --- */
    --primary: #4f46e5;      
    --primary-dark: #4338ca;
    --secondary: #0ea5e9;    
    --accent: #f59e0b;       
    --accent-dark: #d97706;
    
    /* Theme Colors */
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    
    /* Component Specific */
    --grid-cell-bg: #f8fafc;
    --select-bg: #f9fafb;
    --chip-bg: #e0e7ff;
    --chip-text: #4338ca;
    
    --grid-gap: 4px;
    --cell-size: clamp(28px, 6vw, 45px);
    --font-heading: 'Fredoka', sans-serif;
    --font-body: 'Nunito', sans-serif;
}

/* --- Dark Mode Overrides --- */
body.dark-mode {
    --bg-color: #111827;     
    --card-bg: #1f2937;      
    --text-main: #f9fafb;    
    --text-muted: #9ca3af;   
    --border-color: #374151; 
    
    --grid-cell-bg: #374151;
    --select-bg: #374151;
    --chip-bg: #312e81;      
    --chip-text: #e0e7ff;    
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* --- Layout --- */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
}

/* --- Header --- */
.game-header {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    transition: background-color 0.3s;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--primary);
    white-space: nowrap;
}
h1 span { color: var(--secondary); }

@media (max-width: 420px) {
    h1 .title-highlight { display: none; }
}

/* Score Badge */
.score-badge {
    background: linear-gradient(135deg, #8b5cf6, #d946ef);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 6px -1px rgba(139, 92, 246, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 80px;
    justify-content: center;
}
.score-icon { opacity: 0.9; }
.score-pop { animation: scorePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

/* Header Buttons */
.theme-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.theme-btn:hover { color: var(--primary); background-color: rgba(0,0,0,0.05); }
body.dark-mode .theme-btn:hover { background-color: rgba(255,255,255,0.1); }

.icon-sun { display: none; }
.icon-moon { display: block; }
body.dark-mode .icon-sun { display: block; }
body.dark-mode .icon-moon { display: none; }

.mode-btn {
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.mode-btn:hover { background: var(--chip-text); color: var(--chip-bg); }
.mode-label { font-weight: 400; opacity: 0.8; }
@media (max-width: 500px) { .mode-label { display: none; } }

.blitz-btn {
    border-color: var(--accent);
    color: var(--accent-dark);
    background: transparent;
}
.blitz-btn.active {
    background-color: var(--accent);
    color: white;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
    border-color: var(--accent);
}
.icon-bolt { display: block; }

/* Timer Bar */
.timer-container {
    width: 100%; max-width: 1200px; margin: 0 auto 1rem;
    background: transparent; transition: margin 0.3s ease;
}
.timer-container.hidden { display: none; }

.timer-wrapper {
    display: flex; align-items: center; gap: 12px;
    background: var(--card-bg); padding: 8px 16px;
    border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
}

#timer-text {
    font-weight: 800; font-family: var(--font-heading); color: var(--text-main);
    min-width: 40px; text-align: right; font-size: 0.9rem;
}

.timer-track {
    flex: 1; height: 12px; background: var(--border-color);
    border-radius: 6px; overflow: hidden;
}

.timer-bar {
    height: 100%; background: linear-gradient(90deg, #f59e0b, #ef4444);
    width: 100%; transition: width 1s linear;
}

/* Controls Bar */
.controls-bar {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 10px;
}

.nav-group { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; }

.select-wrapper { flex: 1; }
.select-wrapper select {
    width: 100%; padding: 8px 12px; border-radius: 8px;
    border: 1px solid var(--border-color); background: var(--select-bg);
    font-family: var(--font-body); font-weight: 600; color: var(--text-main);
    cursor: pointer; transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

.nav-btn {
    background: var(--select-bg); border: 1px solid var(--border-color);
    color: var(--text-muted); width: 38px; height: 38px;
    border-radius: 8px; display: flex; align-items: center;
    justify-content: center; cursor: pointer; transition: all 0.2s;
}
#next-topic-btn {
    background-color: var(--primary); color: white; border: none;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}
#next-topic-btn:hover {
    background-color: var(--primary-dark); transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.4);
}
body.dark-mode #next-topic-btn { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); }

/* Main Board */
.game-board { display: flex; flex-direction: column; gap: 1.5rem; flex: 1; }
@media (min-width: 768px) {
    .game-board { flex-direction: row; align-items: start; }
    .grid-section { flex: 2; }
    .info-sidebar { flex: 1; min-width: 300px; }
}

.grid-section { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.grid-wrapper {
    position: relative; padding: 10px; background: var(--card-bg);
    border-radius: 16px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    transition: background-color 0.3s;
}

.game-grid { display: grid; grid-template-columns: repeat(var(--grid-size, 10), 1fr); gap: var(--grid-gap); user-select: none; touch-action: none; }

.grid-cell {
    width: var(--cell-size); height: var(--cell-size); display: flex;
    align-items: center; justify-content: center;
    font-family: var(--font-heading); font-weight: 600; font-size: clamp(14px, 1.5rem, 24px);
    text-transform: uppercase; background: var(--grid-cell-bg);
    border-radius: 6px; cursor: pointer;
    transition: transform 0.1s, background-color 0.3s, color 0.3s;
    color: var(--text-main);
}
.grid-cell.selected { background-color: var(--accent); color: white; transform: scale(1.1); box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); z-index: 2; border-radius: 50%; }
.grid-cell.found { background-color: var(--secondary); color: white; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

/* Loading */
.loading-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.9); display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    z-index: 20; border-radius: 16px; transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}
body.dark-mode .loading-overlay { background: rgba(17, 24, 39, 0.9); }
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
    width: 40px; height: 40px; border: 4px solid var(--chip-bg);
    border-top: 4px solid var(--primary); border-radius: 50%;
    animation: spin 1s linear infinite; margin-bottom: 10px;
}

/* Sidebar */
.word-list-card {
    background: var(--card-bg); padding: 1.5rem;
    border-radius: 16px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    transition: background-color 0.3s;
}
.word-list-card h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--text-muted); }

.word-chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.word-chips li {
    padding: 6px 12px; background: var(--chip-bg); color: var(--chip-text);
    border-radius: 20px; font-size: 0.9rem; font-weight: 700;
    transition: all 0.3s ease; border: 1px solid transparent;
}
.word-chips li.found {
    background-color: #d1fae5; color: #065f46; text-decoration: line-through;
    opacity: 0.6; border-color: #10b981;
}
body.dark-mode .word-chips li.found { background-color: #064e3b; color: #a7f3d0; border-color: #059669; }
.word-chips.hint-active li:not(.found) {
    background-color: #fef3c7; color: #92400e; cursor: pointer;
    border: 2px solid var(--accent); animation: pulse-border 1.5s infinite;
}
body.dark-mode .word-chips.hint-active li:not(.found) { background-color: #451a03; color: #fcd34d; }

/* Buttons */
.btn {
    border: none; padding: 10px 20px; border-radius: 8px;
    font-weight: 700; cursor: pointer; transition: transform 0.1s;
    font-family: var(--font-body); width: 100%;
}
.btn:active { transform: scale(0.95); }
.primary-btn { background: var(--primary); color: white; font-size: 1.1rem; }
.secondary-btn { background: #fee2e2; color: #b91c1c; margin-top: 1rem; }
.secondary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
body.dark-mode .secondary-btn { background: #7f1d1d; color: #fecaca; }
.hint-btn { background: var(--accent); color: white; margin-top: 1rem; }
.hint-btn.active { background: var(--accent-dark); box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }
.test-btn {
    background: #374151; color: white; margin-top: 1rem;
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px;
}
body.dark-mode .test-btn { background: #111827; border: 1px solid #374151; }

.share-game-btn { background-color: #e0e7ff; color: var(--primary); }
body.dark-mode .share-game-btn { background-color: #312e81; color: #e0e7ff; }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center; z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
    background: var(--card-bg); padding: 2.5rem; border-radius: 24px;
    text-align: center; width: 90%; max-width: 400px; animation: slideUp 0.3s ease-out; position: relative;
}
.close-btn {
    position: absolute; top: 15px; right: 20px; background: none; border: none; font-size: 2rem; color: var(--text-muted); cursor: pointer;
}
.modal-actions { display: flex; gap: 10px; margin-top: 1.5rem; width: 100%; }
.modal-actions .btn { margin-top: 0; flex: 1; }
@media (max-width: 400px) { .modal-actions { flex-direction: column; } }
.modal-icon { margin-bottom: 1rem; display: flex; justify-content: center; }
.modal-icon svg {
    width: 5rem; height: 5rem; filter: drop-shadow(0 4px 3px rgba(0,0,0,0.1));
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-score { font-size: 1.25rem; font-weight: 700; color: var(--primary); margin: 1rem 0 2rem; }
.message-area { min-height: 24px; text-align: center; margin-top: 10px; font-weight: 600; font-size: 0.9rem; }

/* Share Buttons */
.share-section { margin-bottom: 1rem; margin-top: 1rem; }
.share-section p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.share-buttons { display: flex; gap: 12px; justify-content: center; }
.share-btn {
    width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: white;
    transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.share-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.15); }
.share-btn:active { transform: scale(0.95); }
.share-btn.fb { background-color: #1877F2; }
.share-btn.x { background-color: #000000; }
body.dark-mode .share-btn.x { background-color: #ffffff; color: black; }
.share-btn.ig { background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888); }

.float-text {
    position: absolute; font-weight: 800; font-size: 1.5rem; color: var(--accent);
    pointer-events: none; animation: floatUp 1s ease-out forwards; z-index: 50; text-shadow: 0 2px 0 #fff;
}

@media (max-width: 768px) {
    .game-board { flex-direction: column; gap: 0.5rem; }
    .info-sidebar { display: contents; } 
    .word-list-card {
        order: -1; width: 100%; padding: 0.5rem; background: var(--card-bg);
        border-radius: 12px; position: sticky; top: 0; z-index: 10;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); margin-bottom: 0;
    }
    .word-list-card h2 { display: none; }
    .word-chips {
        display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 8px;
        padding-bottom: 2px; scrollbar-width: none; -ms-overflow-style: none;
    }
    .word-chips::-webkit-scrollbar { display: none; }
    .word-chips li { flex: 0 0 auto; font-size: 0.8rem; padding: 4px 10px; white-space: nowrap; }
    .grid-wrapper { z-index: 1; }
    .actions { order: 1; display: flex; flex-direction: row; gap: 10px; width: 100%; margin-top: 0.5rem; }
    .actions button { margin-top: 0; font-size: 0.9rem; padding: 12px; }
}

@keyframes scorePop { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes popIn { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes slideUp { 0% { transform: translateY(50px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-border { 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); } 70% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); } 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); } }
@keyframes floatUp { 0% { transform: translateY(0) scale(1); opacity: 1; } 100% { transform: translateY(-50px) scale(1.5); opacity: 0; } }
@keyframes shake { 0% { transform: translate(1px, 1px) rotate(0deg); } 10% { transform: translate(-1px, -2px) rotate(-1deg); } 20% { transform: translate(-3px, 0px) rotate(1deg); } 30% { transform: translate(3px, 2px) rotate(0deg); } 40% { transform: translate(1px, -1px) rotate(1deg); } 50% { transform: translate(-1px, 2px) rotate(-1deg); } 60% { transform: translate(-3px, 1px) rotate(0deg); } 70% { transform: translate(3px, 1px) rotate(-1deg); } 80% { transform: translate(-1px, -1px) rotate(1deg); } 90% { transform: translate(1px, 2px) rotate(0deg); } 100% { transform: translate(1px, -2px) rotate(-1deg); } }
.shake-screen { animation: shake 0.5s; }