body { margin: 0; padding: 0; background-color: #000; overflow: hidden; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; user-select: none; -webkit-user-select: none; display: flex; flex-direction: column; height: 100vh; touch-action: none; }
#game-viewport { position: relative; flex-grow: 1; overflow: hidden; background: radial-gradient(circle at center, #0b1026 0%, #000000 100%); }
canvas { display: block; width: 100%; height: 100%; }
.vignette { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle, transparent 60%, rgba(0,0,0,0.8) 100%); pointer-events: none; z-index: 6; }
#ui-layer { position: relative; width: 100%; height: 80px; background-color: #050508; border-bottom: 2px solid #333; display: flex; align-items: center; justify-content: space-between; padding: 0 25px; box-sizing: border-box; z-index: 20; box-shadow: 0 0 20px rgba(0, 200, 255, 0.1); }
.hud-group { display: flex; gap: 20px; }
.hud-panel { display: flex; align-items: center; background: rgba(0, 20, 40, 0.8); border: 1px solid rgba(0, 200, 255, 0.3); border-radius: 12px; padding: 8px 20px; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5); }
.hud-panel.highscore { border-color: rgba(255, 215, 0, 0.3); }
.hud-text { color: #00ffff; font-size: 16px; font-weight: 700; letter-spacing: 1px; text-shadow: 0 0 5px rgba(0, 255, 255, 0.6); }
.hud-value { color: #ffffff; margin-left: 10px; font-size: 20px; font-weight: 600; }
.bonus-active { border-color: #ffd700 !important; box-shadow: 0 0 15px rgba(255, 215, 0, 0.3) !important; }
.bonus-text-active { color: #ffd700 !important; text-shadow: 0 0 8px rgba(255, 215, 0, 0.8) !important; }

/* --- JOYSTICK STYLES --- */
#joystick-zone { position: absolute; top: 0; right: 0; width: 50%; height: 100%; z-index: 40; touch-action: none; }
#joystick-base { 
    width: 150px; 
    height: 150px; 
    background: rgba(255, 255, 255, 0.1); 
    border: 2px solid rgba(0, 255, 255, 0.5); 
    border-radius: 50%; 
    position: absolute; 
    display: none; 
    justify-content: center; 
    align-items: center; 
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.2); 
    pointer-events: none; 
    transform: translate(-50%, -50%); 
}

#joystick-base::after { 
    content: ''; 
    position: absolute; 
    width: 20px; 
    height: 20px; 
    border: 1px dashed rgba(255, 255, 255, 0.3); 
    border-radius: 50%; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%);
}

#joystick-stick { 
    width: 60px; 
    height: 60px; 
    background: radial-gradient(circle at 30% 30%, #00ffff, #005577); 
    border-radius: 50%; 
    position: absolute; 
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.6); 
    transform: translate(0, 0); 
    pointer-events: none; 
}

#shield-btn { position: absolute; bottom: 150px; left: 30px; width: 60px; height: 60px; z-index: 50; touch-action: none; background: linear-gradient(135deg, rgba(0, 200, 255, 0.3), rgba(0, 100, 200, 0.5)); border: 2px solid rgba(0, 255, 255, 0.8); border-radius: 6px 6px 30px 30px; display: flex; justify-content: center; align-items: center; box-shadow: 0 0 15px rgba(0, 255, 255, 0.3); cursor: pointer; transition: transform 0.1s, background 0.1s, box-shadow 0.1s; }
#shield-btn:active { transform: scale(0.95); background: rgba(0, 255, 255, 0.6); box-shadow: 0 0 25px rgba(0, 255, 255, 0.8); }
#shield-count-mobile { font-size: 28px; font-weight: 900; color: #ffffff; text-shadow: 0 0 10px #00ffff; font-family: 'Segoe UI', monospace; }

#pause-btn { position: absolute; top: 20px; left: 20px; width: 50px; height: 50px; z-index: 50; background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0.5); border-radius: 8px; color: #fff; font-weight: bold; font-size: 20px; font-family: monospace; display: flex; justify-content: center; align-items: center; cursor: pointer; touch-action: none; text-shadow: 0 0 5px #fff; transition: all 0.1s; }
#pause-btn:active { background: rgba(255, 255, 255, 0.3); transform: scale(0.95); }

#center-screen-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(5, 10, 15, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 80; pointer-events: auto; backdrop-filter: blur(8px); }
#pause-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); display: none; flex-direction: column; align-items: center; justify-content: center; z-index: 60; pointer-events: auto; backdrop-filter: blur(5px); }

#pause-text { color: #fff; font-size: 48px; font-weight: bold; letter-spacing: 10px; text-shadow: 0 0 20px rgba(0, 255, 255, 0.5); margin-bottom: 40px; }
.pause-menu-btn { margin: 10px; padding: 15px 50px; font-size: 24px; width: 280px; border: 2px solid rgba(255,255,255,0.2); border-radius: 8px; cursor: pointer; text-transform: uppercase; font-weight: bold; color: white; }
#resume-btn { background: linear-gradient(45deg, #0044cc, #0088ff); box-shadow: 0 0 15px rgba(0, 136, 255, 0.4); }
#quit-btn { background: linear-gradient(45deg, #880000, #cc0000); box-shadow: 0 0 15px rgba(255, 0, 0, 0.4); }

#dev-menu { position: absolute; top: 20px; right: 20px; background: rgba(0, 0, 0, 0.9); border: 2px solid #00ff00; padding: 20px; border-radius: 10px; display: none; flex-direction: column; align-items: center; z-index: 40; box-shadow: 0 0 20px rgba(0, 255, 0, 0.3); }
#dev-menu h3 { color: #00ff00; margin: 0 0 15px 0; text-transform: uppercase; }
#dev-level-input { background: #111; border: 1px solid #00ff00; color: #00ff00; padding: 5px; font-size: 16px; width: 60px; text-align: center; margin-bottom: 10px; }
.dev-btn { background: #004400; color: #00ff00; border: 1px solid #00ff00; padding: 5px 15px; cursor: pointer; text-transform: uppercase; font-weight: bold; }
.dev-btn:hover { background: #006600; }

body.desktop .mobile-control { display: none !important; }

/* Desktop joystick: keep the floating joystick enabled even when other mobile controls are hidden */
body.desktop #joystick-zone.mobile-control { display: block !important; }

h1 { color: #fff; background: -webkit-linear-gradient(#fff, #00ffff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; filter: drop-shadow(0 0 20px rgba(0, 255, 255, 0.4)); font-size: 72px; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 900; }
h2 { color: #00ffff; text-shadow: 0 0 15px rgba(0, 255, 255, 0.5); font-size: 36px; margin-bottom: 20px; text-transform: uppercase; font-weight: 600; }
p { color: #aaa; font-size: 16px; line-height: 1.6; text-align: center; max-width: 600px; }

button { margin-top: 40px; padding: 18px 60px; font-size: 20px; background: linear-gradient(45deg, #0044cc, #0088ff); color: #fff; border: none; border-radius: 4px; cursor: pointer; transition: transform 0.1s, box-shadow 0.1s, background 0.3s; box-shadow: 0 0 20px rgba(0, 100, 255, 0.4); text-transform: uppercase; font-weight: bold; letter-spacing: 2px; touch-action: manipulation; }
@media (hover: hover) { button:hover { transform: scale(1.05); box-shadow: 0 0 30px rgba(0, 150, 255, 0.6); background: linear-gradient(45deg, #0055ee, #00aaff); } }
button:active { transform: scale(0.95); box-shadow: 0 0 10px rgba(0, 100, 255, 0.8); background: linear-gradient(45deg, #003399, #0066cc); }

@media (max-width: 768px) { button { padding: 15px 30px; font-size: 18px; margin-top: 20px; width: auto; } #start-content > div { flex-wrap: wrap; justify-content: center; } }

.title-perfect { color: #44ff44 !important; text-shadow: 0 0 20px rgba(0, 255, 0, 0.6); background: none; -webkit-text-fill-color: #44ff44; }
.title-poor { color: #ffaa00 !important; text-shadow: 0 0 15px rgba(255, 170, 0, 0.5); background: none; -webkit-text-fill-color: #ffaa00; }

.controls-info { margin-top: 30px; background: rgba(255, 255, 255, 0.05); border-radius: 8px; padding: 20px 40px; border: 1px solid rgba(255,255,255,0.1); }
.key { color: #00aaff; font-weight: bold; }

#start-content, #game-over-content, #level-complete-content, #game-complete-content { display: none; flex-direction: column; align-items: center; }

.glitch-hud { animation: glitch-anim 0.2s infinite; }
@keyframes glitch-anim { 0% { transform: translate(0); text-shadow: 2px 0 #ff0000, -2px 0 #0000ff; } 25% { transform: translate(2px, 2px); text-shadow: -2px 0 #ff0000, 2px 0 #0000ff; } 50% { transform: translate(-2px, -2px); text-shadow: 2px 0 #00ff00, -2px 0 #ff00ff; } 75% { transform: translate(0); text-shadow: none; } 100% { transform: translate(0); } }

/* ---------- LEADERBOARD FIX ---------- */
#leaderboard-view { display: none; flex-direction: column; align-items: center; width: 100%; max-width: 600px; }

.leaderboard-container {
    background: rgba(5, 10, 20, 0.95);
    border: 2px solid #00ffff;
    border-radius: 12px;
    padding: 10px 20px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 20px;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.15);
    min-height: 100px;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

#leaderboard-entries { touch-action: pan-y; }

.score-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 10px; border-bottom: 1px solid rgba(0, 255, 255, 0.2); font-family: 'Segoe UI', sans-serif; }
.score-row:last-child { border-bottom: none; }

.score-rank { color: #ffd700; width: 40px; font-weight: 800; font-size: 20px; text-align: left; }
.score-name { flex-grow: 1; text-align: left; padding-left: 10px; color: #ffffff; font-size: 20px; font-weight: 600; text-transform: uppercase; text-shadow: 0 0 5px rgba(0, 255, 255, 0.8); }
.score-value { color: #44ff44; font-weight: bold; font-family: monospace; font-size: 24px; text-align: right; text-shadow: 0 0 8px rgba(68, 255, 68, 0.5); }

.score-row:nth-child(1) .score-name { color: #ffd700; text-shadow: 0 0 15px rgba(255, 215, 0, 0.8); }
.score-row:nth-child(2) .score-name { color: #e0e0e0; }
.score-row:nth-child(3) .score-name { color: #cd7f32; }

.loading-text { color: #00ffff; margin: 20px 0; font-style: italic; }
.no-scores { color: #888; font-style: italic; text-align: center; padding: 20px; }

#high-score-input { display: none; flex-direction: column; align-items: center; margin: 20px 0; animation: pulse-gold 2s infinite; }
@keyframes pulse-gold { 0% { filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3)); } 50% { filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.8)); } 100% { filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3)); } }
#player-name-input { background: rgba(0, 0, 0, 0.8); border: 2px solid #ffd700; color: #ffd700; padding: 10px 20px; font-size: 24px; text-align: center; text-transform: uppercase; border-radius: 4px; width: 150px; font-family: 'Segoe UI', sans-serif; font-weight: bold; outline: none; margin-bottom: 10px; user-select: text; -webkit-user-select: text; touch-action: manipulation; z-index: 90; }
#submit-score-btn { background: linear-gradient(45deg, #aa8800, #ffdd00); color: #000; border: none; padding: 10px 30px; font-weight: 900; cursor: pointer; text-transform: uppercase; border-radius: 4px; font-size: 16px; box-shadow: 0 0 15px rgba(255, 215, 0, 0.4); }

@media (max-width: 768px) {
    body:not(.desktop) #ui-layer { height: 56px; padding: 0 8px; }
    body:not(.desktop) .hud-group { gap: 8px; }
    body:not(.desktop) .hud-panel { padding: 4px 8px; border-radius: 8px; }

    /* 15% smaller top HUD text on mobile (base before scaling) */
    body:not(.desktop) .hud-text { font-size: 9px; letter-spacing: 0.5px; }
    body:not(.desktop) .hud-value { font-size: 12px; margin-left: 6px; }

    /* Mobile: scale top HUD to match menus (same 0.6 as overlay) */
    body:not(.desktop) #ui-layer {
        transform: scale(0.6);
        transform-origin: top left;
        width: calc(100% / 0.6);
    }

    body:not(.desktop) #pause-overlay { padding: 10px; }
    body:not(.desktop) .pause-menu-btn { padding: 8px 20px; font-size: 14px; margin-top: 10px; }

    body:not(.desktop) #start-content h1 { font-size: 32px; letter-spacing: 1px; margin-bottom: 4px; }
    body:not(.desktop) #start-content h2 { font-size: 16px; margin-bottom: 12px; }
    body:not(.desktop) #start-content p { font-size: 13px; max-width: 320px; }
    body:not(.desktop) #start-content button { font-size: 14px; padding: 10px 22px; margin-top: 10px; }

    body:not(.desktop) #center-screen-overlay > div { transform: scale(0.6); transform-origin: center center; }
    body:not(.desktop) #level-complete-content, body:not(.desktop) #victory-content { transform: scale(0.6); }
    body:not(.desktop) #game-over-content, body:not(.desktop) #game-complete-content { transform: scale(0.6); }
}

/* ---------- SPLASH SCREEN ---------- */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 120;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    background:
        radial-gradient(circle at 10% -20%, rgba(0, 255, 255, 0.25) 0%, transparent 45%),
        radial-gradient(circle at 80% 120%, rgba(255, 60, 0, 0.35) 0%, transparent 45%),
        url("../assets/tutorialsplash2.jpg?ver=116") center center / cover no-repeat,
        #02030a;
    opacity: 1;
    transition: opacity 0.30s ease-out;
}

#splash-screen.splash-hide { opacity: 0; pointer-events: none; }

.splash-inner {
    background: radial-gradient(circle at top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.6) 55%, transparent 100%);
    padding: 40px 30px;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 255, 0.25);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9);
}

.splash-title {
    font-size: 40px;
    letter-spacing: 8px;
    font-weight: 900;
    text-transform: uppercase;
    background: -webkit-linear-gradient(#ffffff, #00ffff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(0, 255, 255, 0.6);
    margin-bottom: 10px;
}

.splash-subtitle {
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: #88ffff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
    margin-bottom: 30px;
}

.splash-hint {
    font-size: 14px;
    color: #dddddd;
    opacity: 0.8;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

@media (max-width: 600px) {
    .splash-inner { padding: 25px 18px; }
    .splash-title { font-size: 28px; letter-spacing: 5px; }
    .splash-subtitle { font-size: 14px; letter-spacing: 3px; }
    .splash-hint { font-size: 12px; }
}

/* Small spacing tweaks */
.leaderboard-container { padding: 18px 22px; }
.score-row { padding: 14px 10px; }
.score-row span[style*="min-width:64px"] { margin-left: 12px; margin-right: 10px; }
.score-value { min-width: 96px; }

/* Touch devices (iPad landscape etc.): apply the same scaling as "mobile" */
@media (hover: none) and (pointer: coarse) {
  body:not(.desktop) #center-screen-overlay > div {
    transform: scale(0.6);
    transform-origin: center center;
  }

  body:not(.desktop) #ui-layer {
    transform: scale(0.6);
    transform-origin: top left;
    width: calc(100% / 0.6);
  }
}
/* --- Mobile/tablet landscape: make start menu fit, avoid cut-off buttons --- */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-width: 900px) {

  /* Allow content to start higher and scroll if needed */
  body:not(.desktop) #center-screen-overlay {
    justify-content: flex-start;
    padding-top: 8px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Tighten the start menu specifically */
  body:not(.desktop) #start-content {
    margin-top: 0;
    padding-top: 6px;
  }

  body:not(.desktop) #start-content h1 {
    font-size: 22px;
    letter-spacing: 1px;
    margin: 0 0 2px 0;
  }

  body:not(.desktop) #start-content h2 {
    font-size: 12px;
    margin: 0 0 8px 0;
  }

  body:not(.desktop) #start-content .controls-info {
    margin-top: 8px;
    padding: 10px 14px;
  }

  body:not(.desktop) #start-content .controls-info p {
    font-size: 12px;
    line-height: 1.3;
    max-width: 520px;
  }

  body:not(.desktop) #start-content > div {
    gap: 10px;
  }

  body:not(.desktop) #start-content button {
    margin-top: 8px;
    padding: 8px 16px;
    font-size: 12px;
  }
}

/* Large tablets (e.g. iPad 11") landscape: don't shrink start/menu overlay */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (min-width: 901px) {
  body:not(.desktop) #center-screen-overlay {
    justify-content: center !important;
    padding-top: env(safe-area-inset-top) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    overflow-y: hidden;
  }

  body:not(.desktop) #center-screen-overlay > div {
    transform: scale(0.95) !important;
    transform-origin: center center;
  }
}

/* iPhone/iPad safe-area + fix HUD black band (no transform scaling on ui-layer) */
@media (hover: none) and (pointer: coarse) {

  /* Stop using transform-scaling for the top HUD (it creates extra empty space) */
  body:not(.desktop) #ui-layer {
    transform: none !important;
    width: 100% !important;

    /* Make it small like your menus, but via real sizes (no layout gap) */
    height: calc(34px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: calc(8px + env(safe-area-inset-left));
    padding-right: calc(8px + env(safe-area-inset-right));
    box-sizing: border-box;
  }

  body:not(.desktop) .hud-group { gap: 6px; }
  body:not(.desktop) .hud-panel { padding: 2px 6px; border-radius: 7px; }
  body:not(.desktop) .hud-text { font-size: 9px; letter-spacing: 0.3px; }
  body:not(.desktop) .hud-value { font-size: 12px; margin-left: 5px; }

  /* Keep the gameplay buttons out of the notch / Dynamic Island area */
  body:not(.desktop) #pause-btn {
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
  }

  body:not(.desktop) #shield-btn {
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(150px + env(safe-area-inset-bottom));
  }

  /* Optional: avoid joystick being too close to right notch area */
  body:not(.desktop) #joystick-zone {
    right: env(safe-area-inset-right);
  }
}
/* Shield button: force into bottom-left safe corner on iPhone/iPad touch */
@media (hover: none) and (pointer: coarse) {
  body:not(.desktop) #shield-btn {
    left: calc(10px + env(safe-area-inset-left)) !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
  }

  body:not(.desktop) #shield-btn:active {
    transform: translateY(-50%) scale(0.95) !important;
  }
}

/* Menu background (start + leaderboard): reuse the UFO splash image as a backdrop */
#center-screen-overlay.menu-bg {
    background:
        radial-gradient(circle at 10% -20%, rgba(0, 255, 255, 0.18) 0%, transparent 45%),
        radial-gradient(circle at 80% 120%, rgba(255, 60, 0, 0.22) 0%, transparent 45%),
        linear-gradient(rgba(5, 10, 15, 0.78), rgba(5, 10, 15, 0.88)),
        url("../assets/ufo-splash.jpg?ver=113") center center / cover no-repeat,
        #02030a;

    /* No need to blur the gameplay behind when we render a full-screen background image */
    backdrop-filter: none;
}