/* Citadel mobile / touch-first overlay — additive; keep Desktop WASD intact.
   Loaded only as assets/mobile/citadel-mobile.css from index.html. */

:root {
  --citadel-touch-safe-top: env(safe-area-inset-top, 0px);
  --citadel-touch-safe-right: env(safe-area-inset-right, 0px);
  --citadel-touch-safe-bottom: env(safe-area-inset-bottom, 0px);
  --citadel-touch-safe-left: env(safe-area-inset-left, 0px);
  --citadel-touch-min: 44px;
  --citadel-touch-pad: 12px;
}

/* ---------- Touch HUD (joystick + look pad) ---------- */
.citadel-touch-hud {
  position: fixed;
  inset: 0;
  z-index: 9200;
  pointer-events: none;
  display: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body.is-touch-ui.citadel-touch-hud-on .citadel-touch-hud {
  display: block;
}
.citadel-touch-hud__zone {
  position: absolute;
  bottom: calc(18px + var(--citadel-touch-safe-bottom));
  width: min(42vw, 168px);
  height: min(42vw, 168px);
  pointer-events: auto;
  touch-action: none;
}
.citadel-touch-hud__zone--move {
  left: calc(14px + var(--citadel-touch-safe-left));
}
.citadel-touch-hud__zone--look {
  right: calc(14px + var(--citadel-touch-safe-right));
}
.citadel-touch-hud__base {
  position: absolute;
  inset: 18% 18%;
  border-radius: 50%;
  border: 1.5px solid rgba(126, 240, 255, 0.35);
  background: radial-gradient(circle at 50% 45%, rgba(14, 30, 55, 0.42), rgba(2, 6, 14, 0.55));
  box-shadow: 0 0 24px rgba(46, 230, 255, 0.12), inset 0 0 18px rgba(0, 0, 0, 0.35);
}
.citadel-touch-hud__stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 38%;
  margin: -19% 0 0 -19%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(180, 245, 255, 0.95), rgba(46, 230, 255, 0.55) 55%, rgba(14, 116, 144, 0.75));
  box-shadow: 0 0 16px rgba(46, 230, 255, 0.45);
  transform: translate(0, 0);
  will-change: transform;
}
.citadel-touch-hud__zone--look .citadel-touch-hud__base {
  border-color: rgba(232, 197, 106, 0.4);
  background: radial-gradient(circle at 50% 45%, rgba(40, 28, 12, 0.4), rgba(2, 6, 14, 0.55));
}
.citadel-touch-hud__zone--look .citadel-touch-hud__stick {
  background: radial-gradient(circle at 35% 30%, rgba(255, 230, 170, 0.95), rgba(232, 197, 106, 0.55) 55%, rgba(120, 80, 20, 0.75));
  box-shadow: 0 0 16px rgba(232, 197, 106, 0.4);
}
.citadel-touch-hud__label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  text-align: center;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(200, 230, 255, 0.55);
  pointer-events: none;
}
.citadel-touch-hud__actions {
  position: absolute;
  right: calc(14px + var(--citadel-touch-safe-right));
  bottom: calc(18px + var(--citadel-touch-safe-bottom) + min(42vw, 168px) + 10px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}
.citadel-touch-hud__btn {
  min-width: var(--citadel-touch-min);
  min-height: var(--citadel-touch-min);
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(126, 240, 255, 0.4);
  background: rgba(8, 16, 32, 0.72);
  color: #d8f7ff;
  font: 600 0.78rem/1 Outfit, system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  touch-action: manipulation;
  box-shadow: 0 0 14px rgba(46, 230, 255, 0.18);
}
.citadel-touch-hud__btn.is-active,
.citadel-touch-hud__btn:active {
  background: rgba(46, 230, 255, 0.28);
  color: #021018;
  border-color: rgba(180, 245, 255, 0.85);
}
.citadel-touch-hud__btn--gold {
  border-color: rgba(232, 197, 106, 0.45);
  color: #ffe9b0;
  box-shadow: 0 0 14px rgba(232, 197, 106, 0.18);
}
.citadel-touch-hud__btn--gold.is-active,
.citadel-touch-hud__btn--gold:active {
  background: rgba(232, 197, 106, 0.35);
  color: #1a1204;
}

/* ---------- Coarse / narrow layout + safe areas ---------- */
@media (pointer: coarse), (max-width: 720px) {
  html, body {
    overscroll-behavior: none;
  }

  .btn,
  button.btn,
  .btn-mini,
  .gate-nav button,
  .modal-overlay .modal-close,
  .modal-head button,
  #btnReturnToSky,
  .bolt-approach__enter-land,
  .bolt-approach button,
  .constellation-fs-toolbar button,
  [data-touch-target] {
    min-height: var(--citadel-touch-min);
    min-width: var(--citadel-touch-min);
    padding-top: max(0.55rem, 10px);
    padding-bottom: max(0.55rem, 10px);
  }

  .modal-overlay {
    align-items: flex-end !important;
    padding: var(--citadel-touch-safe-top) var(--citadel-touch-safe-right)
      max(0.5rem, var(--citadel-touch-safe-bottom)) var(--citadel-touch-safe-left);
  }
  .modal-overlay .modal,
  .modal-overlay.open .modal,
  #detailModal.open .modal,
  .play-modal .modal {
    width: min(100%, 100vw) !important;
    max-width: 100% !important;
    max-height: min(92dvh, calc(100dvh - var(--citadel-touch-safe-top) - 0.5rem));
    margin: 0 !important;
    border-radius: 18px 18px 10px 10px;
    padding-bottom: max(0.75rem, var(--citadel-touch-safe-bottom));
  }

  .gate-header,
  footer.about,
  .intro-strip {
    padding-left: max(0.75rem, var(--citadel-touch-safe-left));
    padding-right: max(0.75rem, var(--citadel-touch-safe-right));
  }

  /* Hall chrome: keep primary actions in thumb band */
  .shell[data-view="home"] .gate-header {
    padding-top: max(0.5rem, var(--citadel-touch-safe-top));
  }

  .constellation-hint,
  .bolt-approach__hint {
    font-size: 0.78rem;
    line-height: 1.35;
    padding-bottom: max(0.35rem, var(--citadel-touch-safe-bottom));
  }

  /* Avoid expensive canvas CSS blur on phones (does not gut HC_GFX shaders) */
  canvas,
  #relicConstellationSky,
  .bolt-approach canvas,
  .constellation-sky canvas {
    filter: none !important;
  }

  /* Soften backdrop blurs that thrash mobile GPUs */
  .modal-overlay .modal,
  .btn-ghost,
  .constellation-fs-toolbar,
  .bolt-approach__hud {
    backdrop-filter: blur(6px) saturate(1.05) !important;
    -webkit-backdrop-filter: blur(6px) saturate(1.05) !important;
  }
}

/* Hover-only affordances: keep for real hover devices; on touch, rely on visible CTAs */
@media (hover: none) {
  .btn-ghost:hover,
  .btn-primary:hover,
  .btn-gold:hover {
    filter: none;
  }
  /* Anything marked hover-only must not be the only path */
  .citadel-hover-only {
    display: none !important;
  }
}

@media (hover: hover) and (pointer: fine) {
  .citadel-touch-only {
    display: none !important;
  }
}

/* When touch HUD is up, keep Return-to-Sky / land CTAs above pads */
body.citadel-touch-hud-on #btnReturnToSky,
body.citadel-touch-hud-on .bolt-approach__enter-land,
body.citadel-touch-hud-on .bolt-approach__hc-near {
  bottom: calc(12px + var(--citadel-touch-safe-bottom) + min(42vw, 168px) + 56px) !important;
  z-index: 9300;
}

body.citadel-touch-hud-on .constellation-hint,
body.citadel-touch-hud-on #constellationHint {
  margin-bottom: calc(8px + min(42vw, 168px));
}


/* ---------- Narrow Hall shell / side-nav ---------- */
@media (max-width: 900px) {
  .shell { --side-w: 0px; }
  .main, .main-col, .content, .hall-main {
    margin-left: 0 !important;
    padding-left: max(0.75rem, var(--citadel-touch-safe-left));
    padding-right: max(0.75rem, var(--citadel-touch-safe-right));
  }
  .nav-map-toggle {
    min-height: var(--citadel-touch-min);
    min-width: var(--citadel-touch-min);
  }
  .forge-featured-grid,
  .explore-grid,
  .tile-grid {
    grid-template-columns: 1fr !important;
  }
  .side-nav-item {
    min-height: var(--citadel-touch-min);
  }
}
