/* ==========================================================================
   ORBITAL DEFENSE — HUD shell
   Sits on top of the main site stylesheet (which supplies fonts + tokens).
   External file only: the site's CSP disallows inline CSS.
   ========================================================================== */

.lab {
  --hud-bg: #04060d;
  --hud-panel: rgba(9, 15, 26, 0.82);
  --hud-panel-solid: rgba(8, 13, 23, 0.95);
  --hud-line: rgba(96, 176, 255, 0.20);
  --hud-line-hot: rgba(77, 226, 255, 0.55);
  --hud-cyan: #4de2ff;
  --hud-violet: #b98cff;
  --hud-green: #49f2c8;
  --hud-amber: #ffc857;
  --hud-red: #ff5a7a;
  --hud-text: #dceaff;
  --hud-dim: #7d93b4;
  margin: 0;
  background: var(--hud-bg);
  color: var(--hud-text);
  overflow: hidden;
  font-family: var(--font-body, Inter, system-ui, sans-serif);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* the HUD is an interface, not text to be selected — and double-tap zoom on a
   game canvas is never wanted */
.lab-bar, .lab-dock, .sel-panel, .lab-banner, .lab-tip, .lab-card {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.lab-lead, .lab-howto { user-select: text; -webkit-user-select: text; }

.lab-app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100svh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* grid/flex children default to min-width:auto, which lets a wide row of stat
   chips push the whole HUD past the viewport and clip the tool buttons off the
   right edge. Allow them to shrink instead. */
.lab-app > * { min-width: 0; }
.lab-bar > *, .lab-dock > *, .lab-stats > *, .lab-wave > * { min-width: 0; }

/* ── top command bar ──────────────────────────────────────────────────── */
.lab-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px clamp(12px, 2.2vw, 26px);
  background: linear-gradient(180deg, rgba(10, 17, 30, 0.95), rgba(6, 10, 18, 0.78));
  border-bottom: 1px solid var(--hud-line);
  backdrop-filter: blur(16px);
  z-index: 5;
}
.lab-bar::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--hud-cyan), transparent);
  opacity: .5;
}

.lab-brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 600; font-size: .98rem;
  letter-spacing: -.01em; color: var(--hud-text); text-decoration: none;
}
.lab-brand em { font-style: normal; color: var(--hud-dim); font-weight: 400; }

.lab-stats { display: flex; align-items: center; gap: clamp(8px, 1.6vw, 20px); }
.lab-stat {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px;
  border: 1px solid var(--hud-line);
  border-radius: 3px;
  background: rgba(12, 22, 38, 0.6);
  font-size: .9rem;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}
.lab-stat b {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: 1.02rem;
  color: #fff;
  text-shadow: 0 0 12px rgba(120, 220, 255, .55);
}
.lab-stat small {
  color: var(--hud-dim);
  font-family: var(--font-mono);
  font-size: .56rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.lab-stat i { width: 7px; height: 7px; border-radius: 99px; display: inline-block; }
.ic-credit { background: var(--hud-amber); box-shadow: 0 0 10px rgba(255, 200, 87, .7); }
.ic-hull   { background: var(--hud-red);   box-shadow: 0 0 10px rgba(255, 90, 122, .7); }
.ic-wave   { background: var(--hud-violet);box-shadow: 0 0 10px rgba(185, 140, 255, .7); }
.ic-kill   { background: var(--hud-green); box-shadow: 0 0 10px rgba(73, 242, 200, .7); }
.ic-score  { background: var(--hud-cyan);  box-shadow: 0 0 10px rgba(77, 226, 255, .7); }
.lab-stat--score { border-color: var(--hud-line-hot); }

.lab-tools { display: flex; align-items: center; gap: 7px; }
.lab-btn {
  border: 1px solid var(--hud-line);
  background: rgba(14, 24, 40, 0.65);
  color: var(--hud-text);
  padding: 7px 13px;
  border-radius: 3px;
  font-size: .78rem;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: color .2s, border-color .2s, box-shadow .2s, background .2s;
}
.lab-btn:hover {
  color: #fff;
  border-color: var(--hud-line-hot);
  box-shadow: 0 0 18px -4px rgba(77, 226, 255, .55) inset, 0 0 12px -4px rgba(77, 226, 255, .5);
  background: rgba(20, 40, 64, 0.75);
}

/* ── stage ────────────────────────────────────────────────────────────── */
.lab-stage { position: relative; overflow: hidden; }
.lab-stage::after {                       /* scanlines + vignette */
  content: '';
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background:
    repeating-linear-gradient(0deg, rgba(120, 200, 255, .035) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse 90% 80% at 50% 50%, transparent 45%, rgba(2, 4, 10, .72) 100%);
}
#gl { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; }

/* centred announcement */
.lab-banner {
  position: absolute; left: 50%; top: 13%;
  transform: translate(-50%, -8px);
  padding: 9px 22px;
  border: 1px solid var(--hud-line-hot);
  border-radius: 3px;
  background: rgba(6, 14, 26, .8);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: .82rem; letter-spacing: .18em; text-transform: uppercase;
  color: #fff; white-space: nowrap;
  opacity: 0; visibility: hidden;
  transition: opacity .3s, transform .3s, visibility .3s;
  z-index: 4;
  box-shadow: 0 0 40px -12px rgba(77, 226, 255, .8);
}
.lab-banner.is-on { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.lab-banner.is-big { font-size: 1rem; letter-spacing: .3em; padding: 12px 30px; }

/* horror variant — used for sector announcements and anything the rift does */
.lab-banner.is-horror {
  border-color: rgba(255, 42, 74, .85);
  color: #ffdbe2;
  background: rgba(28, 2, 8, .84);
  text-shadow: 0 0 16px rgba(255, 40, 70, .95), 0 0 40px rgba(255, 0, 40, .5);
  box-shadow: 0 0 50px -8px rgba(255, 20, 50, .9), 0 0 0 1px rgba(255, 70, 100, .2) inset;
  animation: horrorFlicker 2.4s steps(1, end) infinite;
}
@keyframes horrorFlicker {
  0%, 100% { opacity: 1; }
  42% { opacity: 1; }
  43% { opacity: .48; }
  45% { opacity: 1; }
  70% { opacity: .72; }
  71% { opacity: 1; }
}

/* the station is nearly lost — the whole view bleeds */
.lab-stage.is-danger::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse 78% 68% at 50% 50%, transparent 32%, rgba(196, 8, 34, .46) 100%);
  animation: dangerPulse 1.45s ease-in-out infinite;
}
@keyframes dangerPulse {
  0%, 100% { opacity: .38; }
  50% { opacity: 1; }
}

/* the wave button reads as a warning once things get bad */
.lab-stage.is-danger ~ .lab-dock #btn-wave,
.lab.is-danger #btn-wave { box-shadow: 0 0 30px -8px rgba(255, 40, 70, .95); }

/* ── selected unit panel ──────────────────────────────────────────────── */
.sel-panel {
  --c: var(--hud-cyan);
  position: absolute; right: clamp(10px, 2vw, 22px); top: clamp(10px, 2vh, 22px);
  width: min(252px, 62vw);
  padding: 12px 14px 13px;
  border: 1px solid var(--hud-line);
  border-radius: 4px;
  background: var(--hud-panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px -30px #000, 0 0 0 1px rgba(255, 255, 255, .02) inset;
  z-index: 4;
  opacity: 0; visibility: hidden; transform: translateX(12px);
  transition: opacity .22s, transform .22s, visibility .22s;
}
.sel-panel.is-on { opacity: 1; visibility: visible; transform: none; }
.sel-panel::before,
.sel-panel::after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border: 2px solid var(--c); opacity: .9;
}
.sel-panel::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; }
.sel-panel::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; }

.sel-head {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: .58rem; letter-spacing: .22em;
  text-transform: uppercase; color: var(--hud-dim);
}
.sel-head i { flex: 1; height: 1px; background: linear-gradient(90deg, var(--hud-line), transparent); }

.sel-name {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-top: 9px;
  font-family: var(--font-display); font-size: 1rem; color: #fff; letter-spacing: -.01em;
}
.sel-lv {
  font-family: var(--font-mono); font-size: .6rem; letter-spacing: .12em;
  padding: 2px 7px; border: 1px solid var(--c); border-radius: 2px; color: var(--c);
  white-space: nowrap;
}
.sel-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 10px;
  margin-top: 10px; font-size: .76rem;
}
.sel-grid span { font-family: var(--font-mono); font-size: .58rem; letter-spacing: .14em; color: var(--hud-dim); text-transform: uppercase; align-self: center; }
.sel-grid b { font-variant-numeric: tabular-nums; color: #fff; font-weight: 600; text-align: right; }

.sel-pips { display: flex; gap: 4px; margin-top: 10px; }
.sel-pips i { flex: 1; height: 3px; background: rgba(255, 255, 255, .12); border-radius: 2px; }
.sel-pips i.on { background: var(--c); box-shadow: 0 0 10px var(--c); }

.sel-actions { display: flex; gap: 7px; margin-top: 12px; }
.sel-btn {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--hud-line);
  border-radius: 3px;
  background: rgba(16, 28, 46, .8);
  color: var(--hud-text);
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer;
  transition: all .2s;
}
.sel-btn b { color: var(--hud-amber); font-size: .72rem; }
.sel-btn--up { border-color: var(--c); color: #fff; }
.sel-btn--up:hover:not(:disabled) { background: color-mix(in srgb, var(--c) 22%, transparent); box-shadow: 0 0 20px -6px var(--c); }
.sel-btn--sell:hover { border-color: var(--hud-red); color: #fff; }
.sel-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── overlays (mission briefing / debrief) ────────────────────────────── */
.lab-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 22px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(77, 140, 255, .16), transparent 65%),
    radial-gradient(ellipse 50% 50% at 80% 80%, rgba(185, 140, 255, .12), transparent 60%),
    rgba(3, 5, 11, .86);
  backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden;
  transition: opacity .35s var(--ease, ease), visibility .35s;
  z-index: 6;
}
.lab-overlay.is-open { opacity: 1; visibility: visible; }

.lab-card {
  position: relative;
  max-width: min(660px, 100%);
  min-width: 0;
  width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--hud-line);
  border-radius: 5px;
  background: linear-gradient(180deg, rgba(12, 20, 34, .97), rgba(6, 10, 18, .97));
  padding: clamp(22px, 3.6vw, 40px);
  box-shadow: 0 40px 90px -50px #000, 0 0 0 1px rgba(120, 200, 255, .05) inset;
}
.lab-card::before,
.lab-card::after {
  content: ''; position: absolute; width: 22px; height: 22px; border: 2px solid var(--hud-cyan); opacity: .8;
}
.lab-card::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; }
.lab-card::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; }

.lab-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3.4vw, 2.25rem);
  font-weight: 700; letter-spacing: -.025em; line-height: 1.08;
  margin: 12px 0 0; color: #fff;
}
.lab-lead { color: #a9c0dd; margin-top: 14px; font-size: .96rem; line-height: 1.62; }
.lab-howto { margin: 18px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 9px; }
.lab-howto li { position: relative; padding-left: 20px; color: #8fa6c4; font-size: .88rem; line-height: 1.5; }
.lab-howto li::before {
  content: ''; position: absolute; left: 0; top: .58em;
  width: 8px; height: 2px; background: var(--hud-cyan); box-shadow: 0 0 8px var(--hud-cyan);
}
.lab-card-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 26px; }
.lab-hint { color: var(--hud-dim); font-size: .78rem; font-family: var(--font-mono); letter-spacing: .03em; }

/* ── bottom dock ──────────────────────────────────────────────────────── */
.lab-dock {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px clamp(12px, 2.2vw, 26px);
  border-top: 1px solid var(--hud-line);
  background: linear-gradient(0deg, rgba(8, 14, 24, .96), rgba(6, 10, 18, .78));
  backdrop-filter: blur(16px);
  z-index: 5;
}

.lab-towers { display: flex; gap: 9px; flex-wrap: wrap; }
.tower-card {
  --c: var(--hud-cyan);
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 13px 9px 10px;
  border: 1px solid var(--hud-line);
  border-radius: 4px;
  background: rgba(12, 21, 36, .75);
  color: var(--hud-text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
  transition: border-color .2s, box-shadow .2s, background .2s, transform .12s;
}
.tower-card:hover { border-color: var(--hud-line-hot); transform: translateY(-1px); }
.tower-card.is-active {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, rgba(12, 21, 36, .9));
  box-shadow: 0 0 26px -8px var(--c), 0 0 0 1px var(--c) inset;
}
.tower-card.is-poor { opacity: .5; }

.tc-key {
  position: absolute; right: 6px; top: 4px;
  font-family: var(--font-mono); font-size: .54rem; color: var(--hud-dim);
}
.tc-icon {
  position: relative;
  width: 30px; height: 30px; flex: 0 0 30px;
  display: grid; place-items: center;
  border: 1px solid var(--c);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--c) 45%, transparent), transparent 70%);
  box-shadow: 0 0 16px -4px var(--c);
}
.tc-icon i { width: 9px; height: 9px; background: var(--c); box-shadow: 0 0 12px var(--c); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.tc-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tc-name { font-size: .84rem; font-weight: 600; color: #fff; white-space: nowrap; }
.tc-tag { font-family: var(--font-mono); font-size: .56rem; letter-spacing: .1em; text-transform: uppercase; color: var(--hud-dim); white-space: nowrap; }
.tc-cost {
  font-family: var(--font-display); font-variant-numeric: tabular-nums;
  font-size: .92rem; color: var(--hud-amber); margin-left: 4px;
}
.tc-cost::before { content: '◈'; font-size: .7rem; margin-right: 3px; opacity: .8; }

.lab-wave { display: flex; align-items: center; gap: 12px; }
.lab-wave .btn { white-space: nowrap; }

/* ── cursor tooltip ───────────────────────────────────────────────────── */
.lab-tip {
  position: absolute; z-index: 7; pointer-events: none;
  transform: translate(12px, -130%);
  padding: 5px 10px;
  border: 1px solid var(--hud-line-hot);
  border-radius: 3px;
  background: rgba(5, 12, 22, .92);
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .04em;
  color: #fff; white-space: nowrap;
  opacity: 0; transition: opacity .18s;
}
.lab-tip.is-on { opacity: 1; }

/* ── responsive ───────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .lab-stat small { display: none; }
  .lab-stat { padding: 5px 8px; }
}
@media (max-width: 860px) {
  .lab-bar { flex-wrap: wrap; gap: 9px; }
  .lab-stats { order: 3; flex: 1 1 100%; justify-content: space-between; }
  .lab-dock { flex-direction: column-reverse; align-items: stretch; }
  .lab-wave { justify-content: space-between; }
  .lab-towers { justify-content: center; }
  .tower-card { flex: 1 1 30%; min-width: 132px; }
  .sel-panel { width: min(240px, 74vw); }
  .lab-banner { font-size: .7rem; letter-spacing: .1em; }
}

/* ── landscape phones: vertical space is precious, keep the HUD to two rows ─ */
@media (max-height: 560px) {
  .lab-bar { flex-wrap: nowrap; padding: 6px 10px; gap: 8px; }
  .lab-stats { order: 0; flex: 1 1 auto; width: auto; justify-content: center; gap: 6px; overflow: visible; }
  .lab-stat { padding: 3px 7px; font-size: .78rem; }
  .lab-stat b { font-size: .86rem; }
  .lab-dock { flex-direction: row; align-items: center; padding: 6px 10px; gap: 10px; }
  .lab-towers { flex: 1 1 auto; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; }
  .tower-card { min-width: 112px; min-height: 44px; padding: 6px 9px; }
  .tc-tag { display: none; }
  .lab-wave .btn { padding: 10px 16px; font-size: .8rem; }
  .lab-hint { display: none; }
  .lab-brand span { display: none; }
  .lab-btn { padding: 7px 10px; font-size: .7rem; }
  .lab-overlay { padding: 10px; }
  .lab-card { padding: 16px 20px; max-height: 94vh; overflow-y: auto; }
  .lab-title { font-size: 1.3rem; margin-top: 8px; }
  .lab-lead { font-size: .84rem; margin-top: 9px; }
  .lab-howto { margin-top: 11px; gap: 5px; }
  .lab-howto li { font-size: .78rem; }
  .lab-card-actions { margin-top: 15px; }
  .lab-banner { top: 8%; }
}

@media (max-width: 640px) {
  .lab-btn--site { display: none; }     /* the logo already links home */
}

@media (max-width: 640px) {
  /* explicit grid: brand + tools on row one, stats scrolling underneath —
     flex wrapping kept squeezing the tool buttons off screen */
  .lab-bar {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "brand tools" "stats stats";
    row-gap: 7px;
    padding: 8px 10px;
  }
  .lab-brand { grid-area: brand; align-self: center; }
  .lab-tools { grid-area: tools; justify-content: flex-end; gap: 5px; margin-left: 0; }
  .lab-stats {
    grid-area: stats;
    gap: 5px;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }
  .lab-stats::-webkit-scrollbar { display: none; }
  .lab-stat { padding: 4px 8px; gap: 5px; font-size: .82rem; flex: 0 0 auto; }
  .lab-stat b { font-size: .9rem; }
  .lab-btn { padding: 8px 10px; font-size: .68rem; letter-spacing: 0; }
  .lab-dock { padding: 8px 10px; }
  .tower-card { min-width: 106px; padding: 8px 10px; gap: 8px; min-height: 52px; }
  .tc-icon { width: 26px; height: 26px; flex-basis: 26px; }
  .tc-icon i { width: 8px; height: 8px; }
  .tc-name { font-size: .76rem; }
  .tc-cost { font-size: .82rem; }
  .lab-wave .btn { padding: 12px 18px; font-size: .84rem; }
  .lab-hint { font-size: .68rem; }
  .sel-panel { width: min(200px, 58vw); padding: 9px 11px 10px; }
  .sel-name { font-size: .88rem; }
  .sel-grid { font-size: .68rem; gap: 3px 8px; }
  .sel-btn { padding: 10px 8px; font-size: .62rem; }
  .lab-banner { top: 9%; padding: 7px 14px; font-size: .64rem; letter-spacing: .08em; }
  .lab-banner.is-big { font-size: .8rem; padding: 9px 18px; letter-spacing: .18em; }
}

@media (max-width: 520px) {
  .tc-tag { display: none; }
  .lab-brand span { display: none; }
  .sel-panel { top: auto; bottom: 8px; right: 8px; }
}

/* ── touch devices ────────────────────────────────────────────────────── */
@media (pointer: coarse) {
  .lab-btn { padding: 10px 14px; font-size: .8rem; }
  .tower-card { min-height: 58px; padding: 10px 12px; }
  .tc-icon { width: 34px; height: 34px; flex-basis: 34px; }
  .sel-btn { padding: 12px 10px; font-size: .7rem; }
  .lab-wave .btn { padding: 13px 22px; }
  .lab-tip { display: none; }          /* hover tooltips are meaningless on touch */
}
@media (max-width: 760px) {
  .lab-dock { padding: 9px 10px; gap: 10px; }
  .lab-towers {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 3px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .lab-towers::-webkit-scrollbar { display: none; }
  .tower-card { flex: 0 0 auto; }
  .lab-card { padding: 20px 18px; }
  .lab-howto li { font-size: .82rem; }
  .lab-title { font-size: 1.42rem; }
  .lab-lead { font-size: .9rem; }
  .sel-panel { width: min(214px, 62vw); padding: 10px 12px 11px; }
  .sel-grid { font-size: .72rem; }
  .lab-stage::after { background-size: auto, 100% 100%; }
}
