:root {
  --neon-purple: #b026ff;
  --neon-pink: #ff00ff;
  --neon-green: #60a5fa;
  --neon-yellow: #fff01f;
  --bg-dark: #090011;
}
body {
  margin: 0;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: 'Courier New', Courier, monospace;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#mobile-controls {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 14px max(14px, env(safe-area-inset-bottom)) 14px;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 20;
}
.mc-cluster {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}
.mc-right {
  flex-direction: row;
  align-items: flex-end;
}
.mc-btn {
  width: 62px;
  height: 62px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(15, 5, 25, 0.6);
  border: 2px solid rgba(176, 38, 255, 0.55);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  transition:
    transform 0.08s ease,
    background-color 0.12s ease,
    border-color 0.12s ease;
}
.mc-btn:active,
.mc-btn.is-active {
  background: rgba(176, 38, 255, 0.35);
  border-color: var(--neon-pink);
  transform: scale(0.94);
}
.mc-fire {
  width: 74px;
  height: 74px;
  border-color: rgba(236, 72, 153, 0.7);
  background: rgba(60, 10, 40, 0.55);
}
.mc-shield {
  border-color: rgba(96, 165, 250, 0.7);
}
#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
canvas {
  box-shadow: 0 0 50px rgba(176, 38, 255, 0.2);
  border: 2px solid var(--neon-purple);
  background: radial-gradient(circle at center, #1a0b2e 0, #000 100%);
}
.ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  text-shadow: 0 0 10px var(--neon-purple);
}
.hidden {
  display: none !important;
}
#hud {
  justify-content: space-between;
  align-items: flex-start;
  flex-direction: row;
  padding: 20px;
  box-sizing: border-box;
  height: auto;
}
.hud-panel {
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--neon-green);
  padding: 10px 20px;
  border-radius: 4px;
}
h1 {
  font-size: 4rem;
  margin: 0;
  background: -webkit-linear-gradient(45deg, var(--neon-pink), var(--neon-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px var(--neon-purple);
  letter-spacing: 2px;
  text-transform: uppercase;
}
h2 {
  font-size: 2rem;
  color: var(--neon-green);
  margin-bottom: 10px;
}
p {
  font-size: 1.2rem;
  color: #ddd;
  max-width: 600px;
  line-height: 1.5;
}
.tagline {
  color: var(--neon-yellow);
  font-size: 1.2rem;
  margin-bottom: 30px;
  font-style: italic;
}
button {
  pointer-events: auto;
  background: transparent;
  color: #d4d4d4;
  border: 1px solid #404040;
  border-radius: 9999px;
  padding: 0.625rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  margin-top: 20px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    color 0.3s ease,
    transform 0.15s ease,
    box-shadow 0.3s ease;
}
button:hover {
  background-color: #262626;
  color: #f5f5f5;
  border-color: #525252;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}
button:active {
  transform: translateY(0);
  filter: brightness(0.95);
}
.stat-label {
  font-size: 0.8rem;
  color: #aaa;
  display: block;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}
#toast-container {
  position: absolute;
  bottom: 20%;
  width: 100%;
  text-align: center;
  pointer-events: none;
}
.toast {
  display: inline-block;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--neon-yellow);
  color: var(--neon-yellow);
  padding: 10px 20px;
  border-radius: 20px;
  animation: 2s forwards floatUp;
  font-weight: 700;
}
@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  10% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(-20px);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px);
  }
}
.bar-container {
  width: 200px;
  height: 10px;
  background: #333;
  margin-top: 5px;
  position: relative;
}
.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.2s;
}
#integrity-bar {
  background-color: var(--neon-pink);
  box-shadow: 0 0 10px var(--neon-pink);
}
#shield-bar {
  background-color: var(--neon-purple);
  box-shadow: 0 0 10px var(--neon-purple);
}
.controls-hint {
  margin-top: 30px;
  font-size: 0.9rem;
  color: #888;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px 14px;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 14px;
}
.key-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.key-label {
  color: #aaa;
}
.key {
  border: 1px solid #666;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  background: #222;
}
.key + .key {
  margin-left: 2px;
}

@media (max-width: 640px) {
  body {
    overflow: hidden;
  }

  #game-container {
    min-height: 100svh;
    overflow: hidden;
  }

  canvas {
    box-shadow: 0 0 28px rgba(176, 38, 255, 0.16);
    transition:
      opacity 0.2s ease,
      filter 0.2s ease;
  }

  .ui-layer {
    justify-content: center;
    padding: max(18px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
    box-sizing: border-box;
    overflow-y: auto;
    text-shadow: 0 0 8px rgba(176, 38, 255, 0.36);
  }

  #start-screen,
  #game-over-screen {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(calc(100% - 32px), 340px);
    height: auto;
    max-height: calc(100svh - 40px);
    padding: 1.4rem 1.1rem;
    border: 1px solid rgba(176, 38, 255, 0.5);
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(11, 3, 24, 0.96), rgba(6, 1, 14, 0.985));
    box-shadow:
      0 22px 52px rgba(0, 0, 0, 0.6),
      0 0 0 1px rgba(255, 255, 255, 0.03),
      inset 0 1px 0 rgba(255, 255, 255, 0.03);
    overflow-y: auto;
    pointer-events: auto;
    touch-action: pan-y manipulation;
    -webkit-overflow-scrolling: touch;
    justify-content: center;
  }

  #start-screen .start-intro,
  #start-screen .start-footer,
  #start-screen .td-screen-story,
  #start-screen .tagline {
    display: none !important;
  }

  #start-screen {
    scroll-padding-bottom: 18px;
  }

  #start-screen > * {
    max-width: 100%;
  }

  #start-screen .start-logo-badge {
    order: 1;
  }

  #start-screen h1 {
    order: 2;
  }

  #start-screen .tagline {
    order: 3;
  }

  #start-screen .start-intro {
    order: 4;
  }

  h1 {
    font-size: clamp(2.5rem, 14vw, 3.5rem);
    line-height: 0.92;
    margin-bottom: 0.4rem;
  }

  h2 {
    font-size: clamp(1.6rem, 8vw, 2.1rem);
    margin-top: 0;
  }

  p {
    max-width: 100%;
    font-size: 0.96rem;
    line-height: 1.45;
    margin: 0 0 1rem;
  }

  .tagline {
    font-size: 1rem;
    margin-bottom: 1rem;
  }

  .controls-hint {
    width: 100%;
    box-sizing: border-box;
    margin-top: 18px;
    padding: 9px;
    font-size: 0.76rem;
    line-height: 1.5;
  }

  button {
    width: min(100%, 280px);
    margin-top: 16px;
  }

  #start-screen .start-logo-badge {
    width: 68px !important;
    height: 68px !important;
    margin-bottom: 0.45rem !important;
  }

  #start-screen .start-logo-badge img {
    width: 40px !important;
    height: 40px !important;
  }

  #start-screen .controls-hint {
    order: 6;
  }

  #start-screen #start-btn {
    order: 5;
    margin-top: 14px;
  }

  #start-screen .td-screen-story {
    order: 7;
  }

  #start-screen .start-footer {
    order: 8;
    margin-top: 14px !important;
    font-size: 0.74rem !important;
  }

  #hud {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: max(10px, env(safe-area-inset-top)) 10px 14px;
    height: auto;
  }

  .hud-left,
  .hud-right {
    width: auto;
    max-width: 54%;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .hud-right {
    align-items: flex-end;
    text-align: right;
  }

  .hud-panel {
    padding: 6px 10px;
    border-radius: 6px;
  }

  .stat-label {
    font-size: 0.55rem;
    letter-spacing: 0.04em;
  }
  .stat-value {
    font-size: 1rem;
  }

  .bar-container {
    width: 140px;
    max-width: 140px;
    height: 6px;
  }

  .hud-right > div:last-child {
    display: none;
  }

  #toast-container {
    bottom: 12%;
    padding: 0 16px;
    box-sizing: border-box;
  }

  .toast {
    max-width: 100%;
    font-size: 0.78rem;
    padding: 6px 14px;
  }

  body[data-launch-pilot-screen='start'] canvas,
  body[data-launch-pilot-screen='gameover'] canvas {
    opacity: 0.18;
    filter: saturate(0.82) brightness(0.72);
  }

  body[data-launch-pilot-screen='playing'] canvas {
    opacity: 1;
    filter: none;
  }
}

@media (max-width: 640px) and (max-height: 700px) {
  .ui-layer {
    padding:
      max(12px, env(safe-area-inset-top))
      12px
      max(14px, env(safe-area-inset-bottom));
  }

  #start-screen,
  #game-over-screen {
    width: min(100%, 340px);
    max-height: calc(100svh - 24px);
    padding: 1rem 0.9rem 1rem;
  }

  h1 {
    font-size: clamp(2.15rem, 12vw, 3rem);
  }

  h2 {
    font-size: clamp(1.45rem, 7vw, 1.9rem);
  }

  p {
    font-size: 0.9rem;
    line-height: 1.38;
    margin: 0 0 0.85rem;
  }

  .tagline {
    font-size: 0.94rem;
    margin-bottom: 0.8rem;
  }

  #start-screen .start-logo-badge {
    width: 60px !important;
    height: 60px !important;
    margin-bottom: 0.35rem !important;
  }

  #start-screen .start-logo-badge img {
    width: 36px !important;
    height: 36px !important;
  }

  .controls-hint {
    margin-top: 12px;
    padding: 8px;
    font-size: 0.72rem;
  }

  button {
    margin-top: 12px;
    padding: 0.6rem 1.1rem;
  }

  #start-screen .start-footer {
    margin-top: 10px !important;
    font-size: 0.7rem !important;
  }

  #start-screen .td-screen-story {
    margin-top: 10px;
    padding-top: 8px;
  }

  #start-screen .td-screen-story__lead {
    font-size: 0.78rem;
    line-height: 1.34;
  }

  #start-screen .td-screen-story__chips {
    gap: 5px;
    margin-top: 8px;
  }

  #start-screen .td-story-chip:nth-child(n + 4) {
    display: none;
  }

  #start-screen .start-footer {
    display: none;
  }
}

@media (max-width: 768px), (pointer: coarse) {
  body[data-launch-pilot-screen='playing'] #mobile-controls {
    display: flex;
  }

  body[data-launch-pilot-screen='playing'] #game-container {
    padding-top: calc(84px + env(safe-area-inset-top));
    padding-bottom: calc(150px + env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  body[data-launch-pilot-screen='playing'] #hud {
    padding-bottom: 0;
  }

  body[data-launch-pilot-screen='playing'] #toast-container {
    bottom: calc(160px + env(safe-area-inset-bottom));
  }
}
