* {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--c-bg);
  color: var(--c-primary);
  font-family: "Courier New", Courier, monospace;
  overflow: hidden;
  touch-action: none;
}

a {
  text-decoration: none;
  color: inherit;
}

canvas {
  background-color: var(--c-canvas);
  z-index: 1;
  border: 1px solid #333;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

#ui-layer {
  position: absolute;
  top: 20px;
  left: 20px;
  pointer-events: none;
  z-index: 999;
  text-shadow: 0 0 5px var(--c-primary);
}

.glitch-bar-ui {
  width: 15rem;
  height: 1rem;
  background: #333;
  border: 1px solid #555;
}

.glitch-bar-fill {
  background: var(--c-secondary);
  box-shadow: 0 0 1rem var(--c-secondary);
}

.play-button {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 2rem;
  font-size: 2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--c-primary);
  color: var(--c-primary);
  width: 30rem;
  transition: all 0.2s;
  clip-path: polygon(
    20px 0,
    100% 0,
    100% calc(100% - 20px),
    calc(100% - 20px) 100%,
    0 100%,
    0 20px
  );
}

.play-button.btn-completed {
  opacity: 0.8;
  border-color: #4dff4d;
  color: #4dff4d;
}

.menu-button {
  pointer-events: auto;
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: transparent;
  font-weight: bold;
  border: 1px solid var(--c-primary);
  color: var(--c-primary);
  width: 10rem;
  transition: all 0.2s;
}

#main-menu {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background-color: #05050a;
  z-index: 90;
}

#level-select-container {
  overflow-y: auto;
  max-height: 50vh;
  padding: 1rem;
  width: 60vw;
}

/* Custom Scrollbar */
#level-select-container::-webkit-scrollbar {
  width: 8px;
}
#level-select-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.5);
}
#level-select-container::-webkit-scrollbar-thumb {
  background: var(--c-primary);
  border: 1px solid var(--c-bg);
}

.menu-title {
  color: var(--c-secondary);
  text-transform: uppercase;
  text-shadow: 2px 2px 0px var(--c-primary);
  letter-spacing: 5px;
  font-size: 7rem;
  margin-bottom: 2rem;
  font-weight: 900;
  font-style: italic;
  animation: neon-flicker 4s infinite;
}

@keyframes neon-flicker {
  0%,
  18%,
  22%,
  25%,
  53%,
  57%,
  100% {
    opacity: 1;
    text-shadow: 4px 4px 0px var(--c-secondary), -4px -4px 0 var(--c-primary);
  }
  20%,
  24%,
  55% {
    opacity: 0.4;
    text-shadow: none;
  }
}

/* Theme Button */
#theme-btn {
  position: absolute;
  top: 2.5rem;
  right: 2.5rem;
  pointer-events: auto;
  background: transparent;
  border: 1px solid var(--c-primary);
  color: var(--c-primary);
  padding: 8px 15px;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: bold;
  z-index: 100;
  transition: all 0.2s;
}

.btn-hover:hover {
  background: var(--c-primary) !important;
  color: var(--c-bg) !important;
  box-shadow: 0 0 10px var(--c-primary);
}

.donate-btn {
  position: absolute;
  top: 2.5rem;
  right: 18rem;
  pointer-events: auto;
  background: transparent;
  border: 1px solid var(--c-primary);
  color: var(--c-primary);
  padding: 8px 15px;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: bold;
  z-index: 100;
  transition: all 0.2s;
}

.scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0) 50%,
    rgba(0, 0, 0, 0.1) 50%,
    rgba(0, 0, 0, 0.1)
  );
  background-size: 100% 4px;
  pointer-events: none;
  z-index: 60;
}

.glitch-save-msg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateY(-7rem);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 5rem;
  font-weight: 900;
  color: var(--c-secondary);
  z-index: 2000;
  text-shadow: 4px 4px 0 var(--c-primary);
  pointer-events: none;
  font-style: italic;
  letter-spacing: 5px;
}

/* Base state: Hidden on desktop */
#mobile-controls {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  padding: 0 20px;
  justify-content: space-between;
  pointer-events: none;
  z-index: 1000;
}

.control-group {
  display: flex;
  gap: 20px;
  pointer-events: auto;
}

.touch-btn {
  width: 60px;
  height: 60px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 2px solid var(--c-primary);
  border-radius: 50%;
  color: var(--c-primary);
  font-size: 24px;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
  user-select: none;
  opacity: 0.8;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.touch-btn:active {
  opacity: 1;
  transform: scale(0.95);
  background-color: var(--c-primary);
  color: var(--c-bg);
}

@media (max-width: 600px) {
  #level-select-container {
    width: 95vw;
    max-height: 40vh;
  }

  body.game-active #theme-btn,
  body.game-active #desktop-hints,
  body.game-active .donate-btn {
    display: none;
  }

  .donate-btn {
    right: 16rem;
  }
}

@media (max-width: 980px) {
  #theme-btn,
  .donate-btn {
    padding: 1rem;
    font-size: 1.2rem;
  }

  body.game-active .donate-btn,
  body.game-active #desktop-hints {
    display: none;
  }

  body.game-active #mobile-controls {
    display: flex;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  #main-menu {
    padding-top: 5rem;
    justify-content: flex-start;
  }

  .menu-title {
    margin-top: 3rem;
    margin-bottom: 2rem;
  }

  body.game-active #desktop-hints {
    display: none;
  }
}
