/* ================= معرفی فونت‌های اختصاصی ================= */
@font-face { font-family: 'IRANYekanX'; src: url('IRANYekanX-Regular.woff2') format('woff2'); font-weight: normal; }
@font-face { font-family: 'IRANYekanX'; src: url('IRANYekanX-Bold.woff2') format('woff2'); font-weight: bold; }

/* ================= متغیرهای رنگی ================= */
:root {
    --bg-color: #f0f9ff;        
    --surface-color: #ffffff;   
    --primary: #3b82f6;         
    --primary-shadow: #2563eb;
    --success: #22c55e;         
    --success-shadow: #16a34a;
    --warning: #f59e0b;         
    --warning-shadow: #d97706;
    --text-main: #334155;
    --track-color: #94a3b8;     
}

/* ================= تنظیمات پایه (حل مشکل سفیدی/خاکستری زمینه) ================= */
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; font-family: 'IRANYekanX', Tahoma, sans-serif; touch-action: manipulation; }

html, body { 
    width: 100%; height: 100%; overflow: hidden; 
    background: linear-gradient(135deg, #38bdf8, #818cf8, #3b82f6);
    background-size: 200% 200%;
    animation: gradientMove 6s ease infinite;
    color: var(--text-main);
}

@keyframes gradientMove { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

#game-container { width: 100%; max-width: 600px; height: 100%; position: relative; margin: 0 auto; display: flex; flex-direction: column; padding: 15px; }

/* ================= هدر و چراغ‌های پیشرفت بازی ================= */
.header { display: flex; justify-content: space-between; align-items: center; background: var(--surface-color); padding: 12px 15px; border-radius: 18px; margin-bottom: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); flex-shrink: 0; gap: 10px; }
.user-info { display: flex; flex-direction: column; gap: 2px; }
.user-rank { font-size: 15px; font-weight: bold; color: var(--primary); }
.progress-dots { display: flex; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #e2e8f0; border: 2px solid #cbd5e1; transition: all 0.3s; }
.dot.success { background: var(--success); border-color: var(--success-shadow); }
.dot.active { box-shadow: 0 0 10px var(--primary); background: var(--surface-color); border-color: var(--primary); }

.btn-home { background: #f1f5f9; border: 2px solid #cbd5e1; color: var(--text-main); width: 40px; height: 40px; border-radius: 12px; font-size: 20px; display: flex; justify-content: center; align-items: center; cursor: pointer; box-shadow: 0 3px 0 #cbd5e1; transition: all 0.1s; }
.btn-home:active { transform: translateY(3px); box-shadow: none; }

/* ================= جعبه سوال بازی ================= */
.question-box { background: var(--surface-color); padding: 20px; border-radius: 15px; text-align: center; margin-bottom: 20px; border: 2px solid #bae6fd; box-shadow: 0 4px 0 #bae6fd; flex-shrink: 0; }
.question-title { font-size: 13px; color: var(--primary); font-weight: bold; margin-bottom: 10px; }
.question-text { font-size: 20px; font-weight: bold; color: var(--text-main); }

/* ================= ریل و ایستگاه قطار ================= */
.train-station { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; position: relative; min-height: 120px; }
.track-area { min-height: 70px; border-bottom: 5px dashed var(--track-color); display: flex; align-items: center; padding-bottom: 5px; gap: 6px; flex-wrap: wrap; direction: ltr; }
.locomotive { font-size: 35px; animation: idle 2s infinite ease-in-out; }
@keyframes idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* ================= واگن‌ها (کلمات پایین صفحه) ================= */
.words-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 15px 5px; min-height: 130px; direction: ltr; align-content: flex-start; flex-shrink: 0; }
.word-btn { background: var(--surface-color); color: var(--text-main); border: 2px solid #e2e8f0; padding: 12px 18px; border-radius: 12px; font-size: 16px; font-family: Arial, sans-serif; font-weight: bold; cursor: pointer; box-shadow: 0 4px 0 #cbd5e1; transition: transform 0.1s; }
.word-btn:active { transform: translateY(4px); box-shadow: 0 0 0 #cbd5e1; }
.word-btn.placeholder { background: #f1f5f9; color: transparent; border-color: dashed #cbd5e1; box-shadow: none; pointer-events: none; }
.word-btn.in-train { background: var(--warning); color: #fff; border-color: var(--warning-shadow); box-shadow: 0 4px 0 var(--warning-shadow); animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); position: relative; padding: 10px 14px; }
@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.word-btn.in-train:not(:last-child)::after { content: '-'; color: #475569; position: absolute; right: -12px; top: 50%; transform: translateY(-50%); font-weight: 900; }

/* ================= دکمه‌های پایین بازی ================= */
.action-area { display: flex; gap: 10px; margin-top: auto; padding-bottom: 10px; flex-shrink: 0; }
.btn-check { flex-grow: 1; padding: 15px; background: var(--surface-color); color: var(--text-main); border: 3px solid #e2e8f0; border-radius: 15px; font-size: 16px; font-weight: bold; box-shadow: 0 5px 0 #e2e8f0; cursor: pointer; transition: background 0.2s, color 0.2s; }
.btn-check:active { transform: translateY(5px); box-shadow: none !important; }
.btn-check.disabled { opacity: 0.6; pointer-events: none; }
.btn-undo { padding: 15px 20px; background: #ef4444; color: #fff; border: none; border-radius: 15px; font-size: 18px; font-weight: bold; box-shadow: 0 5px 0 #b91c1c; cursor: pointer; }
.btn-undo:active { transform: translateY(5px); box-shadow: 0 0 0 #b91c1c; }

/* ================= انیمیشن قطار ================= */
.error-shake { animation: simple-shake 0.4s ease-in-out; border-bottom-color: #ef4444 !important; background: #fef2f2; border-radius: 10px; }
@keyframes simple-shake { 0%, 100% { transform: translateX(0); } 25%, 75% { transform: translateX(-8px); } 50% { transform: translateX(8px); } }
.departing { animation: train-leave 1s cubic-bezier(0.55, 0.085, 0.68, 0.53) forwards; }
@keyframes train-leave { 0% { transform: translateX(0); opacity: 1; } 100% { transform: translateX(-150%); opacity: 0; } }

/* ================= استایل‌های Modal ================= */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.75); z-index: 9999; display: none; justify-content: center; align-items: center; backdrop-filter: blur(4px); }
.modal-content { background: var(--surface-color); width: 90%; max-width: 380px; border-radius: 25px; padding: 30px 25px; text-align: center; box-shadow: 0 15px 30px rgba(0,0,0,0.3); animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes modalPop { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.modal-icon { font-size: 50px; margin-bottom: 15px; }
.modal-title { font-size: 22px; color: var(--text-main); margin-bottom: 12px; font-weight: bold; }
.modal-text { font-size: 15px; color: #475569; margin-bottom: 25px; line-height: 1.7; }
.modal-btn { background: var(--primary); color: #fff; border: none; padding: 14px 20px; border-radius: 15px; font-size: 16px; font-weight: bold; width: 100%; cursor: pointer; box-shadow: 0 5px 0 var(--primary-shadow); transition: all 0.1s; }
.modal-btn.success { background: var(--success); box-shadow: 0 5px 0 var(--success-shadow); }
.modal-btn.error { background: #ef4444; box-shadow: 0 5px 0 #b91c1c; }
.modal-btn:active { transform: translateY(5px); box-shadow: none !important; }

/* ========================================================================= */
/*                   صفحه اصلی خانگی (Minimal & Compact)                     */
/* ========================================================================= */
.home-container { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; padding: 15px; }

.home-glass {
    background: rgba(255, 255, 255, 0.25); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 20px; padding: 20px 15px; 
    width: 100%; max-width: 300px; display: flex; flex-direction: column; align-items: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); 
    animation: popInGlass 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popInGlass { 0% { transform: scale(0.9) translateY(20px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }

.header-minimal { display: flex; flex-direction: column; align-items: center; margin-bottom: 20px; }

.train-static {
    width: 45px; height: 45px; background: #fff; border-radius: 12px;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1), inset 0 -3px 0 #e2e8f0; margin-bottom: 8px; 
}

.home-logo { font-size: 26px; } 

.home-title { font-size: 20px; color: #fff; font-weight: 900; margin-bottom: 8px; text-shadow: 0px 1px 0px rgba(0,0,0,0.2); }

.home-username { background: rgba(255,255,255,0.9); color: #334155; font-size: 11px; font-weight: bold; padding: 4px 12px; border-radius: 8px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-bottom: 20px; }

.stat-box-mini { background: #fff; border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: row; justify-content: space-between; align-items: center; box-shadow: 0 3px 0 rgba(203, 213, 225, 0.7); }
.mistake-box { grid-column: 1 / -1; }
.stat-label-group { display: flex; align-items: center; gap: 6px; }
.stat-icon-small { font-size: 14px; }
.stat-label { font-size: 12px; color: #64748b; font-weight: bold; }
.stat-val { font-size: 14px; font-weight: 900; color: #334155; }
.error-text { color: #ef4444; }

.cefr-badge { display: inline-block; background: #fef08a; color: #ca8a04; padding: 2px 6px; border-radius: 6px; font-size: 11px; }

.btn-start-small {
    background: #fde047; color: #854d0e; border: none; padding: 14px; border-radius: 15px; font-size: 17px; 
    font-weight: 900; cursor: pointer; box-shadow: 0 5px 0 #ca8a04, 0 8px 15px rgba(0,0,0,0.1);
    width: 100%; text-shadow: 0 1px 0px rgba(255,255,255,0.3); transition: transform 0.1s; 
}
.btn-start-small:active { transform: translateY(5px); box-shadow: 0 0px 0 #ca8a04; }
.btn-start-small.disabled { opacity: 0.7; pointer-events: none; }

/* بهینه‌سازی موبایل */
@media (max-width: 400px) {
    .word-btn { padding: 8px 12px; font-size: 14px; }
    .question-text { font-size: 17px; }
    .btn-check { font-size: 15px; }
    .locomotive { font-size: 28px; }
}