/* 90s Cyber/CRT Theme */
:root {
  --bg-color: #050510;
  --screen-bg: #000;
  --primary-neon: #33ff00;
  /* Classic Terminal Green */
  --secondary-neon: #ff0099;
  /* Hot Pink */
  --text-main: #33ff00;
  --text-dim: #22aa00;
  --grid-color: rgba(51, 255, 0, 0.1);
  --crt-flicker: rgba(51, 255, 0, 0.02);
  --scanline-color: rgba(0, 0, 0, 0.5);
  --aspect-ratio: 1.333333;
  /* 4:3 */
}

/* Reset and Base Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 40px 40px;
  color: var(--text-main);
  font-family: 'VT323', monospace;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-transform: uppercase;
}

/* CRT Scanline Overlay */
body.crt-active::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(to bottom,
      rgba(18, 16, 16, 0) 50%,
      rgba(0, 0, 0, 0.25) 50%);
  background-size: 100% 4px;
  z-index: 999;
  pointer-events: none;
  animation: flicker 0.15s infinite;
}

@keyframes flicker {
  0% {
    opacity: 0.9;
  }

  5% {
    opacity: 0.85;
  }

  10% {
    opacity: 0.95;
  }

  15% {
    opacity: 0.9;
  }

  100% {
    opacity: 0.9;
  }
}

/* Screen Container */
#screen_container {
  position: relative;
  background-color: var(--screen-bg);
  border: 4px solid var(--text-dim);
  box-shadow:
    0 0 20px var(--text-dim),
    inset 0 0 20px rgba(0, 0, 0, 0.8);

  /* Responsive Aspect Ratio Logic */
  width: min(95vw, calc(70vh * var(--aspect-ratio)));
  height: min(calc(95vw / var(--aspect-ratio)), 70vh);
  max-width: 95vw;
  max-height: 70vh;

  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  visibility: hidden;
  /* Hidden until game starts */
}

#screen_container canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  image-rendering: pixelated;
  /* Enhance retro look */
}

/* Startup Dialog */
.dialog-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 100;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.dialog-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.dialog-box {
  background: #000;
  border: 4px double var(--primary-neon);
  padding: 40px;
  text-align: center;
  box-shadow: 0 0 20px var(--primary-neon);
  max-width: 500px;
  width: 90%;
  position: relative;
}

/* Decorative corners */
.dialog-box::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 2px solid var(--primary-neon);
  pointer-events: none;
}

/* CRT Toggle Switch */
.crt-toggle-container {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px;
  border-radius: 4px;
}

.crt-label {
  font-family: 'VT323', monospace;
  color: var(--text-dim);
  font-size: 1rem;
}

.crt-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.crt-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #333;
  transition: .2s;
  border: 1px solid var(--text-dim);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-dim);
  transition: .2s;
  box-shadow: 0 0 5px var(--text-dim);
}

input:checked+.slider {
  background-color: #000;
  border-color: var(--primary-neon);
}

input:checked+.slider:before {
  transform: translateX(20px);
  background-color: var(--primary-neon);
  box-shadow: 0 0 10px var(--primary-neon);
}

h1 {
  font-family: 'Press Start 2P', cursive;
  /* Retro Header Font */
  font-size: 1.5rem;
  margin: 0 0 20px 0;
  color: var(--secondary-neon);
  text-shadow: 2px 2px var(--primary-neon);
  line-height: 1.5;
  background: none;
  background-clip: unset;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: initial;
}

p {
  color: var(--text-main);
  font-size: 1.5rem;
  /* Larger for VT323 */
  margin-bottom: 40px;
  letter-spacing: 1px;
}

/* Buttons */
.btn-group {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  flex-direction: row;
}

.btn {
  background-color: #000;
  color: var(--primary-neon);
  border: 2px solid var(--primary-neon);
  padding: 15px 30px;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.8rem;
  font-weight: normal;
  cursor: pointer;
  transition: all 0.1s steps(2);
  box-shadow: 4px 4px 0 var(--text-dim);
  text-transform: uppercase;
  border-radius: 0;
  height: auto;
  min-width: unset;
}

.btn:hover {
  background-color: var(--primary-neon);
  color: #000;
  box-shadow: 2px 2px 0 var(--text-dim);
  transform: translate(2px, 2px);
  filter: none;
}

.btn:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-primary {
  color: var(--secondary-neon);
  border-color: var(--secondary-neon);
  box-shadow: 4px 4px 0 #aa0066;
  background: #000;
}

.btn-primary:hover {
  background-color: var(--secondary-neon);
  color: #fff;
  box-shadow: 2px 2px 0 #aa0066;
}

/* Input Field */
.input-group {
  margin-top: 30px;
  display: none;
  animation: none;
}

.input-wrapper {
  display: flex;
  gap: 10px;
  justify-content: center;
  background: none;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

input[type="text"] {
  background-color: #000;
  border: 2px solid var(--primary-neon);
  color: var(--primary-neon);
  padding: 10px;
  font-family: 'VT323', monospace;
  font-size: 1.5rem;
  outline: none;
  width: 200px;
  text-transform: none;
  /* Keep ID case sensitive visual */
}

input[type="text"]:focus {
  box-shadow: 0 0 10px var(--primary-neon);
  border-color: var(--primary-neon);
}

/* Share Link Container */
#share_container {
  background: #000;
  border: 2px solid var(--primary-neon);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  opacity: 0;
  visibility: hidden;
  max-width: 90vw;
  box-shadow: 4px 4px 0 var(--text-dim);
  border-radius: 0;
  backdrop-filter: none;
}

#share_container.visible {
  opacity: 1;
  visibility: visible;
}

.share-label {
  color: var(--text-dim);
  font-family: 'Press Start 2P', cursive;
  font-size: 0.7rem;
  font-weight: normal;
}

.share-link {
  color: var(--text-main);
  font-family: 'VT323', monospace;
  font-size: 1.5rem;
  text-transform: none;
}

/* Copy Button */
.btn-icon {
  background: var(--primary-neon);
  border: 2px solid #000;
  color: #000;
  cursor: pointer;
  padding: 5px;
  border-radius: 0;
  /* Square buttons */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}

.btn-icon:hover {
  background-color: var(--secondary-neon);
  color: #fff;
}

/* Screen Controls Group */
.screen-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

/* Control Buttons (Fullscreen / Restore) */
.control-btn {
  background: transparent;
  color: var(--primary-neon);
  border: 2px solid var(--primary-neon);
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
  border-radius: 0;
}

.control-btn:hover {
  background: var(--primary-neon);
  color: #000;
}



/* Fullscreen Mode Overrides */
canvas:fullscreen {
  width: 100vw !important;
  height: 100vh !important;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
  h1 {
    font-size: 1rem;
  }

  p {
    font-size: 1.2rem;
  }

  .btn {
    padding: 10px 20px;
    font-size: 0.7rem;
  }

  #share_container {
    flex-direction: column;
    padding: 15px;
    gap: 10px;
  }
}

/* Instructions Overlay */
.instructions-overlay {
  position: fixed;
  bottom: 20px;
  left: 20px;
  color: var(--text-dim);
  font-family: 'VT323', monospace;
  font-size: 1rem;
  max-width: 400px;
  pointer-events: none;
  opacity: 0;
  /* Start invisible for animation */
  text-shadow: 1px 1px 0 #000;
  z-index: 50;
  text-transform: none;
  animation: fadeSlideUp 0.8s ease-out forwards;
  animation-delay: 1s;
  /* Wait a bit after load */
  transition: opacity 1s ease;
}

.instructions-overlay.fade-out {
  opacity: 0;
}

.instructions-overlay p {
  margin: 5px 0;
  font-size: 1rem;
  color: var(--text-dim);
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 0.7;
    transform: translateY(0);
  }
}

.username-instruction {
  left: auto;
  right: 20px;
  text-align: right;
  bottom: 20px;
}