: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: 1040px;
  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));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

.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;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 960 / 540;
  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;
}

.mode-select {
  display: flex;
  gap: 1em;
  margin: 0.4em 0;
}

.mode-btn {
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  padding: 0.8em 1.2em;
  cursor: pointer;
  line-height: 1.4;
}

.mode-btn span {
  color: var(--green-dim);
  font-size: 0.75rem;
  letter-spacing: normal;
}

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

.start-btn {
  margin-top: 0.4em;
  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.hidden {
  display: none;
}

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

.share-btn {
  display: block;
  margin: 0.6em auto 0;
  background: transparent;
  border: 1px solid var(--green-dim);
  color: var(--green-dim);
  font-family: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  padding: 0.5em 1.4em;
  cursor: pointer;
}

.share-btn:hover,
.share-btn:focus {
  color: var(--green-bright);
  border-color: var(--green);
  background: rgba(51, 255, 51, 0.08);
}

.share-btn.hidden {
  display: none;
}

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

.hint-touch {
  display: none;
}

.rotate-prompt {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  background: rgba(2, 5, 2, 0.92);
  text-align: center;
  padding: 1.5em;
  color: var(--green-bright);
}

.rotate-prompt svg {
  animation: rotate-hint 1.8s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

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

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  .rotate-prompt {
    display: flex;
  }
}

@media (max-width: 600px) {
  .title {
    font-size: clamp(1rem, 5.5vw, 2.2rem);
    letter-spacing: 0.18em;
  }
  .topbar-spacer {
    width: 40px;
  }
  .wrap {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .mode-select {
    flex-direction: column;
    width: 100%;
  }
}
