:root {
  --bg: #050805;
  --green: #33ff33;
  --green-bright: #39ff14;
  --green-dim: #1f8f1f;
  --glow: 0 0 2px currentColor, 0 0 8px rgba(51, 255, 51, 0.5);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--green);
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "JetBrains Mono", "IBM Plex Mono", "Courier New", monospace;
  font-size: 16px;
  line-height: 1.5;
  text-shadow: var(--glow);
  overflow-x: hidden;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, 0.25) 2px,
    rgba(0, 0, 0, 0.25) 3px
  );
  mix-blend-mode: multiply;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 55%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: max(3vh, env(safe-area-inset-top)) 20px 6vh;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8em;
}

.back-link {
  color: var(--green-dim);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.back-link:hover,
.back-link:focus {
  color: var(--green-bright);
  text-shadow: 0 0 2px currentColor, 0 0 12px rgba(57, 255, 20, 0.8);
}

.title {
  flex: 1;
  min-width: 0;
  text-align: center;
  color: var(--green-bright);
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  letter-spacing: 0.3em;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer {
  width: 90px;
}

.hud {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2em;
  margin: 0 0 0.8em;
  color: var(--green-dim);
  font-size: 0.95rem;
}

.hud-cell span {
  color: var(--green-bright);
  font-weight: 700;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 620;
  background: #050805;
  border: 1px solid var(--green-dim);
  box-shadow: 0 0 12px rgba(51, 255, 51, 0.25) inset, 0 0 18px rgba(51, 255, 51, 0.15);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  background: rgba(2, 5, 2, 0.75);
  text-align: center;
  padding: 1em;
}

.overlay.hidden {
  display: none;
}

.overlay-line {
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  color: var(--green-bright);
  letter-spacing: 0.2em;
  margin: 0 0 0.2em;
}

.overlay-sub {
  color: var(--green-dim);
  font-size: 0.9rem;
  margin: 0;
  text-shadow: none;
}

.overlay-sub-touch {
  display: none;
}

.start-btn {
  margin-top: 0.8em;
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 0.2em;
  padding: 0.6em 1.6em;
  cursor: pointer;
}

.start-btn:hover,
.start-btn:focus {
  background: rgba(51, 255, 51, 0.12);
  box-shadow: 0 0 12px rgba(57, 255, 20, 0.6);
}

.hint {
  text-align: center;
  color: var(--green-dim);
  font-size: 0.85rem;
  text-shadow: none;
  margin: 1em 0 0;
}

.hint-touch,
.hint-rotate {
  display: none;
}

/* Touch controls overlay the canvas so play never requires scrolling. */
.touch-controls {
  display: none;
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 10px max(10px, env(safe-area-inset-bottom));
  pointer-events: none;
}

.touch-left,
.touch-right {
  display: flex;
  align-items: flex-end;
  gap: 0.6em;
  pointer-events: none;
}

.tbtn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid var(--green);
  background: rgba(5, 10, 5, 0.55);
  backdrop-filter: blur(1px);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
}

.tbtn:active {
  background: rgba(51, 255, 51, 0.3);
}

.tbtn-small {
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
  align-self: flex-start;
}

.tbtn-fire {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
  .overlay-sub-kb,
  .hint-kb {
    display: none;
  }
  .overlay-sub-touch,
  .hint-touch {
    display: block;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 700px) and (orientation: portrait) {
  .hint-rotate {
    display: block;
  }
}

@media (max-width: 600px) {
  .title {
    font-size: clamp(1rem, 5.5vw, 2.2rem);
    letter-spacing: 0.18em;
  }
  .hud {
    gap: 1em;
    font-size: 0.8rem;
  }
  .topbar-spacer {
    width: 40px;
  }
  .wrap {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .tbtn {
    width: 50px;
    height: 50px;
    font-size: 1.1rem;
  }
  .tbtn-small {
    width: 38px;
    height: 38px;
    font-size: 0.9rem;
  }
  .tbtn-fire {
    width: 64px;
    height: 64px;
    font-size: 0.7rem;
  }
}
