/* Painted presentation shared by the normal and Extra campaigns. */
#stage1-paint {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#stage1-paint[hidden],
#stage1-art-warning[hidden] {
  display: none !important;
}
body.harbor-stage1 #board {
  position: relative;
  z-index: 1;
  background: transparent;
}
body.harbor-stage1 #effects-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
body.harbor-stage1 #pause-badge { z-index: 4; }
#stage1-art-warning {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  overflow: auto;
  color: #fff0cf;
  background: #143540;
  text-align: center;
  font: 600 13px/1.65 "Yu Gothic UI", "Meiryo", sans-serif;
  white-space: normal;
  overflow-wrap: anywhere;
  pointer-events: auto;
}
#stage1-art-warning strong { font-size: 16px; }
#stage1-art-warning p { max-width: 32em; margin: 0; }

/* The existing rail is reserved even when the equipment panel is closed.
   An opened panel replaces that rail's controls; it never widens over the map. */
body.harbor-stage1.mobile-game .control-panel {
  position: fixed;
  z-index: 60;
  top: max(4px, env(safe-area-inset-top));
  right: max(6px, env(safe-area-inset-right));
  bottom: max(4px, env(safe-area-inset-bottom));
  left: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  grid-template-rows: 44px var(--harbor-weapon-rows, 44px) minmax(0, 1fr) auto 44px;
  gap: 3px 2px;
  width: var(--mobile-rail, 164px);
  max-width: var(--mobile-rail, 164px);
  height: auto;
  min-height: 0;
  max-height: none;
  box-sizing: border-box;
  padding: 4px;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: none;
  transform: none;
  transition: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
body.harbor-stage1.mobile-game.mobile-panel-open .control-panel {
  transform: none;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
body.harbor-stage1.mobile-game.mobile-panel-open .masthead,
body.harbor-stage1.mobile-game.mobile-panel-open .forecast-bar,
body.harbor-stage1.mobile-game.mobile-panel-open .mobile-toolbar {
  visibility: hidden;
  pointer-events: none;
}
body.harbor-stage1.mobile-game .control-panel .panel-heading {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  gap: 0;
}
body.harbor-stage1.mobile-game .control-panel .panel-heading > span { display: none; }
body.harbor-stage1.mobile-game #deselect-button {
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
}
body.harbor-stage1.mobile-game #mobile-panel-close {
  position: static;
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 2px;
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
}
body.harbor-stage1.mobile-game .control-panel .weapon-list {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  gap: 2px;
  width: 100%;
  min-width: 0;
  height: var(--harbor-weapon-rows, 44px);
}
body.harbor-stage1.mobile-game .control-panel .weapon-list button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 2px 1px;
  gap: 2px;
  text-align: center;
  line-height: 1.15;
}
body.harbor-stage1.mobile-game .control-panel .weapon-symbol { display: none; }
body.harbor-stage1.mobile-game .control-panel .weapon-name {
  max-width: 100%;
  font-size: 10px;
  line-height: 1.2;
}
body.harbor-stage1.mobile-game .control-panel .weapon-cost { font-size: 9px; }
body.harbor-stage1.mobile-game .control-panel .selection-panel {
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  min-width: 0;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 4px;
  overflow: hidden;
}
body.harbor-stage1.mobile-game #selection-content {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-right: 2px;
  overflow-wrap: anywhere;
}
body.harbor-stage1.mobile-game #selection-content h3 {
  font-size: 11px;
  line-height: 1.35;
  margin: 0 0 4px;
  flex-wrap: wrap;
}
body.harbor-stage1.mobile-game #selection-content p {
  display: block;
  overflow: visible;
  font-size: 10px;
  line-height: 1.45;
  -webkit-line-clamp: unset;
}
body.harbor-stage1.mobile-game #selection-content .selection-stats {
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  font-size: 10px;
}
body.harbor-stage1.mobile-game #selection-content .subtle {
  white-space: normal;
  overflow: visible;
}
body.harbor-stage1.mobile-game #selection-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  margin: 0;
}
body.harbor-stage1.mobile-game #selection-actions:empty { display: none; min-height: 0; }
body.harbor-stage1.mobile-game #selection-actions button {
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
}
body.harbor-stage1.mobile-game #ship-panel {
  grid-column: 1 / -1;
  grid-row: 4;
  min-width: 0;
  margin: 0;
}
body.harbor-stage1 #ship-panel[hidden] { display: none !important; }
body.harbor-stage1.mobile-game .control-panel .utility-controls {
  grid-column: 1 / -1;
  grid-row: 5;
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border-top: 0;
}
body.harbor-stage1.mobile-game .control-panel .utility-controls button {
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Preserve the accepted mobile rail dimensions without a debug notice. */
body.harbor-stage1.mobile-game #game-screen {
  grid-template-rows: 76px minmax(0, 1fr) 92px;
}

/* Reserve the desktop notice row so announcing or hiding a message cannot
   recenter the board. The hidden attribute and visibility keep it out of AX. */
body.harbor-stage1:not(.mobile-game) #notice[hidden] {
  display: flex !important;
  visibility: hidden;
}

/* Clip the scaled desktop app without creating a focus-scroll container. */
body.harbor-stage1:not(.mobile-game) #viewport {
  overflow: clip;
}

/* Give the boss its own rail row, including before and after its appearance. */
body.harbor-stage1.mobile-game .forecast-bar.has-giant-hud {
  grid-template-rows: 22px minmax(28px, 1fr) 30px 28px;
}
body.harbor-stage1.mobile-game .forecast-bar.has-giant-hud .resources {
  grid-row: 4;
}
body.harbor-stage1.mobile-game .forecast-bar > #giant-boss-hud {
  position: static;
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 12px 4px;
  gap: 2px 4px;
  width: auto;
  min-width: 0;
  height: 30px;
  min-height: 30px;
  margin: 0;
  padding: 3px 4px;
  box-sizing: border-box;
  overflow: hidden;
  pointer-events: none;
}
body.harbor-stage1.mobile-game .forecast-bar > #giant-boss-hud.reserve-mobile[hidden] {
  display: grid !important;
  visibility: hidden;
}
body.harbor-stage1.mobile-game .forecast-bar .giant-boss-title {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  font-size: 10px;
  line-height: 12px;
  white-space: nowrap;
}
body.harbor-stage1.mobile-game .forecast-bar .giant-boss-health {
  grid-column: 2;
  grid-row: 1;
  font-size: 10px;
  line-height: 12px;
}
body.harbor-stage1.mobile-game .forecast-bar .giant-boss-meter {
  grid-column: 1 / -1;
  grid-row: 2;
  width: auto;
  height: 4px;
}

/* The hidden utility buttons must not keep an empty 44px grid track. */
@media (max-height: 330px) {
  body.harbor-stage1.mobile-game .control-panel {
    grid-template-rows: 44px var(--harbor-weapon-rows, 44px) minmax(0, 1fr) auto;
    gap: 2px;
    padding: 3px;
  }
  body.harbor-stage1.mobile-game .control-panel .selection-panel {
    gap: 3px;
    padding: 3px;
  }
  body.harbor-stage1.mobile-game .control-panel .utility-controls {
    display: none;
  }
}

/* Final victory text stays in the DOM; only the fireworks have a timer. */
#victory-effects {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
body #dialog-backdrop.is-victory {
  position: fixed;
  overflow: hidden;
  background: #102d3ad9;
  backdrop-filter: blur(2px);
}
body #dialog-backdrop.is-victory > #victory-effects { display: block; }
body #dialog.is-victory {
  position: relative;
  z-index: 1;
  width: min(700px, 100%);
  max-width: 100%;
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  min-height: 0;
  padding: 12px 16px;
  gap: 8px;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}
#dialog.is-victory .dialog-top {
  flex: 0 0 auto;
  justify-content: center;
  min-height: 0;
}
#dialog.is-victory #dialog-eyebrow { display: none; }
#dialog.is-victory #dialog-title {
  color: #fff0b3;
  font-size: clamp(26px, 4vw, 46px);
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 2px 8px #051a24;
}
#dialog.is-victory #dialog-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.victory-message {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 8px;
}
#dialog .victory-subtitle {
  flex: 0 0 auto;
  margin: 0;
  color: #fff4cf;
  font-size: clamp(16px, 2.6vw, 24px);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 2px 6px #051a24;
}
.victory-letter {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 16px;
  border: 1px solid #d6b775;
  border-radius: 10px;
  background: #faf5e8f5;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  animation: victory-letter-in .35s ease-out 1s both;
}
#dialog .victory-thanks {
  text-align: center;
  margin: 0;
  color: #284c48;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.55;
  white-space: pre-wrap;
}
#dialog .victory-congratulations {
  display: block;
  margin-top: 8px;
  color: #96531f;
  font-size: clamp(20px, 3.4vw, 32px);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: pre-wrap;
}
#dialog.is-victory #dialog-actions {
  flex: 0 0 auto;
  justify-content: center;
  gap: 6px;
  padding-top: 4px;
  border: 0;
}
#dialog.is-victory #dialog-actions button.quiet {
  color: #fff8e6;
  background: #24465a;
  border: 1px solid #d8c18a;
}
#dialog.is-victory #dialog-actions button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.3;
  white-space: normal;
}
@keyframes victory-letter-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-height: 350px) {
  body #dialog.is-victory { padding: 8px 12px; gap: 4px; }
  #dialog.is-victory #dialog-title { font-size: 26px; }
  .victory-message { gap: 5px; }
  #dialog .victory-subtitle { font-size: 16px; }
  .victory-letter { padding: 8px 10px; }
  #dialog .victory-thanks { font-size: 14px; line-height: 1.4; }
  #dialog .victory-congratulations { margin-top: 4px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .victory-letter { animation: none; }
}
