:root {
  color-scheme: dark;
  --bg: #05070d;
  --panel: rgba(7, 12, 24, 0.82);
  --panel-strong: rgba(10, 18, 34, 0.94);
  --cyan: #40f7ff;
  --magenta: #ff3df2;
  --green: #5dff8a;
  --yellow: #ffd84a;
  --red: #ff4e66;
  --text: #f3fbff;
  --muted: #92a9bc;
  --line: rgba(128, 240, 255, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

#app {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 26% 18%, rgba(64, 247, 255, 0.13), transparent 24rem),
    radial-gradient(circle at 82% 76%, rgba(255, 61, 242, 0.13), transparent 22rem),
    linear-gradient(145deg, #060710, #080d16 50%, #05070d);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 3;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.75);
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand,
.stats {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4, 8, 18, 0.72);
  backdrop-filter: blur(8px);
}

.brand {
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 16px;
  height: 16px;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(64, 247, 255, 0.8), inset 0 0 8px rgba(255, 61, 242, 0.75);
  transform: rotate(45deg);
}

.stats {
  gap: 10px;
  color: #dffbff;
  font-weight: 700;
}

.stats span {
  white-space: nowrap;
}

.bars {
  width: min(460px, 62vw);
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.meter {
  height: 11px;
  overflow: hidden;
  border: 1px solid rgba(210, 245, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.meter span {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 120ms linear;
}

.hp-meter span {
  background: linear-gradient(90deg, var(--red), var(--yellow));
  box-shadow: 0 0 16px rgba(255, 78, 102, 0.75);
}

.xp-meter span {
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 16px rgba(64, 247, 255, 0.75);
}

.skill-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(680px, 74vw);
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid rgba(128, 240, 255, 0.22);
  border-radius: 8px;
  background: rgba(4, 8, 18, 0.64);
  color: #dffbff;
  font-size: 0.78rem;
  font-weight: 700;
}

.tile-icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  background-image: url("assets/sci-fi-sprite-sheet-transparent.png?v=1");
  background-repeat: no-repeat;
  background-size: 768px 768px;
  image-rendering: pixelated;
}

.top-actions {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 48px);
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(210, 245, 255, 0.26);
  border-radius: 8px;
  background: rgba(6, 12, 25, 0.78);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.25);
}

.icon-btn:focus-visible,
.action-btn:focus-visible,
.upgrade-card:focus-visible,
.primary-btn:focus-visible {
  outline: 3px solid rgba(64, 247, 255, 0.85);
  outline-offset: 2px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 5, 12, 0.58);
  backdrop-filter: blur(5px);
}

.overlay[hidden] {
  display: none;
}

.modal {
  width: min(720px, 100%);
  max-height: min(86dvh, 680px);
  overflow: hidden;
  border: 1px solid rgba(128, 240, 255, 0.32);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.5), 0 0 36px rgba(64, 247, 255, 0.18);
}

.modal-head {
  padding: 18px;
  border-bottom: 1px solid rgba(128, 240, 255, 0.18);
}

.modal h1,
.modal h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.35rem);
  letter-spacing: 0;
}

.modal p {
  margin: 8px 0 0;
  color: var(--muted);
}

.modal-body {
  padding: 18px;
}

.primary-btn,
.upgrade-card,
.secondary-btn {
  border: 1px solid rgba(128, 240, 255, 0.28);
  border-radius: 8px;
  background: rgba(11, 23, 44, 0.92);
  color: var(--text);
  cursor: pointer;
}

.primary-btn {
  width: min(260px, 100%);
  min-height: 48px;
  font-weight: 900;
  color: #061019;
  background: linear-gradient(90deg, var(--cyan), var(--green));
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-btn {
  min-height: 48px;
  padding: 0 18px;
  font-weight: 800;
}

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

.upgrade-card {
  min-height: 132px;
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  text-align: left;
}

.upgrade-card:hover {
  transform: translateY(-1px);
  border-color: rgba(64, 247, 255, 0.72);
  box-shadow: 0 0 26px rgba(64, 247, 255, 0.18);
}

.upgrade-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
}

.upgrade-card p {
  margin: 0;
  color: #b7cbd9;
  font-size: 0.9rem;
  line-height: 1.35;
}

#controls {
  position: absolute;
  inset: auto max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
}

.stick {
  width: clamp(116px, 18vw, 152px);
  height: clamp(116px, 18vw, 152px);
  border: 1px solid rgba(128, 240, 255, 0.24);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(64, 247, 255, 0.16) 0 18%, transparent 19%),
    rgba(5, 12, 24, 0.42);
  box-shadow: inset 0 0 22px rgba(64, 247, 255, 0.16), 0 12px 30px rgba(0, 0, 0, 0.24);
  pointer-events: auto;
  touch-action: none;
}

.stick-knob {
  position: relative;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: rgba(220, 252, 255, 0.88);
  box-shadow: 0 0 22px rgba(64, 247, 255, 0.75), inset 0 0 14px rgba(255, 61, 242, 0.45);
  transform: translate(-50%, -50%);
}

.action-pad {
  display: grid;
  grid-template-columns: auto auto;
  gap: 10px;
  pointer-events: auto;
}

.action-btn {
  --cooldown: 0;
  position: relative;
  width: clamp(72px, 12vw, 96px);
  height: clamp(72px, 12vw, 96px);
  overflow: hidden;
  border: 1px solid rgba(210, 245, 255, 0.28);
  border-radius: 50%;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  background: rgba(6, 12, 25, 0.76);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  touch-action: none;
  display: grid;
  place-items: center;
  grid-template-rows: 1fr auto auto;
  padding: 12px 5px 10px;
}

.action-btn::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--cooldown) * 100%);
  background: rgba(0, 0, 0, 0.48);
  pointer-events: none;
}

.action-btn span {
  position: relative;
  z-index: 1;
}

.action-label {
  align-self: end;
  font-size: clamp(0.94rem, 2.45vw, 1.14rem);
  line-height: 1;
}

.action-key,
.action-cooldown {
  color: #bdd4df;
  font-size: clamp(0.5rem, 1.55vw, 0.64rem);
  font-weight: 800;
  line-height: 1.1;
}

.action-cooldown {
  min-height: 0.75rem;
  color: var(--yellow);
}

.action-btn--dash {
  border-color: rgba(64, 247, 255, 0.42);
  box-shadow: 0 0 22px rgba(64, 247, 255, 0.22);
}

.action-btn--nova {
  border-color: rgba(255, 61, 242, 0.45);
  box-shadow: 0 0 24px rgba(255, 61, 242, 0.24);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
  }

  .brand,
  .stats {
    min-height: 28px;
    padding: 5px 7px;
    font-size: 0.78rem;
  }

  .stats {
    gap: 7px;
  }

  .bars {
    width: min(330px, 70vw);
    gap: 4px;
  }

  .skill-chips {
    max-width: 72vw;
  }

  .chip {
    min-height: 24px;
    padding: 3px 6px;
    font-size: 0.7rem;
  }

  .top-actions {
    top: auto;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 102px);
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .upgrade-card {
    min-height: 86px;
  }
}

@media (max-height: 520px) {
  .skill-chips {
    display: none;
  }

  .modal {
    max-height: 92dvh;
  }

  .modal-head,
  .modal-body {
    padding: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
