* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  background: #0b0e13;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #eef2f7;
  overscroll-behavior: none;
}

#map { position: absolute; inset: 0; }
#map canvas { outline: none; }

.hidden { display: none !important; }

/* screen-reader / crawler text, visually gone */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button { font: inherit; cursor: pointer; touch-action: manipulation; user-select: none; }

/* ---------- location bar ---------- */
#locbar {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 44px); left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 6px; z-index: 6; max-width: 96vw;
  flex-wrap: wrap; justify-content: center;
  padding: 4px;
}
#locbar button {
  flex: 0 0 auto;
  background: rgba(10, 14, 20, .66); color: #dfe7f0; border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px; padding: 6px 12px; font-size: 12px;
}
#locbar button:active { background: rgba(60, 80, 110, .8); }
body.in-flight #locbar { display: none; }

/* ---------- bottom sheet ---------- */
#panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(12, 16, 23, .88); backdrop-filter: blur(14px);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid rgba(255,255,255,.12);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  max-height: 62vh; display: flex; flex-direction: column;
  transition: transform .25s ease;
}
#panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; flex: 0 0 auto;
}
#chev { font-size: 13px; color: #8fa2b8; transition: transform .25s; }
#panel.collapsed #chev { transform: rotate(180deg); }
#gun-summary { font-size: 13.5px; font-weight: 600; color: #dfe7f0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#panel.collapsed #panel-body { display: none; }

#fire {
  background: linear-gradient(180deg, #ff5252, #d32f2f);
  color: #fff; font-weight: 800; letter-spacing: 2px; font-size: 15px;
  border: none; border-radius: 12px; padding: 12px 26px;
  box-shadow: 0 2px 14px rgba(255, 60, 60, .45);
}
#fire:active { transform: scale(.96); }

#panel-body { overflow-y: auto; padding: 0 14px 14px; }

.sec-label {
  font-size: 10.5px; letter-spacing: 1.6px; color: #8fa2b8;
  margin: 12px 0 6px; font-weight: 700;
}

#gun-cats { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.cat-tab {
  flex: 0 0 auto; background: transparent; border: 1px solid rgba(255,255,255,.16);
  color: #9fb0c3; border-radius: 14px; padding: 6px 12px; font-size: 11.5px; white-space: nowrap;
}
.cat-tab.sel { background: rgba(255,255,255,.1); color: #eef2f7; border-color: rgba(255,255,255,.4); }

#gun-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.gun-chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.13);
  color: #dfe7f0; border-radius: 12px; padding: 7px 12px 8px; min-width: 128px; max-width: 150px; text-align: left;
}
.gun-chip .icon { display: block; width: 100%; color: #8fa2b8; margin-bottom: 2px; }
.gun-chip .icon svg { width: 74px; height: 34px; display: block; }
.gun-chip .icon img {
  width: 74px; height: 34px; object-fit: contain; display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .55));
}
.gun-chip b { font-size: 13px; }
.gun-chip span { font-size: 10.5px; color: #9fb0c3; }
.gun-chip .v0 { color: #ffd54f; }
.gun-chip.sel { background: rgba(255, 213, 79, .14); border-color: #ffd54f; }
.gun-chip.sel .icon { color: #ffd54f; }

.slider-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.slider-row label { flex: 0 0 84px; font-size: 12.5px; color: #b9c6d4; }
.slider-row output { flex: 0 0 86px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; color: #ffd54f; }
.slider-row input[type=range] { flex: 1; min-width: 0; accent-color: #ffd54f; height: 28px; }

.model-row { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.model-row span { flex: 0 0 84px; font-size: 12.5px; color: #b9c6d4; }
.model-row button {
  flex: 1; background: transparent; border: 1px solid rgba(255,255,255,.16);
  color: #9fb0c3; border-radius: 10px; padding: 7px 4px; font-size: 11.5px; white-space: nowrap;
}
.model-row button.sel { background: rgba(255, 213, 79, .14); color: #ffd54f; border-color: #ffd54f; }

#fetch-wx {
  width: 100%; margin: 4px 0 2px;
  background: rgba(84, 200, 255, .1); border: 1px solid rgba(84, 200, 255, .4);
  color: #54c8ff; border-radius: 10px; padding: 9px; font-size: 12.5px;
}
#fetch-wx:disabled { opacity: .7; }

#predict {
  margin-top: 10px; font-size: 12px; color: #9fd49f;
  background: rgba(60, 120, 60, .12); border: 1px solid rgba(120, 200, 120, .25);
  border-radius: 10px; padding: 8px 10px; line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

/* ---------- loading overlay + countdown ---------- */
#overlay {
  position: absolute; inset: 0; z-index: 30;
  background: #070a10; /* fully opaque, hides the tile-buffering camera jumps */
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
}
#ov-spin {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(255, 213, 79, .18);
  border-top-color: #ffd54f;
  animation: ovspin 1s linear infinite;
  margin-bottom: 22px;
}
@keyframes ovspin { to { transform: rotate(360deg); } }
#ov-title { font-size: 15px; letter-spacing: 4px; font-weight: 800; color: #ffd54f; }
#ov-sub { margin-top: 12px; font-size: 13px; color: #b9c6d4; white-space: pre-line; line-height: 1.6; }
#ov-bar { width: min(320px, 70vw); height: 4px; background: rgba(255,255,255,.12); border-radius: 2px; margin-top: 22px; overflow: hidden; }
#ov-bar-fill { height: 100%; width: 0; background: #ffd54f; border-radius: 2px; transition: width .3s ease; }

#countdown {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(1.4);
  font-size: 96px; font-weight: 900; color: #fff; z-index: 31;
  text-shadow: 0 0 30px rgba(255, 180, 60, .9), 0 2px 8px rgba(0,0,0,.8);
  opacity: 0; pointer-events: none; transition: opacity .1s, transform .4s;
}
#countdown.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- flight HUD ---------- */
#gesture-blocker { position: absolute; inset: 0; z-index: 15; }

#hud { position: absolute; inset: 0; z-index: 20; pointer-events: none; font-variant-numeric: tabular-nums; }
#hud-top {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 50%; transform: translateX(-50%);
  text-align: center;
}
#hud-speed {
  font-size: 44px; font-weight: 800; line-height: 1;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  text-shadow: 0 0 12px rgba(0,0,0,.9), 0 2px 4px rgba(0,0,0,.9);
}
#hud-speed::after { content: ' km/h'; font-size: 15px; font-weight: 600; color: #b9c6d4; }
#hud-speed-sub { font-size: 12.5px; color: #cfd8e3; margin-top: 3px; text-shadow: 0 1px 4px #000; }
#hud-phase {
  margin-top: 7px; font-size: 10.5px; letter-spacing: 2.5px; font-weight: 700; color: #ffd54f;
  text-shadow: 0 1px 4px #000;
}
.hud-corner {
  position: absolute; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  text-shadow: 0 1px 5px #000; line-height: 1.25;
}
.hud-corner .lbl { font-size: 10px; letter-spacing: 1.6px; color: #9fb0c3; display: block; }
.hud-corner .val { font-size: 19px; font-weight: 700; }
#hud-alt-box { left: calc(env(safe-area-inset-left, 0px) + 14px); top: 38%; }
#hud-dist-box { right: calc(env(safe-area-inset-right, 0px) + 14px); top: 38%; text-align: right; }
#hud-time-box { right: calc(env(safe-area-inset-right, 0px) + 14px); top: calc(env(safe-area-inset-top, 0px) + 14px); text-align: right; }

#vignette {
  position: absolute; inset: 0; z-index: 16; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .5) 100%);
}

#flash { position: absolute; inset: 0; z-index: 25; pointer-events: none; opacity: 0; background: radial-gradient(circle, #fff7e0 0%, #ffb347 45%, transparent 75%); }
#flash.go { animation: flashAnim .8s ease-out; }
@keyframes flashAnim { 0% { opacity: .95; } 100% { opacity: 0; } }

/* ---------- flight controls ---------- */
#flight-ctl {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); left: 50%;
  transform: translateX(-50%); z-index: 21;
  display: flex; gap: 6px; align-items: center;
  background: rgba(10, 14, 20, .72); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.14); border-radius: 24px; padding: 6px 8px;
}
#flight-ctl button {
  background: transparent; border: none; color: #cfd8e3;
  border-radius: 18px; padding: 8px 12px; font-size: 13px; white-space: nowrap;
}
#flight-ctl button.sel { background: rgba(255, 213, 79, .18); color: #ffd54f; }
#flight-ctl .div { width: 1px; height: 20px; background: rgba(255,255,255,.16); }
#ctl-abort { color: #ff8a80 !important; }

/* ---------- summary ---------- */
#summary {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateX(-50%); z-index: 22;
  width: min(400px, calc(100vw - 28px));
  background: rgba(12, 16, 23, .9); backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.14); border-radius: 16px; padding: 16px;
}
#summary h2 { margin: 0 0 12px; font-size: 14px; letter-spacing: 3px; color: #ffd54f; text-align: center; }
#sum-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
#sum-stats div { display: flex; flex-direction: column; }
#sum-stats span { font-size: 10.5px; letter-spacing: 1px; color: #8fa2b8; }
#sum-stats b { font-size: 14.5px; font-variant-numeric: tabular-nums; }
#sum-btns { display: flex; gap: 10px; margin-top: 14px; }
#sum-btns button {
  flex: 1; border-radius: 10px; padding: 11px; font-weight: 700; font-size: 13.5px; border: none;
}
#sum-replay { background: rgba(255,255,255,.1); color: #dfe7f0; border: 1px solid rgba(255,255,255,.2) !important; }
#sum-new { background: linear-gradient(180deg, #ffd54f, #f5b400); color: #241d00; }

@media (max-width: 480px) {
  #hud-speed { font-size: 36px; }
  .slider-row label { flex-basis: 74px; font-size: 12px; }
  .slider-row output { flex-basis: 78px; }
}

/* ================= GAME HUD (aim mode, all screen sizes) ================= */
  #mhud { display: block; position: absolute; inset: 0; z-index: 8; pointer-events: none; }
  #mhud > * { pointer-events: auto; }
  body.in-flight #mhud { display: none; }

  /* --- top row: places chip / hint / wind chip --- */
  #m-loc, #m-wind {
    position: absolute; top: calc(env(safe-area-inset-top, 0px) + 10px);
    background: rgba(10, 14, 20, .72); backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,.16); border-radius: 18px;
    color: #dfe7f0; font-size: 12.5px; padding: 8px 12px; white-space: nowrap;
  }
  #m-loc { left: 10px; }
  #m-wind { right: 10px; color: #54c8ff; font-variant-numeric: tabular-nums; }

  /* --- places dropdown (re-styled #locbar) --- */
  #locbar {
    display: none; top: calc(env(safe-area-inset-top, 0px) + 52px); left: 10px; right: auto;
    transform: none; flex-direction: column; align-items: stretch; gap: 4px;
    background: rgba(10, 14, 20, .9); backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,.14); border-radius: 14px; padding: 7px; z-index: 9;
  }
  #locbar.open { display: flex; }
  #locbar button { text-align: left; font-size: 13.5px; padding: 10px 14px; border: none; background: transparent; }

  /* --- wind popover (hosts the real wind sliders) --- */
  #m-wind-pop {
    position: absolute; top: calc(env(safe-area-inset-top, 0px) + 52px); right: 10px; z-index: 9;
    width: min(330px, calc(100vw - 20px));
    background: rgba(10, 14, 20, .9); backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,.14); border-radius: 14px; padding: 2px 14px 12px;
  }

  /* --- elevation ribbon (vertical twin of the compass) --- */
  #m-elev {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    touch-action: none;
  }
  #m-elev-val {
    font-size: 11.5px; font-weight: 700; color: #ffd54f;
    text-shadow: 0 1px 4px #000; font-variant-numeric: tabular-nums;
  }
  #m-elev-win {
    position: relative; width: 46px; height: 38vh; max-height: 320px;
    overflow: hidden; border-radius: 12px;
    background: rgba(10, 14, 20, .55); border: 1px solid rgba(255,255,255,.14);
    -webkit-mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
            mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
  }
  #m-elev-strip { position: absolute; inset: 0; will-change: transform; }
  .e-tick { position: absolute; right: 6px; height: 1px; width: 8px; background: rgba(255,255,255,.35); }
  .e-tick.major { height: 2px; width: 12px; background: rgba(255,255,255,.75); }
  .e-tick.major::after {
    content: attr(data-lbl); position: absolute; right: 15px; top: 50%; transform: translateY(-50%);
    font-size: 10.5px; font-weight: 700; color: #dfe7f0;
  }
  #m-elev-needle {
    position: absolute; top: 50%; left: 3px; right: 3px; height: 2px; margin-top: -1px;
    background: #ffd54f; box-shadow: 0 0 6px #ffd54f;
  }

  /* --- compass ribbon --- */
  #m-compass {
    position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 100px);
    left: 50%; transform: translateX(-50%);
    width: min(330px, 64vw); touch-action: none;
  }
  #m-compass-val {
    text-align: center; font-size: 11.5px; font-weight: 700; color: #ffd54f;
    text-shadow: 0 1px 4px #000; margin-bottom: 3px; font-variant-numeric: tabular-nums;
  }
  #m-compass-win {
    position: relative; height: 44px; overflow: hidden; border-radius: 12px;
    background: rgba(10, 14, 20, .55); border: 1px solid rgba(255,255,255,.14);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
            mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  }
  #m-compass-strip { position: absolute; inset: 0; will-change: transform; }
  .c-tick { position: absolute; bottom: 6px; width: 1px; height: 8px; background: rgba(255,255,255,.35); }
  .c-tick.major { height: 12px; width: 2px; background: rgba(255,255,255,.75); }
  .c-tick.major::after {
    content: attr(data-lbl); position: absolute; bottom: 15px; left: 50%; transform: translateX(-50%);
    font-size: 11px; font-weight: 700; color: #dfe7f0;
  }
  #m-compass-needle {
    position: absolute; left: 50%; top: 3px; bottom: 3px; width: 2px; margin-left: -1px;
    background: #ffd54f; box-shadow: 0 0 6px #ffd54f;
  }

  /* --- weapon chip + FIRE --- */
  #m-weapon {
    position: absolute; left: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    display: flex; align-items: center; gap: 8px;
    background: rgba(10, 14, 20, .72); backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 213, 79, .5); border-radius: 14px; padding: 8px 12px;
    color: #eef2f7; max-width: 50vw;
  }
  #m-weapon .icon { color: #ffd54f; }
  #m-weapon .icon svg { width: 46px; height: 22px; display: block; }
  #m-weapon .icon img {
    width: 46px; height: 22px; object-fit: contain; display: block;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .55));
  }
  #m-weapon .wname {
    font-size: 12.5px; font-weight: 700; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }

  /* --- guarded fire switch --- */
  #m-fire {
    display: block; position: absolute; right: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    width: 84px; height: 98px; z-index: 21; perspective: 300px;
  }
  #m-fire-btn {
    position: absolute; left: 3px; bottom: 0;
    width: 78px; height: 78px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ff7961, #d32f2f 65%, #8e1c1c);
    border: 2px solid rgba(255,255,255,.25);
    color: #fff; font-weight: 900; letter-spacing: 1.5px; font-size: 14px;
    pointer-events: none; filter: grayscale(.5) brightness(.75);
  }
  #m-fire-btn.armed { pointer-events: auto; filter: none; animation: armpulse 1.1s ease-in-out infinite; }
  #m-fire-btn.armed:active { transform: scale(.93); }
  @keyframes armpulse {
    0%, 100% { box-shadow: 0 0 14px rgba(255, 60, 60, .5); }
    50% { box-shadow: 0 0 32px rgba(255, 90, 60, .95); }
  }
  #m-fire-guard {
    position: absolute; inset: 0; border-radius: 16px;
    background: repeating-linear-gradient(45deg, #e6b800 0 10px, #15161a 10px 20px);
    border: 2px solid rgba(255,255,255,.3); box-shadow: 0 4px 14px rgba(0,0,0,.5);
    transform-origin: top center; transition: transform .45s cubic-bezier(.3, 1.4, .4, 1);
    display: flex; align-items: center; justify-content: center;
  }
  #m-fire-guard span {
    background: rgba(0, 0, 0, .78); color: #ffd54f; font-size: 11px; font-weight: 800;
    letter-spacing: 2px; padding: 3px 10px; border-radius: 8px;
  }
  #m-fire-guard.flipped { transform: rotateX(-142deg); }
  body.launched #m-fire { display: none; }

  /* arming spinner: lives on the fire button while the shot is prepared */
  #m-fire-spin {
    display: none; position: absolute; left: 3px; bottom: 0;
    width: 78px; height: 78px; border-radius: 50%;
    background: rgba(10, 14, 20, .85);
    flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  }
  #m-fire.arming #m-fire-spin { display: flex; }
  #m-fire-spin .ring {
    width: 30px; height: 30px; border-radius: 50%;
    border: 3px solid rgba(255, 213, 79, .2); border-top-color: #ffd54f;
    animation: ovspin 0.9s linear infinite;
  }
  #m-fire-spin span { font-size: 8.5px; font-weight: 800; letter-spacing: 1.5px; color: #ffd54f; }

  /* flight controls must fit a phone width, no page-level horizontal scroll */
  #flight-ctl { max-width: calc(100vw - 10px); gap: 2px; padding: 5px 6px; }
  #flight-ctl button { padding: 7px 7px; font-size: 12px; }

  /* --- bottom sheet becomes the weapon drawer --- */
  #panel { transform: translateY(108%); transition: transform .3s cubic-bezier(.2, .9, .25, 1); max-height: 72vh; }
  #panel.open { transform: none; }
  #panel.collapsed #panel-body { display: block; } /* header click closes, never collapses */
  #panel #fire { display: none; }                  /* the guarded FIRE switch replaces it */
  #shot-rows { display: none; }                    /* compass + elevation ribbons replace these */
  #gun-list { flex-wrap: wrap; }
  #gun-list .gun-chip { flex: 1 1 44%; max-width: none; }

/* Wide screens: same HUD, but the drawer/popover don't span the full width */
@media (min-width: 900px) {
  #panel {
    left: 50%; right: auto; width: 560px;
    transform: translate(-50%, 108%);
  }
  #panel.open { transform: translate(-50%, 0); }
}
