:root {
  --bg: #06141e;
  --bg-soft: #0c2231;
  --panel: rgba(8, 28, 40, 0.9);
  --panel-border: rgba(127, 205, 255, 0.15);
  --text: #d9eef8;
  --muted: #87aaba;
  --bright: #7ce6d4;
  --accent: #f6b95f;
  --danger: #ff7676;
  --estimate: #7de3ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  overflow-y: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(circle at top left, rgba(78, 133, 175, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(10, 77, 95, 0.28), transparent 30%),
    linear-gradient(140deg, #041018, #081823 45%, #07111a);
  color: var(--text);
  font-family: Bahnschrift, "Trebuchet MS", sans-serif;
}

.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow,
.panel-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--bright);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3.4vw, 3.6rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.2rem;
}

.mission-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  min-width: min(900px, 100%);
}

.metric,
.status-card {
  padding: 12px 14px;
  background: rgba(8, 26, 38, 0.76);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.metric span,
.status-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.metric strong,
.status-card strong {
  font-size: 1.12rem;
}

.status-grid-compact .status-card {
  padding: 8px 10px;
  border-radius: 10px;
}

.status-grid-compact .status-card span {
  font-size: 0.74rem;
  margin-bottom: 3px;
}

.status-grid-compact .status-card strong {
  font-size: 0.95rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.sidebar {
  display: grid;
  gap: 12px;
  align-self: start;
}

.panel {
  background:
    linear-gradient(180deg, rgba(16, 44, 63, 0.14), transparent 25%),
    var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.sidebar .panel {
  padding: 14px;
  border-radius: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 14px;
}

.sidebar .panel-header {
  margin-bottom: 10px;
}

.panel-readout {
  color: var(--accent);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: right;
  flex-shrink: 1;
  min-width: 0;
  word-break: break-word;
}

canvas {
  width: 100%;
  max-width: 100%;
  touch-action: none;
  border-radius: 18px;
  border: 1px solid rgba(127, 205, 255, 0.14);
  background:
    linear-gradient(180deg, rgba(22, 59, 82, 0.45), rgba(5, 15, 22, 0.94)),
    radial-gradient(circle at 50% 50%, rgba(30, 78, 101, 0.22), transparent 60%);
  display: block;
}

#mapCanvas {
  aspect-ratio: 3 / 2;
}

#sonarCanvas {
  aspect-ratio: 1 / 1;
}

.ppi-wrap {
  max-height: min(40vh, 360px);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.ppi-wrap canvas {
  width: min(100%, min(40vh, 360px));
  height: auto;
  max-height: min(40vh, 360px);
  aspect-ratio: 1 / 1;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: middle;
}

.swatch.helo {
  background: var(--text);
}

.swatch.buoy {
  background: var(--bright);
}

.swatch.return {
  background: var(--accent);
}

.swatch.estimate {
  background: var(--estimate);
}

.sonar-caption {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 8px;
  line-height: 1.3;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.action {
  appearance: none;
  border: 1px solid rgba(127, 205, 255, 0.18);
  border-radius: 12px;
  background: rgba(14, 37, 52, 0.95);
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.action:hover {
  transform: translateY(-1px);
  border-color: rgba(124, 230, 212, 0.55);
}

.action:disabled {
  cursor: not-allowed;
  transform: none;
  opacity: 0.45;
  border-color: rgba(127, 205, 255, 0.12);
}

.action.primary {
  background: linear-gradient(135deg, rgba(17, 53, 67, 1), rgba(11, 38, 55, 1));
  border-color: rgba(124, 230, 212, 0.42);
}

.control-notes {
  margin-top: 8px;
}

.control-notes p {
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.8rem;
}

.control-notes strong {
  color: var(--text);
}

.touch-hint {
  display: none;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.fly-pad {
  display: none;
  margin-top: 12px;
  padding: 10px;
  background: rgba(5, 18, 27, 0.5);
  border: 1px solid rgba(127, 205, 255, 0.1);
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
}

.fly-pad-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.fly-pad-mid {
  margin: 6px 0;
}

.fly-btn {
  appearance: none;
  width: min(88px, 28vw);
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(127, 205, 255, 0.22);
  background: rgba(14, 37, 52, 0.95);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: none;
}

.fly-btn:active {
  background: rgba(22, 58, 78, 0.95);
  border-color: rgba(124, 230, 212, 0.45);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.status-grid-compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.status-card-span2 {
  grid-column: 1 / -1;
}

.confidence-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: rgba(5, 22, 34, 0.55);
  border: 1px solid rgba(127, 205, 255, 0.08);
  border-radius: 10px;
  font-size: 0.9rem;
}

.confidence-row strong {
  white-space: nowrap;
}

.confidence-hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.message-board {
  background: rgba(5, 18, 27, 0.86);
  border: 1px solid rgba(127, 205, 255, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 80px;
  max-height: min(180px, 22vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message-board h3 {
  margin-bottom: 6px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bright);
}

#messageLog {
  margin: 0;
  padding-left: 16px;
  display: grid;
  gap: 5px;
  color: var(--muted);
  line-height: 1.3;
  font-size: 0.82rem;
}

#messageLog li strong {
  color: var(--text);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .mission-strip {
    min-width: 0;
    width: 100%;
  }

  /* Pinned controls whenever the page is single-column — map stays visible above the dock */
  .shell {
    padding-bottom: calc(17rem + env(safe-area-inset-bottom, 0px));
  }

  .controls-panel {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: 0;
    z-index: 40;
    margin: 0;
    border-radius: 16px 16px 0 0;
    padding-top: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
    overscroll-behavior: contain;
  }

  .controls-panel .control-notes {
    display: none;
  }

  .controls-panel .controls-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .controls-panel .controls-grid .action {
    min-height: 44px;
    font-size: 0.72rem;
    padding: 8px 4px;
    line-height: 1.2;
  }

  .controls-panel .fly-pad {
    margin-top: 8px;
    padding: 6px 8px;
  }

  .controls-panel .fly-btn {
    min-height: 44px;
    width: min(76px, 24vw);
    font-size: 0.95rem;
  }

  .controls-panel .fly-pad-mid {
    margin: 4px 0;
  }

  .map-panel #mapCanvas {
    max-height: 40svh;
    width: min(100%, calc(40svh * 3 / 2));
    height: auto;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 900px) {
  .touch-hint {
    display: block;
  }

  .fly-pad {
    display: block;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: calc(17rem + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: clamp(1.35rem, 6vw, 2rem);
  }

  .mission-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid,
  .status-grid-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-header {
    flex-wrap: wrap;
  }

  .panel-readout {
    text-align: left;
    width: 100%;
    font-size: 0.82rem;
  }

  .legend {
    font-size: 0.82rem;
    gap: 8px 12px;
  }

  .message-board {
    max-height: min(220px, 28vh);
  }

  .confidence-row strong {
    white-space: normal;
  }

  .win-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 400px) {
  .mission-strip {
    grid-template-columns: 1fr;
  }

  .status-grid-compact {
    grid-template-columns: 1fr;
  }
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(16, 60, 82, 0.55), transparent 60%),
    rgba(3, 10, 16, 0.92);
  backdrop-filter: blur(8px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  max-width: 520px;
  width: 90vw;
  text-align: center;
}

.overlay-card h1 {
  margin-bottom: 14px;
}

.overlay-desc {
  color: var(--muted);
  line-height: 1.55;
  font-size: 1rem;
  margin-bottom: 28px;
}

.difficulty-pick {
  display: grid;
  gap: 12px;
}

.difficulty-pick h2 {
  margin-bottom: 4px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--bright);
}

.difficulty-btn {
  text-align: left;
  padding: 14px 18px;
}

.difficulty-btn strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.difficulty-btn span {
  color: var(--muted);
  font-size: 0.85rem;
}

.win-card {
  text-align: center;
}

.win-card h1 {
  color: var(--bright);
  margin-bottom: 8px;
}

.win-subtitle {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 22px;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.win-stat {
  padding: 12px 10px;
  background: rgba(8, 26, 38, 0.76);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}

.win-stat span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.win-stat strong {
  font-size: 1.2rem;
}

.win-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.win-actions .action {
  min-width: 160px;
  padding: 14px 24px;
  font-size: 1rem;
}

/* Embedded mode: single column layout */
body.embedded .layout {
  flex-direction: column;
}

body.embedded .sidebar {
  width: 100%;
}

body.embedded .map-panel {
  width: 100%;
}

body.embedded .topbar .mission-strip {
  flex-wrap: wrap;
}
