html, body {
  margin: 0; background: #0b1a2a; color: #eaf6ff;
  font-family: system-ui, sans-serif; height: 100%;
  overflow: hidden; overscroll-behavior: none;
  touch-action: manipulation; /* ⚡ позволяет pan-y, блокирует двойной тап-зум */
}

/* Игровой канвас — без прокрутки/зума (плеер не должен листать игру) */
#game {
  display: block; background: #1a3a58; cursor: crosshair;
  touch-action: none !important;
}

/* Остальные canvas по умолчанию — тоже блокируем, 
   но КРОМЕ тех, что внутри overlay */
canvas {
  display: block;
  touch-action: none;
}

    .overlay {
    position: fixed; inset: 0; display: none;
    justify-content: center;
    align-items: flex-start;
    padding: 15px 20px;
    z-index: 10;
    background: radial-gradient(circle at 50% 30%, rgba(30, 80, 130, 0.85), rgba(8, 18, 32, 0.96) 70%);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y !important;
    overscroll-behavior: contain;
    }
    .overlay.show { display: flex; }

    .panel {
    background: #0e2233; border: 1px solid #1e3a55; border-radius: 14px;
    padding: 28px 32px; max-width: 720px; width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.7); text-align: center;
    margin: auto 0;       /* ⚡ центрирует по вертикали, но не обрезает при переполнении */
    flex-shrink: 0;
    }    
  .panel h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: 1px; color: #7fd6ff; }
  .panel h2 { margin: 0 0 16px; font-size: 24px; }
  .panel p { font-size: 15px; opacity: 0.85; line-height: 1.55; margin: 8px 0; }

  .story-text {
    text-align: left; font-size: 17px; line-height: 1.75; margin: 20px 0;
    background: #0a1a28; border: 1px solid #1e3a55; border-left: 5px solid #d4a259;
    border-radius: 10px; padding: 20px 24px; color: #d8e8f4;
  }
  .story-text b { color: #ffd166; }
  .story-text em { color: #7fd6ff; font-style: normal; }

  .btn {
    display: inline-block; padding: 12px 24px; margin: 6px;
    background: #1f6feb; color: white; border: none; border-radius: 10px;
    font-size: 15px; cursor: pointer; transition: background 0.15s, transform 0.05s;
    touch-action: manipulation; font-family: inherit;
  }
  .btn:hover { background: #2b7fff; }
  .btn:active { transform: scale(0.98); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .btn.secondary { background: #14324a; border: 1px solid #1e3a55; }
  .btn.secondary:hover { background: #1a3f5c; }
  .btn.gold { background: linear-gradient(145deg, #d4a259, #a87c37); color: #1a0d00; font-weight: 600; }
  .btn.danger { background: #7a1f2a; border: 1px solid #b83a4a; }

  .play-btn {
    width: 130px; height: 130px; border-radius: 50%;
    background: linear-gradient(145deg, #2b7fff, #1f6feb);
    border: 4px solid #d4a259; display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; margin: 24px 0 8px; box-shadow: 0 0 0 0 rgba(212, 162, 89, 0.5);
    animation: pulse 2s infinite; transition: transform 0.1s; touch-action: manipulation;
  }
  .play-btn:hover { transform: scale(1.06); }
  .play-btn:active { transform: scale(0.96); }
  .play-btn svg { margin-left: 6px; }
  @keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(212, 162, 89, 0.5); }
    70%  { box-shadow: 0 0 0 22px rgba(212, 162, 89, 0); }
    100% { box-shadow: 0 0 0 0 rgba(212, 162, 89, 0); }
  }

  .menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
  .menu-list .btn { width: 100%; padding: 14px; font-size: 16px; }

  /* HUD (скрыт на мобилке) */
  #hud {
    position: absolute; top: 10px; left: 10px; font-family: monospace; font-size: 13px;
    background: rgba(7, 19, 32, 0.75); padding: 8px 12px; border: 1px solid #1e3a55;
    border-radius: 8px; pointer-events: none; line-height: 1.5;
  }

  /* HP Bar */
  #hpbar {
    position: absolute; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: calc(20px + env(safe-area-inset-left, 0px));
    width: 180px; height: 24px; background: rgba(7, 19, 32, 0.85);
    border: 2px solid #1e3a55; border-radius: 8px; overflow: hidden;
    pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,0.5); z-index: 2;
  }
  #hpfill { height: 100%; width: 100%; background: linear-gradient(90deg, #6ee787, #3ddc84); transition: width 0.15s linear, background 0.2s; }

  /* Шкала энергии */
  #energybar {
    position: absolute; bottom: calc(50px + env(safe-area-inset-bottom, 0px));
    left: calc(20px + env(safe-area-inset-left, 0px));
    width: 180px; height: 16px; background: rgba(7, 19, 32, 0.85);
    border: 2px solid #1e3a55; border-radius: 6px; overflow: hidden; pointer-events: none;
    box-shadow: 0 4px 14px rgba(0,0,0,0.5); z-index: 2;
  }
  #energyfill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffd166, #ffb347); transition: width 0.15s linear; }

  #energytext {
    position: absolute; bottom: calc(50px + env(safe-area-inset-bottom, 0px));
    left: calc(28px + env(safe-area-inset-left, 0px));
    font-family: monospace; font-size: 11px; font-weight: bold;
    pointer-events: none; color: #ffffff; text-shadow: 0 0 3px #000; z-index: 3;
  }
  #hptext {
    position: absolute; bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    left: calc(28px + env(safe-area-inset-left, 0px));
    font-family: monospace; font-size: 13px; font-weight: bold;
    pointer-events: none; color: #ffffff; text-shadow: 0 0 4px #000, 0 0 8px rgba(0,0,0,0.8); z-index: 3;
  }

  /* Миникарта */
  #minimap-container {
    position: absolute; bottom: 85px; left: calc(20px + env(safe-area-inset-left, 0px));
    width: 100px; height: 100px; background: rgba(7, 19, 32, 0.85);
    border: 2px solid #d4a259; border-radius: 50%; overflow: hidden; z-index: 40;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6); pointer-events: none;
  }
  #minimapCanvas { display: block; width: 100%; height: 100%; }
  #minimap-label { position: absolute; bottom: 10px; left: 0; width: 100%; text-align: center; font-family: monospace; font-size: 12px; color: #d4a259; letter-spacing: 1px; text-shadow: 0 0 4px #000, 0 0 8px #000; }

  /* Артефакты в паузе */
  #artifactPanel { display: flex; gap: 10px; justify-content: center; margin-top: 20px; padding-top: 15px; border-top: 1px dashed #1e3a55; }
  .art-btn { width: 60px; height: 60px; border-radius: 12px; background: #0a1a28; border: 2px solid #1e3a55; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #5a6a7a; cursor: pointer; position: relative; transition: all 0.2s; }
  .art-btn .icon { font-size: 24px; margin-bottom: 2px; }
  .art-btn .name { font-size: 10px; font-family: monospace; }
  .art-btn.active { color: #ffd166; border-color: #ffd166; box-shadow: 0 0 10px rgba(255,209,102,0.3); }
  .art-btn.off { opacity: 0.4; filter: grayscale(100%); cursor: not-allowed; }

  /* Cooldowns */
  #cooldownPanel { position: absolute; bottom: 90px; right: 20px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; z-index: 10; }
  .cd-circle { width: 44px; height: 44px; border-radius: 50%; background: rgba(7, 19, 32, 0.8); border: 2px solid #1e3a55; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #7fd6ff; position: relative; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.5); }
  .cd-circle .fill { position: absolute; bottom: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); transform-origin: bottom; transition: transform 0.1s linear; }
  .cd-circle .icon { position: relative; z-index: 1; }

  #hint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 13px; opacity: 0.8; background: rgba(7, 19, 32, 0.75); padding: 6px 14px; border-radius: 8px; pointer-events: none; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
  .hidden { display: none !important; }

  /* Верхние кнопки */
  #gameControls { position: absolute; top: 10px; right: 110px; display: flex; gap: 6px; z-index: 50; pointer-events: auto; }
  .gc-btn { width: 42px; height: 42px; border-radius: 10px; background: rgba(7, 19, 32, 0.85); border: 1px solid #1e3a55; color: #7fd6ff; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.15s; user-select: none; -webkit-tap-highlight-color: transparent; padding: 0; font-family: inherit; font-size: 18px; touch-action: manipulation; }
  .gc-btn:hover { background: rgba(20, 50, 74, 0.95); border-color: #2b7fff; }

  #ctrlPanel { position: fixed; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 300; }
  #fsBtn, #winBtn, #muteBtn { width: 44px; height: 44px; border-radius: 10px; background: rgba(7, 19, 32, 0.85); border: 1px solid #1e3a55; color: #7fd6ff; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.15s; user-select: none; -webkit-tap-highlight-color: transparent; padding: 0; font-family: inherit; font-size: 20px; touch-action: manipulation; }

  .player-badge { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); font-family: monospace; font-size: 12px; background: rgba(7, 19, 32, 0.85); padding: 5px 12px; border: 1px solid #d4a259; border-radius: 20px; color: #ffd166; pointer-events: none; white-space: nowrap; z-index: 5; }

  /* Таблицы и настройки */
  .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed #1e3a55; font-family: monospace; font-size: 14px; text-align: left; }
  .val { color: #7fd6ff; }
  .good { color: #6ee787; } .warn { color: #ffd166; } .bad  { color: #ff6b6b; }
  .controls-list { text-align: left; font-family: monospace; font-size: 14px; line-height: 1.7; margin: 12px 0; background: #0a1a28; border: 1px solid #1e3a55; border-radius: 8px; padding: 12px; }
  .controls-list b { color: #7fd6ff; }
  .leaderboard { width: 100%; border-collapse: collapse; margin: 12px 0; font-family: monospace; font-size: 14px; }
  .leaderboard th, .leaderboard td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #1e3a55; }
  .leaderboard th { color: #7fd6ff; font-weight: 500; font-size: 12px; text-transform: uppercase; }
  .leaderboard tr.top1 td { color: #ffd166; font-weight: bold; } .leaderboard tr.top2 td { color: #cfd8e0; } .leaderboard tr.top3 td { color: #d29060; }
  .leaderboard td.rank { width: 40px; text-align: center; }
  .leaderboard td.score { text-align: right; color: #6ee787; }
  .empty-msg { text-align: center; opacity: 0.6; padding: 24px 0; font-style: italic; }

  .choice-tabs { display: flex; gap: 6px; margin: 16px 0 10px; background: #0a1a28; border: 1px solid #1e3a55; border-radius: 10px; padding: 4px; }
  .choice-tab { flex: 1; padding: 12px 8px; background: transparent; border: none; border-radius: 8px; color: #7fd6ff; font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer; transition: background 0.15s; }
  .choice-tab.active { background: linear-gradient(145deg, #2b7fff, #1f6feb); color: #ffffff; }
  .choice-pane { display: none; } .choice-pane.active { display: block; }
  .select-block { text-align: left; margin: 12px 0; }
  .select-block label { display: block; font-family: monospace; font-size: 13px; opacity: 0.8; margin-bottom: 6px; }
  .select-block select, .select-block input[type="text"] { width: 100%; padding: 12px 16px; background: #0a1a28; border: 1px solid #1e3a55; border-radius: 8px; color: #eaf6ff; font-size: 16px; font-family: inherit; box-sizing: border-box; }
  .select-block select:focus, .select-block input:focus { outline: none; border-color: #2b7fff; }
  #loadingMsg { padding: 20px; font-family: monospace; font-size: 14px; color: #7fd6ff; text-align: center; }
  .selected-preview { margin: 12px 0; padding: 12px 16px; background: rgba(212, 162, 89, 0.15); border: 1px solid #d4a259; border-radius: 8px; font-family: monospace; font-size: 15px; color: #ffd166; text-align: center; font-weight: 600; }

  /* Пауза */
  #pauseOverlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(4, 12, 22, 0.85); z-index: 200; padding: 20px; }
  #pauseOverlay.show { display: flex; }
  #pausePanel { background: #0e2233; border: 1px solid #1e3a55; border-radius: 14px; padding: 28px 32px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.7); max-width: 450px; width: 100%; max-height: 92vh; overflow-y: auto; }
  #pausePanel h2 { margin: 0 0 20px; color: #7fd6ff; }
  #pausePanel .btn { display: block; width: 100%; margin: 8px 0; }

  .game-toast { position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.9); color: #7fd6ff; padding: 8px 18px; border-radius: 20px; font-size: 13px; z-index: 400; font-family: monospace; pointer-events: none; white-space: nowrap; border: 1px solid #2b7fff; animation: toastFade 2.2s ease forwards; }
  @keyframes toastFade { 0% { opacity: 1; transform: translateX(-50%) translateY(0); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-20px); visibility: hidden; } }

  .server-status { position: fixed; bottom: 14px; right: 14px; font-family: monospace; font-size: 10px; padding: 3px 8px; border-radius: 10px; background: rgba(7, 19, 32, 0.8); border: 1px solid #1e3a55; z-index: 150; pointer-events: none; }
  .server-status.online { color: #6ee787; border-color: #6ee787; } .server-status.offline { color: #ff6b6b; border-color: #ff6b6b; }

  /* Мобильный мотор и стик (базовые стили) */
  #thrustButton { display: none; position: fixed; z-index: 60; touch-action: none; user-select: none; -webkit-tap-highlight-color: transparent; opacity: 0.35; transition: opacity 0.3s; }
  body.input-touch #thrustButton:not(.hidden) { display: block; }
  #thrustButton:active, #thrustButton.active { opacity: 0.85; }
  #thrustBtn { width: 100px; height: 100px; border-radius: 50%; background: radial-gradient(circle at 38% 35%, #ff9a6a, #c9482a); border: 3px solid #ffd166; color: #ffffff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-family: monospace; font-size: 11px; font-weight: bold; letter-spacing: 1px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; box-shadow: 0 0 34px rgba(255, 120, 60, 0.45); transition: transform 0.08s, box-shadow 0.08s, background 0.08s; padding: 0; text-shadow: 0 0 6px rgba(0,0,0,0.6); }
  #thrustBtn svg { width: 30px; height: 30px; stroke: currentColor; stroke-width: 2.5; fill: none; pointer-events: none; }
  #thrustBtn .label { pointer-events: none; font-size: 10px; }
  #thrustBtn.active { transform: scale(0.94); background: radial-gradient(circle at 38% 35%, #ffd166, #ff6a3a); }

  #mobileControls { display: none; position: fixed; z-index: 60; touch-action: none; user-select: none; -webkit-tap-highlight-color: transparent; opacity: 0.35; transition: opacity 0.3s; }
  body.input-touch #mobileControls:not(.hidden) { display: block; }
  #mobileControls:active, #mobileControls.active { opacity: 0.85; }
  #joystickBase { position: absolute; inset: 0; border-radius: 50%; background: rgba(7, 19, 32, 0.5); border: 2px solid rgba(127, 214, 255, 0.4); box-shadow: inset 0 0 24px rgba(127, 214, 255, 0.15); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
  #joystickKnob { position: absolute; width: 50px; height: 50px; left: 50%; top: 50%; margin-left: -25px; margin-top: -25px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #a4dfff, #4a9edb); border: 2px solid #7fd6ff; box-shadow: 0 0 22px rgba(127, 214, 255, 0.6); pointer-events: none; will-change: transform; }

  #mobileArtifacts { display: none; position: fixed; z-index: 65; }
  body.input-touch #mobileArtifacts:not(.hidden) { display: block; }
  .mob-art-btn { width: 50px; height: 50px; border-radius: 50%; background: rgba(7, 19, 32, 0.85); border: 2px solid #1e3a55; color: #fff; font-size: 20px; display: flex; align-items: center; justify-content: center; touch-action: manipulation; opacity: 0.5; }
  .mob-art-btn.active { opacity: 1; border-color: #ffd166; background: rgba(212,162,89,0.4); }

  /* Настройки звука */
  #soundSettings { margin-top: 18px; padding-top: 16px; border-top: 1px solid #1e3a55; text-align: left; }
  #soundSettings h3 { margin: 0 0 14px; font-size: 16px; color: #7fd6ff; text-align: center; }
  .slider-row { display: grid; grid-template-columns: 70px 1fr 30px; gap: 8px; align-items: center; margin-bottom: 8px; font-family: monospace; font-size: 12px; }
  .slider-row label { color: #d8e8f4; }
  .slider-val { text-align: right; color: #ffd166; font-weight: bold; }
  .slider-row input[type="range"] { -webkit-appearance: none; width: 100%; height: 5px; background: linear-gradient(90deg, #1f6feb, #7fd6ff); border-radius: 3px; outline: none; }
  .slider-row input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid #1f6feb; }
  .sound-test-btns { display: flex; gap: 6px; margin-top: 10px; justify-content: center; flex-wrap: wrap; }
  .test-btn { flex: 1; min-width: 80px; padding: 8px; background: #14324a; color: #7fd6ff; border: 1px solid #1e3a55; border-radius: 6px; font-family: monospace; font-size: 11px; cursor: pointer; }

  /* Прочее */
  #startHint { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: #fff; padding: 20px 40px; border-radius: 12px; font-size: 24px; font-family: monospace; font-weight: bold; text-align: center; pointer-events: none; border: 2px solid #ffd166; animation: blink 1.5s infinite; z-index: 100; }
  @keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
  #bossbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: 60%; max-width: 520px; height: 30px; background: rgba(7, 19, 32, 0.9); border: 2px solid #ff6b6b; border-radius: 8px; overflow: hidden; z-index: 60; pointer-events: none; box-shadow: 0 0 24px rgba(255, 107, 107, 0.5); }
  #bossbar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #a02020, #ff4444, #ff8888); transition: width 0.3s ease; }
  #bossbar-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: monospace; font-size: 13px; font-weight: bold; color: #ffffff; text-shadow: 0 0 4px #000, 0 0 8px #000; letter-spacing: 2px; white-space: nowrap; }

  .mode-tabs { display: flex; gap: 8px; justify-content: center; background: #0a1a28; border: 1px solid #1e3a55; border-radius: 12px; padding: 6px; margin-bottom: 14px; }
  .mode-tab { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; background: transparent; border: 2px solid transparent; border-radius: 10px; font-size: 26px; cursor: pointer; transition: all 0.15s; padding: 0; line-height: 1; -webkit-tap-highlight-color: transparent; }
  .mode-tab:hover { background: rgba(43, 127, 255, 0.2); border-color: #2b7fff; transform: scale(1.05); }
  .mode-tab.active { background: linear-gradient(145deg, #2b7fff, #1f6feb); border-color: #ffd166; box-shadow: 0 4px 12px rgba(43, 127, 255, 0.5); transform: scale(1.08); filter: drop-shadow(0 0 6px rgba(255, 209, 102, 0.8)); }
  .mode-tab.disabled, .mode-tab.locked { opacity: 0.4; cursor: not-allowed; position: relative; }
  .mode-tab.locked::after { content: '🔒'; position: absolute; bottom: -2px; right: -2px; font-size: 14px; filter: drop-shadow(0 0 2px #000); }

  @media (max-width: 700px) {
    .mode-tab { width: 44px; height: 44px; font-size: 20px; }
    .mode-tabs { gap: 4px; padding: 4px; }
    #hud { font-size: 11px; }
    #hpbar { width: 120px; height: 20px; bottom: calc(140px + env(safe-area-inset-bottom, 0px)); }
    #hptext { font-size: 11px; bottom: calc(143px + env(safe-area-inset-bottom, 0px)); }
    #energybar { width: 120px; height: 14px; bottom: calc(165px + env(safe-area-inset-bottom, 0px)); }
    #energytext { font-size: 10px; bottom: calc(167px + env(safe-area-inset-bottom, 0px)); }
    #mobileControls { width: 110px; height: 110px; }
    #joystickKnob { width: 44px; height: 44px; margin-left: -22px; margin-top: -22px; }
    #thrustBtn { width: 80px; height: 80px; }
    #mobileArtifacts { bottom: calc(90px + env(safe-area-inset-bottom, 0px)); left: calc(15px + env(safe-area-inset-left, 0px)); }
    .mob-art-btn { width: 44px; height: 44px; font-size: 18px; }
    #cooldownPanel { bottom: 70px; right: 15px; }
    .cd-circle { width: 36px; height: 36px; font-size: 16px; }
  }

  /* ============================================
     МОБИЛЬНЫЙ ИНТЕРФЕЙС — БАЗОВЫЕ ПОЗИЦИИ
     ============================================ */
  body.input-touch #hud,
  body.input-touch #playerBadge,
  body.input-touch #cooldownPanel,
  body.input-touch #hint,
  body.input-touch #hptext,
  body.input-touch #energytext { display: none !important; }

  body.input-touch .hidden { display: none !important; }

  body.input-touch #minimap-container {
    position: fixed !important; top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    left: calc(10px + env(safe-area-inset-left, 0px)) !important; bottom: auto !important;
    width: clamp(60px, 15vmin, 120px) !important; height: clamp(60px, 15vmin, 120px) !important; z-index: 70 !important;
  }
  body.input-touch #hpbar {
    position: fixed !important; bottom: calc(15px + env(safe-area-inset-bottom, 0px)) !important;
    left: calc(50% - clamp(10px, 3vmin, 18px)) !important; transform: translateX(-100%) !important;
    width: clamp(90px, 22vmin, 180px) !important; height: clamp(14px, 4vmin, 24px) !important;
    z-index: 70 !important; border-color: #1e3a55 !important; overflow: visible !important;
  }
  body.input-touch #hpfill { border-radius: 6px !important; }
  body.input-touch #hpbar::before {
    content: '❤️'; position: absolute; right: 100%; margin-right: 8px; top: 50%;
    transform: translateY(-50%); font-size: clamp(14px, 4vmin, 24px); line-height: 1; filter: drop-shadow(0 0 2px #000); pointer-events: none;
  }
  body.input-touch #energybar {
    position: fixed !important; bottom: calc(15px + env(safe-area-inset-bottom, 0px)) !important;
    left: calc(50% + clamp(10px, 3vmin, 18px)) !important; transform: translateX(0) !important;
    width: clamp(90px, 22vmin, 180px) !important; height: clamp(14px, 4vmin, 24px) !important;
    z-index: 70 !important; border-color: #1e3a55 !important; overflow: visible !important;
  }
  body.input-touch #energyfill { border-radius: 6px !important; }
  body.input-touch #energybar::before {
    content: '🔦'; position: absolute; right: 100%; margin-right: 8px; top: 50%;
    transform: translateY(-50%); font-size: clamp(14px, 4vmin, 24px); line-height: 1; filter: drop-shadow(0 0 2px #000); pointer-events: none;
  }
  body.input-touch #mobileControls {
    display: block !important; width: clamp(90px, 25vmin, 180px) !important; height: clamp(90px, 25vmin, 180px) !important;
    bottom: calc(15px + env(safe-area-inset-bottom, 0px)) !important; right: calc(15px + env(safe-area-inset-right, 0px)) !important;
  }
  body.input-touch #joystickKnob {
    width: clamp(40px, 12vmin, 80px) !important; height: clamp(40px, 12vmin, 80px) !important;
    margin-left: clamp(-20px, -6vmin, -40px) !important; margin-top: clamp(-20px, -6vmin, -40px) !important;
  }
  body.input-touch #thrustButton {
    display: block !important; bottom: calc(15px + env(safe-area-inset-bottom, 0px)) !important; left: calc(15px + env(safe-area-inset-left, 0px)) !important;
  }
  body.input-touch #thrustBtn {
    width: clamp(80px, 25vmin, 180px) !important; height: clamp(80px, 25vmin, 180px) !important; font-size: clamp(10px, 3vmin, 16px) !important;
  }
  body.input-touch #mobileArtifacts:not(.hidden) {
    display: block !important; position: fixed !important;
    bottom: calc(15px + env(safe-area-inset-bottom, 0px) + clamp(40px, 12.5vmin, 90px)) !important;
    left: calc(15px + env(safe-area-inset-left, 0px) + clamp(40px, 12.5vmin, 90px)) !important;
    transform: translate(-50%, 50%) !important; width: clamp(160px, 50vmin, 360px) !important; height: clamp(160px, 50vmin, 360px) !important;
    z-index: 61 !important; pointer-events: none !important;
  }
  body.input-touch .mob-art-btn {
    position: absolute !important; width: clamp(36px, 10vmin, 70px) !important; height: clamp(36px, 10vmin, 70px) !important;
    font-size: clamp(18px, 5vmin, 32px) !important; border-width: 2px !important; border-radius: 50% !important;
    pointer-events: auto !important; display: flex !important; align-items: center !important; justify-content: center !important;
    opacity: 0.8 !important; transform: translate(-50%, -50%) !important; background: rgba(7, 19, 32, 0.9) !important; margin: 0 !important;
  }
  body.input-touch .mob-art-btn.active { opacity: 1 !important; background: rgba(212,162,89,0.4) !important; }
  body.input-touch #mobWinchBtn { left: 15% !important; top: 15% !important; }
  body.input-touch #mobFlashBtn { left: 85% !important; top: 15% !important; }
  body.input-touch #mobTorpedoBtn { left: 95% !important; top: 60% !important; }

  /* ============================================
     РЕДАКТОР ИНТЕРФЕЙСА — ПЕРЕБИВАЕТ ВСЁ ВЫШЕ
     ============================================ */
  #editLayoutToolbar {
    display: none; position: fixed; top: calc(10px + env(safe-area-inset-top, 0px));
    left: 50%; transform: translateX(-50%); z-index: 10000;
    background: rgba(14, 34, 51, 0.95); border: 2px solid #ffd166; border-radius: 12px;
    padding: 8px 14px; gap: 8px; align-items: center; box-shadow: 0 4px 20px rgba(0,0,0,0.7);
    font-family: monospace; color: #ffd166; font-size: 13px;
  }
  body.edit-layout #editLayoutToolbar { display: flex; }
  #editLayoutToolbar button { padding: 8px 14px; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: bold; }
  #editLayoutSaveBtn { background: #6ee787; color: #0b1a2a; }
  #editLayoutResetBtn { background: #7a1f2a; color: #fff; }

  body.edit-layout #game, body.custom-layout #game { pointer-events: none !important; }

  /* КОГДА СОХРАНЕНО или В РЕЖИМЕ РЕДАКТИРОВАНИЯ — ЖЕСТКО ПЕРЕБИВАЕМ ПОЗИЦИИ */
  body.edit-layout #hpbar, body.custom-layout #hpbar,
  body.edit-layout #energybar, body.custom-layout #energybar,
  body.edit-layout #mobileControls, body.custom-layout #mobileControls,
  body.edit-layout #thrustButton, body.custom-layout #thrustButton,
  body.edit-layout #minimap-container, body.custom-layout #minimap-container,
  body.edit-layout #mobileArtifacts .mob-art-btn, body.custom-layout #mobileArtifacts .mob-art-btn {
    position: fixed !important;
    left: var(--edit-x, 50%) !important;
    top: var(--edit-y, 50%) !important;
    bottom: auto !important; right: auto !important;
    transform: translate(-50%, -50%) !important;
    margin: 0 !important;
  }

  /* Контейнер артефактов становится прозрачным на весь экран, чтобы кнопки летали отдельно */
  body.edit-layout #mobileArtifacts, body.custom-layout #mobileArtifacts {
    position: fixed !important; inset: 0 !important; width: 100vw !important; height: 100vh !important;
    pointer-events: none !important; background: none !important; border: none !important;
    bottom: 0 !important; left: 0 !important; display: block !important; transform: none !important;
  }
  body.custom-layout #mobileArtifacts .mob-art-btn { pointer-events: auto !important; }

  /* ВИЗУАЛ во время редактирования */
  body.edit-layout #hpbar, body.edit-layout #energybar, body.edit-layout #mobileControls,
  body.edit-layout #thrustButton, body.edit-layout #minimap-container, body.edit-layout #mobileArtifacts .mob-art-btn {
    border: 2px dashed #ffd166 !important;
    box-shadow: 0 0 15px rgba(255, 209, 102, 0.6) !important;
    pointer-events: auto !important; touch-action: none !important; cursor: move !important; z-index: 9999 !important; opacity: 0.9 !important;
  }
/* В режиме редактора отключаем вложенные элементы управления,
   чтобы они не мешали таскать контейнеры */
body.edit-layout #joystickBase,
body.edit-layout #joystickKnob,
body.edit-layout #thrustBtn {
  pointer-events: none !important;
}

/* Захват и перетаскивание должно работать на самих контейнерах */
body.edit-layout #mobileControls,
body.edit-layout #thrustButton {
  pointer-events: auto !important;
}

/* .hidden всегда побеждает custom-layout/edit-layout */
body.custom-layout #mobileArtifacts.hidden,
body.edit-layout #mobileArtifacts.hidden,
body.custom-layout #mobileControls.hidden,
body.edit-layout #mobileControls.hidden,
body.custom-layout #thrustButton.hidden,
body.edit-layout #thrustButton.hidden,
body.custom-layout #hpbar.hidden,
body.edit-layout #hpbar.hidden,
body.custom-layout #energybar.hidden,
body.edit-layout #energybar.hidden,
body.custom-layout #minimap-container.hidden,
body.edit-layout #minimap-container.hidden,
body.custom-layout #mobWinchBtn.hidden,
body.custom-layout #mobFlashBtn.hidden,
body.custom-layout #mobTorpedoBtn.hidden,
body.edit-layout #mobWinchBtn.hidden,
body.edit-layout #mobFlashBtn.hidden,
body.edit-layout #mobTorpedoBtn.hidden {
  display: none !important;
}

/* ⚡ ФИКС: контейнер артефактов в режиме редактора не должен быть трансформирован,
   иначе его position: fixed дети считают координаты от него, а не от экрана */
body.input-touch.edit-layout #mobileArtifacts,
body.input-touch.custom-layout #mobileArtifacts {
  transform: none !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  pointer-events: none !important;
  background: none !important;
  border: none !important;
  display: block !important;
}

/* ⚡ ФИКС: .hidden должен побеждать кастомный лэйаут */
body.custom-layout #mobileArtifacts.hidden,
body.edit-layout #mobileArtifacts.hidden,
body.custom-layout #mobileControls.hidden,
body.edit-layout #mobileControls.hidden,
body.custom-layout #thrustButton.hidden,
body.edit-layout #thrustButton.hidden,
body.custom-layout #hpbar.hidden,
body.edit-layout #hpbar.hidden,
body.custom-layout #energybar.hidden,
body.edit-layout #energybar.hidden,
body.custom-layout #minimap-container.hidden,
body.edit-layout #minimap-container.hidden {
  display: none !important;
}

/* ============================================
   ПРОКРУТКА ЭКРАНОВ
   ============================================ */



/* Красивый видимый скроллбар во всех overlay */
.overlay::-webkit-scrollbar {
  width: 8px;
}
.overlay::-webkit-scrollbar-track {
  background: rgba(7, 19, 32, 0.5);
  border-radius: 4px;
}
.overlay::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #7fd6ff, #2b7fff);
  border-radius: 4px;
  border: 1px solid #0a1a28;
}
.overlay::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #a4e2ff, #3d8fff);
}
/* Firefox */
.overlay {
  scrollbar-width: thin;
  scrollbar-color: #7fd6ff rgba(7, 19, 32, 0.5);
}
#screen-multiplayer {
  background: linear-gradient(rgba(8, 18, 32, 0.7), rgba(8, 18, 32, 0.9)), url('../assets/ui/lobby-bg.jpg') no-repeat center center !important;
  background-size: cover !important;
}

/* Панель паузы тоже скроллится */
#pausePanel {
  touch-action: pan-y !important;
  scrollbar-width: thin;
  scrollbar-color: #7fd6ff rgba(7, 19, 32, 0.5);
}
#pausePanel::-webkit-scrollbar {
  width: 8px;
}
#pausePanel::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #7fd6ff, #2b7fff);
  border-radius: 4px;
}

/* На мобилке в горизонтальном режиме — убираем лишние отступы,
   чтобы кнопка Плей была видна */
@media (max-height: 500px) {
  #screen-splash .panel {
    padding: 16px 24px !important;
  }
  #screen-splash .story-text {
    display: none !important; /* Скрываем длинную историю, чтобы всё влезло */
  }
  #screen-splash .play-btn {
    width: 90px !important;
    height: 90px !important;
    margin: 16px 0 8px !important;
  }
  #screen-splash .play-btn svg {
    width: 36px !important;
    height: 36px !important;
  }
  #screen-splash h1 {
    font-size: 26px !important;
  }
  #screen-splash .version-badge {
    margin-bottom: 6px !important;
  }
}

/* ⚡ ВСЁ внутри overlay разрешает pan-y — чтобы карта/статистика прокручивались */
.overlay,
.overlay *,
.overlay canvas,
.overlay .panel,
.overlay .story-text,
.overlay .leaderboard,
.overlay .controls-list {
  touch-action: pan-y !important;
}

/* Кнопки и интерактивные элементы внутри overlay — манипуляция,
   чтобы тапы работали без задержек, но скролл тоже не ломался */
.overlay button,
.overlay .btn,
.overlay .choice-tab,
.overlay .mode-tab,
.overlay input,
.overlay select {
  touch-action: manipulation !important;
}

/* Карта в overlay — разрешаем скролл при перетаскивании */
#mapCanvas {
  touch-action: pan-y !important;
}


/* ============================================
   ЖЕЛЕЗОБЕТОННЫЙ ФИКС ДЛЯ СКРЫТИЯ ЭЛЕМЕНТОВ
   ============================================ */

/* Если у элемента есть класс .hidden — его не должно быть видно НИКОГДА,
   даже если у него есть правила display: block !important от мобильной верстки */
#thrustButton.hidden,
#mobileControls.hidden,
#mobileArtifacts.hidden,
#minimap-container.hidden,
#hpbar.hidden,
#energybar.hidden,
#cooldownPanel.hidden {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

@media (max-width: 700px) {
  #ctrlPanel {
    top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    right: calc(10px + env(safe-area-inset-right, 0px)) !important;
    gap: 4px !important;
  }
  #fsBtn, #winBtn, #muteBtn {
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }
}