/* ============================================
   DINO RUN — STYLES
   ============================================ */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --accent: #e94560;
    --accent2: #f5a623;
    --accent3: #00d4aa;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --text-muted: #666;
    --danger: #ff4757;
    --success: #2ed573;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0,0,0,0.3);
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.3s cubic-bezier(.4,0,.2,1);
}

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

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

/* ========== SCREENS ========== */
.screen {
    display: none;
    width: 100%; height: 100%;
    position: absolute;
    top: 0; left: 0;
}
.screen.active { display: flex; }

/* ========== LOADING ========== */
#loading-screen {
    display: flex;
    align-items: center; justify-content: center;
    background: var(--bg-primary);
    z-index: 1000;
}
.loader { text-align: center; }
.dino-loader { font-size: 64px; animation: dinoBounce 0.8s infinite alternate; }
@keyframes dinoBounce {
    from { transform: translateY(0); }
    to { transform: translateY(-20px); }
}
.loader p { margin: 16px 0; color: var(--text-secondary); font-size: 14px; }
.loader-bar {
    width: 200px; height: 4px;
    background: var(--bg-card); border-radius: 4px;
    overflow: hidden; margin: 0 auto;
}
.loader-bar div {
    width: 30%; height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 4px;
    animation: loadBar 1.2s infinite ease-in-out;
}
@keyframes loadBar {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ========== AUTH ========== */
#auth-screen {
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    padding: 20px;
}
.auth-container {
    width: 100%; max-width: 420px;
}
.auth-box {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: var(--shadow);
}
.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}
.logo-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-logo h1 {
    font-size: 28px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 4px;
}
.tagline {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
}
.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-form h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--accent3);
}
.input-group {
    margin-bottom: 16px;
    position: relative;
}
.input-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.input-group input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    transition: var(--transition);
    outline: none;
}
.input-group input:focus {
    border-color: var(--accent3);
    box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.15);
    background: rgba(255,255,255,0.12);
}
.input-group input::placeholder { color: var(--text-muted); }
.input-group small {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}
.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.toggle-pass {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    opacity: 0.6;
    transition: var(--transition);
}
.toggle-pass:hover { opacity: 1; }

.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #ff6b81);
    color: white;
    margin-top: 8px;
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.4);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-sm {
    width: auto;
    padding: 8px 16px;
    font-size: 13px;
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
}
.btn-sm:hover { background: rgba(255,255,255,0.2); }

.spinner {
    display: none;
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-text { display: none; }

.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.auth-switch a { color: var(--accent3); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-top: 10px;
    display: none;
    text-align: center;
}

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

#game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 50px;
    z-index: 10;
}
.user-info { display: flex; align-items: center; gap: 8px; }
#player-avatar { font-size: 24px; }
#player-name { font-size: 14px; font-weight: 600; }
.header-center { position: absolute; left: 50%; transform: translateX(-50%); }
.game-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.header-actions { display: flex; gap: 4px; }
.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    opacity: 0.7;
}
.icon-btn:hover { opacity: 1; background: rgba(255,255,255,0.1); }

#game-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}
#gameCanvas {
    display: block;
    width: 100%; height: 100%;
    background: var(--bg-primary);
}

#game-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
#game-message {
    text-align: center;
    padding: 24px 40px;
    background: rgba(0,0,0,0.7);
    border-radius: var(--radius);
    backdrop-filter: blur(8px);
    pointer-events: none;
}
#game-message h2 { font-size: 28px; margin-bottom: 8px; }
#game-message p { font-size: 14px; color: var(--text-secondary); }
#game-message kbd {
    background: rgba(255,255,255,0.15);
    padding: 2px 10px;
    border-radius: 4px;
    font-family: var(--font);
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.2);
}
.hidden { display: none !important; }

#touch-zone {
    display: none;
    position: absolute;
    bottom: 0; left: 0;
    width: 100%; height: 40%;
    pointer-events: none;
}
.touch-half {
    position: absolute;
    width: 50%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: rgba(255,255,255,0.2);
    pointer-events: auto;
}
#touch-left { left: 0; }
#touch-right { right: 0; }

/* ========== HUD ========== */
#game-hud {
    display: flex;
    justify-content: space-around;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid rgba(255,255,255,0.06);
}
.hud-item {
    text-align: center;
    min-width: 70px;
}
.hud-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.hud-item span:last-child {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent3);
}
#combo-display { color: var(--accent2); }

/* ========== MODAL ========== */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 100; }
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-backdrop {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}
.modal-content {
    position: relative;
    width: 90%; max-width: 500px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-header h2 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: white; }
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    justify-content: flex-end;
}

/* ========== LEADERBOARD ========== */
.leaderboard-tabs {
    display: flex;
    padding: 10px 16px 0;
    gap: 4px;
}
.lb-tab {
    flex: 1;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    font-family: var(--font);
}
.lb-tab.active {
    color: var(--accent3);
    border-bottom-color: var(--accent3);
}
.lb-tab:hover { color: var(--text-primary); }

#leaderboard-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 200px;
}
.lb-loading, .lb-empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.lb-entry {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    transition: var(--transition);
    gap: 12px;
}
.lb-entry:hover { background: rgba(255,255,255,0.05); }
.lb-entry.is-player {
    background: rgba(0, 212, 170, 0.1);
    border: 1px solid rgba(0, 212, 170, 0.2);
}
.lb-rank {
    width: 28px;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
}
.lb-rank-1 { color: gold; }
.lb-rank-2 { color: silver; }
.lb-rank-3 { color: #cd7f32; }
.lb-avatar { font-size: 20px; }
.lb-name { flex: 1; font-size: 14px; font-weight: 500; }
.lb-score { font-size: 16px; font-weight: 700; color: var(--accent2); }
.lb-date { font-size: 11px; color: var(--text-muted); min-width: 70px; text-align: right; }

/* ========== SETTINGS ========== */
.settings-body {
    padding: 16px 20px;
    overflow-y: auto;
}
.setting-group {
    margin-bottom: 20px;
}
.setting-group h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}
.character-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.char-option {
    padding: 12px;
    text-align: center;
    background: rgba(255,255,255,0.06);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}
.char-option:hover { background: rgba(255,255,255,0.1); }
.char-option.active {
    border-color: var(--accent3);
    background: rgba(0, 212, 170, 0.1);
}
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    cursor: pointer;
    gap: 12px;
}
.toggle-row span:first-child { font-size: 14px; flex: 1; }
.toggle-row input[type=checkbox] { display: none; }
.toggle-switch {
    width: 44px; height: 24px;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 20px; height: 20px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}
.toggle-row input:checked + .toggle-switch {
    background: var(--accent3);
}
.toggle-row input:checked + .toggle-switch::after {
    transform: translateX(20px);
}

/* ========== ACHIEVEMENT TOAST ========== */
#achievement-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
    border: 1px solid var(--accent2);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: slideInRight 0.4s cubic-bezier(.4,0,.2,1);
    min-width: 250px;
}
@keyframes slideInRight {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.ach-icon { font-size: 32px; }
.ach-text { flex: 1; }
.ach-title { font-size: 13px; font-weight: 700; color: var(--accent2); }
.ach-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ========== TOASTS ========== */
#toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}
.toast {
    padding: 10px 20px;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    animation: toastIn 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--accent3); }
@keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 600px) {
    .auth-box { padding: 24px 20px; }
    .input-row { grid-template-columns: 1fr; gap: 0; }
    .auth-logo h1 { font-size: 22px; }
    #touch-zone { display: flex !important; }
    #game-message h2 { font-size: 22px; }
    .game-title { display: none; }
    .header-center { display: none; }
}

@media (max-height: 500px) {
    .auth-logo { margin-bottom: 12px; }
    .logo-icon { font-size: 32px; }
    .auth-logo h1 { font-size: 20px; }
    .auth-box { padding: 16px; }
    .input-group { margin-bottom: 10px; }
    .input-group input { padding: 8px 12px; }
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ========== DEATH SCREEN OVERLAY ========== */
.death-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}
.death-overlay h2 { font-size: 32px; }
.death-overlay .final-score { font-size: 18px; color: var(--accent2); }
.death-overlay .new-record { font-size: 14px; color: gold; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.death-overlay .btn {
    max-width: 200px;
    margin-top: 8px;
}

/* Score popup */
.score-popup {
    position: absolute;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent2);
    pointer-events: none;
    animation: floatUp 0.8s ease-out forwards;
}
@keyframes floatUp {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-60px); opacity: 0; }
}