:root {
  --bg: #05131a;
  --panel: rgba(9, 28, 37, 0.74);
  --panel-strong: rgba(10, 25, 34, 0.92);
  --line: rgba(148, 218, 228, 0.2);
  --text: #ebf8ff;
  --muted: #99b8c3;
  --accent: #74d8ff;
  --accent-warm: #ffd27f;
  --danger: #ff816e;
  --success: #7af0bf;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(53, 123, 131, .32), transparent 28%),
    radial-gradient(circle at bottom right, rgba(252, 150, 74, .14), transparent 22%),
    linear-gradient(145deg, #041117 0%, #061c25 48%, #08151c 100%);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  pointer-events: none;
  z-index: 0;
}

body::before {
  top: -12rem;
  left: -10rem;
  width: 30rem;
  height: 30rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(90, 218, 255, .18), transparent 68%);
  filter: blur(24px);
}

body::after {
  right: -8rem;
  bottom: -12rem;
  width: 28rem;
  height: 28rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 104, .12), transparent 72%);
  filter: blur(22px);
}

/* ═══════════════════════════════════════════
   PORTRAIT ROTATION PROMPT
   ═══════════════════════════════════════════ */
.rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(145deg, #041117 0%, #061c25 48%, #08151c 100%);
  place-items: center;
  padding: 2rem;
}

.rotate-prompt-inner {
  text-align: center;
  max-width: 280px;
}

.rotate-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
  color: var(--muted);
}

.rotate-prompt h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.rotate-prompt p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0;
}

/* ═══════════════════════════════════════════
   ONE-TIME MOBILE INSTRUCTIONS MODAL
   ═══════════════════════════════════════════ */
.mobile-instructions-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(2, 10, 16, 0.88);
  backdrop-filter: blur(12px);
  place-items: center;
  padding: 1rem;
}

.mobile-instructions-overlay.visible {
  display: grid;
}

.mobile-instructions-card {
  width: min(100%, 420px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.4rem 1.5rem 1.2rem;
  border-radius: 1.2rem;
  background: linear-gradient(180deg, rgba(10, 33, 44, 0.96), rgba(6, 16, 23, 0.97));
  border: 1px solid rgba(118, 204, 216, 0.22);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.mobile-instructions-card h2 {
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
}

.mobile-instructions-card>p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0 0 1rem;
}

.mobile-instructions-grid {
  display: grid;
  gap: 0.55rem;
  text-align: left;
  margin-bottom: 1rem;
}

.mi-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  background: rgba(4, 13, 18, 0.7);
  border: 1px solid rgba(116, 216, 255, 0.1);
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

.mi-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   MAIN PAGE LAYOUT
   ═══════════════════════════════════════════ */
.page-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
  gap: 1.25rem;
  height: 100vh;
  padding: 1.25rem;
  overflow: hidden;
}

.briefing-panel,
.game-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow-y: auto;
}

.briefing-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  border-radius: 1.6rem;
}

.brand-tag,
.overlay-kicker,
.label {
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .72rem;
  color: var(--muted);
}

h1,
h2,
.overlay-card h2 {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-weight: 700;
  letter-spacing: .03em;
}

h1 {
  font-size: clamp(2.8rem, 6vw, 4.4rem);
  line-height: .94;
}

h2 {
  font-size: 1.25rem;
}

.deck {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.info-card {
  padding: 1rem 1.05rem;
  border-radius: 1.1rem;
  background: linear-gradient(180deg, rgba(9, 32, 42, .85), rgba(7, 18, 24, .92));
  border: 1px solid rgba(127, 203, 214, .14);
}

.info-card ul {
  margin: .8rem 0 0;
  padding-left: 1rem;
  color: var(--muted);
  display: grid;
  gap: .65rem;
}

.controls-copy {
  display: grid;
  gap: .5rem;
  margin-top: .8rem;
  color: var(--muted);
}

.controls-copy strong {
  color: var(--text);
}

.controls-copy code {
  padding: .12rem .35rem;
  border-radius: .45rem;
  background: rgba(116, 216, 255, .12);
  color: var(--text);
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
}

.event-feed {
  display: grid;
  gap: .65rem;
  margin-top: .95rem;
}

.event-row {
  padding: .75rem .85rem;
  border-radius: .9rem;
  background: rgba(4, 13, 18, .64);
  border: 1px solid rgba(116, 216, 255, .12);
}

.event-row strong {
  display: block;
  margin-bottom: .2rem;
  color: var(--accent);
  font-size: .82rem;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.event-row span {
  color: var(--muted);
  line-height: 1.4;
}

.game-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: .5rem;
  padding: .8rem;
  border-radius: 1.8rem;
  min-height: 0;
}

.status-grid {
  display: grid;
  grid-template-columns: minmax(14rem, 2fr) repeat(6, minmax(0, 1fr));
  gap: .65rem;
}

.status-card {
  display: grid;
  gap: .25rem;
  padding: .7rem .8rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(8, 26, 35, .94), rgba(8, 18, 25, .76));
  border: 1px solid rgba(118, 204, 216, .14);
}

.status-card strong {
  font-size: 1rem;
}

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

.canvas-shell {
  position: relative;
  min-height: 0;
  border-radius: 1.5rem;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, rgba(116, 216, 255, .12), transparent 18%),
    linear-gradient(180deg, rgba(4, 18, 26, .55), rgba(2, 10, 16, .86));
  border: 1px solid rgba(125, 210, 220, .18);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: linear-gradient(180deg, rgba(2, 10, 16, .55), rgba(2, 10, 16, .76));
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 220ms ease;
  z-index: 10;
}

.overlay.visible {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  width: min(100%, 34rem);
  padding: 1.5rem 1.5rem 1.2rem;
  border-radius: 1.4rem;
  background: linear-gradient(180deg, rgba(10, 33, 44, .94), rgba(6, 16, 23, .95));
  border: 1px solid rgba(118, 204, 216, .22);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .4);
}

.overlay-card p {
  margin: .65rem 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.primary-button,
.control-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}

.primary-button {
  margin-top: 1.2rem;
  padding: .95rem 1.25rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #75d8ff, #ffc375);
  color: #041017;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.primary-button:hover,
.control-button:hover,
.control-button.active {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.04);
}

.canvas-badge {
  position: absolute;
  padding: .55rem .7rem;
  border-radius: 999px;
  background: rgba(5, 16, 22, .7);
  border: 1px solid rgba(116, 216, 255, .14);
  color: var(--text);
  font-size: .75rem;
  letter-spacing: .03em;
  backdrop-filter: blur(10px);
  pointer-events: none;
  z-index: 5;
}

.top-left {
  top: .8rem;
  left: .8rem;
}

.top-right {
  top: .8rem;
  right: .8rem;
}

.bottom-left {
  left: .8rem;
  bottom: .8rem;
}

/* ── Desktop control pad (keyboard users) ── */
.control-pad {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: .6rem;
}

.control-button {
  padding: .8rem .6rem;
  border-radius: 1rem;
  color: var(--text);
  background: linear-gradient(180deg, rgba(12, 35, 46, .92), rgba(7, 18, 24, .94));
  border: 1px solid rgba(116, 216, 255, .15);
  font-weight: 700;
  font-size: .82rem;
  touch-action: manipulation;
}

.control-button.steer {
  box-shadow: inset 0 0 0 1px rgba(114, 210, 255, .05);
}

.control-button.thrust {
  background: linear-gradient(180deg, rgba(9, 45, 59, .95), rgba(6, 25, 33, .98));
}

.control-button.reverse {
  background: linear-gradient(180deg, rgba(53, 28, 24, .92), rgba(20, 11, 10, .95));
}

.control-button.action {
  background: linear-gradient(180deg, rgba(34, 34, 24, .92), rgba(16, 16, 10, .96));
}

/* ═══════════════════════════════════════════
   TABLET BREAKPOINT
   ═══════════════════════════════════════════ */
@media (max-width: 1100px) {
  .page-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .briefing-panel {
    order: 2;
  }

  .game-panel {
    order: 1;
  }

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

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

  .canvas-shell {
    aspect-ratio: 16/10;
    min-height: 20rem;
  }
}

/* ═══════════════════════════════════════════
   MOBILE — FULL-SCREEN GAME, HIDE BRIEFING
   Show portrait rotation prompt
   ═══════════════════════════════════════════ */
@media (max-width: 720px) {

  /* ── Portrait: show rotate prompt ── */
  @media (orientation: portrait) {
    .rotate-prompt {
      display: grid;
    }

    .page-shell {
      display: none !important;
    }
  }

  /* ── Landscape: full-screen game ── */
  @media (orientation: landscape) {
    .rotate-prompt {
      display: none !important;
    }

    html,
    body {
      height: 100%;
      overflow: hidden;
    }

    .page-shell {
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: 1fr;
      height: 100vh;
      height: 100dvh;
      padding: 0;
      gap: 0;
      overflow: hidden;
    }

    /* Hide briefing panel completely in landscape mobile */
    .briefing-panel {
      display: none;
    }

    .game-panel {
      order: 1;
      grid-template-rows: auto 1fr;
      gap: 0;
      padding: 0;
      border: none;
      border-radius: 0;
      background: transparent;
      box-shadow: none;
      backdrop-filter: none;
      height: 100vh;
      height: 100dvh;
      overflow: hidden;
    }

    .status-grid {
      display: flex;
      flex-wrap: nowrap;
      gap: 0;
      overflow-x: auto;
      padding: 0.2rem 0.3rem;
      background: rgba(4, 16, 22, 0.92);
      border-bottom: 1px solid rgba(116, 216, 255, 0.1);
      scrollbar-width: none;
      -ms-overflow-style: none;
      z-index: 6;
    }

    .status-grid::-webkit-scrollbar {
      display: none;
    }

    .status-card {
      flex: 0 0 auto;
      padding: 0.2rem 0.45rem;
      border-radius: 0.5rem;
      gap: 0.05rem;
      border: none;
      background: transparent;
      min-width: 0;
    }

    .status-card .label {
      font-size: 0.52rem;
      letter-spacing: 0.1em;
    }

    .status-card strong {
      font-size: 0.65rem !important;
      white-space: nowrap;
    }

    .status-card.compact strong {
      font-size: 0.7rem !important;
    }

    /* First card (objective) — let it take available space */
    .status-card:first-child {
      flex: 1 1 auto;
      min-width: 100px;
    }

    .status-card:first-child strong {
      font-size: 0.6rem !important;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .canvas-shell {
      position: relative;
      flex: 1;
      aspect-ratio: unset;
      min-height: 0;
      border-radius: 0;
      border: none;
    }

    /* Hide the bottom control pad entirely — canvas touch overlay handles it */
    .control-pad {
      display: none;
    }

    .canvas-badge {
      font-size: 0.55rem;
      padding: 0.25rem 0.45rem;
    }

    .top-left {
      top: 0.35rem;
      left: 0.35rem;
    }

    .top-right {
      top: 0.35rem;
      right: 0.35rem;
    }

    .bottom-left {
      left: 0.35rem;
      right: auto;
      bottom: 0.35rem;
      max-width: 55%;
    }

    /* Overlay card smaller on mobile landscape */
    .overlay-card {
      padding: 1rem;
    }

    .overlay-card h2 {
      font-size: 1.1rem;
    }

    .overlay-card p {
      font-size: 0.8rem;
      line-height: 1.4;
    }

    .primary-button {
      padding: 0.6rem 1rem;
      font-size: 0.8rem;
    }
  }
}

/* ═══════════════════════════════════════════
   VERY SMALL MOBILE (phones)
   ═══════════════════════════════════════════ */
@media (max-width: 420px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  h1 {
    font-size: 2rem;
  }

  .canvas-shell {
    aspect-ratio: 3/2;
  }
}

/* Also catch small-height landscape (phones) */
@media (max-height: 500px) and (orientation: landscape) {
  .rotate-prompt {
    display: none !important;
  }

  .page-shell {
    display: grid !important;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  .briefing-panel {
    display: none;
  }

  .game-panel {
    grid-template-rows: auto 1fr;
    gap: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .status-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
    overflow-x: auto;
    padding: 0.2rem 0.3rem;
    background: rgba(4, 16, 22, 0.92);
    border-bottom: 1px solid rgba(116, 216, 255, 0.1);
    scrollbar-width: none;
  }

  .status-grid::-webkit-scrollbar {
    display: none;
  }

  .status-card {
    flex: 0 0 auto;
    padding: 0.2rem 0.45rem;
    border-radius: 0.5rem;
    gap: 0.05rem;
    border: none;
    background: transparent;
  }

  .status-card .label {
    font-size: 0.52rem;
  }

  .status-card strong {
    font-size: 0.65rem !important;
    white-space: nowrap;
  }

  .status-card:first-child {
    flex: 1 1 auto;
    min-width: 100px;
  }

  .status-card:first-child strong {
    font-size: 0.6rem !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .canvas-shell {
    aspect-ratio: unset;
    min-height: 0;
    border-radius: 0;
    border: none;
  }

  .control-pad {
    display: none;
  }

  .canvas-badge {
    font-size: 0.55rem;
    padding: 0.25rem 0.45rem;
  }
}

/* ═══════════════════════════════════════════
   MOBILE INSTRUCTION MODAL — only on touch
   ═══════════════════════════════════════════ */
@media (max-width: 720px) and (orientation: landscape) {
  .mobile-instructions-card {
    max-width: 480px;
    max-height: 85vh;
    padding: 1rem 1.2rem;
  }

  .mobile-instructions-card h2 {
    font-size: 1.1rem;
  }

  .mobile-instructions-card>p {
    font-size: 0.78rem;
    margin-bottom: 0.6rem;
  }

  .mi-item {
    padding: 0.4rem 0.55rem;
    font-size: 0.75rem;
  }

  .mi-icon {
    font-size: 1rem;
  }

  .mobile-instructions-card .primary-button {
    margin-top: 0.6rem;
    padding: 0.55rem 1rem;
    font-size: 0.78rem;
  }
}