:root {
  --bg-color: #000;
  --ui-bg: rgba(0, 0, 0, 0.75);
  --text-color: #ffffff;
  --highlight-color: #fff;
  --border-radius: 10px;
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}

#game-container {
  overflow: hidden;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
}

#game-content {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
  background: #000;
  transition: var(--transition);
}

#canvas, #overlayDiv {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0 none;
}

#canvas {
  background: var(--bg-color);
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
  will-change: transform;
  touch-action: none;
}

.visible {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.1s linear;
}

.hidden {
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s 0.25s, opacity 0.25s linear;
}

#statusDiv, #inputDiv {
  background: var(--ui-bg);
  width: min(90%, 500px);
  margin: 0 auto;
  padding: 12px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  backdrop-filter: blur(5px);
  z-index: 100;
}

#statusTextDiv {
  overflow: auto;
  max-height: 40vh;
  color: #ccc;
  font-size: 14px;
}

#statusProgress {
  display: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #333;
  margin-top: 10px;
}

#statusProgress::-webkit-progress-bar {
  background: #333;
  border-radius: 4px;
}

#statusProgress::-webkit-progress-value {
  background: #4a90e2;
  border-radius: 4px;
  transition: width 0.3s ease;
}

#inputDiv {
  width: min(90%, 600px);
  padding: 15px;
}

#inputPrompt {
  color: var(--text-color);
  font-size: 1.4rem;
  margin-bottom: 1em;
}

#inputText {
  width: 100%;
  font-size: 1.2rem;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-color);
  border: 1px solid #555;
  border-radius: var(--border-radius);
  outline: none;
  transition: var(--transition);
}

#inputText:focus {
  color: var(--highlight-color);
  border-color: #4a90e2;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.3);
}

#ContextContainer {
  position: absolute;
  top: 20px;
  left: 20px;
  color: white;
  z-index: 1000;
}

#TopRightContainer {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 1000;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: lightgrey;
  background: rgba(0, 0, 0, 0.5);
  border-radius: var(--border-radius);
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
  border: none;
  padding: 0;
  font-size: 24px;
}

.icon-button:hover, .icon-button:focus {
  color: var(--highlight-color);
  background: rgba(0, 0, 0, 0.7);
  outline: none;
}

.icon-button:active {
  transform: scale(0.9);
}

.icon-button img {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

#ContextMenu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: rgba(0, 0, 0, 0.85);
  border-radius: 0 var(--border-radius) var(--border-radius) var(--border-radius);
  padding: 8px;
  z-index: 1001;
  backdrop-filter: blur(10px);
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.4);
  min-width: 200px;
}

#ContextMenu.visible {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  color: var(--text-color);
  background: rgba(50, 50, 50, 0.7);
  border-radius: var(--border-radius);
  margin: 6px 0;
  text-decoration: none;
  transition: var(--transition);
  font-size: 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.context-menu-item:hover {
  background: rgba(70, 70, 70, 0.9);
  color: var(--highlight-color);
  transform: translateX(5px);
  border-color: rgba(255, 255, 255, 0.3);
}

#presplash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  animation: fadeIn 1s ease-out;
}

.loader {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border: 5px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s linear infinite;
  z-index: 10000;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

#installModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  backdrop-filter: blur(5px);
  justify-content: center;
  align-items: center;
}

#installModal.visible {
  display: flex;
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  background: var(--ui-bg);
  padding: 25px;
  border-radius: var(--border-radius);
  max-width: 90%;
  width: 400px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 1.5rem;
  margin-bottom: 15px;
  color: var(--highlight-color);
}

.modal-text {
  margin-bottom: 20px;
  line-height: 1.5;
  color: var(--text-color);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-button {
  padding: 10px 20px;
  border-radius: var(--border-radius);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
}

.modal-button.primary {
  background: #4a90e2;
  color: white;
}

.modal-button.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-color);
}

.modal-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.silent-warning {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: var(--border-radius);
  text-align: center;
  backdrop-filter: blur(5px);
}

.silent-warning-content p {
  margin: 0;
  font-size: 14px;
}

@media (max-width: 768px) {
  #ContextContainer, #TopRightContainer {
    top: 15px;
  }
  #ContextContainer {
    left: 15px;
  }
  #TopRightContainer {
    right: 15px;
  }
  #statusDiv, #inputDiv {
    width: 95%;
    padding: 10px;
  }
  #inputPrompt {
    font-size: 1.2rem;
  }
  #inputText {
    font-size: 1rem;
    padding: 8px 12px;
  }
  .context-menu-item {
    padding: 10px 12px;
    font-size: 1rem;
  }
  .icon-button {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  .icon-button img {
    width: 20px;
    height: 20px;
  }
  .modal-content {
    padding: 20px;
    width: 95%;
  }
  .modal-title {
    font-size: 1.3rem;
  }
  @supports (padding: max(0px)) {
    #ContextContainer {
      top: max(15px, env(safe-area-inset-top));
      left: max(15px, env(safe-area-inset-left));
    }
    #TopRightContainer {
      top: max(15px, env(safe-area-inset-top));
      right: max(15px, env(safe-area-inset-right));
    }
    .silent-warning {
      top: max(70px, calc(env(safe-area-inset-top) + 50px));
    }
  }
}