/* ============ CSS VARIABLES ============ */
:root {
    --paper-bg: #fbf8f1;
    --ink-dark: #2b1d14;
    --ink-light: #594336;
    --gold-accent: #a67c00;
    --gold-border: #d4c095;
    --success-green: #2e7d32;
    --error-red: #c62828;
    --duel-purple: #8e24aa;
    --overlay-bg: rgba(43, 29, 20, 0.92);
    --box-bg: #fffcf5;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}
body.dark-mode {
    --paper-bg: #1c1815;
    --ink-dark: #f0eadd;
    --ink-light: #bfaea3;
    --gold-accent: #d4af37;
    --gold-border: #594336;
    --success-green: #66bb6a;
    --error-red: #ef5350;
    --duel-purple: #ba68c8;
    --overlay-bg: rgba(0,0,0,0.96);
    --box-bg: #26211d;
}

/* ============ BASE RESET ============ */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Amiri Quran', serif;
    background-color: var(--paper-bg);
    background-image: radial-gradient(var(--gold-border) 1px, transparent 1px), radial-gradient(var(--gold-border) 1px, transparent 1px);
    background-size: 30px 30px; background-position: 0 0, 15px 15px;
    color: var(--ink-dark);
    display: flex; flex-direction: column; align-items: center;
    min-height: 100vh; min-height: -webkit-fill-available;
    margin: 0;
    padding: 8px 10px calc(8px + var(--safe-bottom));
    padding-top: calc(8px + var(--safe-top));
    gap: 8px;
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* ============ MAIN MENU (Professor UI) ============ */
#main-menu-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 90vh;
    padding: 20px;
}

.main-menu-card {
    background: var(--box-bg);
    border: 2px solid var(--gold-border);
    border-radius: 16px;
    padding: 35px 25px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 15px 30px rgba(0,0,0,0.08);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-title {
    font-family: 'Aref Ruqaa', serif;
    font-size: 2.8rem;
    color: var(--ink-dark);
    margin-top: 0;
    margin-bottom: 25px;
    border-bottom: 2px dashed var(--gold-border);
    padding-bottom: 15px;
    width: 100%;
    line-height: 1.2;
}

.main-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.btn-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px;
    border-radius: 8px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 900;
    font-size: 1.05rem;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.2s ease;
    outline: none;
}
.btn-menu:active { transform: scale(0.97); }

.btn-menu-primary { background: var(--ink-dark); color: var(--paper-bg); border: 2px solid var(--ink-dark); }
.btn-menu-secondary { background: transparent; color: var(--ink-dark); border: 2px solid var(--gold-accent); }
.btn-menu-outline { background: transparent; color: var(--ink-light); border: 2px dashed var(--gold-border); }

.menu-footer {
    margin-top: 25px;
    width: 100%;
    font-family: 'Tajawal', sans-serif;
    color: var(--ink-dark);
}

.coffee-link {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    color: var(--ink-dark); text-decoration: none; font-size: 0.95rem;
    border: 1px solid var(--gold-border); background: var(--paper-bg);
    padding: 10px 20px; border-radius: 20px; font-weight: bold;
}

/* ============ XP BAR ANIMATION ============ */
.xp-container { background: var(--box-bg); border: 1px solid var(--gold-border); padding: 10px; border-radius: 8px; margin-top: 15px; }
.xp-header { display: flex; justify-content: space-between; font-family: 'Tajawal'; font-weight: bold; font-size: 0.9rem; margin-bottom: 5px; color: var(--ink-dark); }
.xp-bar-bg { width: 100%; height: 10px; background: var(--paper-bg); border-radius: 5px; overflow: hidden; border: 1px solid #ccc; }
.xp-bar-fill { height: 100%; background: var(--success-green); width: 0%; transition: width 1.5s cubic-bezier(0.2, 0.8, 0.3, 1); }

/* ============ TOP BAR ============ */
.top-bar {
    width: 100%; max-width: 480px;
    display: flex; justify-content: space-between; align-items: center;
    background: var(--box-bg);
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--gold-border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.store-buttons { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

/* ============ BUTTONS ============ */
.btn-action {
    background: transparent;
    border: 1.5px solid var(--gold-accent);
    color: var(--ink-dark);
    font-family: 'Tajawal', sans-serif; font-weight: 700;
    padding: 7px 9px;
    border-radius: 6px; cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.15s ease;
    display: flex; align-items: center; gap: 4px;
    outline: none; text-decoration: none;
    min-height: 36px;
    -webkit-user-select: none; user-select: none;
}
.btn-action:active { background: var(--gold-accent); color: var(--paper-bg); transform: scale(0.95); }

.start-btn {
    background: var(--ink-dark); color: var(--paper-bg);
    border: 1.5px solid var(--gold-accent);
    padding: 13px 16px; font-size: 1rem;
    font-family: 'Tajawal', sans-serif; font-weight: bold;
    cursor: pointer; transition: all 0.2s ease;
    border-radius: 8px; margin-top: 8px; width: 100%;
    min-height: 48px;
    -webkit-user-select: none; user-select: none;
}
.start-btn:active { transform: scale(0.97); opacity: 0.85; }
.start-btn.btn-secondary { background: var(--box-bg); color: var(--ink-dark); border-color: var(--gold-border); }
.close-btn { background: var(--error-red); color: #fff; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; margin-top: 15px; font-family: 'Tajawal'; font-weight: bold; font-size: 1rem; width: 100%; min-height: 44px; }

/* ============ TIMER CONTAINERS ============ */
.timer-container {
    display: none; text-align: center;
    font-family: 'Tajawal'; font-size: 1.7rem;
    font-weight: bold;
    background: var(--box-bg); border-radius: 10px;
    padding: 10px; width: 100%; max-width: 480px;
}
#speed-timer-container { color: var(--error-red); border: 2px dashed var(--error-red); }
#duel-timer-container  { color: var(--duel-purple); border: 2px dashed var(--duel-purple); }
.timer-msg { font-size: 0.85rem; color: var(--ink-light); margin-top: 4px; }

/* ============ LIVE DUEL STATS ============ */
.live-stats {
    display: flex; flex-direction: column; gap: 6px;
    background: var(--paper-bg);
    border: 1px solid var(--duel-purple); border-radius: 6px;
    padding: 8px 12px; margin-top: 8px;
    font-size: 1rem; color: var(--ink-dark);
    font-family: 'Tajawal'; font-weight: bold;
}
.player-stat-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px; border-bottom: 1px dashed var(--gold-border);
}
.player-stat-row:last-child { border-bottom: none; }

/* ============ PROGRESS WIDGET ============ */
.progress-widget {
    width: 100%; max-width: 480px;
    background: var(--box-bg);
    border: 1px solid var(--gold-border);
    border-radius: 10px; padding: 10px 14px;
    display: flex; flex-direction: column; gap: 8px;
}
.progress-header {
    display: flex; justify-content: space-between;
    font-family: 'Tajawal', sans-serif; color: var(--ink-dark);
    font-weight: bold; font-size: 0.9rem; align-items: center;
}
.rank-badge {
    background: var(--gold-accent); color: #fff;
    padding: 2px 8px; border-radius: 10px;
    font-size: 0.78rem; font-weight: bold;
    animation: pulse-glow 2s infinite;
}
@keyframes pulse-glow {
    0%   { box-shadow: 0 0 0 0 rgba(166,124,0,0.4); }
    70%  { box-shadow: 0 0 0 5px rgba(166,124,0,0); }
    100% { box-shadow: 0 0 0 0 rgba(166,124,0,0); }
}
.progress-bar { width: 100%; height: 7px; background: var(--paper-bg); border: 1px solid var(--gold-border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--gold-accent); width: 0%; transition: width 0.6s cubic-bezier(0.4,0,0.2,1); }

/* ============ OVERLAYS ============ */
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--overlay-bg); backdrop-filter: blur(8px);
    display: none; flex-direction: column;
    justify-content: center; align-items: center;
    z-index: 2000; padding: 16px;
    overflow-y: auto;
}
.overlay.active { display: flex; }
#countdownOverlay { background: rgba(28,24,21,0.95); z-index: 3000; }

.countdown-text {
    font-size: 7rem; font-family: 'Tajawal', sans-serif; font-weight: 900;
    color: #FFD700;
    text-shadow: 0 0 40px rgba(255,215,0,0.8), 0 0 80px rgba(255,140,0,0.6);
    text-align: center;
}
@keyframes pulse-glow-text {
    0%   { transform: scale(0.5); opacity: 0; }
    30%  { transform: scale(1.2); opacity: 1; text-shadow: 0 0 50px rgba(255,215,0,1), 0 0 100px rgba(255,140,0,0.8); }
    70%  { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* ============ CARDS ============ */
.intro-card, .leaderboard-card {
    background: var(--paper-bg);
    padding: 22px 18px;
    border-radius: 12px;
    text-align: center;
    border: 3px double var(--gold-accent);
    width: 100%; max-width: 420px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.intro-card h2 { font-family: 'Tajawal', sans-serif; font-weight: 900; font-size: 1.4rem; margin: 0 0 10px; }

/* ============ FORM INPUTS ============ */
.name-input {
    width: 100%; padding: 12px; margin-bottom: 10px;
    border: 1.5px solid var(--gold-border); border-radius: 8px;
    font-family: 'Tajawal', sans-serif; text-align: center;
    font-size: 1rem; background: var(--box-bg); color: var(--ink-dark);
    outline: none; transition: border-color 0.3s;
    min-height: 44px;
    -webkit-appearance: none; appearance: none;
}
.name-input:focus { border-color: var(--gold-accent); }
.name-input:disabled { opacity: 0.6; cursor: not-allowed; }

select.name-input { -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a67c00' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; padding-left: 30px; }

/* ============ RANGE SLIDER ============ */
.range-slider { -webkit-appearance: none; width: 100%; height: 6px; background: var(--gold-border); border-radius: 4px; outline: none; margin-bottom: 10px; }
.range-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: var(--gold-accent); cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
.settings-label { display: flex; justify-content: space-between; font-family: 'Tajawal'; font-weight: bold; color: var(--ink-dark); margin-top: 4px; font-size: 0.95rem; }

/* ============ LEADERBOARD ============ */
.leaderboard-tabs { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.tab-btn { background: transparent; border: 1px solid var(--gold-border); color: var(--ink-light); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-family: 'Tajawal'; font-weight: bold; transition: all 0.2s; min-height: 40px; }
.tab-btn.active { background: var(--gold-accent); color: #fff; border-color: var(--gold-accent); }
.leaderboard-table { width: 100%; border-collapse: collapse; font-family: 'Tajawal', sans-serif; }
.leaderboard-table th, .leaderboard-table td { padding: 9px 4px; border-bottom: 1px solid var(--gold-border); text-align: center; color: var(--ink-dark); }
.leaderboard-table th { color: var(--gold-accent); font-weight: bold; font-size: 0.9rem; }
.rank-1 { color: #FFD700 !important; font-weight: bold; font-size: 1.1rem; }
.rank-2 { color: #C0C0C0 !important; font-weight: bold; }
.rank-3 { color: #CD7F32 !important; font-weight: bold; }

/* ============ MAIN GAME CONTAINER ============ */
.container {
    background: var(--paper-bg);
    padding: 16px 14px;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.07);
    width: 100%; max-width: 480px;
    border: 2px solid var(--gold-accent);
    outline: 1px solid var(--gold-accent);
    outline-offset: -5px;
    position: relative;
    transition: all 0.3s ease;
}
.golden-shake { animation: goldenShake 0.8s ease-in-out; box-shadow: 0 0 35px var(--gold-accent) !important; border-color: #FFD700 !important; outline-color: #FFD700 !important; }
@keyframes goldenShake { 0%,100%{transform:translateY(0) scale(1);} 25%{transform:translateY(-8px) scale(1.02);} 50%{transform:translateY(8px) scale(1.02);} 75%{transform:translateY(-4px) scale(1.01);} }

.header-stats {
    display: flex; justify-content: space-between;
    margin-bottom: 12px; padding-bottom: 10px;
    border-bottom: 2px dotted var(--gold-border);
    font-family: 'Tajawal', sans-serif; font-weight: 700;
    font-size: 0.9rem; color: var(--ink-light);
}

/* ============ LETTER BOXES ============ */
.boxes-container {
    display: flex; justify-content: center;
    gap: 7px; margin-bottom: 20px;
    direction: rtl; flex-wrap: wrap;
}
.box {
    width: 58px; height: 90px;
    border: 1.5px solid var(--gold-border);
    border-radius: 8px;
    display: flex; flex-direction: column;
    justify-content: space-between; align-items: center;
    padding: 6px 0;
    background: var(--box-bg);
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.box.filled {
    border-color: var(--gold-accent);
    border-width: 2px;
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(166,124,0,0.18);
}
.dots {
    height: 22px; color: var(--ink-dark);
    font-size: 17.1px; /* تم تصغيرها 5% بالضبط (كانت 18px) */
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s ease, color 0.2s ease; /* إضافة transform لنزول النقطة بنعومة */
}
.char-display {
    font-size: 34px;
    font-family: 'Amiri Quran', serif;
    height: 44px;
    display: flex; align-items: center; justify-content: center;
    color: var(--ink-dark);
    transition: color 0.2s ease;
}

/* ============ INPUT ============ */
.input-wrapper { width: 100%; display: flex; justify-content: center; margin-bottom: 8px; }
input#answer-input {
    width: 92%; max-width: 300px;
    padding: 10px 14px;
    font-size: 26px; text-align: center;
    border: none; border-bottom: 2.5px dashed var(--ink-light);
    font-family: 'Amiri Quran', serif;
    background: transparent; color: var(--ink-dark);
    outline: none; transition: border-color 0.3s ease;
    caret-color: var(--gold-accent);
}
input#answer-input:focus { border-bottom: 2.5px solid var(--gold-accent); }

/* ============ FEEDBACK ============ */
#feedback {
    margin-top: 12px; text-align: center;
    font-family: 'Tajawal', sans-serif; font-weight: 700;
    font-size: 0.95rem; min-height: 26px;
}

/* ============ BONUS LOG ============ */
.bonus-log {
    background: var(--box-bg); border: 1px dashed var(--gold-border);
    padding: 8px; border-radius: 8px;
    width: 100%; max-width: 360px; max-height: 100px;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    font-family: 'Tajawal', sans-serif;
    display: none; margin: 14px auto 0; text-align: center;
}
.bonus-log ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.bonus-log li { background: var(--paper-bg); border: 1px solid var(--gold-border); padding: 2px 8px; border-radius: 10px; font-size: 0.85rem; font-family: 'Amiri Quran', serif; }

/* ============ ANIMATIONS ============ */
@keyframes shake { 0%,100%{transform:translateX(0);} 20%,60%{transform:translateX(-5px);} 40%,80%{transform:translateX(5px);} }
.shake { animation: shake 0.4s ease-in-out; border-color: var(--error-red) !important; color: var(--error-red); }
.speed-error .box { border-color: var(--error-red) !important; animation: shake 0.4s ease-in-out; box-shadow: 0 4px 10px rgba(198,40,40,0.2); }
.speed-error .dots, .speed-error .char-display { color: var(--error-red) !important; }

.mini-particle { position: absolute; pointer-events: none; z-index: 9999; font-size: 1.4rem; animation: pop-out 1s cubic-bezier(0.1,0.8,0.3,1) forwards; }
@keyframes pop-out { 0%{transform:translate(-50%,-50%) scale(0.5); opacity:1;} 100%{transform:translate(var(--tx),var(--ty)) scale(1.5); opacity:0;} }

/* ============ ROOMS ============ */
.room-box { background: var(--box-bg); border: 1px dashed var(--duel-purple); padding: 12px; border-radius: 8px; margin: 12px 0; font-family: 'Tajawal'; font-size: 1rem; color: var(--ink-dark); }
.code-display { font-size: 2.2rem; font-weight: 900; letter-spacing: 7px; color: var(--duel-purple); user-select: all; cursor: pointer; display: block; margin: 8px 0; }
.players-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0; }
.player-tag { background: var(--success-green); color: #fff; padding: 7px 13px; border-radius: 18px; font-family: 'Tajawal'; font-weight: bold; box-shadow: 0 2px 5px rgba(0,0,0,0.1); font-size: 0.9rem; }
.player-tag.waiting { background: var(--gold-accent); opacity: 0.8; }
.public-room-item { display: flex; justify-content: space-between; align-items: center; background: var(--paper-bg); padding: 10px; border: 1px solid var(--gold-border); border-radius: 6px; margin-bottom: 7px; }
.public-room-item span { font-family: 'Tajawal'; font-weight: bold; color: var(--ink-dark); font-size: 0.9rem; }

/* ============ HISTORY ============ */
.history-list { text-align: right; margin-top: 12px; border-top: 1px solid var(--gold-border); padding-top: 8px; width: 100%; }
.history-item { display: flex; justify-content: space-between; font-family: 'Tajawal'; padding: 7px 0; border-bottom: 1px dashed var(--gold-border); font-size: 0.9rem; }
.history-item:last-child { border-bottom: none; }
.win { color: var(--success-green); font-weight: bold; }
.loss { color: var(--error-red); font-weight: bold; }
.draw { color: var(--gold-accent); font-weight: bold; }

/* ============ LEVEL OVERLAY ============ */
.level-text { color: var(--gold-accent); font-family: 'Aref Ruqaa', serif; font-size: 3.5rem; text-shadow: 0 8px 18px rgba(0,0,0,0.5); margin: 0; text-align: center; }

/* ============ CONFETTI ============ */
.confetti { position: fixed; width: 9px; height: 9px; background-color: var(--gold-accent); opacity: 0; z-index: 9999; pointer-events: none; border-radius: 50%; }

/* ============ FOOTER ============ */
.developer-footer {
    text-align: center; font-family: 'Tajawal', sans-serif;
    background: var(--box-bg); padding: 10px 16px;
    border-radius: 8px; border: 1px solid var(--gold-border);
    width: 100%; max-width: 480px; font-size: 0.82rem;
}

/* ============ MOBILE KEYBOARD HANDLING ============ */
@media (max-height: 600px) {
    .box { width: 50px; height: 78px; }
    .char-display { font-size: 28px; height: 36px; }
    input#answer-input { font-size: 22px; }
    .boxes-container { gap: 5px; margin-bottom: 14px; }
}

/* ============ SMALL PHONE ============ */
@media (max-width: 360px) {
    .box { width: 52px; height: 82px; }
    .char-display { font-size: 30px; }
    .dots { font-size: 16px; }
    input#answer-input { font-size: 22px; }
}

/* ============ القوائم المبسطة ============ */
.simple-modal {
    background: #ffffff; 
    padding: 15px;
    border-radius: 6px; 
    text-align: center;
    width: 90%;
    max-width: 320px; 
    border: 2px solid #2b1d14; 
    box-shadow: none;
}

.modal-title { margin: 0 0 15px 0; font-family: 'Tajawal', sans-serif; color: #2b1d14; font-size: 1.1rem; font-weight: 900; }
.simple-btn-group { display: flex; flex-direction: column; gap: 6px; }
.btn-flat {
    width: 100%; padding: 10px;
    border: 2px solid transparent; border-radius: 4px;
    font-size: 0.95rem; font-weight: bold; font-family: 'Tajawal', sans-serif;
    cursor: pointer; outline: none; transition: background 0.1s;
}

.btn-flat.primary { background: #8e24aa; color: #fff; }
.btn-flat.secondary { background: #a67c00; color: #fff; }
.btn-flat.outline { background: transparent; border-color: #594336; color: #2b1d14; }
.btn-flat.danger { background: #c62828; color: #fff; margin-top: 5px; }
.btn-flat.action { background: #2e7d32; color: #fff; width: auto; padding: 10px 15px; }

.simple-input-group { display: flex; gap: 4px; margin-top: 4px; }
.input-flat {
    flex: 1; padding: 8px;
    border: 2px solid #594336; border-radius: 4px;
    text-align: center; font-size: 1rem; font-family: 'Tajawal', sans-serif;
    outline: none; background: #fffcf5; color: #2b1d14;
}
.input-flat:focus { border-color: #8e24aa; }
/* ============ إضافات الـ Juiciness للخبرة ============ */
.xp-bar-fill { 
    box-shadow: 0 0 12px var(--success-green); 
}
.xp-tick { 
    display: inline-block;
    animation: popTick 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
}
@keyframes popTick { 
    0% { transform: scale(1); } 
    50% { transform: scale(1.4); color: var(--gold-accent); } 
    100% { transform: scale(1); } 
}
/* ============ تأثيرات السلاسة (Juiciness) ============ */
/* تلاشي الشاشات بنعومة */
.fade-in { 
    animation: smoothFade 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; 
}
@keyframes smoothFade { 
    0% { opacity: 0; transform: translateY(8px); } 
    100% { opacity: 1; transform: translateY(0); } 
}

/* قفزة الحروف عند الكتابة */
@keyframes popChar { 
    0% { transform: scale(0.5); opacity: 0; } 
    60% { transform: scale(1.3); opacity: 1; } 
    100% { transform: scale(1); opacity: 1; } 
}
.pop-char { 
    animation: popChar 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
}

/* نعومة استجابة الأزرار والمربعات */
.btn-menu, .btn-action, .start-btn { 
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s ease, box-shadow 0.2s ease !important; 
}
.box { 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
}
.box.filled {
    box-shadow: 0 6px 12px rgba(166,124,0,0.25);
}
/* ============ تأثير التغبيش لطور السرعة ============ */
.blurred-boxes {
    filter: blur(10px) grayscale(30%);
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
    transition: filter 0.3s ease, opacity 0.3s ease;
}
/* ============ الإضافات البصرية العميقة (Juiciness) ============ */
.floating-text {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Tajawal', sans-serif;
    font-weight: 900;
    font-size: 1.8rem;
    pointer-events: none;
    z-index: 5000;
    animation: floatUp 1.2s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
    text-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -30px) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -80px) scale(0.8); }
}

.success-glow {
    border-bottom-color: var(--success-green) !important;
    color: var(--success-green) !important;
    text-shadow: 0 0 15px rgba(46, 125, 50, 0.5);
    transform: translateY(-2px);
}

/* ============ رسالة بدء التحدي ============ */
.speed-start-overlay {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Tajawal', sans-serif;
    font-size: 1.3rem;
    font-weight: 900;
    background: var(--ink-dark);
    color: var(--paper-bg);
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 100;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    border: 2px solid var(--gold-accent);
}

/* ============ بطاقة الارتقاء الأكاديمي (Level Up) ============ */
/* إخفاء التنسيق القديم إن وُجد */
h1.level-text { text-shadow: none !important; margin: 0 !important; }

.level-up-card {
    background: var(--paper-bg);
    border: 4px double var(--gold-accent);
    border-radius: 12px;
    padding: 35px 50px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5), inset 0 0 20px rgba(166,124,0,0.1);
    animation: academicStamp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    position: relative;
    max-width: 350px;
    width: 90%;
}

.level-icon-wrapper {
    font-size: 2.5rem;
    color: var(--gold-accent);
    margin-bottom: 5px;
}

.level-subtitle {
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    color: var(--ink-light);
    margin: 0 0 10px 0;
    font-weight: 900;
    letter-spacing: 1px;
}

.level-text {
    color: var(--ink-dark) !important;
    font-family: 'Aref Ruqaa', serif;
    font-size: 3.5rem !important;
}

.level-divider {
    color: var(--gold-border);
    font-size: 0.8rem;
    margin-top: 15px;
    letter-spacing: 5px;
}

/* حركة الختم (القفز والارتداد) */
@keyframes academicStamp {
    0% { transform: scale(1.5) translateY(-20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}


/* ============ معرض المخطوطات النفيسة ============ */
.golden-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 10px;
    direction: rtl;
    -webkit-overflow-scrolling: touch;
}

.golden-card {
    background: linear-gradient(135deg, #fdfbf7 0%, #ecdac2 100%);
    border: 2px solid var(--gold-accent);
    border-radius: 4px;
    height: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 4px 12px rgba(166,124,0,0.15);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease;
}

.golden-card::before {
    content: '';
    position: absolute;
    top: 4px; left: 4px; right: 4px; bottom: 4px;
    border: 1px dashed var(--gold-border);
    pointer-events: none;
}

.golden-card span {
    font-family: 'Aref Ruqaa', serif;
    font-size: 1.8rem;
    color: var(--ink-dark);
    font-weight: bold;
    text-shadow: 1px 1px 0px rgba(255,255,255,0.7);
    z-index: 2;
}

/* حالة المخطوطة المجهولة (المقفلة) */
.golden-card.locked {
    background: #e8e1d5;
    border-color: #bfaea3;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
}

.golden-card.locked::before { border-color: #d1c8bd; }

.golden-card.locked span {
    filter: blur(4px);
    opacity: 0.4;
    user-select: none;
}

.golden-card.locked .lock-icon {
    position: absolute;
    font-size: 1.5rem;
    color: var(--ink-light);
    opacity: 0.6;
    z-index: 3;
}


/* ============ تصميم بطاقة تسجيل الدخول ============ */
.login-card {
    background: var(--paper-bg);
    padding: 40px 30px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25), 0 0 0 8px rgba(255,255,255,0.1);
    text-align: center;
    border: 2px solid var(--gold-accent);
    max-width: 420px;
    width: 90%;
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, transparent, var(--gold-accent), transparent);
}

.google-btn-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    transform: scale(1.1); /* تكبير الزر قليلاً ليبرز أكثر */
}

.login-footer {
    margin-top: 30px;
    font-size: 0.85rem;
    color: #999;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-top: 15px;
}

.login-footer i {
    color: var(--success-green);
    margin-left: 5px;
}