:root {
    --bg-color: #0d0e12;
    --surface-color: #1a1c23;
    --primary-color: #00ff9d;
    /* Neon Green */
    --accent-color: #bf00ff;
    /* Neon Purple */
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --font-family: 'Inter', sans-serif;
    --grid-color: rgba(255, 255, 255, 0.03);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: relative;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 10px;
    position: relative;
    z-index: 50;
    /* Ensure header is above main overlays */
}

h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-board {
    display: flex;
    gap: 20px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.score-item .label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.score-item span:not(.label) {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
    height: 100%;
}

canvas {
    background-color: var(--surface-color);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    touch-action: none;
    /* Prevent scrolling while swiping */
}

/* Glassmorphism Overlay */
.overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: rgba(13, 14, 18, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 16px;
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.content {
    text-align: center;
    background: rgba(30, 32, 40, 0.9);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 150px;
    /* Raise window to avoid overlap with controls */
}

.content h2 {
    font-size: 32px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #fff, #bbb);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.content p {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

button {
    background: linear-gradient(135deg, var(--primary-color), #00cc7a);
    color: #000;
    border: none;
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 20px rgba(0, 255, 157, 0.2);
}

button:active {
    transform: scale(0.95);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-color);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
}

/* Modal */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: var(--surface-color);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 85%;
    max-width: 320px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-list {
    margin: 20px 0;
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 14px;
}

.leaderboard-item:last-child {
    border: none;
}

.leaderboard-item .name {
    color: var(--text-primary);
    font-weight: 500;
}

.leaderboard-item .score {
    color: var(--accent-color);
    font-weight: 700;
}

.modal-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 0, 128, 0.3);
    transition: transform 0.2s;
}

.modal-btn:active {
    transform: scale(0.95);
}

#game-over-overlay h2 {
    color: #ff4d4d;
    background: none;
    -webkit-text-fill-color: initial;
}

/* Controls */
.controls {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    /* Fixed to viewport + safe area */
    left: 0;
    width: 100%;
    z-index: 1000;
    /* Ensure it's on top of everything */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding-bottom: 0;
    pointer-events: none;
    /* Allow clicks to pass through valid areas */
}

.control-row {
    display: flex;
    gap: 20px;
    pointer-events: auto;
    /* Re-enable pointer events for buttons */
}

.control-btn {
    width: 65px;
    height: 65px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: var(--text-primary);
    padding: 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    backdrop-filter: blur(5px);
}

.control-btn svg {
    display: block;
    width: 32px;
    height: 32px;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(0.92);
}

#btn-up {
    /* margin-bottom: -10px; */
    /* Removed to align with grid-like structure */
}

#btn-pause {
    background: rgba(255, 200, 0, 0.15);
    /* Slight yellow tint for pause */
    border-color: rgba(255, 200, 0, 0.3);
}

#btn-pause:active {
    background: rgba(255, 200, 0, 0.25);
}

/* Adjust Main Layout to fit controls */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overflow: hidden;
    padding-bottom: 180px;
    /* Extra space for fixed controls (optimized) */
}

canvas {
    max-height: 100%;
    margin-bottom: auto;
    margin-top: 10px;
}

.loader {
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top: 3px solid var(--primary-color);
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}