:root {
  --border-radius: 4px;
  --color-background: #000;
  --color-surface--100: #faf2e6;
  --color-surface--200: #e0d8cc;
  --color-on-surface: hsl(236, 18%, 30%);
  --color-sound-on: hsl(99, 97%, 45%);
  --nominal-size: 3.33rem;
}

/* Disable long-press callout menu (Safari) */
* {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  padding: 0;
  margin: 0;
  background-color: black;
}

body {
  position: fixed;
  touch-action: none; /* Prevents touch scroll/zoom gestures */
  overscroll-behavior: none; /* Prevents overscroll bounce on mobile */
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
}

.game {
  overflow: hidden; /* Prevents scrollbars */
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}

canvas {
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  background-color: #0b0630;
  aspect-ratio: 1;
  width: min(90vw, 90vh);
  height: min(90vw, 90vh);
}

.controls {
  display: none;
  position: absolute;
  width: 100%;
  height: 100%;
}

.controls-left {
  position: absolute;
  left: 0;
  bottom: 0;
  padding-left: 5rem;
  padding-bottom: 5rem;
  display: flex;
  gap: 0.2rem;
}

.controls-right {
  position: absolute;
  right: 0;
  bottom: 0;
  padding-right: 5rem;
  padding-bottom: 5rem;
  display: flex;
  gap: 0.2rem;
}

.controls button {
  background-color: var(--color-surface--100);
  border-radius: var(--border-radius);
  border-color: transparent;
  color: var(--color-on-surface);
  display: inline-block;
  letter-spacing: 0.1em;
  line-height: 1.15;
  font-size: 1rem;
  height: var(--nominal-size);
  width: var(--nominal-size);
  padding: 0.3rem;
  position: relative;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.1s ease;
}

/* This add the round elevation on the button. Making it look crazy nice.*/
.controls button::before {
  border-radius: 50%;
  box-shadow: 4px 6px 8px rgba(0, 0, 0, 0.2);
  content: "";
  display: flex;
  height: 85%;
  left: 7.5%;
  position: absolute;
  top: 7.5%;
  width: 85%;
}

/* Button pressed state - scale down to 0.9 */
.controls button.pressed {
  transform: scale(0.9);
  background-color: var(--color-surface--200);
}

/* Sound toggle: S icon stays same; indicator line shows state */
#sound-toggle .sound-toggle-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
}
#sound-toggle {
  color: var(--color-on-surface);
}
#sound-toggle path {
  fill: var(--color-on-surface);
}
#sound-toggle .sound-indicator {
  color: var(--color-on-surface);
  transition: color 0.2s ease;
}
#sound-toggle .sound-indicator line {
  stroke: currentColor;
}
#sound-toggle:not(.muted) .sound-indicator {
  color: var(--color-sound-on);
  filter: drop-shadow(0 0 1px var(--color-sound-on));
}

/* Mobile portrait - check for portrait orientation with height constraint */
@media (max-width: 480px) and (max-height: 960px) {
  .game {
    flex-direction: column;
    justify-content: flex-start;
  }
  canvas {
    width: min(104vw, 104vh);
    height: min(104vw, 104vh);
  }
  .controls {
    display: block;
    padding: 0 1rem;
  }
}

/* Mobile landscape - prioritize height over width */
@media (max-height: 600px) {
  canvas {
    width: min(100vw, 100vh);
    height: min(100vw, 100vh);
  }
  .controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex: 1;
    align-self: flex-end;
    padding-bottom: 4rem;
  }
  .controls-left,
  .controls-right {
    padding-right: 4rem;
    padding-left: 4rem;
  }
}

.crt-container {
  position: relative;
  display: flex;
}

.crt {
  clip-path: url(#path);
}

.crt::before {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
    linear-gradient(
      90deg,
      rgba(255, 0, 0, 0.06),
      rgba(0, 255, 0, 0.02),
      rgba(0, 0, 255, 0.06)
    );
  z-index: 2;
  background-size:
    100% 3px,
    4px 100%;
  pointer-events: none;
}

@keyframes flicker {
  0% {
    opacity: 0.27861;
  }
  5% {
    opacity: 0.34769;
  }
  10% {
    opacity: 0.23604;
  }
  15% {
    opacity: 0.90626;
  }
  20% {
    opacity: 0.18128;
  }
  25% {
    opacity: 0.83891;
  }
  30% {
    opacity: 0.65583;
  }
  35% {
    opacity: 0.67807;
  }
  40% {
    opacity: 0.26559;
  }
  45% {
    opacity: 0.84693;
  }
  50% {
    opacity: 0.96019;
  }
  55% {
    opacity: 0.08594;
  }
  60% {
    opacity: 0.20313;
  }
  65% {
    opacity: 0.71988;
  }
  70% {
    opacity: 0.53455;
  }
  75% {
    opacity: 0.37288;
  }
  80% {
    opacity: 0.71428;
  }
  85% {
    opacity: 0.70419;
  }
  90% {
    opacity: 0.7003;
  }
  95% {
    opacity: 0.36108;
  }
  100% {
    opacity: 0.24387;
  }
}

.crt::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(18, 16, 16, 0.1);
  opacity: 0;
  z-index: 2;
  pointer-events: none;
  animation: flicker 0.15s infinite;
}
