:root {
  --bg-top: #09111f;
  --bg-bottom: #120d1e;
  --panel: rgba(11, 20, 37, 0.78);
  --panel-edge: rgba(124, 164, 255, 0.22);
  --text: #eef4ff;
  --muted: #9cb2d1;
  --accent: #ffd36b;
  --success: #86f7b4;
  --page-gap: 16px;
  --shell-height: calc(100dvh - (var(--page-gap) * 2));
  --canvas-max-height: calc(100dvh - 110px);
  --mobile-sidebar-width: 154px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Chakra Petch", sans-serif;
  color: var(--text);
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(77, 132, 255, 0.18), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #05070d;
}

.title-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.start-button {
  position: relative;
  z-index: 1;
  padding: 14px 28px;
  border: 0;
  border-radius: 999px;
  font: 700 1rem "Chakra Petch", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #09111f;
  background: linear-gradient(180deg, #ffe08a, #ffbf47);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.start-button:hover {
  filter: brightness(1.06);
}

.title-screen.hidden {
  display: none;
}

.shell {
  width: min(1200px, calc(100vw - (var(--page-gap) * 2)));
  height: var(--shell-height);
  margin: var(--page-gap) auto;
  display: grid;
  grid-template-columns: 278px 1fr;
  gap: 16px;
  align-items: stretch;
}

.hud-panel,
.game-panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
}

.hud-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.eyebrow,
.label,
.caption-label {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-size: 0.78rem;
}

h1 {
  margin: 6px 0 0;
  font-size: clamp(1.65rem, 2.7vw, 2.35rem);
  line-height: 0.95;
}

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

.stat {
  min-width: 0;
  padding: 10px 11px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.wide {
  grid-column: 1 / -1;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 1.08rem;
}

.wide strong {
  font-size: 0.9rem;
}

.legend {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

kbd {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 211, 107, 0.12);
  border: 1px solid rgba(255, 211, 107, 0.25);
  color: var(--accent);
  font: inherit;
}

.game-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

canvas {
  width: min(100%, calc(var(--canvas-max-height) * 16 / 9));
  max-height: var(--canvas-max-height);
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 20px;
  background: linear-gradient(180deg, #09111f 0%, #14112d 100%);
  aspect-ratio: 16 / 9;
}

.caption-bar {
  margin-top: 14px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--success);
  font-size: 0.92rem;
}

.mobile-controls {
  display: none;
}

@media (max-width: 980px) {
  .hud-panel {
    padding: 12px;
    gap: 10px;
  }

  .stat {
    padding: 8px 9px;
    border-radius: 14px;
  }

  .stat strong {
    margin-top: 2px;
    font-size: 0.94rem;
  }

  .wide strong {
    font-size: 0.8rem;
    line-height: 1.2;
  }

  :root {
    --page-gap: 10px;
    --shell-height: calc(100dvh - (var(--page-gap) * 2));
    --canvas-max-height: calc(100dvh - 280px);
  }

  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    gap: 14px;
    height: auto;
    min-height: calc(100dvh - (var(--page-gap) * 2));
  }

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

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

  .mobile-button {
    min-height: 56px;
    border: 0;
    border-radius: 18px;
    font: 700 0.95rem "Chakra Petch", sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #09111f;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .thrust-button {
    background: linear-gradient(180deg, #ffd36b, #ff9f43);
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.24);
  }

  .gear-button {
    background: linear-gradient(180deg, #dce7ff, #9db7ff);
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.24);
  }

  .mobile-button:active,
  .mobile-button.is-active {
    transform: translateY(1px) scale(0.985);
    filter: brightness(0.94);
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  :root {
    --page-gap: 8px;
    --shell-height: calc(100dvh - (var(--page-gap) * 2));
    --canvas-max-height: calc(100dvh - 96px);
  }

  body {
    overflow: hidden;
  }

  .shell {
    width: calc(100vw - (var(--page-gap) * 2));
    grid-template-columns: minmax(126px, var(--mobile-sidebar-width)) minmax(0, 1fr);
    gap: 10px;
    height: var(--shell-height);
    min-height: 0;
  }

  .hud-panel {
    padding: 10px;
    gap: 8px;
    border-radius: 18px;
  }

  .eyebrow,
  .label,
  .caption-label {
    font-size: 0.58rem;
    letter-spacing: 0.12em;
  }

  h1 {
    margin-top: 4px;
    font-size: 1.2rem;
  }

  .hud-grid {
    gap: 6px;
  }

  .stat {
    padding: 6px 7px;
    border-radius: 12px;
  }

  .stat strong {
    margin-top: 2px;
    font-size: 0.82rem;
  }

  .wide strong {
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .legend {
    gap: 4px;
    font-size: 0.62rem;
    line-height: 1.25;
  }

  kbd {
    padding: 1px 4px;
  }

  .game-panel {
    padding: 10px;
    border-radius: 18px;
  }

  canvas {
    width: 100%;
    max-height: var(--canvas-max-height);
    border-radius: 16px;
  }

  .caption-bar {
    margin-top: 8px;
    padding: 7px 10px;
    gap: 8px;
    border-radius: 12px;
    font-size: 0.72rem;
  }

  .mobile-controls {
    margin-top: 8px;
    margin-bottom: 8px;
    gap: 8px;
  }

  .mobile-button {
    min-height: 44px;
    border-radius: 14px;
    font-size: 0.78rem;
  }
}
