/*
 * Battlefield left, full turret command rail right, compact launch card
 * centred directly beneath the field. On narrow screens the arsenal becomes
 * a horizontal bottom dock; the launch remains underneath the field.
 */
body.siege-mode #app {
  max-width: 1640px;
  padding: clamp(10px, 1.1vw, 18px) clamp(10px, 1.5vw, 22px) 30px;
}

body.siege-mode .siege-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 330px);
  align-items: start;
  gap: clamp(12px, 1.2vw, 20px);
}

body.siege-mode .siege-battle-zone {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.siege-mode .siege-canvas-wrap {
  min-width: 0;
  box-shadow: 0 12px 36px rgba(0,0,0,.34);
}

body.siege-mode #siege-canvas {
  height: clamp(315px, calc(100dvh - var(--gb-sticky-header-height) - 150px), 680px);
}

/* The only scrollable shop on desktop is its own rail.
   The canvas and its controls never need to move to reach a turret. */
body.siege-mode .siege-loadout {
  position: sticky;
  top: calc(var(--gb-sticky-header-height) + 12px);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: calc(100dvh - var(--gb-sticky-header-height) - 24px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid rgba(214,162,76,.49);
  border-radius: 15px;
  padding: 10px;
  background: linear-gradient(160deg,#21182d,#111523 72%,#121123);
  box-shadow: 0 14px 42px rgba(0,0,0,.34);
}

body.siege-mode .siege-loadout .siege-deploy-panel {
  position: static;
  top: auto;
  z-index: auto;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px;
  border-radius: 11px;
  box-shadow: inset 0 0 18px rgba(116,230,92,.07);
}

body.siege-mode .siege-loadout .siege-deploy-copy {
  min-width: 0;
  flex: 0 0 auto;
}

body.siege-mode .siege-loadout .siege-deploy-panel h2 {
  margin: 4px 0;
  font-size: clamp(1.4rem, 1.7vw, 1.8rem);
}

body.siege-mode .siege-loadout .siege-deploy-panel p {
  font-size: .78rem;
  line-height: 1.35;
}

body.siege-mode .siege-loadout .siege-deploy-summary {
  margin-top: 6px;
  font-size: .79rem;
}

body.siege-mode .siege-loadout .siege-launch-button {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  min-height: 56px;
  font-size: clamp(1.3rem,1.8vw,1.65rem);
}

body.siege-mode .siege-loadout-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 9px;
  padding: 2px 3px 0;
}

body.siege-mode .siege-loadout-heading strong {
  color: #ffe09a;
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 400;
  letter-spacing: .03em;
}

body.siege-mode .siege-loadout-heading span {
  color: #cfc3d9;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.15;
}

body.siege-mode .siege-loadout .shop-bar {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #a0844a #211a2c;
  border: 1px solid rgba(153,125,179,.25);
  background: rgba(9,8,20,.67);
  padding: 12px;
}

body.siege-mode .siege-loadout .shop-budget {
  margin: 0 0 6px;
  font-weight: 900;
  color: #e7daee;
}

body.siege-mode .siege-loadout .shop-budget strong {
  font-size: 1.4rem;
  color: #ffde7a;
}

body.siege-mode .siege-loadout .shop-hint {
  font-size: .74rem;
  margin-bottom: 11px;
  color: #c4b8d2;
}

body.siege-mode .siege-loadout .shop-turrets {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 9px;
  margin: 0;
  overflow: visible;
}

body.siege-mode .siege-loadout .shop-buy-btn {
  min-width: 0;
  min-height: 103px;
  padding: 8px 4px 6px;
  border-radius: 10px;
  gap: 4px;
  background: rgba(16,13,30,.86);
}

body.siege-mode .siege-loadout .shop-buy-btn img {
  width: 64px;
  height: 61px;
  margin-top: 7px;
  object-fit: contain;
}

body.siege-mode .siege-loadout .turret-name {
  width: 100%;
  font-size: .68rem;
  line-height: 1.15;
  white-space: normal;
  overflow: visible;
  font-weight: 900;
}

body.siege-mode .siege-loadout .price-tag {
  font-size: .65rem;
  padding: 1px 5px;
  top: 4px;
  right: 4px;
}

body.siege-mode .siege-command-bar {
  padding: 1px 0;
}

/* Bonus choice needs the whole canvas on mobile. The shop disappears
   temporarily while that choice is on screen, then comes straight back. */
body.siege-mode .siege-layout.is-bonus-offer .siege-loadout,
body.siege-mode .siege-layout.is-battle-done .siege-loadout {
  display: none;
}

@media (max-width: 959px) {
  body.siege-mode #app {
    max-width: none;
    padding: 10px 10px clamp(178px, 36dvh, 235px);
  }

  body.siege-mode .siege-layout {
    display: block;
  }

  body.siege-mode #siege-canvas {
    height: clamp(225px, calc(100dvh - var(--gb-sticky-header-height) - 225px), 470px);
  }

  body.siege-mode .siege-loadout {
    position: fixed;
    top: auto;
    bottom: max(7px,env(safe-area-inset-bottom,0px));
    left: 8px;
    right: 8px;
    width: auto;
    z-index: 65;
    max-height: min(39dvh, 235px);
    min-height: 0;
    padding: 7px;
    gap: 5px;
    border-radius: 12px;
    background: rgba(22,16,34,.98);
    box-shadow: 0 -5px 25px rgba(0,0,0,.65);
  }

  body.siege-mode .siege-loadout .siege-deploy-panel {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(165px, 40%);
    align-items: center;
    padding: 6px 9px;
    gap: 8px;
  }

  body.siege-mode .siege-loadout .siege-deploy-panel h2 {
    margin: 2px 0;
    font-size: 1.18rem;
  }

  body.siege-mode .siege-loadout .siege-deploy-panel p {
    font-size: .69rem;
    line-height: 1.18;
  }

  body.siege-mode .siege-loadout .siege-deploy-summary {
    margin-top: 3px;
    font-size: .69rem;
  }

  body.siege-mode .siege-loadout .siege-launch-button {
    min-height: 50px;
    padding: 6px 8px;
    font-size: clamp(1.05rem,2.9vw,1.35rem);
  }

  body.siege-mode .siege-loadout-heading {
    display: none;
  }

  body.siege-mode .siege-loadout .shop-bar {
    padding: 5px 7px 4px;
    overflow-y: hidden;
    overflow-x: hidden;
  }

  body.siege-mode .siege-loadout .shop-budget {
    font-size: .79rem;
    margin-bottom: 4px;
  }

  body.siege-mode .siege-loadout .shop-budget strong {
    font-size: 1.04rem;
  }

  body.siege-mode .siege-loadout .shop-hint {
    display: none;
  }

  body.siege-mode .siege-loadout .shop-turrets {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1px 3px 5px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  body.siege-mode .siege-loadout .shop-buy-btn {
    flex: 0 0 86px;
    min-height: 76px;
    padding: 2px 2px 4px;
    gap: 1px;
  }

  body.siege-mode .siege-loadout .shop-buy-btn img {
    width: 42px;
    height: 42px;
    margin-top: 5px;
  }

  body.siege-mode .siege-loadout .turret-name {
    font-size: .55rem;
    line-height: 1.06;
  }

  body.siege-mode .siege-loadout .price-tag {
    font-size: .49rem;
    padding: 1px 3px;
    top: 2px;
    right: 2px;
  }

  body.siege-mode .siege-command-bar {
    padding-bottom: 12px;
  }

  body.siege-mode .siege-layout.is-bonus-offer .siege-loadout,
  body.siege-mode .siege-layout.is-battle-done .siege-loadout {
    display: none;
  }
}

@media (max-width: 490px) {
  body.siege-mode .siege-loadout .siege-deploy-panel {
    grid-template-columns: 1fr;
  }

  body.siege-mode .siege-loadout .siege-deploy-panel p {
    display: none;
  }

  body.siege-mode .siege-loadout .siege-deploy-panel h2 {
    display: none;
  }

  body.siege-mode .siege-loadout .siege-deploy-summary {
    font-size: .72rem;
  }

  body.siege-mode .siege-loadout .siege-launch-button {
    min-height: 42px;
  }
}

@media (prefers-reduced-motion:reduce) {
  body.siege-mode .siege-loadout .shop-turrets {
    scroll-behavior: auto;
  }
}


/* Launch now lives BELOW the field, centred in the unused footer space.
   The right-hand arsenal contains turrets only, so the shop gets the full
   height of the rail instead of sacrificing its first 260px to a banner. */
body.siege-mode .siege-battle-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 520px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

body.siege-mode .siege-battle-footer .siege-command-bar {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0;
}

body.siege-mode .siege-battle-footer .siege-command-bar .btn-fire-nukes {
  margin-left: 0;
}

body.siege-mode .siege-battle-footer .siege-deploy-panel {
  position: static;
  top: auto;
  z-index: auto;
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(205px, .92fr);
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid rgba(129,231,109,.65);
  border-radius: 12px;
  box-shadow: inset 0 0 15px rgba(120,239,95,.07), 0 5px 15px rgba(0,0,0,.2);
}

body.siege-mode .siege-battle-footer .siege-deploy-copy {
  min-width: 0;
  flex: auto;
}

body.siege-mode .siege-battle-footer .siege-deploy-panel h2 {
  display: none;
}

body.siege-mode .siege-battle-footer .siege-deploy-eyebrow {
  display: block;
  font-size: .7rem;
  line-height: 1.15;
}

body.siege-mode .siege-battle-footer .siege-deploy-panel p {
  margin: 5px 0 0;
  color: #dfebdd;
  font-size: .78rem;
  line-height: 1.2;
}

body.siege-mode .siege-battle-footer .siege-deploy-summary {
  margin: 5px 0 0;
  font-size: .8rem;
  line-height: 1.3;
}

body.siege-mode .siege-battle-footer .siege-launch-wrap {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
}

body.siege-mode .siege-battle-footer .siege-launch-button {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  min-height: 61px;
  padding: 8px 12px;
  font-size: clamp(1.25rem, 1.6vw, 1.65rem);
  line-height: 1.05;
  overflow-wrap: break-word;
  text-wrap: balance;
}

body.siege-mode .siege-footer-spacer {
  grid-column: 3;
  grid-row: 1;
}

/* Shorter desktop viewports still get the full turret rail, with the
   launch card and nuke controls stacked under the field if needed. */
@media (min-width: 960px) and (max-width: 1399px) {
  body.siege-mode .siege-battle-footer {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 8px;
  }

  body.siege-mode .siege-battle-footer .siege-deploy-panel {
    grid-column: 1;
    grid-row: 1;
    max-width: 520px;
  }

  body.siege-mode .siege-battle-footer .siege-command-bar {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  body.siege-mode .siege-footer-spacer {
    display: none;
  }
}

@media (max-width: 959px) {
  /* Turrets remain in the bottom dock, but the battle cry stays below the
     FIELD, not inside the dock where it would steal turret space. */
  body.siege-mode #app {
    padding-bottom: max(155px, calc(135px + env(safe-area-inset-bottom, 0px)));
  }

  body.siege-mode .siege-battle-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-top: 4px;
  }

  body.siege-mode .siege-battle-footer .siege-deploy-panel {
    width: 100%;
    max-width: 520px;
    grid-template-columns: minmax(0,1fr) minmax(165px,41%);
    padding: 10px;
    gap: 8px;
    order: -1;
  }

  body.siege-mode .siege-battle-footer .siege-launch-button {
    min-height: 49px;
    font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  }

  body.siege-mode .siege-battle-footer .siege-command-bar {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
  }

  body.siege-mode .siege-footer-spacer {
    display: none;
  }

  body.siege-mode .siege-loadout {
    max-height: min(25dvh, 160px);
  }

  body.siege-mode .siege-loadout .shop-bar {
    overflow: hidden;
  }
}

@media (max-width: 490px) {
  body.siege-mode .siege-battle-footer .siege-deploy-panel {
    grid-template-columns: minmax(0, 1fr) minmax(140px, 47%);
  }

  body.siege-mode .siege-battle-footer .siege-deploy-panel p {
    font-size: .71rem;
  }

  body.siege-mode .siege-battle-footer .siege-deploy-summary {
    font-size: .7rem;
  }

  body.siege-mode .siege-battle-footer .siege-launch-button {
    font-size: 1.05rem;
    min-height: 48px;
    padding: 7px;
  }
}

/* Battle speed: a chunky gold button so kids spot it straight away. */
body.siege-mode .wave-controls #btn-speed {
  min-width: 120px;
  min-height: 46px;
  padding: 6px 16px;
  border: 2px solid #ffe18a;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffeb8a, #ffb235 55%, #e97a20);
  color: #2a1102;
  font-size: 1.45rem;
  letter-spacing: .03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
  box-shadow: 0 4px 0 #8f4c10, 0 6px 18px rgba(0, 0, 0, .55), 0 0 16px rgba(255, 180, 50, .45);
  cursor: pointer;
}

body.siege-mode .wave-controls #btn-speed:hover {
  background: linear-gradient(180deg, #fff2a8, #ffc04d 55%, #f08a2a);
  transform: translateY(-1px);
}

body.siege-mode .wave-controls #btn-speed:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8f4c10, 0 3px 10px rgba(0, 0, 0, .5);
}

body.siege-mode .wave-controls #btn-speed[data-speed="2"],
body.siege-mode .wave-controls #btn-speed[data-speed="3"] {
  border-color: #ffb08a;
  background: linear-gradient(180deg, #ff9a6a, #ff5a2e 55%, #c8300f);
  color: #fff;
  text-shadow: 0 2px 0 rgba(90, 20, 0, .6);
  box-shadow: 0 4px 0 #7a1c06, 0 6px 18px rgba(0, 0, 0, .55), 0 0 18px rgba(255, 90, 40, .6);
}

/* Porch hearts: how many more aliens Granny can let through. */
body.siege-mode .leak-meter {
  position: absolute;
  top: 100px;
  right: 10px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 12px 6px 10px;
  border: 2px solid rgba(255, 140, 140, .55);
  border-radius: 14px;
  background: rgba(30, 6, 10, .72);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
  pointer-events: none;
}

body.siege-mode .leak-meter-label {
  margin-right: 5px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: .06em;
  color: #ffd0c8;
}

body.siege-mode .leak-heart {
  position: relative;
  font-size: 1.35rem;
  line-height: 1;
}

body.siege-mode .leak-heart-glyph {
  display: block;
  filter: drop-shadow(0 0 4px rgba(255, 60, 60, .6));
}

body.siege-mode .leak-heart.is-lost .leak-heart-glyph {
  opacity: .45;
  filter: grayscale(1);
}

/* The dead heart only shows once the explosion has cleared. */
body.siege-mode .leak-heart.is-breaking .leak-heart-glyph {
  animation: heart-dead-reveal .8s ease-out both;
}

body.siege-mode .heart-burst {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

body.siege-mode .heart-burst > span {
  position: absolute;
  left: 50%;
  top: 50%;
}

body.siege-mode .heart-burst-core {
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 10px #ff2a2a);
  animation: heart-pop .45s ease-in forwards;
}

body.siege-mode .heart-burst-flash {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fff6c8 18%, rgba(255, 170, 60, .95) 34%, rgba(255, 40, 30, .7) 52%, transparent 70%);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  animation: heart-flash .55s ease-out .3s forwards;
}

body.siege-mode .heart-burst-ring {
  width: 30px;
  height: 30px;
  border: 4px solid #ffd27a;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255, 120, 40, .9);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.3);
  animation: heart-ring .6s ease-out .32s forwards;
}

body.siege-mode .heart-shard {
  width: 11px;
  height: 11px;
  border-radius: 3px 7px;
  background: linear-gradient(135deg, #fff 0%, #ff8a8a 25%, #e0101e 70%);
  box-shadow: 0 0 8px rgba(255, 60, 40, .95);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(var(--a));
  animation: heart-shard .9s cubic-bezier(.15, .7, .3, 1) .32s forwards;
}

@keyframes heart-pop {
  0% { transform: translate(-50%, -50%) scale(1); }
  55% { transform: translate(-50%, -50%) scale(1.9) rotate(-8deg); }
  70% { transform: translate(-50%, -50%) scale(2.1) rotate(6deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.6); opacity: 0; }
}

@keyframes heart-flash {
  0% { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  35% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0; }
}

@keyframes heart-ring {
  0% { transform: translate(-50%, -50%) scale(.3); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(3); opacity: 0; }
}

@keyframes heart-shard {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--a)) translateY(0) rotate(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--a)) translateY(calc(var(--d) * -1)) rotate(260deg) scale(.6); }
}

@keyframes heart-dead-reveal {
  0%, 55% { opacity: 0; transform: scale(.4); }
  100% { opacity: .45; transform: scale(1); }
}

body.siege-mode .leak-meter.is-hit {
  animation: leak-shake .5s ease-out;
}

body.siege-mode .leak-meter.is-danger {
  border-color: #ff5a4a;
  animation: leak-danger 1s ease-in-out infinite;
}

body.siege-mode .leak-meter.is-danger.is-hit {
  animation: leak-shake .5s ease-out, leak-danger 1s ease-in-out infinite;
}

/* A red flash around the field edge each time an alien gets through. */
body.siege-mode .siege-canvas-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  box-shadow: inset 0 0 0 0 rgba(255, 30, 30, 0);
  pointer-events: none;
}

body.siege-mode .siege-canvas-wrap.is-leak-flash::after {
  animation: leak-flash .6s ease-out;
}

@keyframes leak-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

@keyframes leak-danger {
  50% { box-shadow: 0 0 18px rgba(255, 40, 40, .75), 0 4px 14px rgba(0, 0, 0, .5); }
}

@keyframes leak-flash {
  0% { box-shadow: inset 0 0 60px 18px rgba(255, 30, 30, .7); }
  100% { box-shadow: inset 0 0 0 0 rgba(255, 30, 30, 0); }
}

@media (prefers-reduced-motion: reduce) {
  body.siege-mode .leak-meter,
  body.siege-mode .leak-heart-glyph,
  body.siege-mode .siege-canvas-wrap::after { animation: none !important; }

  body.siege-mode .heart-burst { display: none; }
}
