/*
 * This file is part of a project licensed under the GNU Affero General Public License v3.0 (AGPLv3).
 * See the LICENSE file in the project root or visit https://www.gnu.org/licenses/agpl-3.0.html
 */

html, body {
  margin: 0;
  padding: 0;
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  padding-top: max(0px, env(safe-area-inset-top));
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
  font-family: 'Arial', sans-serif;
  color: #fff;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-app-region: no-drag;
}

:root {
  --color-bg: #000;
  --color-fg: #fff;
  --color-accent: #4CAF50;
  --color-accent-light: #66bb6a;
  --color-btn-bg: rgba(76,175,80,0.15);
  --color-btn-bg-active: #4CAF50;
  --color-btn-bg-hover: rgba(76,175,80,0.35);
  --color-btn-bg-focus: #81c784;
  --color-btn-bg-shadow: #4CAF5088;
  --color-panel-bg: rgba(0,0,0,0.5);
  --color-panel-bg-solid: rgba(0,0,0,0.8);
}

/* Debug label styling for Three.js CSS2DObject */
.three-label {
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  padding: 2px 6px;
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: bold;
  pointer-events: none;
  user-select: none;
  text-shadow: 0 0 2px #000, 0 0 4px #000;
  white-space: nowrap;
  position: absolute;
}
#operatorOverlay, #operatorOverlay * {
  pointer-events: auto !important;
}

canvas {
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

/* Chat window responsive wrapping and scrolling */
#chatTarget,
#chatInput {
  height: 32px;
  font-size: 1em;
  border-radius: 8px;
  border: none;
  background: var(--color-panel-bg-solid);
  color: var(--color-fg);
  padding: 6px 8px;
  outline: none;
  z-index: 101;
  display: inline-block;
  box-sizing: border-box;
}
#chatTarget {
  margin-right: 6px;
  min-width: 80px;
  max-width: 160px;
}
#chatInput {
  width: 100%;
  margin-top: 2px;
  display: block;
}
#chatWindow {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: 95vw;
  max-height: 33vh;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font: 16px monospace;
  padding: 8px 10px 6px 10px;
  border-radius: 12px 12px 0 0;
  pointer-events: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  align-items: stretch;
}

#chatWindow div {
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  box-sizing: border-box;
}
#chatWindow .chat-input-row {
  display: flex;
  align-items: center;
  flex-grow: 0;
  min-height: 40px;
  width: 100%;
  background: transparent;
}

#chatTarget {
  height: 32px;
  font-size: 1em;
  margin-right: 6px;
  border-radius: 8px;
  border: none;
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 6px 8px;
  outline: none;
  z-index: 101;
  display: inline-block;
  box-sizing: border-box;
  min-width: 80px;
  max-width: 160px;
}
/* Responsive chat area for small screens */
@media (max-width: 800px) {
  #chatWindow {
    width: 98vw;
    max-width: 98vw;
    min-width: 0;
    max-height: 33vh;
    font-size: 12px;
    left: 50%;
    right: auto !important;
    top: auto !important;
    bottom: 0 !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
    padding: 4px 4px 2px 4px;
    border-radius: 10px 10px 0 0;
    position: fixed !important;
    box-sizing: border-box;
    z-index: 100;
  }
  #chatWindow input,
  #chatWindow textarea {
    font-size: 12px;
    padding: 2px 4px;
  }
  #chatWindow div {
    font-size: 12px;
    margin-bottom: 2px;
    max-width: 100%;
  }
}
/* Mobile Controls Overlay Styles */
#controlsOverlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 9999;
}

.mobile-joystick {
  position: absolute;
  left: 2vw;
  bottom: 10vh;
  width: 120px;
  height: 120px;
  background: rgba(60,60,60,0.18);
  border-radius: 50%;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-knob {
  width: 60px;
  height: 60px;
  background: rgba(200,200,200,0.7);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  pointer-events: auto;
  transition: background 0.1s;
}

.mobile-btn {
  position: absolute;
  right: 2vw;
  width: 80px;
  height: 80px;
  background: rgba(76,175,80,0.85);
  color: #fff;
  font-size: 2.2em;
  border: none;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.mobile-btn.pressed {
  filter: brightness(1.2) drop-shadow(0 0 12px #fff8);
  transform: scale(0.93);
  opacity: 0.85;
  transition: filter 0.1s, transform 0.1s, opacity 0.1s;
}

#jumpBtn { bottom: 25vh; }
#fireBtn { bottom: 2vh; background: rgba(244,67,54,0.85); }

@media (min-width: 900px) {
  #controlsOverlay { display: none; }
}

#hudButtons button {
  background: var(--color-btn-bg);
  color: var(--color-accent);
  border: 2px solid var(--color-accent);
  border-radius: 5px;
  font-weight: bold;
  padding: 6px 6px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  outline: none;
  cursor: pointer;
}
#hudButtons button.active {
  background: var(--color-btn-bg-active);
  color: var(--color-fg);
  border-color: var(--color-accent-light);
  box-shadow: 0 0 6px var(--color-btn-bg-shadow);
}
#hudButtons button:focus {
  border-color: var(--color-btn-bg-focus);
}
#hudButtons button:hover {
  background: var(--color-btn-bg-hover);
  color: var(--color-fg);
}

body {
  font-family: 'Arial', sans-serif;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-fg);
}

#mainhud {
  position: fixed;
  top: 10px;
  left: 10px;
  padding: 1vw;
  border-radius: 10px;
  box-sizing: border-box;
  background: var(--color-panel-bg);
}

@media (max-width: 900px), (max-width: 600px) {
  #mainhud {
    width: 35vw;
    height: auto;
    padding: 5px;
    font-size: 5px;
  }
}

#info h1 {
  font-size: 24px;
  margin-bottom: 15px;
  color: #4CAF50;
}

#stats {
  margin-bottom: 15px;
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#hudButtons {
  display: flex !important;
  gap: 6px;
  margin-left: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
#stats span {
  font-weight: bold;
  color: #4CAF50;
}

#scoreboard {
  border-top: 1px solid #444;
  padding-top: 1vw;
}

#scoreboard h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: #4CAF50;
}

#scoreboardHeader {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #888;
  margin-bottom: 5px;
  padding-bottom: 5px;
  border-bottom: 1px solid #333;
}

#scoreboardList {
  font-size: 14px;
}

.scoreboardEntry {
  display: flex;
  justify-content: space-between;
  margin: 5px 0;
  padding: 5px 8px;
  border-radius: 3px;
}

.scoreboardEntry.current {
  color: #4CAF50;
  font-weight: bold;
  background: rgba(76, 175, 80, 0.25);
}

.scoreboardName {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scoreboardStats {
  margin-left: 10px;
  white-space: nowrap;
}

#helpHint {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #444;
  font-size: 14px;
  color: #4CAF50;
}

#helpHint strong {
  color: #fff;
  font-size: 16px;
}

#helpPanel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  background: rgba(0, 0, 0, 0.95);
  padding: 30px;
  border-radius: 15px;
  border: 2px solid #4CAF50;
  overflow-y: auto;
}

#helpPanel h1 {
  font-size: 28px;
  margin-bottom: 20px;
  color: #4CAF50;
  text-align: center;
}

#helpPanel h2 {
  font-size: 20px;
  margin-top: 20px;
  margin-bottom: 10px;
  color: #4CAF50;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
}

#helpPanel h2:first-child {
  margin-top: 0;
}

#helpPanel p {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.6;
}

#helpPanel strong {
  color: #fff;
}

/* Operator Panel Styling */
#operatorOverlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 300;
  background: rgba(0, 0, 0, 0.95);
  padding: 30px;
  border-radius: 15px;
  border: 2px solid #4CAF50;
}

#operatorOverlay .dialogTitle {
  margin: 0 0 20px 0;
  color: #4CAF50;
  text-align: center;
  font-size: 22px;
}

#operatorOverlay label {
  color: #fff;
  font-weight: bold;
}

#operatorOverlay input[type="text"] {
  width: 100%;
  padding: 8px;
  font-size: 15px;
  border: 2px solid #4CAF50;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  margin-bottom: 10px;
  box-sizing: border-box;
}

#operatorOverlay input[type="text"]:focus {
  outline: none;
  border-color: #66bb6a;
}

#operatorOverlay button {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: bold;
  border: 2px solid #4CAF50;
  border-radius: 5px;
  background: rgba(76, 175, 80, 0.2);
  color: #4CAF50;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: 6px;
}

#operatorOverlay button:hover {
  background: rgba(76, 175, 80, 0.4);
  border-color: #66bb6a;
}

#operatorOverlay button:active {
  background: rgba(76, 175, 80, 0.6);
}

#entryDialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 300;
  background: rgba(0, 0, 0, 0.95);
  padding: 30px;
  border-radius: 15px;
  border: 2px solid #4CAF50;
}

#entryDialog h2 {
  margin: 0 0 20px 0;
  color: #4CAF50;
  text-align: center;
}

#entryInput {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border: 2px solid #4CAF50;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  margin-bottom: 20px;
  box-sizing: border-box;
}

#entryInput:focus {
  outline: none;
  border-color: #66bb6a;
}

.entryDialogButtons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.entryDialogButtons button {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: bold;
  border: 2px solid #4CAF50;
  border-radius: 5px;
  background: rgba(76, 175, 80, 0.2);
  color: #4CAF50;
  cursor: pointer;
  transition: all 0.2s;
}

.entryDialogButtons button:hover {
  background: rgba(76, 175, 80, 0.4);
  border-color: #66bb6a;
}

.entryDialogButtons button:active {
  background: rgba(76, 175, 80, 0.6);
}

#messages {
  margin-top: 15px;
  font-size: 14px;
  max-height: 100px;
  overflow-y: auto;
  border-top: 1px solid #444;
  padding-top: 10px;
}

.message {
  margin: 5px 0;
  padding: 5px;
  background: rgba(76, 175, 80, 0.2);
  border-radius: 3px;
  animation: fadeIn 0.3s;
}

.message.kill {
  background: rgba(255, 87, 34, 0.3);
  color: #ff5722;
}

#debugHud {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 100;
  background: var(--color-panel-bg);
  padding: 15px;
  border-radius: 10px;
  width: 320px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  box-sizing: border-box;
  overflow-x: auto;
  max-height: 90vh;
  overflow-y: auto;
}

@media (max-width: 600px) {
  #debugHud {
    width: 90vw;
    font-size: 11px;
    padding: 8px;
  }
}

#debugHud h3 {
  font-size: 14px;
  margin-bottom: 10px;
  color: #FFD700;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
}

#debugContent {
  line-height: 1.6;
}

#debugContent div {
  margin: 3px 0;
  display: flex;
  justify-content: space-between;
}

#debugContent .label {
  color: #AAA;
}

#debugContent .value {
  color: #0F0;
  font-weight: bold;
}

.message.death {
  background: rgba(244, 67, 54, 0.3);
  color: #f44336;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.player-label {
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: bold;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  white-space: nowrap;
  text-align: center;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  user-select: none;
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  pointer-events: none;
  z-index: 50;
}

#controlBox {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50vmin;
  height: 50vmin;
  max-width: 100vw;
  max-height: 100vh;
  border: 2px solid rgba(76, 175, 80, 0.6);
  pointer-events: none;
  z-index: 49;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  transition: border-color 0.3s;
}

#controlBox.keyboard-mode {
  border-color: rgba(255, 152, 0, 0.6);
}

#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

#crosshair::before {
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  transform: translateY(-50%);
}

#crosshair::after {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
}

#crosshair .center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

#radar {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 120;
  border: none;
  border-radius: 50%;
  box-shadow: 0 0 16px #222b, 0 0 0 4px rgba(0,0,0,0.5);
  background: none;
  opacity: 1;
  width: min(35vw, 35vh);
  height: min(35vw, 35vh);
  min-width: 60px;
  min-height: 60px;
  max-width: 240px;
  max-height: 240px;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  pointer-events: none;
}

@media (max-width: 600px) {
  #radar {
    width: 32vw;
    height: 32vw;
    max-width: calc(100vw - 8vw);
    max-height: calc(100vw - 8vw);
    right: 2vw;
    min-width: 40px;
    min-height: 40px;
  }
}

#settingsHud {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-panel-bg-solid);
  border-radius: 4vw;
  padding: 4vw 3vw;
  z-index: 1000;
  box-shadow: 0 0.5vw 2vw #0008;
  min-width: 40vw;
  min-height: 20vw;
  width: 80vw;
  height: 40vw;
  max-width: 95vw;
  max-height: 80vh;
  text-align: center;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
  overflow-x: auto;
}

@media (orientation: portrait) {
  #settingsHud {
    width: 90vw;
    height: 35vw;
    min-width: 60vw;
    min-height: 20vw;
    max-width: 98vw;
    max-height: 60vh;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
  }
  .settingsHudContent {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3vw;
    width: 100%;
    justify-content: center;
    align-items: center;
  }
  .settingsHudBtn {
    width: 40vw;
    min-width: 30vw;
    max-width: 45vw;
    height: 12vw;
    font-size: 1.2em;
  }
}
.settingsHudContent {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2vw;
  width: 100%;
}
.settingsHudBtn {
  font-size: 1.2em;
  border-radius: 2vw;
  border: none;
  background: #444;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  box-sizing: border-box;
}
@media (max-width: 600px) {
  .settingsHudBtn {
    min-width: 60vw;
    max-width: 98vw;
    min-height: 40px;
    font-size: 1em;
  }
}

#altimeter {
  position: fixed;
  top: 50%;
  right: calc(50% - 25vmin - 40px); /* right of controlBox, adjust as needed */
  transform: translateY(-50%);
  width: 4vmin;
  height: 50vmin;
  z-index: 50;
  pointer-events: none;
  background: transparent;
}
#degreeBar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  height: 4vmin;
  width: 50vmin;
  z-index: 51;
  pointer-events: none;
  background: transparent;
}
