:root {
    --bg-dark: #040711;
    --hud-bg: rgba(10, 15, 29, 0.88);
    --hud-border: rgba(99, 102, 241, 0.25);
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;
    --accent-indigo: #6366f1;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;
    color: var(--text-main);
}

.game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #090e1f 0%, #040711 100%);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.95);
}

.hud-bar {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--hud-bg);
    border-bottom: 1px solid var(--hud-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-center {
    flex: 1;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.hud-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hud-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.5);
}

.hud-btn.icon-only {
    padding: 6px 10px;
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 12px;
    font-weight: 700;
}

.stat-pill .label {
    color: var(--accent-cyan);
}

.stat-pill .val {
    color: var(--text-main);
    font-family: monospace;
}

.timer-display {
    font-family: monospace;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(6, 182, 212, 0.6);
}

.xp-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(6, 182, 212, 0.3);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}

.xp-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #06b6d4, #10b981, #38bdf8);
    box-shadow: 0 0 10px #06b6d4;
    transition: width 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.canvas-container {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.joystick-zone {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: auto;
    touch-action: none;
}

.joystick-base {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid rgba(6, 182, 212, 0.5);
    background: radial-gradient(circle, rgba(6, 182, 212, 0.15) 0%, rgba(6, 182, 212, 0.02) 70%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 25px rgba(6, 182, 212, 0.25);
}

.joystick-stick {
    position: absolute;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #38bdf8 0%, #0284c7 70%, #0369a1 100%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 16px #38bdf8;
    pointer-events: none;
}

.start-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(4, 7, 16, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.overlay-card {
    background: #0b1120;
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 18px;
    padding: 32px 26px;
    max-width: 450px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(99, 102, 241, 0.2);
}

.hero-icon {
    font-size: 46px;
    margin-bottom: 14px;
    filter: drop-shadow(0 0 16px rgba(6, 182, 212, 0.6));
}

.overlay-card h2 {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.overlay-card .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 22px;
}

.control-hints {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 24px;
    text-align: left;
    font-size: 12px;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.hint-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hint-badge {
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
    font-weight: 700;
    font-size: 11px;
}

.start-btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #6366f1 100%);
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(6, 182, 212, 0.45);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    letter-spacing: 0.02em;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(6, 182, 212, 0.65);
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    z-index: 30;
    background: rgba(2, 5, 12, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.modal-backdrop,
.modal-backdrop * {
    touch-action: pan-y;
}

.upgrade-window {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(6, 182, 212, 0.35) transparent;
    padding: 6px 8px;
    box-sizing: border-box;
    touch-action: pan-y;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.upgrade-window::-webkit-scrollbar,
.gameover-window::-webkit-scrollbar {
    width: 4px;
}

.upgrade-window::-webkit-scrollbar-thumb {
    background: rgba(6, 182, 212, 0.35);
    border-radius: 9999px;
}

.gameover-window::-webkit-scrollbar-thumb {
    background: rgba(239, 68, 68, 0.35);
    border-radius: 9999px;
}

.upgrade-header {
    text-align: center;
    margin-bottom: 20px;
}

.level-badge {
    display: inline-block;
    padding: 5px 16px;
    border-radius: 9999px;
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid rgba(245, 158, 11, 0.5);
    color: #fbbf24;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    margin-bottom: 8px;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.25);
}

.upgrade-header h3 {
    font-size: 22px;
    font-weight: 800;
    color: #ffffff;
}

.cards-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.upgrade-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.upgrade-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent-cyan);
    background: linear-gradient(90deg, rgba(15, 23, 42, 0.98), rgba(6, 182, 212, 0.18));
    box-shadow: 0 10px 28px rgba(6, 182, 212, 0.35), inset 0 0 12px rgba(6, 182, 212, 0.08);
}

.card-icon {
    font-size: 30px;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.05);
}

.card-info {
    flex: 1;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.card-name {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
}

.card-lvl {
    font-size: 11px;
    font-weight: 800;
    color: var(--accent-cyan);
    font-family: monospace;
}

.card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.gameover-window {
    background: #0b1120;
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 18px;
    padding: 32px 26px;
    max-width: 420px;
    max-height: 90vh;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(239, 68, 68, 0.35) transparent;
    touch-action: pan-y;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 35px rgba(239, 68, 68, 0.2);
}

.gameover-skull {
    font-size: 42px;
    margin-bottom: 12px;
}

.gameover-window h2 {
    font-size: 24px;
    font-weight: 800;
    color: #ef4444;
    margin-bottom: 20px;
}

.score-summary {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
}

.summary-val {
    font-weight: 700;
    color: #ffffff;
    font-family: monospace;
}

.summary-item.highlight {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 10px;
    margin-top: 4px;
}

.summary-item.highlight .summary-val {
    color: #f59e0b;
}

.restart-btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.45);
    transition: all 0.2s ease;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(239, 68, 68, 0.65);
}

.hidden {
    display: none !important;
}

@media (max-height: 650px) {
    .upgrade-header {
        margin-bottom: 12px;
    }
    .level-badge {
        padding: 3px 12px;
        font-size: 11px;
        margin-bottom: 4px;
    }
    .upgrade-header h3 {
        font-size: 18px;
    }
    .cards-grid {
        gap: 8px;
    }
    .upgrade-card {
        padding: 10px 14px;
        gap: 12px;
    }
    .card-icon {
        width: 38px;
        height: 38px;
        font-size: 24px;
    }
    .card-name {
        font-size: 14px;
    }
    .card-desc {
        font-size: 11px;
    }
}
