:root {
  color-scheme: dark;
  --panel: rgba(18, 22, 19, 0.86);
  --panel-solid: #151915;
  --line: rgba(233, 239, 225, 0.18);
  --text: #eef4e8;
  --muted: #a8b2a2;
  --accent: #5fd08b;
  --blue: #6db7ff;
  --red: #e84646;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101410;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: #0d100d;
}

.topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.brand {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
}

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.status span {
  min-height: 22px;
  padding: 4px 7px;
  border: 1px solid rgba(233, 239, 225, 0.12);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  white-space: nowrap;
}

#gpsStatus {
  cursor: pointer;
}

#gpsStatus:active {
  border-color: rgba(95, 208, 139, 0.55);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 8, 5, 0.74);
  backdrop-filter: blur(12px);
}

.modal-backdrop[hidden] {
  display: none;
}

.join-modal {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

.join-modal h1 {
  margin: 0 0 18px;
  font-size: 25px;
  line-height: 1.1;
}

.join-modal label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.join-modal input {
  width: 100%;
  height: 50px;
  margin-bottom: 12px;
  padding: 0 13px;
  border: 1px solid rgba(233, 239, 225, 0.22);
  border-radius: 8px;
  outline: 0;
  background: #0f130f;
  color: var(--text);
  font-size: 18px;
}

.join-modal input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(95, 208, 139, 0.18);
}

.join-modal button,
.sheet-actions button,
.secondary-action {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #081108;
  font-weight: 750;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.action-sheet {
  position: fixed;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 10px;
  z-index: 900;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 21, 19, 0.96);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.44);
}

.sheet-title {
  padding: 4px 4px 10px;
  color: var(--muted);
  font-size: 13px;
}

.sheet-actions {
  display: grid;
  gap: 8px;
}

.sheet-actions button.danger {
  background: var(--red);
  color: #fff;
}

.sheet-actions button.marker-choice {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 10px;
  background: #242622;
  color: var(--text);
  text-align: left;
}

.secondary-action {
  margin-top: 8px;
  background: #2b302b;
  color: var(--text);
}

.marker-glyph {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
}

.marker-glyph.soldier {
  border-radius: 50%;
}

.marker-glyph.fob {
  border-radius: 4px;
}

.marker-glyph.armor {
  clip-path: polygon(18% 0, 82% 0, 100% 30%, 100% 70%, 82% 100%, 18% 100%, 0 70%, 0 30%);
  background: var(--red);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 1100;
  max-width: min(420px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(5, 8, 5, 0.92);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.leaflet-control-attribution {
  max-width: calc(100vw - 20px);
  background: rgba(10, 12, 10, 0.75);
  color: rgba(255, 255, 255, 0.72);
  font-size: 10px;
}

.grid-line {
  stroke: rgba(255, 255, 255, 0.45);
  stroke-width: 1;
  stroke-dasharray: 5 5;
}

.grid-border {
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 2;
}

.grid-label,
.axis-label {
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 3px #000, 0 0 8px #000;
  pointer-events: none;
}

.grid-label {
  opacity: 0.36;
}

.axis-label {
  opacity: 0.88;
}

.grid-hud {
  position: fixed;
  inset: 0;
  z-index: 690;
  pointer-events: none;
}

.edge-label {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 25px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 5px;
  background: rgba(5, 8, 5, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 3px #000;
}

.edge-label.col-label {
  transform: translate(-50%, 0);
}

.edge-label.row-label {
  transform: translate(0, -50%);
}

.player-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -50%);
}

.player-arrow {
  position: absolute;
  left: 50%;
  top: -2px;
  width: 0;
  height: 0;
  border-right: 7px solid transparent;
  border-bottom: 17px solid var(--blue);
  border-left: 7px solid transparent;
  filter: drop-shadow(0 1px 3px #000);
  transform: translateX(-50%) rotate(var(--heading));
  transform-origin: 50% 19px;
}

.player-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border: 3px solid #101410;
  border-radius: 50%;
  background: var(--blue);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45), 0 2px 8px rgba(0, 0, 0, 0.6);
}

.player-marker.self .player-arrow {
  border-bottom-color: var(--accent);
}

.player-marker.self .player-core {
  background: var(--accent);
}

.player-name {
  position: absolute;
  left: 50%;
  top: 33px;
  max-width: 108px;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.74);
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
}

.hostile-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #fff;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -50%);
}

.hostile-symbol.enemy_soldier {
  border-radius: 50%;
}

.hostile-symbol.enemy_fob {
  border-radius: 4px;
}

.hostile-symbol.enemy_armor {
  clip-path: polygon(18% 0, 82% 0, 100% 30%, 100% 70%, 82% 100%, 18% 100%, 0 70%, 0 30%);
}

.accuracy-ring {
  stroke: rgba(109, 183, 255, 0.55);
  stroke-width: 1;
  fill: rgba(109, 183, 255, 0.12);
}

@media (max-width: 520px) {
  .topbar {
    align-items: flex-start;
  }

  .status {
    max-width: 62vw;
  }

  .brand {
    font-size: 14px;
  }
}
