html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05050a;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-container.gameplay-active canvas {
  filter: contrast(1.08) saturate(0.88) sepia(0.08);
  animation: vhs-picture-drop 5s steps(1, end) infinite;
}

#game-container.gameplay-active::before,
#game-container.gameplay-active::after {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  content: "";
}

#game-container.gameplay-active::before {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 2px,
      rgba(0, 0, 0, 0.24) 3px,
      transparent 4px
    ),
    radial-gradient(ellipse, transparent 55%, rgba(0, 0, 0, 0.4) 100%);
  animation: vhs-tracking 5s steps(1, end) infinite;
}

#game-container.gameplay-active::after {
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
  animation: vhs-grain 140ms steps(2, end) infinite;
}

@keyframes vhs-grain {
  0% {
    background-position: 0 0;
  }
  25% {
    background-position: 13px -17px;
  }
  50% {
    background-position: -8px 9px;
  }
  75% {
    background-position: 19px 15px;
  }
  100% {
    background-position: 0 0;
  }
}

@keyframes vhs-tracking {
  0%,
  83%,
  89%,
  100% {
    clip-path: inset(0);
    transform: translateX(0);
    filter: none;
    opacity: 1;
  }
  84% {
    clip-path: inset(42% 0 52%);
    transform: translateX(18px);
    filter: hue-rotate(70deg);
    opacity: 0.95;
  }
  85% {
    clip-path: inset(68% 0 29%);
    transform: translateX(-24px);
    filter: hue-rotate(-90deg);
    opacity: 0.85;
  }
  86% {
    clip-path: inset(18% 0 78%);
    transform: translateX(9px);
    filter: hue-rotate(35deg);
    opacity: 0.9;
  }
}

@keyframes vhs-picture-drop {
  0%,
  83%,
  89%,
  100% {
    filter: contrast(1.08) saturate(0.88) sepia(0.08);
    transform: translateX(0);
  }
  84% {
    filter: contrast(1.45) saturate(1.8) hue-rotate(-16deg) brightness(0.72);
    transform: translateX(3px);
  }
  85% {
    filter: contrast(1.7) saturate(0.4) brightness(1.25);
    transform: translateX(-3px);
  }
  86% {
    filter: contrast(1.15) saturate(1.5) sepia(0.3) brightness(0.82);
    transform: translateX(1px);
  }
}

#game-container canvas {
  display: block;
  touch-action: none;
}

#intro-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: #000000;
}

#intro-video {
  display: block;
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  object-position: center;
}

#joystick {
  display: none;
  position: fixed;
  left: 24px;
  bottom: 24px;
  width: 132px;
  height: 132px;
  z-index: 10;
  border: 2px solid rgba(0, 229, 255, 0.68);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(0, 229, 255, 0.2),
    rgba(5, 20, 35, 0.72)
  );
  box-shadow:
    inset 0 0 18px rgba(0, 229, 255, 0.18),
    0 0 18px rgba(0, 220, 255, 0.3);
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: rgba(0, 229, 255, 0.82);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.75);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#health-bar {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1;
  width: min(220px, calc(100vw - 48px));
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 4px;
  background: rgba(5, 20, 35, 0.88);
  box-shadow: 0 0 12px rgba(0, 220, 255, 0.22);
  color: #ffffff;
  font:
    bold 11px Arial,
    sans-serif;
  letter-spacing: 0;
  pointer-events: none;
}

#health-track {
  height: 10px;
  margin-top: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.6);
}

#health-fill {
  width: 100%;
  height: 100%;
  background: #00e5ff;
  transition: width 120ms linear;
}

#objectives-panel {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  width: fit-content;
  max-width: calc(100vw - 40px);
  padding: 9px 12px;
  box-sizing: border-box;
  border: 2px solid rgba(0, 229, 255, 0.68);
  border-radius: 6px;
  color: #ffffff;
  background: rgba(5, 20, 35, 0.9);
  box-shadow: 0 0 12px rgba(0, 220, 255, 0.3);
  pointer-events: none;
  user-select: none;
}

#objective-password {
  color: #00e5ff;
  font: bold 16px monospace;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.78);
}

.modal-backdrop[hidden] {
  display: none;
}

.terminal-monitor {
  position: relative;
  width: min(92vw, 800px);
  aspect-ratio: 16 / 9;
  background: #000000;
  box-sizing: border-box;
}

.terminal-machine {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.terminal-screen {
  position: absolute;
  inset: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
}

.terminal-window-controls {
  display: none;
}

.terminal-window-controls span {
  width: 11px;
  height: 11px;
  display: grid;
  place-items: center;
  color: #00f5ee;
  background: #d000ff;
  border-radius: 2px;
  line-height: 10px;
}

.terminal-screen h2 {
  display: none;
}

.terminal-code {
  position: absolute;
  top: 26.4%;
  left: 26.4%;
  width: 48%;
  height: 40%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5%;
}

.terminal-code span {
  display: grid;
  place-items: center;
  border: 0;
  color: #ffffff;
  font: bold clamp(28px, 7vw, 58px) monospace;
}

.terminal-logo {
  display: none;
}

.terminal-stand {
  display: none;
}

.terminal-close {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  display: block;
  padding: 9px 14px;
  border: 2px solid #00f5ee;
  border-radius: 4px;
  color: #00f5ee;
  background: rgba(5, 5, 10, 0.92);
  font: bold 14px monospace;
  cursor: pointer;
}

.terminal-close:hover {
  color: #05050a;
  background: #00f5ee;
}

.password-panel {
  width: min(88vw, 390px);
  padding: 28px;
  box-sizing: border-box;
  border: 2px solid #00f5ee;
  color: #ffffff;
  background: #05050a;
  box-shadow: 0 0 30px rgba(0, 245, 238, 0.25);
  font-family: monospace;
  text-align: center;
}

.password-panel h2 {
  margin: 0 0 10px;
  color: #00f5ee;
  font-size: 18px;
}

.password-panel p {
  margin: 8px 0 18px;
}

#password-input {
  width: 160px;
  padding: 9px;
  border: 1px solid #d000ff;
  color: #ffffff;
  background: #000000;
  font: bold 26px monospace;
  letter-spacing: 8px;
  text-align: center;
}

.password-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.password-actions button {
  padding: 9px 12px;
  border: 1px solid #00f5ee;
  color: #00f5ee;
  background: #071719;
  font: bold 13px monospace;
}

.password-error {
  min-height: 16px;
  margin-bottom: 0 !important;
  color: #ff4f91;
}

@media (max-width: 600px) {
  #joystick {
    left: 12px;
    bottom: 12px;
    width: 116px;
    height: 116px;
  }

  #health-bar {
    top: 12px;
    right: 12px;
    width: min(220px, calc(100vw - 24px));
  }

  #objectives-panel {
    top: 72px;
    left: 12px;
    width: min(310px, calc(100vw - 24px));
  }
}

@media (max-width: 760px), (max-height: 560px) {
  .terminal-monitor {
    width: min(86vw, calc(177.78vh - 71px), 700px);
  }

  @supports (height: 100dvh) {
    .terminal-monitor {
      width: min(86vw, calc(177.78dvh - 71px), 700px);
    }
  }

  .terminal-close {
    top: 4%;
    right: 15%;
    bottom: auto;
    display: grid;
    width: 44px;
    height: 44px;
    padding: 0;
    place-items: center;
    border: 1px solid #00f5ee;
    border-radius: 4px;
    color: #00f5ee;
    background: #d000ff;
    font-size: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .terminal-close::before {
    content: "×";
    color: #00f5ee;
    font:
      bold 30px/1 Arial,
      sans-serif;
  }
}
