/* ============ DESIGN SYSTEM ============ */
:root {
    --bg: #0a0e1a;
    --bg2: #111827;
    --surface: #1e293b;
    --surface2: #334155;
    --border: rgba(255,255,255,0.08);
    --text: #f1f5f9;
    --text2: #94a3b8;
    --gold: #fbbf24;
    --gold2: #f59e0b;
    --red: #f43f5e;
    --green: #10b981;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --fire1: #ef4444;
    --fire2: #f97316;
    --emperor: #a855f7;
    --font: 'Inter', 'Tajawal', sans-serif;
    --radius: 16px;
    --radius-sm: 10px;
    --glass: rgba(30, 41, 59, 0.85);
    --glass-border: rgba(255,255,255,0.12);
}

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

html, body {
    width:100%; height:100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* ============ SCREENS ============ */
.screen {
    position: fixed; inset:0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1;
}
.screen.active { display: flex; }

/* ============ START SCREEN ============ */
#start-screen {
    background: radial-gradient(ellipse at 50% 30%, #1a1040 0%, var(--bg) 70%);
}

.bg-particles {
    position: absolute; inset:0;
    overflow: hidden; pointer-events: none;
}
.bg-particles span {
    position: absolute;
    width: 4px; height: 4px;
    background: var(--gold);
    border-radius: 50%;
    opacity: 0;
    animation: floatParticle 6s infinite ease-in-out;
}

@keyframes floatParticle {
    0%   { opacity:0; transform: translateY(100vh) scale(0); }
    20%  { opacity:0.8; }
    100% { opacity:0; transform: translateY(-20vh) scale(1.5); }
}

.start-content {
    position: relative; z-index:2;
    text-align: center;
    animation: fadeInUp 0.8s ease;
}

.logo-glow {
    width: 180px; height: 180px;
    margin: 0 auto 20px;
    background: radial-gradient(circle, rgba(251,191,36,0.15) 0%, transparent 70%);
    border-radius: 50%;
    animation: pulseGlow 3s infinite ease-in-out;
}

@keyframes pulseGlow {
    0%, 100% { transform: scale(1); opacity:0.6; }
    50% { transform: scale(1.15); opacity:1; }
}

.game-title {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -1px;
    margin-top: -100px;
}
.title-icon { font-size: 3rem; margin-left: 12px; }
.title-text {
    background: linear-gradient(135deg, var(--gold), #fde68a, var(--gold2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.3rem;
    color: var(--text2);
    margin-top: 8px;
    font-weight: 600;
}

.start-buttons {
    margin-top: 40px;
    display: flex; flex-direction: column;
    gap: 14px; align-items: center;
}

.start-hint {
    margin-top: 30px;
    font-size: 0.85rem;
    color: var(--text2);
    opacity: 0.6;
}

/* ============ BUTTONS ============ */
.btn {
    font-family: var(--font);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 14px 44px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    justify-content: center;
    transition: all 0.25s ease;
    min-width: 220px;
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute; inset:0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity 0.25s;
}
.btn:hover::after { opacity:1; }

.btn-primary {
    background: linear-gradient(135deg, var(--gold), var(--gold2));
    color: #1a1a2e;
    box-shadow: 0 4px 20px rgba(251,191,36,0.3);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(251,191,36,0.45);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--glass-border);
}
.btn-secondary:hover {
    background: var(--surface2);
    transform: translateY(-2px);
}

.btn-hell {
    background: linear-gradient(135deg, var(--fire1), var(--fire2));
    color: white;
    box-shadow: 0 4px 20px rgba(239,68,68,0.35);
    animation: hellPulse 2s infinite ease-in-out;
}
@keyframes hellPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(239,68,68,0.35); }
    50% { box-shadow: 0 4px 35px rgba(239,68,68,0.6); }
}
.btn-hell:hover { transform: translateY(-2px) scale(1.02); }

.btn-ghost {
    background: transparent;
    color: var(--text2);
    border: 1px solid var(--border);
    min-width: auto;
    padding: 10px 30px;
    font-size: 0.95rem;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text2); }

/* ============ GAME SCREEN ============ */
#game-screen {
    background: var(--bg);
    flex-direction: column;
    gap: 0;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 24px;
    background: var(--surface);
    border-bottom: 2px solid var(--cyan);
    z-index: 5;
    min-height: 56px;
}
.header-item {
    display: flex; flex-direction: column;
    align-items: center; gap: 2px;
}
.header-label {
    font-size: 0.7rem;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.header-value {
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--text);
}
.level-badge .header-value {
    color: var(--green);
    font-size: 1rem;
}
.level-badge.hell .header-value {
    color: var(--fire1);
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

#game-canvas {
    border-radius: var(--radius-sm);
    box-shadow: 0 0 40px rgba(6,182,212,0.08);
    image-rendering: pixelated;
}

/* ============ MOBILE CONTROLS ============ */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 0 20px;
}
.ctrl-row { display: flex; gap: 6px; }
.ctrl-btn {
    width: 58px; height: 58px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
}
.ctrl-btn:active { background: var(--surface2); transform: scale(0.92); }

@media (max-width: 768px) {
    .mobile-controls { display: flex; }
    .start-hint { display: none; }
    .game-title { font-size: 2.2rem; }
}

/* ============ MODALS ============ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-overlay.active { display: flex; }

.glass-modal {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 36px 40px;
    text-align: center;
    max-width: 420px;
    width: 100%;
    position: relative;
    animation: modalIn 0.4s ease;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

@keyframes modalIn {
    from { opacity:0; transform: scale(0.9) translateY(20px); }
    to { opacity:1; transform: scale(1) translateY(0); }
}

@keyframes fadeInUp {
    from { opacity:0; transform: translateY(30px); }
    to { opacity:1; transform: translateY(0); }
}

.modal-close {
    position: absolute;
    top: 14px; left: 14px;
    background: none; border: none;
    color: var(--text2);
    font-size: 1.3rem;
    cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

.modal-title {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 4px;
}
.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text2);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 20px;
}

.gold-text { color: var(--gold); }
.red-text { color: var(--red); }
.emperor-text {
    background: linear-gradient(135deg, var(--emperor), #c084fc, var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 2.2rem;
}

.trophy-icon, .skull-icon, .star-icon, .emperor-crown {
    font-size: 3.5rem;
    margin-bottom: 12px;
    display: block;
}
.emperor-crown {
    font-size: 4rem;
    animation: crownFloat 2s infinite ease-in-out;
}
@keyframes crownFloat {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

.modal-stats {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin: 20px 0;
}
.stat {
    display: flex; flex-direction: column; gap: 4px;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.stat-value {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--gold);
}

.hell-prompt { margin: 20px 0 10px; }
.hell-question {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.fire-text {
    color: var(--fire1);
    font-weight: 900;
}
.hell-desc {
    font-size: 0.85rem;
    color: var(--text2);
}
.emperor-desc {
    color: var(--text2);
    margin-bottom: 10px;
}

.modal-buttons {
    display: flex; flex-direction: column;
    gap: 10px; align-items: center;
    margin-top: 20px;
}

/* ============ NAME ENTRY ============ */
.name-question {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text2);
}
.name-input-wrap { margin-bottom: 6px; }
.name-input {
    width: 100%;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    font-family: var(--font);
    font-size: 1.1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}
.name-input:focus { border-color: var(--gold); }
.name-input::placeholder { color: var(--text2); opacity: 0.5; }
.name-error {
    color: var(--red);
    font-size: 0.85rem;
    min-height: 22px;
    margin-top: 6px;
}

/* ============ LEADERBOARD ============ */
.leaderboard-modal {
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}
.tab-btn {
    font-family: var(--font);
    padding: 8px 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text2);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}
.tab-btn.active {
    background: var(--gold);
    color: #1a1a2e;
    border-color: var(--gold);
}
.tab-btn:hover:not(.active) { border-color: var(--text2); }

.leaderboard-table-wrap {
    flex: 1;
    overflow-y: auto;
    min-height: 200px;
}
.leaderboard-table-wrap::-webkit-scrollbar { width: 4px; }
.leaderboard-table-wrap::-webkit-scrollbar-track { background: transparent; }
.leaderboard-table-wrap::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.lb-table th {
    padding: 10px 8px;
    color: var(--text2);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    background: var(--glass);
}
.lb-table td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle;
}
.lb-table tr:hover td { background: rgba(255,255,255,0.03); }

.rank-cell { font-weight: 900; color: var(--text2); width: 40px; }
.rank-1 { color: var(--gold); font-size: 1.1rem; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.player-name { font-weight: 700; }
.title-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 6px;
}
.badge-king {
    background: linear-gradient(135deg, var(--gold), var(--gold2));
    color: #1a1a2e;
}
.badge-emperor {
    background: linear-gradient(135deg, var(--emperor), #c084fc);
    color: white;
}
.mode-hell { color: var(--fire1); font-weight: 700; }
.mode-normal { color: var(--green); }

.loading-spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--surface2);
    border-top-color: var(--gold);
    border-radius: 50%;
    margin: 40px auto;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ============ RESPONSIVE ============ */
@media (max-width: 500px) {
    .glass-modal { padding: 24px 20px; }
    .modal-title { font-size: 1.4rem; }
    .game-header { padding: 8px 12px; }
    .header-value { font-size: 1.1rem; }
    .btn { padding: 12px 30px; font-size: 1rem; min-width: 190px; }
    .modal-stats { gap: 20px; }
    .stat-value { font-size: 1.3rem; }
}
