:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary: #3b82f6;
    --secondary-hover: #2563eb;
    --tertiary: #f43f5e;
    --tertiary-hover: #e11d48;
    --quaternary: #eab308;
    --quaternary-hover: #ca8a04;
    --success: #10b981;
    --error: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background: linear-gradient(135deg, var(--bg-primary), #312e81);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 40px 0;
}

/* Background gradient blobs */
body::before, body::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
}

body::before {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: rgba(139, 92, 246, 0.2);
}

body::after {
    bottom: -10%;
    right: -10%;
    width: 40vw;
    height: 40vw;
    background: rgba(59, 130, 246, 0.2);
}

#app {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    position: relative;
}

/* ========================================================= 
   SCREEN TRANSITIONS
========================================================= */
.screen {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.screen.active {
    display: flex;
    justify-content: center;
}

/* ========================================================= 
   GLASSMORPHISM PANELS
========================================================= */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 450px;
}

.glass-panel.wide {
    max-width: 700px;
}

.glass-panel.home-wide {
    max-width: 600px;
}

/* ========================================================= 
   TYPOGRAPHY
========================================================= */
.title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -1px;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 30px;
}

.highlight {
    background: linear-gradient(to right, #a78bfa, #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.section-title {
    font-size: 2rem;
    margin-bottom: 30px;
}

/* ========================================================= 
   BUTTONS
========================================================= */
.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
    color: white;
    width: 100%;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary { background: var(--primary); }
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 10px 15px -3px rgba(139, 92, 246, 0.4);
    transform: translateY(-2px);
}

.btn-secondary { background: var(--secondary); }
.btn-secondary:hover {
    background: var(--secondary-hover);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.btn-tertiary { background: var(--tertiary); }
.btn-tertiary:hover {
    background: var(--tertiary-hover);
    box-shadow: 0 10px 15px -3px rgba(244, 63, 94, 0.4);
    transform: translateY(-2px);
}

.btn-quaternary { background: var(--quaternary); }
.btn-quaternary:hover {
    background: var(--quaternary-hover);
    box-shadow: 0 10px 15px -3px rgba(234, 179, 8, 0.4);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--glass-border);
    width: auto;
    padding: 10px 20px;
    font-size: 1rem;
}
.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.3s;
    position: absolute;
    top: 30px;
    left: 30px;
}

.btn-icon:hover {
    color: var(--text-main);
}

/* ========================================================= 
   HOME & LEVEL GRID
========================================================= */
.stats {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 1.2rem;
    font-weight: 600;
}

.language-selector {
    margin-bottom: 30px;
    font-size: 1.1rem;
    color: var(--text-muted);
}
.language-selector select {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    cursor: pointer;
}
.language-selector select option {
    background: var(--bg-secondary);
    color: var(--text-main);
}

.level-count-hint {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 20px;
    letter-spacing: 0.5px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.level-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 18px 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.level-card .level-num {
    font-size: 1.2rem;
    font-weight: 800;
}

.level-card .status-icon {
    font-size: 1rem;
}

.level-card.unlocked {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.3);
}

.level-card.unlocked:hover {
    background: rgba(139, 92, 246, 0.2);
    transform: translateY(-5px);
}

.level-card.completed {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}
.level-card.completed .status-icon {
    color: var(--success);
}

.level-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.2);
}

/* ========================================================= 
   GAME SCREEN UI
========================================================= */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--glass-border);
    position: relative;
}

.game-header .btn-icon {
    position: static;
}

.level-info, .score-info {
    font-weight: 600;
    font-size: 1.1rem;
}

.clue-container {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 30px;
}

.clue-container h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.clue-container p {
    font-size: 1.3rem;
    font-weight: 600;
}

.answer-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 40px;
    min-height: 60px;
}

.letter-slot {
    width: 50px;
    height: 60px;
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
    cursor: pointer;
}

.letter-slot.filled {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

.letter-slot.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    animation: popIn 0.3s ease;
}

.letters-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 30px;
}

.scramble-letter {
    width: 50px;
    height: 50px;
    background: var(--secondary);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, opacity 0.2s;
    user-select: none;
}

.scramble-letter:hover {
    transform: translateY(-3px) scale(1.05);
    background: var(--secondary-hover);
}

.scramble-letter.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

.game-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* ========================================================= 
   MODALS
========================================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}
.win-icon { color: #fbbf24; }
.lose-icon { color: var(--tertiary); }

.modal h2 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.word-reveal {
    margin: 20px 0;
    font-size: 1.2rem;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 30px;
}
.modal-actions .btn { margin-bottom: 0; }

/* ========================================================= 
   LOADING INDICATOR
========================================================= */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loader {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

/* ========================================================= 
   ANIMATIONS & UTILS
========================================================= */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); color: #ff0000; }
    100% { transform: scale(1); }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.hidden { display: none !important; }

/* =========================================================
   PLAYER NAME INPUT
========================================================= */
.name-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.07);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 10px 16px;
    margin-bottom: 20px;
    color: var(--text-muted);
}

.player-name-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
}

.player-name-input::placeholder {
    color: rgba(203, 213, 225, 0.4);
    font-weight: 400;
}

/* =========================================================
   LEADERBOARD SECTION (Home Screen)
========================================================= */
.leaderboard-section {
    margin-top: 28px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    text-align: left;
}

.lb-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.lb-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fbbf24;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-clear-lb {
    background: transparent;
    border: 1px solid rgba(239,68,68,0.3);
    color: rgba(239,68,68,0.7);
    border-radius: 8px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.btn-clear-lb:hover {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lb-row {
    display: grid;
    grid-template-columns: 32px 1fr 72px 80px 90px;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.lb-row.lb-top {
    background: rgba(251, 191, 36, 0.08);
    border-color: rgba(251, 191, 36, 0.3);
}

.lb-rank {
    font-size: 1.1rem;
    text-align: center;
}

.lb-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-diff {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.lb-score {
    font-weight: 800;
    color: var(--text-main);
    text-align: right;
}

.lb-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: right;
}

.lb-empty {
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
    padding: 16px 0;
}

/* =========================================================
   NEW RECORD BADGE (Win Modal)
========================================================= */
.new-record-badge {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1a0a00;
    font-weight: 800;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    border-radius: 20px;
    padding: 6px 18px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* =========================================================
   LEADERBOARD MODAL
========================================================= */
.leaderboard-modal-full {
    max-width: 520px;
}

.lb-icon {
    color: #fbbf24;
}

.lb-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.07);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 10px 16px;
    margin: 16px 0 8px;
    color: var(--text-muted);
}

.lb-current-score {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.lb-current-score strong {
    color: #fbbf24;
    font-size: 1.1rem;
}

.leaderboard-list-modal {
    max-height: 240px;
    overflow-y: auto;
}

/* Save Score button */
.btn-outline-lb {
    background: transparent;
    border: 2px solid #fbbf24;
    color: #fbbf24;
    width: auto;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}
.btn-outline-lb:hover {
    background: rgba(251,191,36,0.15);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(251,191,36,0.2);
}

/* ========================================================= 
   RESPONSIVENESS
========================================================= */
@media (max-width: 600px) {
    .glass-panel { padding: 30px 20px; }
    .title { font-size: 2.5rem; }
    .game-header { flex-wrap: wrap; gap: 15px; justify-content: center; padding-top: 40px; }
    .game-header .btn-icon { top: 20px; left: 20px; }
    .letter-slot { width: 40px; height: 50px; font-size: 1.5rem; }
    .scramble-letter { width: 40px; height: 40px; font-size: 1.5rem; }
    .modal-actions { flex-direction: column; }
    .level-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
    .level-card { padding: 14px 6px; }
    .level-card .level-num { font-size: 1rem; }
    .lb-row { font-size: 0.8rem; gap: 6px; }
    .lb-date { display: none; }
    .modal-actions .btn { font-size: 0.9rem; padding: 10px 14px; }
}
