:root {
    --bg: #0F1219;
    --primary: #64748B;
    --secondary: #94A3B8;
    --accent: #38BDF8;
    --error: #EF4444;
    --success: #10B981;
}

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

body {
    background: var(--bg);
    color: #fff;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    /* Apply screen shake here */
    transform: translate(0, 0);
}

.shake {
    animation: shake 0.3s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-2px, 2px, 0);
    }

    20%,
    80% {
        transform: translate3d(4px, -2px, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-6px, 4px, 0);
    }

    40%,
    60% {
        transform: translate3d(6px, -4px, 0);
    }
}

#flash-overlay {
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 999;
}

.flash {
    animation: flash 0.4s ease-out;
}

@keyframes flash {
    0% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;
    }
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Hidden input for keyboard on mobile/desktop */
#hidden-input {
    position: absolute;
    opacity: 0.01;
    width: 1px;
    height: 1px;
    top: -100px;
    left: -100px;
}

#ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.panel {
    background: rgba(15, 18, 25, 0.85);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    pointer-events: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    max-width: 90%;
    width: 400px;
    transition: all 0.3s ease;
}

.hidden {
    display: none !important;
}

h1 {
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent);
    margin-bottom: 10px;
    letter-spacing: -1px;
}

h2 {
    color: #fff;
    margin-bottom: 30px;
    font-size: 1.5rem;
}

p {
    color: var(--secondary);
    margin-bottom: 30px;
    font-size: 0.9rem;
}

.mobile-hint {
    margin-top: 15px;
    margin-bottom: 0;
    font-size: 0.8rem;
    opacity: 0.5;
}

.lang-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
}

.lang-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.lang-btn.active {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

button {
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 15px 20px;
    border-radius: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    width: 100%;
    pointer-events: auto;
}

button:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(1px);
}

button.outline {
    background: transparent;
    border: 1px solid var(--secondary);
    color: var(--secondary);
}

button.outline:hover {
    color: #fff;
    border-color: #fff;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.stat-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 15px 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-box .label {
    display: block;
    font-size: 0.7rem;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 5px;
}

.stat-box .value {
    display: block;
    font-size: 1.5rem;
    font-weight: 900;
    color: #fff;
}

#countdown-layer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#countdown-text {
    font-size: 10rem;
    color: #fff;
    opacity: 0;
    text-shadow: 0 0 50px var(--accent);
    animation: popIn 1s ease-out;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    20% {
        transform: scale(1.2);
        opacity: 1;
    }

    80% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Leaderboard */
#lb-list {
    text-align: left;
    margin-bottom: 30px;
    max-height: 250px;
    overflow-y: auto;
}

.lb-row {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-rank {
    color: var(--accent);
    font-weight: bold;
    width: 30px;
}

.lb-score {
    color: var(--success);
}

/* Glitch Title */
.glitch-text {
    position: relative;
    display: inline-block;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.glitch-text::before {
    left: 2px;
    text-shadow: -2px 0 var(--error);
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim 3s infinite linear alternate-reverse;
}

.glitch-text::after {
    left: -2px;
    text-shadow: -2px 0 var(--success);
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% {
        clip: rect(28px, 9999px, 86px, 0);
    }

    10% {
        clip: rect(21px, 9999px, 12px, 0);
    }

    20% {
        clip: rect(32px, 9999px, 5px, 0);
    }

    30% {
        clip: rect(54px, 9999px, 83px, 0);
    }

    40% {
        clip: rect(96px, 9999px, 32px, 0);
    }

    50% {
        clip: rect(65px, 9999px, 96px, 0);
    }

    60% {
        clip: rect(4px, 9999px, 25px, 0);
    }

    70% {
        clip: rect(38px, 9999px, 62px, 0);
    }

    80% {
        clip: rect(10px, 9999px, 45px, 0);
    }

    90% {
        clip: rect(32px, 9999px, 21px, 0);
    }

    100% {
        clip: rect(89px, 9999px, 73px, 0);
    }
}