/* ui/map-select/map-select.css — Pre-run map selection overlay. (M9 §5)
   Extends src/styles.css + ui/loadout/loadout.css CSS custom properties.
   z-index 30 (ui-design-system §3: above HUD + touch layer).
   No external assets, no font files. All colors via CSS variables.
   Touch targets ≥44px. Responsive: single-column below 520px. */

/* ── Overlay root ─────────────────────────────────────────────────────────── */
.ms-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  /* Hidden by default; JS adds .ms-visible to show */
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* R2.1.2 — Fully opaque so the 3D scene doesn't bleed through. */
  background: var(--void);
  color: var(--green);
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  overflow: hidden;
  pointer-events: none;
  padding:
    env(safe-area-inset-top,    12px)
    env(safe-area-inset-right,  12px)
    env(safe-area-inset-bottom, 12px)
    env(safe-area-inset-left,   12px);
}

.ms-overlay.ms-visible {
  display: flex;
}

/* ── Background + frame (shared FX language) ─────────────────────────────── */
.ms-bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: .9; }
.ms-frame {
  position: absolute; inset: 14px;
  border: 1px solid var(--fx-green-line-dim);
  pointer-events: none; z-index: 0;
}
.ms-furniture {
  position: absolute; left: 0; right: 0; z-index: 2; pointer-events: none;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 0 clamp(28px, 5vw, 56px);
}
.ms-furniture-top { top: clamp(24px, 4vh, 40px); }
.ms-furniture .fx-dot { margin-right: 6px; }

/* ── Title bar ───────────────────────────────────────────────────────────── */
.ms-header {
  width: 100%; max-width: 920px;
  padding: 10px 24px 14px; margin-top: clamp(40px, 7vh, 72px);
  flex-shrink: 0; position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.ms-title {
  margin: 0; font-family: inherit; font-weight: 700;
  font-size: clamp(20px, 3vw, 30px); letter-spacing: 7px; color: var(--amber);
  text-transform: uppercase;
  text-shadow: 0 0 4px rgba(255,176,0,.7), 0 0 24px rgba(255,176,0,.3);
}
.ms-subtitle { letter-spacing: 2px; }

/* ── Card grid — centered vertically so there's no dead void below ───────── */
.ms-grid {
  display: flex; flex-direction: row; gap: clamp(18px, 3vw, 32px);
  padding: 24px 20px; flex-wrap: wrap;
  justify-content: center; align-items: stretch; align-content: center;
  max-width: 920px; width: 100%; flex: 1;
  position: relative; z-index: 1;
}

/* ── Map card ────────────────────────────────────────────────────────────── */
.ms-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 0 0 16px; overflow: hidden;
  background: var(--fx-sheen);
  border: 1px solid var(--fx-green-line-dim);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  cursor: pointer; flex: 1 1 280px; min-width: 260px; max-width: 360px;
  box-sizing: border-box;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
/* Focus/hover: brighten + glow (inset, so the clip never cuts it) — not invert. */
.ms-card.ui-focused, .ms-card:hover {
  border-color: var(--amber);
  background: linear-gradient(0deg, rgba(255,176,0,.07), rgba(10,14,42,.85));
  box-shadow: inset 0 0 0 1px var(--amber), inset 0 0 26px rgba(255,176,0,.16);
}
.ms-card.ui-focused .ms-card-name, .ms-card:hover .ms-card-name { color: var(--cream, #f0e6c8); }
.ms-card.ui-focused .ms-schematic, .ms-card:hover .ms-schematic { opacity: 1; }

/* ── Card internals ──────────────────────────────────────────────────────── */
.ms-card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px 11px; border-bottom: 1px solid var(--fx-green-line-dim);
  background: rgba(255,176,0,.04);
}
.ms-card-tag {
  font-size: 9px; letter-spacing: 2px; color: var(--void);
  background: var(--amber); padding: 2px 6px; flex: 0 0 auto;
}
.ms-card-name {
  font-size: 15px; color: var(--amber); letter-spacing: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ms-card-thumb {
  margin: 0 14px; padding: 6px; flex-shrink: 0;
  background: rgba(10,14,42,.5); border: 1px solid var(--fx-green-line-dim);
}
.ms-schematic { display: block; width: 100%; height: auto; opacity: .8; transition: opacity .15s ease; }
.ms-card-stats {
  display: flex; gap: 6px; margin: 0 14px;
}
.ms-stat {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 5px 7px; background: rgba(51,255,102,.04);
  border-left: 2px solid var(--fx-green-line);
}
.ms-stat-k { font-size: 8px; letter-spacing: 1.5px; color: var(--green); opacity: .6; }
.ms-stat-v { font-size: 11px; letter-spacing: 1px; color: var(--amber); }
.ms-card-flavor {
  margin: 0 14px; font-size: 10px; color: var(--green); opacity: .75;
  letter-spacing: 1.5px; line-height: 1.5; text-transform: none;
}

/* ── Actions row (top-right pin, R3.1) ──────────────────────────────────────
   COMMENCE + MAIN MENU live in the top-right corner so the CTA never moves
   with map selection. Pick a card → hit COMMENCE. MAIN MENU sits to the
   left of COMMENCE (back affordance always on the left). */
.ms-actions {
  flex-shrink: 0;
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  position: relative; z-index: 3;
}
.ms-actions-top {
  position: absolute;
  top: clamp(18px, 3vh, 32px);
  right: clamp(28px, 5vw, 56px);
  margin: 0;
}

/* ── COMMENCE button (primary, top-right) ─────────────────────────────────── */
.ms-commence-btn {
  flex-shrink: 0;
  padding: 12px 22px; min-height: 44px;
  background: linear-gradient(0deg, rgba(255,176,0,.10), rgba(255,176,0,.03));
  border: 1px solid var(--amber);
  color: var(--amber);
  font-family: 'Courier New', Courier, monospace; font-weight: 700;
  font-size: 14px; letter-spacing: 5px; text-transform: uppercase;
  cursor: pointer; overflow: hidden;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  box-shadow: var(--fx-glow-amber);
  transition: color .14s ease, background .16s ease, box-shadow .16s ease;
  position: relative;
}
.ms-commence-btn::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: var(--amber); box-shadow: 0 0 10px var(--amber);
  transform: scaleY(0); transform-origin: bottom; transition: transform .18s ease;
}
.ms-commence-btn:hover, .ms-commence-btn:active, .ms-commence-btn:focus-visible {
  color: var(--cream, #f0e6c8); outline: none;
  background: linear-gradient(0deg, rgba(255,176,0,.20), rgba(255,176,0,.08));
  box-shadow: 0 0 30px rgba(255,176,0,.32), 0 0 8px rgba(255,176,0,.45);
}
.ms-commence-btn:hover::before, .ms-commence-btn:active::before, .ms-commence-btn:focus-visible::before { transform: scaleY(1); }

/* ── MAIN MENU button (R3 — back to start screen / settings) ─────────────── */
.ms-main-menu-btn {
  flex-shrink: 0;
  padding: 10px 18px; min-height: 40px;
  background: linear-gradient(0deg, rgba(51,255,102,.06), rgba(51,255,102,.02));
  border: 1px solid var(--green-dim, rgba(51,255,102,.4));
  color: var(--green, #33ff66);
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px; letter-spacing: 3px; text-transform: uppercase;
  cursor: pointer; overflow: hidden;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  transition: color .14s ease, background .16s ease;
  position: relative;
}
.ms-main-menu-btn::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--green); box-shadow: 0 0 8px var(--green);
  transform: scaleY(0); transform-origin: bottom; transition: transform .18s ease;
}
.ms-main-menu-btn:hover,
.ms-main-menu-btn:active {
  color: var(--cream, #f0e6c8);
  background: linear-gradient(0deg, rgba(51,255,102,.12), rgba(51,255,102,.04));
}
.ms-main-menu-btn:hover::before, .ms-main-menu-btn:active::before { transform: scaleY(1); }

/* ── Gamepad hint footer ─────────────────────────────────────────────────── */
.ms-hint-footer {
  /* Hidden by default; shown only when gamepad driver active */
  display: none;
  flex-shrink: 0;
  width: 100%;
  padding: 6px 20px;
  font-size: 9px;
  color: var(--green);
  letter-spacing: 2px;
  opacity: .7;
  border-top: 1px solid var(--green-dim);
  background: rgba(10,14,42,.6);
  justify-content: center;
  align-items: center;
  gap: 24px;
  position: relative;
  z-index: 1;
}

.ms-hint-footer.ms-hint-visible {
  display: flex;
}

/* ── Responsive — stack cards on narrow screens ──────────────────────────── */
@media (max-width: 520px) {
  .ms-title {
    font-size: 13px;
    letter-spacing: 3px;
  }
  .ms-grid {
    flex-direction: column;
    align-items: center;
    padding: 14px 12px;
    gap: 12px;
  }
  .ms-card {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }
  .ms-card-thumb {
    font-size: 10px;
  }
  .ms-actions-top {
    top: clamp(12px, 2vh, 18px);
    right: clamp(10px, 3vw, 16px);
    gap: 6px;
  }
  .ms-commence-btn {
    padding: 10px 14px;
    font-size: 12px;
    letter-spacing: 3px;
  }
  .ms-main-menu-btn {
    padding: 8px 12px;
    font-size: 10px;
    letter-spacing: 2px;
  }
}

/* ── Short-height landscape (iPhone 15 landscape ≈ 852×393) ──────────────────
   The header's tall top margin + furniture strips push the card grid below the
   fold. Pull the header up, shrink it, and let the grid scroll if the cards are
   taller than the remaining height. COMMENCE/MAIN MENU are absolute top-right,
   so they stay reachable — just keep them clear of the notch. */
@media (max-height: 480px) {
  .ms-header {
    margin-top: max(env(safe-area-inset-top,0), 10px);
    padding: 6px 16px 8px;
    gap: 3px;
  }
  .ms-title { font-size: clamp(16px, 2.4vw, 22px); letter-spacing: 4px; }
  .ms-subtitle { font-size: 10px; }
  /* Hide the decorative furniture strips so they don't collide with cards. */
  .ms-furniture { display: none; }
  /* Grid scrolls within the remaining space; cards stay 3-up where they fit. */
  .ms-grid {
    padding: 8px 16px;
    gap: clamp(10px, 2vw, 18px);
    align-content: flex-start;
    overflow-y: auto;
    min-height: 0;
  }
  .ms-card { flex: 1 1 220px; min-width: 200px; }
  .ms-card-head { padding: 8px 12px; }
  .ms-card-name { font-size: 13px; }
  /* Keep the top-right CTAs clear of the landscape notch. */
  .ms-actions-top { top: max(env(safe-area-inset-top,0), 10px); }
}

/* ── Reduced motion: drop shimmer, snap transitions ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ms-card {
    transition: none;
  }
  .ms-card.ui-focused::after {
    display: none;
  }
  .ms-commence-btn,
  .ms-main-menu-btn {
    transition: none;
  }
}
