/* Soft-pad: dock US; dual glitch sats US+CN both blue-shielded, opposite on 20-spot ring. Soft-pad. External CSS only (CSP). */

.us-flag-dock {
  position: absolute;
  left: max(0.85rem, calc(env(safe-area-inset-left) + 0.55rem));
  /* Sit above astrolabe (~min(22vw,180px) tall + its bottom inset) */
  bottom: max(
    calc(1.2rem + min(22vw, 180px) + 0.55rem),
    calc(env(safe-area-inset-bottom) + min(22vw, 180px) + 1.55rem)
  );
  z-index: 5; /* above sky-room astrolabe (4); below grain (8) / header */
  width: min(16vw, 118px);
  aspect-ratio: 1.9 / 1.35;
  pointer-events: none;
  display: block;
  isolation: isolate;
}

/* Fallback when injected as page-bottom chrome (no sky-room) — still document flow */
.site > .us-flag-dock,
.wm-dock ~ .us-flag-dock,
.us-flag-dock--page-bottom {
  position: relative;
  left: max(0.85rem, calc(env(safe-area-inset-left) + 0.55rem));
  bottom: auto;
  margin: 0.25rem 0 0.15rem;
  align-self: flex-start;
  width: min(16vw, 118px);
  z-index: 6;
}

.us-flag-shield {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

/* Blue crest / oval shield behind flag */
.us-flag-crest {
  position: absolute;
  inset: -18% -12%;
  border-radius: 50% / 46%;
  background:
    radial-gradient(ellipse 72% 68% at 50% 48%,
      rgba(70, 130, 220, 0.55) 0%,
      rgba(40, 90, 190, 0.42) 38%,
      rgba(20, 50, 120, 0.28) 62%,
      rgba(10, 30, 80, 0.08) 82%,
      transparent 100%);
  box-shadow:
    0 0 10px rgba(90, 170, 255, 0.45),
    0 0 22px rgba(50, 120, 255, 0.28),
    inset 0 0 14px rgba(160, 210, 255, 0.35);
  border: 1.5px solid rgba(120, 190, 255, 0.55);
  animation: us-flag-shield-pulse 2.4s ease-in-out infinite;
  z-index: 0;
  pointer-events: none;
}

.us-flag-crest::before {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50% / 46%;
  border: 1px solid rgba(180, 220, 255, 0.35);
  opacity: 0.85;
  animation: us-flag-ring-flicker 1.8s ease-in-out infinite;
}

.us-flag-img {
  position: relative;
  z-index: 2;
  display: block;
  width: 86%;
  height: auto;
  border-radius: 3px;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.45),
    0 0 8px rgba(90, 160, 255, 0.25);
  transform-origin: 50% 55%;
  animation: us-flag-wave 3.6s ease-in-out infinite;
  filter: saturate(1.05) contrast(1.04);
  pointer-events: none;
  user-select: none;
}

/* Soft spark / lightning accents around the shield */
.us-flag-sparks {
  position: absolute;
  inset: -8%;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
}

.us-flag-sparks svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.us-flag-bolt {
  fill: rgba(170, 215, 255, 0.92);
  stroke: rgba(210, 235, 255, 0.95);
  stroke-width: 0.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 3px rgba(100, 180, 255, 0.95));
  opacity: 0;
  animation: us-flag-bolt-flash 3.2s ease-in-out infinite;
}

.us-flag-bolt.b2 {
  fill: rgba(200, 230, 255, 0.88);
  animation-delay: 1.1s;
  animation-duration: 3.8s;
}

.us-flag-bolt.b3 {
  fill: rgba(140, 200, 255, 0.9);
  animation-delay: 2.0s;
  animation-duration: 2.9s;
}

@keyframes us-flag-shield-pulse {
  0%, 100% {
    box-shadow:
      0 0 8px rgba(90, 170, 255, 0.35),
      0 0 16px rgba(50, 120, 255, 0.2),
      inset 0 0 10px rgba(160, 210, 255, 0.25);
    border-color: rgba(120, 190, 255, 0.45);
    transform: scale(1);
    opacity: 0.92;
  }
  50% {
    box-shadow:
      0 0 16px rgba(120, 200, 255, 0.7),
      0 0 32px rgba(70, 150, 255, 0.45),
      inset 0 0 18px rgba(200, 230, 255, 0.5);
    border-color: rgba(180, 220, 255, 0.85);
    transform: scale(1.04);
    opacity: 1;
  }
}

@keyframes us-flag-ring-flicker {
  0%, 100% { opacity: 0.55; }
  40% { opacity: 0.95; }
  55% { opacity: 0.35; }
  70% { opacity: 0.9; }
}

@keyframes us-flag-wave {
  0%, 100% {
    transform: perspective(220px) rotateY(-4deg) skewX(0deg) scale(1);
  }
  25% {
    transform: perspective(220px) rotateY(3deg) skewX(1.2deg) scale(1.015);
  }
  50% {
    transform: perspective(220px) rotateY(-2deg) skewX(-0.8deg) scale(1.01);
  }
  75% {
    transform: perspective(220px) rotateY(4deg) skewX(0.9deg) scale(1.02);
  }
}

@keyframes us-flag-bolt-flash {
  0%, 72%, 100% { opacity: 0; stroke-dashoffset: 24; }
  76% { opacity: 1; stroke-dashoffset: 0; }
  82% { opacity: 0.15; }
  86% { opacity: 0.95; }
  92% { opacity: 0; }
}

@media (max-width: 640px) {
  .us-flag-dock {
    width: min(28vw, 100px);
    bottom: max(
      calc(1.0rem + min(28vw, 110px) + 0.45rem),
      calc(env(safe-area-inset-bottom) + min(28vw, 110px) + 1.35rem)
    );
  }
  .site > .us-flag-dock,
  .us-flag-dock--page-bottom {
    width: min(28vw, 100px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .us-flag-crest,
  .us-flag-crest::before,
  .us-flag-img,
  .us-flag-bolt {
    animation: none !important;
  }
  .us-flag-crest {
    opacity: 0.9;
    transform: none;
  }
  .us-flag-bolt { opacity: 0.35; }
  .us-flag-img { transform: none; }
}


/* Dock-only: accurate US cloth, no blue shield (shield reserved for CN sats) */
.us-flag-shield--dock .us-flag-img {
  width: 92%;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.45),
    0 0 6px rgba(255, 255, 255, 0.08);
  filter: saturate(1.04) contrast(1.03);
}

/* CN sat wrapper — crest stays behind cloth (z-index 0 vs img 2) */
.cn-flag-shield .us-flag-crest {
  z-index: 0;
}
.cn-flag-shield .us-flag-img {
  z-index: 2;
}

/* Satellite field — ONE sat node, opacity/visibility + transform zap between slots */
.us-flag-field {
  position: fixed;
  inset: 0;
  z-index: 1; /* behind content / lightning; above bare bg */
  pointer-events: none;
  overflow: hidden;
  contain: strict;
}

.us-flag-sat {
  position: absolute;
  width: min(5.8vw, 52px);
  aspect-ratio: 3 / 2;
  pointer-events: none;
  contain: layout style paint;
  opacity: 0;
  visibility: hidden;
  transform: translateZ(0) scale(1);
  will-change: transform, opacity;
}

.us-flag-sat.is-on {
  opacity: 0.82;
  visibility: visible;
  transform: translateZ(0) scale(1);
}

/* Chromatic snap / glitch flash — cheap opacity + translate (no new SVG) */
.us-flag-sat.is-zap {
  visibility: visible;
  animation: us-flag-sat-zap 90ms steps(2, jump-none) forwards;
}

@keyframes us-flag-sat-zap {
  0% {
    opacity: 0;
    transform: translate(-3px, 1px) scale(1.18);
  }
  40% {
    opacity: 1;
    transform: translate(3px, -2px) scale(0.92);
    /* cyan/magenta snap via layered box-shadow (cheaper than continuous filter) */
    box-shadow:
      -2px 0 0 rgba(0, 220, 255, 0.85),
      2px 0 0 rgba(255, 40, 120, 0.75),
      0 0 10px rgba(120, 200, 255, 0.55);
  }
  100% {
    opacity: 0;
    transform: translate(0, 0) scale(1);
    box-shadow: none;
  }
}

.us-flag-sat .us-flag-crest {
  inset: -14% -10%;
  animation-duration: 3.6s;
  box-shadow:
    0 0 6px rgba(90, 170, 255, 0.35),
    0 0 12px rgba(50, 120, 255, 0.18);
}

.us-flag-sat .us-flag-crest::before {
  animation-duration: 2.8s;
}

.us-flag-sat .us-flag-img {
  width: 84%;
  animation-duration: 5.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  filter: saturate(1.02);
}

@media (max-width: 640px) {
  .us-flag-sat { width: min(11vw, 44px); }
  .us-flag-sat.is-on { opacity: 0.72; }
}

@media (prefers-reduced-motion: reduce) {
  .us-flag-field { display: none; }
}

/* US glitch sat — same blue crest behind cloth as CN */
.us-flag-shield--sat-us .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-us .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* JP / TH glitch sats — same blue crest behind cloth */
.us-flag-shield--sat-jp .us-flag-crest,
.us-flag-shield--sat-th .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-jp .us-flag-img,
.us-flag-shield--sat-th .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* AU glitch sat — same blue crest behind cloth */
.us-flag-shield--sat-au .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-au .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* HI glitch sat — same blue crest behind cloth */
.us-flag-shield--sat-hi .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-hi .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* BR / AR / CL / CO glitch sats — same blue crest behind cloth */
.us-flag-shield--sat-br .us-flag-crest,
.us-flag-shield--sat-ar .us-flag-crest,
.us-flag-shield--sat-cl .us-flag-crest,
.us-flag-shield--sat-co .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-br .us-flag-img,
.us-flag-shield--sat-ar .us-flag-img,
.us-flag-shield--sat-cl .us-flag-img,
.us-flag-shield--sat-co .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* PL / UA glitch sats — same blue crest behind cloth */
.us-flag-shield--sat-pl .us-flag-crest,
.us-flag-shield--sat-ua .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-pl .us-flag-img,
.us-flag-shield--sat-ua .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* RU glitch sat — same blue crest behind cloth */
.us-flag-shield--sat-ru .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ru .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* EU glitch sat — same blue crest behind cloth */
.us-flag-shield--sat-eu .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-eu .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* IN glitch sat — same blue crest behind cloth */
.us-flag-shield--sat-in .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-in .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* Africa glitch sats — blue crest behind cloth (same as other sats) */
.us-flag-shield--sat-za .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-za .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ng .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ng .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-eg .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-eg .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ke .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ke .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-gh .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-gh .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-et .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-et .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ma .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ma .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-sn .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-sn .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-tz .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-tz .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-dz .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-dz .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-cm .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-cm .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ug .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ug .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }

/* Native American nation / confederacy glitch sats — blue crest */
.us-flag-shield--sat-hn .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-hn .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-nv .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-nv .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ck .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ck .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-sm .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-sm .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-hp .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-hp .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-lk .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-lk .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-ap .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-ap .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-mc .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-mc .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-cs .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-cs .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
.us-flag-shield--sat-os .us-flag-crest { z-index: 0; }
.us-flag-shield--sat-os .us-flag-img { position: relative; z-index: 2; width: 100%; height: auto; display: block; }
