@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: #0b0f1a;
    color: #f1f5f9;
    margin: 0; padding: 0 0 40px;
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Vibrant background mesh */
body::before {
    content: '';
    position: fixed; inset: 0;
    background:
        radial-gradient(ellipse 70% 40% at 15% 0%,   rgba(239,68,68,0.12) 0%, transparent 55%),
        radial-gradient(ellipse 50% 35% at 85% 5%,   rgba(56,189,248,0.1) 0%, transparent 55%),
        radial-gradient(ellipse 60% 40% at 50% 100%,  rgba(139,92,246,0.08) 0%, transparent 55%);
    pointer-events: none; z-index: 0;
}

/* ── GRID ── */
#main-menu-wrapper {
    width: 100%;
    max-width: 1300px;
    margin: 16px auto 0;
    padding: 0 20px;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr 1.9fr 1fr;
    gap: 16px;
    align-items: start;
    position: relative; z-index: 1;
}

/* ── GLASS CARD ── */
.menu-box {
    background: linear-gradient(145deg, rgba(22,28,46,0.95), rgba(14,20,36,0.95));
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
    max-width: 100%;
    margin: 0 auto;
    padding: 24px 22px;
    position: relative;
}

.side-panel {
    background: linear-gradient(145deg, rgba(18,24,42,0.97), rgba(12,17,32,0.97));
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

/* ── LOGO & TITLE ── */
.logo-container { margin-bottom: 6px; text-align: center; }
.menu-logo { max-width: 70%; height: auto; max-height: 68px; }

h1 {
    color: #ef4444;
    margin: 0 0 4px;
    font-size: 26px;
    text-transform: uppercase;
    letter-spacing: 5px;
    font-weight: 900;
    text-shadow: 0 0 30px rgba(239,68,68,0.4);
}

/* ── BUTTONS ── */
button {
    font-family: 'Inter', sans-serif;
    color: white;
    border: none;
    padding: 13px 24px;
    font-size: 14px; font-weight: 700;
    cursor: pointer;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
    transition: all 0.18s ease;
    margin-top: 8px;
}

#start-btn {
    background: linear-gradient(135deg, #ef4444 0%, #c62828 100%);
    box-shadow: 0 4px 24px rgba(239,68,68,0.4);
}
#start-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(239,68,68,0.55); }

label {
    display: block; text-align: left;
    margin-top: 12px; font-weight: 600;
    color: #64748b; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.8px;
}

input {
    width: 100%;
    padding: 11px 14px;
    margin: 5px 0 14px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: #f1f5f9;
    border-radius: 10px;
    font-size: 14px; font-family: 'Inter', sans-serif;
    transition: border-color 0.15s, background 0.15s;
}
input:focus { border-color: #38bdf8; outline: none; background: rgba(56,189,248,0.07); }

/* ── LEADERBOARD ROWS ── */
.lb-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 6px;
    border-radius: 10px;
    transition: background 0.15s;
    margin-bottom: 3px;
}
.lb-row:hover { background: rgba(255,255,255,0.04); }
.lb-row.lb-me { background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2); }
.lb-row.lb-top1 { background: rgba(251,191,36,0.08); }
.lb-row.lb-top2 { background: rgba(148,163,184,0.06); }
.lb-row.lb-top3 { background: rgba(180,120,60,0.07); }

.lb-rank {
    width: 22px; text-align: center;
    font-weight: 800; font-size: 13px;
    flex-shrink: 0; color: #475569;
}
.lb-rank.gold   { color: #fbbf24; font-size: 16px; }
.lb-rank.silver { color: #94a3b8; font-size: 16px; }
.lb-rank.bronze { color: #b87c3c; font-size: 16px; }

.lb-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 13px;
    flex-shrink: 0; color: #fff;
    border: 2px solid rgba(255,255,255,0.15);
}

.lb-info { flex: 1; min-width: 0; text-align: left; }
.lb-name { font-weight: 700; font-size: 13px; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-name.me { color: #22c55e; }
.lb-score-badge {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 7px; padding: 3px 8px;
    font-size: 11px; font-weight: 700; color: #94a3b8;
    white-space: nowrap; flex-shrink: 0;
}

ol { padding-left: 22px; margin: 0; }
li { padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,0.04); color: #64748b; font-size: 13px; }
li b { color: #f1f5f9; }
li:last-child { border-bottom: none; }

/* ── CHAR SELECT ── */
#char-selector > div:hover:not([style*="not-allowed"]) {
    border-color: #38bdf8 !important;
    background: rgba(56,189,248,0.08) !important;
    transform: translateX(3px);
}

/* ── STAT BAR ── */
.stat-bar-wrap { margin-bottom: 6px; text-align: left; }
.stat-bar-label { display: flex; justify-content: space-between; font-size: 10px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 3px; }
.stat-bar-track { height: 5px; background: rgba(255,255,255,0.08); border-radius: 10px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 10px; transition: width 0.4s ease; }

/* ── MISC ── */
.red-text    { color: #ef4444; animation: blink 1s infinite; }
.cyan-text   { color: #38bdf8; }
.green-text  { color: #22c55e; }
.yellow-text { color: #eab308; }
@keyframes blink { 50% { opacity: 0.4; } }

/* ── GAME CONTAINER ── */
#game-container {
    max-width: 1100px; margin: 16px auto;
    position: relative; border-radius: 14px;
    overflow: hidden;
    border: 1.5px solid rgba(239,68,68,0.35);
    box-shadow: 0 0 50px rgba(239,68,68,0.12), 0 20px 80px rgba(0,0,0,0.7);
}
#game-container { width: 100%; overflow: hidden; }
#game { width: 100% !important; max-width: 1000px; height: auto !important; display: block; touch-action: manipulation; }
canvas { display: block; width: 100%; height: auto; }

/* ── HUD ── */
#hud {
    display: flex; justify-content: space-between; align-items: center;
    background: rgba(11,15,26,0.97);
    padding: 10px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-wrap: wrap; gap: 8px;
    backdrop-filter: blur(10px);
}
.hud-sc { display: flex; gap: 20px; font-weight: 700; font-size: 14px; align-items: center; }
.hud-right { display: flex; align-items: center; gap: 12px; }
.health-container { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.health-bar-border { width: 110px; height: 7px; background: rgba(255,255,255,0.08); border-radius: 10px; overflow: hidden; }
.health-bar-fill { width: 100%; height: 100%; background: linear-gradient(90deg, #ef4444, #dc2626); transition: width 0.25s; border-radius: 10px; }
#pause-btn {
    background: rgba(255,255,255,0.06); color: #94a3b8; width: auto;
    padding: 7px 14px; font-size: 11px;
    border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;
    font-weight: 600; cursor: pointer; margin: 0; letter-spacing: 0.5px;
}

/* ── PAUSE ── */
#pause-screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(11,15,26,0.94); display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: 5;
    backdrop-filter: blur(10px);
}

/* ── GAME OVER ── */
#game-over-screen { position: relative; overflow: hidden; }
#game-over-screen::before {
    content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(ellipse at center, rgba(239,68,68,0.09) 0%, transparent 70%);
    pointer-events: none; animation: goGlow 2s ease-in-out infinite alternate;
}
@keyframes goGlow { from { opacity:0.5; transform:scale(0.95); } to { opacity:1; transform:scale(1.05); } }
.go-crash-title { font-size:36px !important; color:#ef4444 !important; text-shadow:0 0 30px #ef4444; animation:crashShake 0.15s infinite,blink 0.8s infinite; letter-spacing:4px; }
@keyframes crashShake { 0%{transform:translateX(-2px)} 50%{transform:translateX(2px)} 100%{transform:translateX(0)} }
.go-score-big { font-size:48px !important; font-weight:900; color:#f59e0b !important; text-shadow:0 0 20px rgba(245,158,11,0.4); display:block; margin:8px 0 4px; }
.go-subtitle { color:#475569; font-size:12px; margin-bottom:18px; text-transform:uppercase; letter-spacing:2px; }
.go-stars { font-size:26px; margin:6px 0; }

/* ── SHARE ── */
.share-buttons { display:flex; gap:8px; margin:10px 0; flex-wrap:wrap; }
.share-btn { flex:1; min-width:110px; padding:10px 12px; font-size:12px; font-weight:700; border-radius:10px; cursor:pointer; border:none; color:#fff; display:flex; align-items:center; justify-content:center; gap:6px; margin:0; transition:all 0.18s; }
.share-btn:hover { transform:translateY(-2px); filter:brightness(1.12); }
.share-btn-wa { background:linear-gradient(135deg,#25D366,#128C7E); }
.share-btn-ig { background:linear-gradient(135deg,#E1306C,#833AB4); }
.share-btn-copy { background:rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.12) !important; }

/* ── CHAT ── */
.kf-chat-wrap { width:100%; background:rgba(11,15,26,0.97); border-top:1px solid rgba(255,255,255,0.06); display:flex; flex-direction:column; }
.kf-chat-wrap.gameover-style { border-top:none; border:1px solid rgba(255,255,255,0.07); border-radius:12px; overflow:hidden; margin-top:14px; }
.kf-chat-wrap.pause-style { border-top:none; border:1px solid rgba(255,255,255,0.07); border-radius:10px; overflow:hidden; width:90%; max-width:480px; margin:0 auto; }
.kf-chat-header { background:rgba(255,255,255,0.04); padding:7px 14px; font-size:11px; font-weight:700; color:#38bdf8; text-transform:uppercase; letter-spacing:1.5px; display:flex; align-items:center; gap:7px; }
.kf-chat-dot { width:6px; height:6px; background:#22c55e; border-radius:50%; animation:blink 1.5s infinite; flex-shrink:0; }
.kf-chat-msgs { height:110px; overflow-y:auto; padding:6px 12px; display:flex; flex-direction:column; gap:3px; scrollbar-width:thin; scrollbar-color:rgba(255,255,255,0.08) transparent; }
.kf-chat-msgs::-webkit-scrollbar { width:4px; }
.kf-chat-msgs::-webkit-scrollbar-thumb { background:rgba(255,255,255,0.08); border-radius:2px; }
.chat-msg { font-size:12px; line-height:1.5; color:#64748b; word-break:break-word; }
.chat-msg .chat-name { font-weight:700; color:#38bdf8; margin-right:4px; }
.chat-msg .chat-time { font-size:10px; color:#1e293b; margin-left:5px; }
.chat-msg.own .chat-name { color:#22c55e; }
.kf-chat-input-zone { border-top:1px solid rgba(255,255,255,0.05); background:rgba(0,0,0,0.3); padding:8px 10px; display:flex; flex-direction:column; gap:6px; }
.kf-chat-name-row input,.kf-chat-msg-row input { background:rgba(255,255,255,0.05) !important; border:1px solid rgba(255,255,255,0.1) !important; border-radius:8px !important; color:#e2e8f0 !important; font-size:12px !important; padding:9px 12px !important; outline:none !important; width:100% !important; transition:border-color 0.15s; }
.kf-chat-name-row input:focus,.kf-chat-msg-row input:focus { border-color:#38bdf8 !important; }
.kf-chat-name-row input::placeholder,.kf-chat-msg-row input::placeholder { color:#334155 !important; }
.kf-chat-msg-row { display:flex; gap:8px; align-items:center; }
.kf-chat-msg-row input { flex:1 !important; width:auto !important; }
.kf-send-btn { background:linear-gradient(135deg,#38bdf8,#0284c7) !important; color:#fff !important; border:none !important; border-radius:8px !important; padding:9px 16px !important; font-size:12px !important; font-weight:700 !important; cursor:pointer !important; white-space:nowrap !important; flex-shrink:0 !important; width:auto !important; margin:0 !important; transition:opacity 0.15s; }
.kf-send-btn:hover { opacity:0.85; }
.kf-who-label { font-size:10px; color:#334155; text-align:right; padding:0 2px 2px; }
.kf-who-label b { color:#38bdf8; }

/* ── RANK NOTIF ── */
#kf-rank-notif { position:fixed; top:20px; left:50%; transform:translateX(-50%); background:rgba(11,15,26,0.96); border:1px solid rgba(239,68,68,0.4); border-radius:14px; padding:12px 22px; color:#f1f5f9; font-size:13px; font-weight:600; text-align:center; z-index:9999999; box-shadow:0 4px 30px rgba(239,68,68,0.25); animation:rankNotifIn 0.3s ease,rankNotifOut 0.4s ease 4.6s forwards; pointer-events:none; line-height:1.5; backdrop-filter:blur(16px); }
#kf-rank-notif b { color:#ef4444; }
@keyframes rankNotifIn { from{opacity:0;transform:translateX(-50%) translateY(-16px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }
@keyframes rankNotifOut { from{opacity:1} to{opacity:0;transform:translateX(-50%) translateY(-10px)} }

.kf-badge-tag { display:inline-block; font-size:12px; vertical-align:middle; margin-right:2px; }
#powerup-hud { display:inline-flex; align-items:center; gap:5px; font-size:13px; font-weight:700; }

/* ── TUTORIAL ── */
#tutorial-overlay { display:none; position:absolute; top:0; left:0; width:100%; height:100%; background:rgba(11,15,26,0.9); z-index:10; flex-direction:column; align-items:center; justify-content:center; pointer-events:none; }
#tutorial-overlay.active { display:flex; }
.tutorial-text { color:#38bdf8; font-size:18px; font-weight:800; text-transform:uppercase; letter-spacing:2px; text-align:center; padding:0 20px; text-shadow:0 0 20px #38bdf8; animation:tutorialPulse 0.6s ease-in-out infinite alternate; }
.tutorial-arrow { font-size:44px; margin-top:12px; animation:tutorialBounce 0.5s ease-in-out infinite alternate; }
@keyframes tutorialPulse { from{opacity:0.7} to{opacity:1} }
@keyframes tutorialBounce { from{transform:translateY(0)} to{transform:translateY(-10px)} }

/* ── RESPONSIVE ── */
@media (max-width:900px) {
    #main-menu-wrapper { grid-template-columns:1fr !important; max-width:500px !important; }
    #main-menu-wrapper > div:first-child, #main-menu-wrapper > div:last-child { position:static !important; }
}
@media screen and (max-width:600px) and (orientation:portrait) {
    #game-container { margin:5px; border-radius:10px; }
    .hud-sc { font-size:10px; gap:8px; }
    #pause-btn { font-size:9px; padding:5px 8px; }
    .health-bar-border { width:70px; }
    .menu-box { margin:12px auto; padding:16px; }
    h1 { font-size:20px; }
}
@media screen and (orientation:landscape) and (max-height:500px) {
    html { overflow:hidden; height:100dvh; }
    body { overflow:hidden; height:100dvh; margin:0; padding:0; display:flex; flex-direction:column; align-items:center; }
    #game-container { margin:0 auto; width:100%; max-width:100%; max-height:100%; border-radius:0; border-left:none; border-right:none; overflow:hidden; flex-shrink:1; }
    #hud { padding:4px 10px; gap:6px; flex-wrap:nowrap; }
    .hud-sc { font-size:10px; gap:6px; }
    #pause-btn { font-size:9px; padding:3px 7px; }
    .health-bar-border { width:60px; height:7px; }
    canvas { display:block; width:100% !important; height:auto !important; max-width:100%; max-height:calc(100vh - 44px); }
    .menu-box { margin:6px auto; padding:12px; max-width:90vw; }
    h1 { font-size:18px; }
    .kf-chat-wrap { display:none; }
    body > *:not(#game-container):not(#kf-rank-notif) { display:none !important; }
    body.menu-active > .menu-box { display:block !important; }
}
