:root {
  --space-0: #04060f;
  --space-1: #080d20;
  --space-2: #101838;
  --steel-0: #2b3549;
  --steel-1: #3d4a63;
  --steel-2: #56637d;
  --steel-hi: #93a6c4;
  --ink: #e8f2ff;
  --ink-dim: #9fb2cd;
  --cyan: #6fe8ff;
  --cyan-deep: #2aa8c8;
  --amber: #ffc25c;
  --danger: #ff5f6d;
  --ok: #7dffb0;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 20% 0%, #16224d 0%, rgba(22, 34, 77, 0) 60%),
    radial-gradient(100% 80% at 85% 100%, #123043 0%, rgba(18, 48, 67, 0) 55%),
    linear-gradient(170deg, #060a18 0%, #0a1128 45%, #050912 100%);
  min-height: 100%;
  overflow-x: hidden;
}

.deck {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------ top nameplate */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(72, 88, 116, 0.95), rgba(30, 40, 60, 0.95));
  border-bottom: 2px solid rgba(150, 180, 220, 0.28);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.topbar-title {
  margin: 0;
  font-size: 18px;
  letter-spacing: 2px;
  flex: 1;
  text-align: center;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(160, 190, 230, 0.35);
  background: linear-gradient(180deg, #4a5b78, #2c384f);
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.bar-btn:active,
.ctrl-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55);
}

/* ------------------------------------------------------------------- stage */

#stage-core {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  min-height: 0;
}

.porthole {
  flex: 1;
  display: flex;
  justify-content: center;
  min-height: 0;
}

.porthole-frame {
  position: relative;
  width: min(100%, 1080px);
  height: 100%;
  padding: 14px;
  border-radius: 30px;
  background:
    repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 255, 255, 0.05) 0deg 3deg, rgba(0, 0, 0, 0.05) 3deg 6deg),
    linear-gradient(160deg, #6b7c9c 0%, #3a4761 38%, #232c40 70%, #46536d 100%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.35),
    inset 0 -6px 14px rgba(0, 0, 0, 0.6),
    0 18px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.porthole-frame::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 24px;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 18px 18px, rgba(220, 235, 255, 0.85) 0 3px, rgba(20, 28, 44, 0.9) 3px 6px, rgba(0, 0, 0, 0) 6px),
    radial-gradient(circle at calc(100% - 18px) 18px, rgba(220, 235, 255, 0.85) 0 3px, rgba(20, 28, 44, 0.9) 3px 6px, rgba(0, 0, 0, 0) 6px),
    radial-gradient(circle at 18px calc(100% - 18px), rgba(220, 235, 255, 0.85) 0 3px, rgba(20, 28, 44, 0.9) 3px 6px, rgba(0, 0, 0, 0) 6px),
    radial-gradient(circle at calc(100% - 18px) calc(100% - 18px), rgba(220, 235, 255, 0.85) 0 3px, rgba(20, 28, 44, 0.9) 3px 6px, rgba(0, 0, 0, 0) 6px),
    radial-gradient(circle at 50% 10px, rgba(220, 235, 255, 0.7) 0 2.5px, rgba(20, 28, 44, 0.85) 2.5px 5px, rgba(0, 0, 0, 0) 5px),
    radial-gradient(circle at 50% calc(100% - 10px), rgba(220, 235, 255, 0.7) 0 2.5px, rgba(20, 28, 44, 0.85) 2.5px 5px, rgba(0, 0, 0, 0) 5px);
  z-index: 3;
}

/* radar strip inside the frame */
.radar-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 16px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(10, 18, 34, 0.92), rgba(16, 26, 48, 0.92));
  border: 1px solid rgba(120, 200, 230, 0.25);
  box-shadow: inset 0 0 16px rgba(60, 180, 220, 0.18);
  font-size: 12px;
  letter-spacing: 1.4px;
  color: var(--cyan);
}

.radar-cell {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
}

.radar-label {
  color: var(--ink-dim);
}

.radar-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink);
}

.radar-alert {
  margin-left: auto;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(30, 90, 110, 0.6);
  color: var(--cyan);
}

.radar-alert.is-hot {
  background: rgba(150, 30, 45, 0.65);
  color: #ffd9de;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* glass */
.glass-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  background: #04060f;
  box-shadow: inset 0 0 0 3px rgba(10, 16, 30, 0.9), inset 0 0 40px rgba(0, 0, 0, 0.85);
  touch-action: none;
  overscroll-behavior: none;
}

#stage-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(118deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.05) 22%, rgba(255, 255, 255, 0) 42%),
    linear-gradient(200deg, rgba(140, 200, 255, 0.1) 0%, rgba(140, 200, 255, 0) 35%);
  z-index: 2;
}

.glass::after {
  content: "";
  position: absolute;
  left: 12%;
  top: 18%;
  width: 34%;
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
  transform: rotate(-8deg);
  box-shadow: 0 26px 0 rgba(255, 255, 255, 0.07);
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(120% 100% at 50% 45%, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.6) 100%);
}

.hint-strip {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 4;
  max-width: 86%;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(8, 16, 32, 0.82);
  border: 1px solid rgba(120, 200, 230, 0.3);
  color: var(--ink);
  font-size: 13px;
  text-align: center;
}

/* ------------------------------------------------------------ fire console */

.console {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, #46536d 0%, #2b3549 45%, #1c2434 100%);
  border: 1px solid rgba(150, 180, 220, 0.22);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), inset 0 -8px 18px rgba(0, 0, 0, 0.55), 0 10px 24px rgba(0, 0, 0, 0.45);
  flex-wrap: wrap;
}

.gauge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 1.2px;
  color: var(--ink-dim);
}

.gauge-label {
  text-transform: uppercase;
}

.gauge-track {
  width: 128px;
  height: 12px;
  border-radius: 999px;
  background: rgba(6, 10, 22, 0.85);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #52d7a0, #ffc25c 55%, #ff5f6d);
  transition: width 0.08s linear;
}

.gauge-fill.is-locked {
  background: repeating-linear-gradient(90deg, #ff5f6d 0 8px, #7d1f2a 8px 16px);
}

.gauge-num {
  min-width: 54px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.hull-cells {
  display: flex;
  gap: 5px;
}

.hull-cell {
  width: 22px;
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(180deg, #7dffb0, #2fa86a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 0 8px rgba(90, 255, 170, 0.35);
}

.hull-cell.is-lost {
  background: linear-gradient(180deg, #37415a, #1b2130);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7);
}

.mod-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(120, 220, 255, 0.16);
  border: 1px solid rgba(140, 235, 255, 0.5);
  color: #d9fbff;
  font-size: 12px;
  font-weight: 700;
}

.console-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid rgba(160, 190, 230, 0.3);
  background: linear-gradient(180deg, #56657f, #2f3a4f);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 3px 6px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease;
}

.ctrl-btn:active {
  transform: translateY(2px);
}

.ctrl-accent {
  background: linear-gradient(180deg, #37b6d8, #17607a);
  border-color: rgba(160, 240, 255, 0.55);
}

/* --------------------------------------------------------------- overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 8, 18, 0.78);
  backdrop-filter: blur(6px);
}

.hidden {
  display: none !important;
}

.hangar,
.report-card,
.help-card,
.pause-card {
  width: min(100%, 720px);
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(30, 42, 66, 0.96), rgba(14, 20, 36, 0.96));
  border: 1px solid rgba(150, 190, 230, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.hangar-title,
.report-title {
  margin: 0 0 14px;
  font-size: 22px;
  letter-spacing: 2px;
  text-align: center;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(150, 190, 230, 0.25);
  background: linear-gradient(180deg, rgba(70, 92, 128, 0.75), rgba(24, 34, 56, 0.85));
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.mode-card:hover,
.mode-card.is-active {
  border-color: rgba(120, 235, 255, 0.7);
  transform: translateY(-2px);
}

.mode-name {
  font-size: 15px;
  font-weight: 700;
}

.mode-desc {
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.6;
}

.level-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.level-btn {
  position: relative;
  padding: 10px 0;
  border-radius: 12px;
  border: 1px solid rgba(150, 190, 230, 0.28);
  background: linear-gradient(180deg, #4d5d7a, #26314a);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.level-btn .level-stars {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--amber);
  letter-spacing: 1px;
}

.level-btn.is-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-btn-wide {
  grid-column: 1 / -1;
  font-size: 15px;
}

/* Returning to a paused sortie from the hangar. */
.menu-continue {
  display: block;
  width: 100%;
  margin-top: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.menu-stats {
  margin-top: 16px;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
  line-height: 1.9;
}

.report-stars {
  text-align: center;
  font-size: 30px;
  color: var(--amber);
  letter-spacing: 6px;
  margin-bottom: 10px;
}

.report-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}

.report-stats div {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(10, 18, 34, 0.7);
  border: 1px solid rgba(120, 180, 220, 0.2);
}

.report-stats dt {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 1px;
}

.report-stats dd {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.report-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.help-body,
.help-keys {
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink);
  margin: 0 0 12px;
}

.help-keys {
  color: var(--ink-dim);
  font-size: 12px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  #stage-core {
    padding: 10px;
  }

  .console {
    gap: 12px;
    padding: 10px 12px;
  }

  .gauge-track {
    width: 92px;
  }
}

@media (max-width: 768px) {
  .deck {
    padding-bottom: max(68px, calc(16px + env(safe-area-inset-bottom)));
  }

  .topbar-title {
    font-size: 15px;
    letter-spacing: 1px;
  }

  .deck {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .glass-wrap {
    flex: none;
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .console {
    justify-content: center;
  }

  .console-actions {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .radar-alert.is-hot {
    animation: none;
  }

  .mode-card,
  .bar-btn,
  .ctrl-btn,
  .level-btn {
    transition: none;
  }

  .gauge-fill {
    transition: none;
  }
}
