/* Design System */
:root {
    /* Colors */
    --bg-dark: #0f0f1a;
    --bg-panel: rgba(15, 15, 30, 0.85);
    --bg-panel-hover: rgba(30, 30, 60, 0.9);
    --border-subtle: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.2);
    --border-bright: rgba(255, 255, 255, 0.4);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.5);

    --accent-red: #ff4757;
    --accent-red-hover: #ff6b7a;
    --accent-blue: #3498db;
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-green: #2ed573;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(255, 255, 255, 0.1);
    --text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

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

html {
    /* Prevent iOS zoom on double-tap and pinch */
    touch-action: manipulation;
}

body {
    overflow: hidden;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    /* Prevent pull-to-refresh and overscroll */
    overscroll-behavior: none;
    /* Prevent text selection on game elements */
    -webkit-user-select: none;
    user-select: none;
    /* Prevent iOS tap highlight */
    -webkit-tap-highlight-color: transparent;
}

#game-container {
    width: 100vw;
    height: 100vh;
    /* Prevent browser gestures on canvas */
    touch-action: none;
}

/* HUD Panels */
#hud,
#resources {
    position: fixed;
    top: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 100;
}

#hud {
    left: var(--space-lg);
}

#resources {
    right: var(--space-lg);
    text-align: right;
}

#hud div,
#resources div {
    margin: var(--space-xs) 0;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    text-shadow: var(--text-shadow);
    letter-spacing: 0.3px;
}

#restart-btn {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 71, 87, 0.3);
    border: 1px solid var(--accent-red);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

#restart-btn:hover {
    background: rgba(255, 71, 87, 0.5);
}

/* Crosshair */
#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    z-index: 100;
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: var(--text-primary);
    border-radius: 1px;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}

#crosshair::before {
    width: 2px;
    height: 24px;
    left: 11px;
}

#crosshair::after {
    width: 24px;
    height: 2px;
    top: 11px;
}

/* Inventory */
#inventory {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.inv-slot {
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.inv-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-medium);
}

.inv-slot.selected {
    border-color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.15);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.3), inset 0 0 12px rgba(0, 212, 255, 0.1);
}

.inv-slot .count {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Messages */
#message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-primary);
    font-size: 56px;
    font-weight: 700;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
    z-index: 200;
    display: none;
    text-align: center;
    letter-spacing: 2px;
}

#instructions {
    position: fixed;
    bottom: 100px;
    left: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
    z-index: 100;
}

/* Start Screen */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a14 0%, #1a1a2e 50%, #16213e 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 300;
    color: var(--text-primary);
}

#start-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, rgba(52, 152, 219, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

#start-screen h1 {
    font-size: 80px;
    font-weight: 800;
    margin-bottom: var(--space-md);
    text-shadow: 0 0 40px rgba(52, 152, 219, 0.5), 0 4px 12px rgba(0, 0, 0, 0.5);
    letter-spacing: 4px;
    background: linear-gradient(180deg, #fff 0%, #a0d2eb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#start-screen p {
    font-size: 18px;
    margin-bottom: var(--space-xl);
    color: var(--text-secondary);
    font-weight: 400;
}

#start-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    align-items: center;
}

#continue-btn,
#start-btn {
    padding: var(--space-lg) 80px;
    font-size: 22px;
    font-weight: 700;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition-normal);
    letter-spacing: 2px;
    text-transform: uppercase;
}

#continue-btn {
    background: linear-gradient(135deg, var(--accent-green) 0%, #27ae60 100%);
    box-shadow: 0 4px 20px rgba(46, 213, 115, 0.4);
}

#continue-btn:hover {
    transform: translateY(-2px) scale(1.02);
    background: linear-gradient(135deg, #58d68d 0%, var(--accent-green) 100%);
    box-shadow: 0 6px 28px rgba(46, 213, 115, 0.5);
}

#start-btn {
    background: linear-gradient(135deg, var(--accent-red) 0%, #c0392b 100%);
    box-shadow: 0 4px 20px rgba(255, 71, 87, 0.4);
}

#start-btn:hover {
    transform: translateY(-2px) scale(1.02);
    background: linear-gradient(135deg, var(--accent-red-hover) 0%, var(--accent-red) 100%);
    box-shadow: 0 6px 28px rgba(255, 71, 87, 0.5);
}

#continue-btn:active,
#start-btn:active {
    transform: translateY(0) scale(0.98);
}

.save-info {
    margin-top: var(--space-md);
    font-size: 14px;
    color: var(--text-muted);
}

/* End Screen */
#end-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 400;
    color: var(--text-primary);
}

#end-screen.show {
    display: flex;
}

#end-screen h1 {
    font-size: 80px;
    font-weight: 800;
    margin-bottom: var(--space-md);
    letter-spacing: 4px;
}

#end-screen.victory h1 {
    color: var(--accent-gold);
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.5);
}

#end-screen.defeat h1 {
    color: var(--accent-red);
    text-shadow: 0 0 40px rgba(255, 71, 87, 0.5);
}

#end-screen p {
    font-size: 24px;
    margin-bottom: var(--space-xl);
    color: var(--text-secondary);
}

#play-again-btn {
    padding: var(--space-lg) 60px;
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-green) 0%, #27ae60 100%);
    border: none;
    color: white;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition-normal);
    box-shadow: 0 4px 20px rgba(46, 213, 115, 0.4);
    letter-spacing: 2px;
    text-transform: uppercase;
}

#play-again-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 28px rgba(46, 213, 115, 0.5);
}

/* Shop */
#shop {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    z-index: 250;
    min-width: 360px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

#shop.open {
    display: block;
    animation: shopOpen 0.2s ease-out;
}

@keyframes shopOpen {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

#shop h2 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: var(--space-lg);
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 1px;
}

#shop-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: 32px;
    height: 32px;
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

#shop-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.shop-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin: var(--space-sm) 0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-primary);
    transition: var(--transition-fast);
}

.shop-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-medium);
    transform: translateX(4px);
}

.shop-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shop-item.disabled:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-subtle);
}

.shop-item .item-name {
    font-size: 16px;
    font-weight: 600;
}

.shop-item .item-cost {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Touch Controls */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 150;
}

#touch-controls.active {
    display: block;
}

#joystick-zone {
    position: absolute;
    bottom: var(--space-lg);
    left: var(--space-lg);
    width: 150px;
    height: 150px;
    pointer-events: auto;
}

#joystick-base {
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--border-medium);
    border-radius: var(--radius-full);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: var(--shadow-sm), inset 0 0 20px rgba(255, 255, 255, 0.05);
}

#joystick-stick {
    position: absolute;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.3) 100%);
    border-radius: var(--radius-full);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: none;
    box-shadow: var(--shadow-md);
}

#look-zone {
    position: absolute;
    top: 0;
    right: 0;
    width: 60%;
    height: 70%;
    pointer-events: auto;
}

.touch-btn {
    position: absolute;
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--border-medium);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--border-bright);
    transform: scale(0.95);
}

#btn-jump {
    bottom: 30px;
    right: 30px;
}

#btn-action {
    bottom: 110px;
    right: 30px;
}

#btn-break {
    bottom: 110px;
    right: 110px;
}

#btn-shop {
    bottom: 190px;
    right: 30px;
}

/* Mobile adjustments */
@media (pointer: coarse) {
    #instructions {
        display: none !important;
    }

    .inv-slot {
        width: 64px;
        height: 64px;
        font-size: 22px;
    }

    #hud,
    #resources {
        padding: var(--space-sm) var(--space-md);
    }

    #hud div,
    #resources div {
        font-size: 14px;
    }
}

/* Small screens */
@media (max-width: 480px) {
    #start-screen h1 {
        font-size: 48px;
    }

    #start-btn {
        padding: var(--space-md) var(--space-xl);
        font-size: 18px;
    }

    #shop {
        min-width: 280px;
        padding: var(--space-lg);
    }
}
