:root {
  color-scheme: dark light;
  --bg: radial-gradient(circle at top, #081226, #111b35, #1c2742);
  --bg-alt: rgba(14, 24, 38, 0.82);
  --bg-panel: rgba(16, 28, 44, 0.86);
  --bg-overlay: rgba(6, 10, 18, 0.84);
  --bg-toast: rgba(11, 45, 78, 0.82);
  --border: rgba(190, 210, 255, 0.12);
  --border-strong: rgba(190, 210, 255, 0.25);
  --text: #ebefff;
  --text-subtle: rgba(235, 239, 255, 0.75);
  --accent: #ff9e00;
  --accent-alt: #4dd5ff;
  --danger: #ff3860;
  --success: #5efc82;
  --shadow: 0 25px 60px rgba(5, 12, 24, 0.55);
  --font-sans: "Poppins", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

*::before,
*::after,
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  font-family: var(--font-sans);
  background: var(--bg), #040916;
  color: var(--text);
}

.app {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  min-height: 100vh;
  background: rgba(6, 12, 24, 0.72);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app__header {
  display: grid;
  gap: clamp(1rem, 2vw, 1.8rem);
  padding: clamp(1.25rem, 3vw, 2rem) clamp(1.5rem, 4vw, 3rem);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  justify-content: space-between;
  flex-wrap: wrap;
}

.header__brand-link,
.header__return {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.header__brand-link {
  text-transform: uppercase;
  opacity: 0.88;
}

.header__return {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.9rem;
  opacity: 0.85;
  transition: background 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

.header__return:hover {
  background: rgba(255, 255, 255, 0.14);
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.22);
}

.header__title {
  text-align: center;
  display: grid;
  gap: 0.5rem;
}

.header__badge {
  display: inline-flex;
  margin: 0 auto;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.header__title h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud {
  display: grid;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  grid-auto-flow: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.hud__stat {
  display: grid;
  gap: 0.2rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  min-width: 90px;
}

.hud__stat--hidden {
  display: none;
}

.hud__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
}

.hud__value {
  font-size: 1.25rem;
  font-weight: 600;
}

.hud__value--danger {
  color: var(--danger);
}

.hud__value--accent {
  color: var(--accent);
}

.header__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.35rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #ff7b00, var(--accent));
  color: #121318;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 12px 24px rgba(255, 158, 0, 0.22);
}

.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn--outline {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  color: var(--text);
}

.app__main {
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2.5rem);
  background: linear-gradient(160deg, rgba(4, 9, 18, 0.9), rgba(7, 14, 26, 0.92));
  overflow: hidden;
}

#gameCanvas {
  width: min(100%, 1100px);
  height: auto;
  max-height: calc(100vh - 280px);
  aspect-ratio: 4 / 3;
  background: radial-gradient(circle at top, rgba(12, 22, 40, 0.95), rgba(6, 12, 22, 0.95));
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: clamp(1.5rem, 4vw, 3rem);
  display: grid;
  gap: 1.25rem;
  place-content: center;
  text-align: center;
  padding: clamp(1.5rem, 4vw, 3rem);
  background: var(--bg-overlay);
  border: 1px solid var(--border-strong);
  border-radius: 28px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  z-index: 5;
}

.overlay--hidden {
  display: none;
}

.overlay__badge {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--text-subtle);
}

.overlay__title {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.06em;
}

.overlay__message {
  margin: 0 auto;
  max-width: 420px;
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  line-height: 1.5;
  color: var(--text-subtle);
}

.overlay__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem;
}

.toast-stack {
  position: absolute;
  top: clamp(1rem, 3vw, 2.5rem);
  right: clamp(1rem, 3vw, 2.5rem);
  display: grid;
  gap: 0.75rem;
  z-index: 6;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.1rem;
  border-radius: 14px;
  background: var(--bg-toast);
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px rgba(7, 12, 22, 0.4);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.toast--success {
  border-color: rgba(94, 252, 130, 0.45);
}

.toast--danger {
  border-color: rgba(255, 56, 96, 0.45);
}

.app__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: clamp(1rem, 3vw, 1.5rem) clamp(1.5rem, 4vw, 3rem);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.control-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
}

.control-hints__group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
}

.control-hints__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
}

.control-hints__keys kbd {
  display: inline-flex;
  padding: 0.32rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: inherit;
}

.status-console {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  min-width: 220px;
}

.hangar {
  width: min(720px, 90vw);
  max-height: 90vh;
  border-radius: 28px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 14, 28, 0.95);
  color: inherit;
  padding: 0;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(18px);
}

.hangar::backdrop {
  background: rgba(1, 4, 12, 0.7);
  backdrop-filter: blur(6px);
}

.hangar__header,
.hangar__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
}

.hangar__footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.hangar__eyebrow {
  display: inline-flex;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-subtle);
}

.hangar__title {
  margin: 0.65rem 0 0;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
}

.hangar__close {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.hangar__content {
  padding: 0 2rem 1.5rem;
  overflow-y: auto;
  max-height: 60vh;
  display: grid;
  gap: 1.5rem;
}

.hangar__section h3 {
  margin: 0 0 0.75rem;
  letter-spacing: 0.05em;
}

.hangar__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.hangar__item {
  display: grid;
  gap: 0.5rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  transition: border-color 0.2s ease, background 0.2s ease;
  cursor: pointer;
}

.hangar__item--selected {
  border-color: rgba(77, 213, 255, 0.65);
  background: rgba(77, 213, 255, 0.12);
  box-shadow: 0 18px 38px rgba(9, 35, 60, 0.4);
}

.hangar__item--locked {
  opacity: 0.65;
  border-style: dashed;
}

.hangar__item--affordable {
  border-color: rgba(77, 213, 255, 0.35);
  background: rgba(77, 213, 255, 0.1);
}

.hangar__item-title {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.hangar__item-meta {
  font-size: 0.85rem;
  color: var(--text-subtle);
}

.hangar__item-cost {
  font-size: 0.82rem;
  color: var(--text-subtle);
  letter-spacing: 0.04em;
}

.hangar__item--locked .hangar__item-cost {
  color: var(--accent);
}

.hangar__credits {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.hangar__item-controls {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(235, 239, 255, 0.6);
}

.header__actions .btn {
  min-width: 160px;
}

.touch-controls {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 6;
}

.touch-controls--active {
  display: block;
}

.touch-controls__panel {
  position: absolute;
  bottom: clamp(0.75rem, 5vw, 1.75rem);
  pointer-events: auto;
  display: flex;
  gap: clamp(0.4rem, 2.5vw, 0.8rem);
  align-items: center;
}

.touch-controls__panel--left {
  left: clamp(0.65rem, 5vw, 2rem);
}

.touch-controls__panel--right {
  right: clamp(0.65rem, 5vw, 2rem);
  flex-direction: column;
  align-items: flex-end;
  gap: clamp(0.45rem, 3vw, 0.8rem);
}

.touch-controls__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(36px, 10vw));
  gap: clamp(0.3rem, 1.8vw, 0.5rem);
}

.touch-controls__button {
  width: clamp(36px, 9.5vw, 52px);
  height: clamp(36px, 9.5vw, 52px);
  border-radius: 14px;
  background: rgba(12, 24, 42, 0.82);
  border: 1px solid rgba(160, 195, 255, 0.35);
  color: var(--text);
  font-size: clamp(0.6rem, 2vw, 0.85rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.touch-controls__button span {
  pointer-events: none;
}

.touch-controls__button--active,
.touch-controls__button:active {
  transform: translateY(3px) scale(0.97);
  border-color: var(--accent-alt);
  background: rgba(30, 80, 130, 0.9);
}

.touch-controls__button--ghost {
  background: rgba(12, 24, 42, 0.6);
  border-style: dashed;
  font-size: clamp(0.75rem, 2.6vw, 0.95rem);
}

.touch-controls__button--fire {
  width: clamp(60px, 18vw, 88px);
  height: clamp(60px, 18vw, 88px);
  border-radius: 999px;
  font-size: clamp(0.75rem, 2.6vw, 1.05rem);
  background: radial-gradient(circle at top, rgba(255, 158, 0, 0.22), rgba(255, 120, 0, 0.35));
  border: 2px solid rgba(255, 190, 90, 0.5);
  letter-spacing: 0.12em;
}

.touch-controls__caption {
  display: block;
  font-size: clamp(0.48rem, 1.8vw, 0.7rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(235, 239, 255, 0.6);
  margin: 0;
}

.touch-controls__panel--right .touch-controls__caption {
  text-align: center;
}

.touch-controls__button--disabled {
  opacity: 0.45;
  border-style: dashed;
  border-color: rgba(160, 195, 255, 0.25);
  pointer-events: none;
}

.touch-controls__button--disabled .touch-controls__caption,
.touch-controls__button--disabled span {
  color: rgba(235, 239, 255, 0.45);
}

.app--immersive {
  max-width: none;
  width: 100vw;
  height: 100vh;
  margin: 0;
  border-left: none;
  border-right: none;
  box-shadow: none;
  position: relative;
}

.app--immersive .app__header {
  position: absolute;
  top: clamp(0.75rem, 2.5vw, 1.6rem);
  left: 0;
  right: 0;
  padding: 0 clamp(1rem, 5vw, 2.5rem);
  background: none;
  border: none;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

.app--immersive .header__brand,
.app--immersive .header__title,
.app--immersive .header__return,
.app--immersive .header__actions {
  display: none;
}

.app--immersive .hud {
  pointer-events: none;
  background: rgba(8, 16, 28, 0.55);
  border: 1px solid rgba(160, 195, 255, 0.3);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  gap: clamp(0.65rem, 2.5vw, 1.4rem);
  box-shadow: 0 18px 36px rgba(3, 6, 12, 0.45);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.app--immersive .app__main {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 100%;
}

.app--immersive .app__footer {
  display: none;
}

.app--immersive #gameCanvas {
  width: 100%;
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: radial-gradient(circle at top, rgba(12, 22, 40, 0.95), rgba(6, 12, 22, 0.95));
}

.app--immersive .overlay {
  inset: clamp(1.25rem, 6vw, 3.5rem);
}

.app--immersive .touch-controls {
  inset: 0;
}

.options {
  width: min(520px, 90vw);
  max-height: 85vh;
  border-radius: 24px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 14, 28, 0.96);
  color: inherit;
  padding: 0;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(18px);
}

.options::backdrop {
  background: rgba(1, 4, 12, 0.75);
  backdrop-filter: blur(6px);
}

.options__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border);
}

.options__eyebrow {
  display: inline-flex;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-subtle);
}

.options__title {
  margin: 0.5rem 0 0;
  font-size: 1.4rem;
  letter-spacing: 0.05em;
}

.options__close {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.options__content {
  padding: 1.5rem 1.75rem 1.75rem;
  display: grid;
  gap: 1.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

.options__section {
  display: grid;
  gap: 0.85rem;
}

.options__summary {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.options__summary div {
  padding: 0.65rem 0.75rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(160, 195, 255, 0.2);
}

.options__summary dt {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.options__summary dd {
  margin: 0.25rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.options__hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-subtle);
}

.options__slots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.options__slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.85rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
}

.options__slot--active {
  border-color: rgba(77, 213, 255, 0.4);
  background: rgba(77, 213, 255, 0.14);
}

.options__slot--empty {
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-subtle);
}

.options__slot-info {
  display: grid;
  gap: 0.2rem;
}

.options__slot-title {
  font-weight: 600;
  letter-spacing: 0.03em;
}

.options__slot-meta {
  font-size: 0.78rem;
  color: var(--text-subtle);
}

.options__slot-actions {
  display: flex;
  gap: 0.4rem;
}

.options__slot-actions button {
  border: none;
  background: rgba(12, 24, 42, 0.6);
  color: var(--text-subtle);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.options__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

@media (max-width: 900px) {
  .app {
    border-left: none;
    border-right: none;
  }

  .app__header {
    padding: 1.25rem 1.5rem;
    gap: 1.25rem;
  }

  .header__brand {
    justify-content: center;
  }

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

  .hud {
    grid-auto-flow: row;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  #gameCanvas {
    max-height: calc(100vh - 360px);
    border-radius: 18px;
  }

  .overlay {
    inset: 1.25rem;
    padding: 1.75rem 1.5rem;
  }

  .header__actions {
    flex-direction: column;
  }

  .header__actions .btn {
    width: 100%;
  }

  .control-hints {
    justify-content: center;
  }
}

@media (max-width: 640px) {
  body {
    align-items: stretch;
  }

  .app {
    grid-template-rows: auto 1fr auto;
  }

  .app__main {
    padding: 1rem;
  }

  #gameCanvas {
    max-height: none;
    width: 100%;
    aspect-ratio: 3 / 4;
  }

  .overlay {
    inset: 1rem;
    padding: 1.5rem 1.25rem;
  }

  .overlay__title {
    font-size: clamp(1.4rem, 6vw, 2rem);
  }

  .overlay__message {
    font-size: clamp(0.95rem, 5vw, 1.1rem);
  }

  .status-console {
    justify-content: center;
    text-align: center;
  }

  .hangar {
    width: 96vw;
  }

  .hangar__content {
    padding: 0 1.25rem 1.25rem;
  }

  .hangar__grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 480px) {
  .header__brand-link,
  .header__return {
    font-size: 0.9rem;
  }

  .hud__value {
    font-size: 1.1rem;
  }

  .control-hints__group {
    flex-direction: column;
    text-align: center;
  }

  .status-console {
    font-size: 0.85rem;
  }
}

@media (pointer: coarse), (max-width: 900px) {
  .control-hints {
    display: none;
  }
}

@media (orientation: portrait) {
  .touch-controls__panel {
    bottom: clamp(1.25rem, 5.5vw, 2.25rem);
  }

  .touch-controls__grid {
    grid-template-columns: repeat(3, minmax(34px, 16vw));
  }
}

.touch-controls:not(.touch-controls--active) {
  display: none;
}

@media (max-width: 740px) {
  .hud {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    padding: 0.85rem 1rem;
    gap: 0.65rem;
  }

  .hud__stat {
    min-width: 0;
    padding: 0.45rem 0.6rem;
    border-radius: 0.65rem;
  }

  .hud__label {
    font-size: 0.65rem;
  }

  .hud__value {
    font-size: 1rem;
  }
}

