:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --accent: #a78bfa;
    --border: #334155;
    --radius: 12px;
}

[data-theme="light"] {
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.container {
    max-width: min(480px, 95vw);
    width: 100%;
    padding: min(2rem, 3vh) min(1.5rem, 3vw);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: min(2rem, 3vh);
}

header h1 { font-size: clamp(1.2rem, 4vw, 1.5rem); font-weight: 700; }

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.2rem;
    width: 40px; height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}

#fullscreen-toggle:hover { background: var(--bg-card-hover); }
#theme-toggle:hover { background: var(--bg-card-hover); }

/* Game mode — hide header, nav, footer so game fills viewport */
.container.game-mode header,
.container.game-mode .back-btn,
.container.game-mode .page-footer {
    display: none !important;
}

.container.game-mode {
    max-width: 100vw;
    max-height: 100dvh;
    height: 100dvh;
    padding: 0.5rem;
    overflow: hidden;
}

.container.game-mode #game-screen {
    height: 100%;
}
.lang-switcher {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 50px;
    overflow: hidden;
    margin-right: 0.5rem;
}
.lang-switcher a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.7rem;
    transition: background 0.2s, color 0.2s;
    line-height: 1.4;
}
.lang-switcher a:hover { color: var(--text); }
.lang-switcher a.active {
    background: var(--accent);
    color: #fff;
}

.subtitle {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: min(2rem, 3vh);
    font-size: clamp(0.9rem, 3vw, 1.1rem);
}

.options {
    display: flex;
    gap: min(1.5rem, 4vw);
    justify-content: center;
    margin-bottom: min(2rem, 3vh);
    flex-wrap: wrap;
}

.options label {
    display: flex; align-items: center; gap: 0.5rem;
    cursor: pointer; color: var(--text-muted);
    font-size: clamp(0.85rem, 2.5vw, 1rem);
}

.options input[type="radio"] { accent-color: var(--primary); }

.btn {
    display: block; width: 100%;
    padding: clamp(0.65rem, 2vh, 0.85rem) 1.5rem;
    border: none; border-radius: var(--radius);
    font-size: clamp(0.9rem, 3vw, 1rem);
    font-weight: 600; cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); margin-top: 0.75rem; }
.btn.secondary:hover { background: var(--bg-card-hover); }

.hidden { display: none !important; }
.screen { text-align: center; }

#start-screen,
#result-screen {
    flex-shrink: 0;
}

#game-screen {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#player-name {
    display: block; width: 100%;
    max-width: min(280px, 80vw);
    margin: 0 auto min(2rem, 3vh);
    padding: clamp(0.5rem, 1.5vh, 0.65rem) 1rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: clamp(0.9rem, 3vw, 1rem);
    text-align: center; outline: none;
    transition: border-color 0.2s;
}

#player-name:focus { border-color: var(--primary); }
#player-name::placeholder { color: var(--text-muted); }

/* Progress */
.progress-bar { width: 100%; height: 6px; background: var(--border); border-radius: 3px; margin-bottom: min(1.5rem, 2vh); overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s ease; }

.stats {
    display: flex; justify-content: space-between;
    margin-bottom: min(1.5rem, 2vh);
    color: var(--text-muted);
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
}

/* Letter card */
.letter-card {
    background: var(--bg-card); border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1.5rem, 4vh, 2.5rem);
    margin-bottom: min(2rem, 3vh);
    transition: border-color 0.3s; position: relative;
}

.letter-card .sound-btn { position: absolute; bottom: 0.5rem; right: 0.5rem; }
.letter-card.correct { border-color: var(--success); }
.letter-card.incorrect { border-color: var(--danger); }

.arabic-letter {
    font-size: clamp(3rem, 12vw, 5rem);
    font-family: 'Amiri', 'Traditional Arabic', 'Scheherazade New', serif;
    direction: rtl; line-height: 1.2;
}

/* Choices */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(0.5rem, 1.5vh, 0.75rem); margin-bottom: min(1.5rem, 2vh); }

.choice-btn {
    padding: clamp(0.65rem, 2vh, 0.85rem) 1rem;
    background: var(--bg-card); border: 2px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    cursor: pointer; transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.choice-btn:hover:not(:disabled) { background: var(--bg-card-hover); border-color: var(--primary); }
.choice-btn:active:not(:disabled) { transform: scale(0.97); }
.choice-btn.correct { border-color: var(--success); background: rgba(34, 197, 94, 0.15); color: var(--success); }
.choice-btn.incorrect { border-color: var(--danger); background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.choice-btn:disabled { cursor: default; opacity: 0.7; }

/* Feedback */
.feedback { padding: clamp(0.5rem, 1.5vh, 0.75rem); border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; font-size: clamp(0.85rem, 2.5vw, 1rem); }
.feedback.correct { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.feedback.incorrect { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Results */
.result-score { font-size: clamp(2.5rem, 10vw, 4rem); font-weight: 800; color: var(--primary); margin: 1rem 0; }
#result-message { color: var(--text-muted); margin-bottom: min(2rem, 3vh); font-size: clamp(0.9rem, 3vw, 1.1rem); }

/* Game cards */
.game-cards { display: flex; flex-direction: column; gap: 1rem; }

.game-card {
    display: block; background: var(--bg-card); border: 2px solid var(--border);
    border-radius: var(--radius); padding: min(2rem, 4vh) min(1.5rem, 3vw);
    text-decoration: none; color: var(--text);
    transition: border-color 0.2s, transform 0.1s;
}

.game-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.game-card-icon { font-size: clamp(2rem, 6vw, 2.5rem); margin-bottom: 0.75rem; }
.game-card h2 { font-size: clamp(1.1rem, 3.5vw, 1.25rem); margin-bottom: 0.5rem; }
.game-card p { color: var(--text-muted); font-size: clamp(0.85rem, 2.5vw, 0.95rem); }

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: clamp(0.75rem, 2.5vw, 0.85rem);
    font-weight: 600;
    margin-bottom: 1rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    cursor: pointer;
}
.back-btn:hover {
    background: var(--bg-card-hover);
    color: var(--primary);
    border-color: var(--primary);
}

/* Falling game canvas */
.falling-canvas {
    width: 100%;
    display: block;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: crosshair;
    flex: 1;
    min-height: 0;
    max-height: 100%;
}

.target-banner {
    background: var(--bg-card); border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: clamp(0.5rem, 1.5vh, 0.75rem) 1rem;
    margin-bottom: 0.5rem;
    display: flex; align-items: center; justify-content: center; gap: 0.75rem;
}

.target-label { color: var(--text-muted); font-weight: 600; font-size: clamp(0.85rem, 2.5vw, 1rem); }
.target-letter { font-size: clamp(1.5rem, 5vw, 2rem); font-family: 'Amiri', 'Traditional Arabic', serif; color: var(--accent); direction: rtl; }
.target-letter.hidden-letter { filter: blur(8px); opacity: 0.3; user-select: none; cursor: default; }
.target-letter.revealed { filter: blur(0); opacity: 1; transition: filter 0.25s ease, opacity 0.25s ease; }

.sound-btn {
    background: none; border: 1px solid var(--border);
    color: var(--text-muted); font-size: 1.1rem;
    width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; transition: background 0.2s, color 0.2s;
}

.sound-btn:hover { background: var(--bg-card-hover); color: var(--primary); }

.hint-btn {
    background: none; border: 1px solid var(--border);
    color: var(--text-muted); font-size: 1.1rem;
    width: 36px; height: 36px; border-radius: 50%;
    cursor: pointer; transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.hint-btn:hover { background: var(--bg-card-hover); color: #fbbf24; border-color: #fbbf24; }
.hint-btn:active { transform: scale(0.9); }

.falling-hud {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.5rem; font-weight: 600;
    font-size: clamp(0.85rem, 2.5vw, 1rem);
}

.falling-hud .lives { color: var(--danger); }
.falling-hud .level { color: var(--accent); }

.explosion {
    position: absolute; pointer-events: none;
    width: 60px; height: 60px; border-radius: 50%;
    background: radial-gradient(circle, rgba(239,68,68,0.8), rgba(239,68,68,0) 70%);
    animation: explode 0.4s ease-out forwards;
}

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

/* Typing input - hidden, game is click-only */
.type-input,
.feedback { display: none !important; }

/* Records */
.records-section {
    margin-top: min(2rem, 3vh);
    background: var(--bg-card); border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: min(1.5rem, 3vh) min(1.5rem, 3vw);
}

.records-section h2 { font-size: clamp(1rem, 3vw, 1.15rem); margin-bottom: 1rem; text-align: center; }

.records-table { width: 100%; border-collapse: collapse; font-size: clamp(0.75rem, 2vw, 0.85rem); margin-bottom: 1rem; }
.records-table th { color: var(--text-muted); font-weight: 600; text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); font-size: clamp(0.7rem, 2vw, 0.8rem); }
.records-table td { padding: 0.45rem 0.4rem; border-bottom: 1px solid var(--border); color: var(--text); }
.records-table tr:last-child td { border-bottom: none; }
.records-table .score-col { font-weight: 700; color: var(--primary); }

.records-empty { color: var(--text-muted); text-align: center; padding: 1rem 0; font-size: clamp(0.8rem, 2.5vw, 0.9rem); }

.btn.small { width: auto; display: inline-block; padding: 0.5rem 1rem; font-size: clamp(0.75rem, 2vw, 0.8rem); }
.btn.danger-outline { background: none; color: var(--danger); border: 1px solid var(--danger); }
.btn.danger-outline:hover { background: rgba(239, 68, 68, 0.1); }

/* Responsive */
@media (max-width: 480px) {
    .container { padding: 1rem; }
    .choices { grid-template-columns: 1fr; }
    .options { flex-direction: column; gap: 0.75rem; }
}

@media (max-width: 360px) {
    .arabic-letter { font-size: 2.5rem; }
    header h1 { font-size: 1.1rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .container { padding: 0.5rem 1rem; }
    header { margin-bottom: 0.5rem; }
    .subtitle { margin-bottom: 0.5rem; }
    .letter-card { padding: 1rem; margin-bottom: 1rem; }
    .arabic-letter { font-size: 3rem; }
}

@media (orientation: landscape) {
    .container:not(.game-mode) { max-width: min(600px, 90vw); }
    .container.game-mode { max-width: 100vw; padding: 0.25rem; }
}

.container::-webkit-scrollbar { width: 6px; }
.container::-webkit-scrollbar-track { background: transparent; }
.container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.container::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.page-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.6;
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.page-footer a { color: var(--text-muted); transition: color 0.2s; }
.page-footer a:hover { color: var(--text); }
