:root {
  --bg-dark: #1a1a2e;
  --bg-panel: #16213e;
  --accent: #e94560;
  --text: #ecf0f1;
  --text-muted: #bdc3c7;
  --btn-primary: #e94560;
  --btn-secondary: #0f3460;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  overflow: hidden;
}

/* Prevent pull-to-refresh and zoom only on game elements, not globally */
#game-canvas { touch-action: none; }

/* --- Launcher --- */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
}

.main-header h1 {
  font-size: 3rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.menu-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
  margin: 2rem 0;
}

.btn {
  padding: 1rem;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--btn-primary); }
.btn-secondary { background: var(--btn-secondary); }

.main-footer { font-size: 0.85rem; color: var(--text-muted); }

/* --- Game --- */
.game-body { background: #000; }

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#ui-layer {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

#ui-layer > * { pointer-events: auto; }

#top-bar {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  background: rgba(0,0,0,0.5);
}

.ui-btn {
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}

.ui-btn:active { background: var(--accent); }

/* Text Overlay */
#text-overlay {
  position: absolute;
  bottom: 10%;
  left: 5%; right: 5%;
  background: rgba(22, 33, 62, 0.95);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.2rem;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

#text-content {
  font-size: 1.15rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

/* Inventory */
#inventory-panel {
  position: absolute;
  top: 10%; left: 10%; right: 10%; bottom: 10%;
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

#inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
  margin: 1rem 0;
}

.inv-slot {
  aspect-ratio: 1;
  background: rgba(0,0,0,0.3);
  border: 1px dashed var(--text-muted);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  text-align: center;
  padding: 0.25rem;
  cursor: pointer;
}

.inv-slot.occupied {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

/* Dialogue */
#dialogue-box {
  position: absolute;
  bottom: 5%;
  left: 3%; right: 3%;
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1rem;
  min-height: 120px;
}

#dialogue-speaker {
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 0.5rem;
}

#dialogue-text {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  line-height: 1.4;
}

#dialogue-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dialogue-option {
  background: var(--btn-secondary);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.hidden { display: none !important; }

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

/* Modals & Toasts */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-box {
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

.modal-box h3 { color: var(--accent); margin-bottom: 0.8rem; font-size: 1.2rem; }

/* Leaflet popup dark theme */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  color: var(--text) !important;
  border: 2px solid var(--accent) !important;
  border-radius: 8px !important;
}

.leaflet-popup-tip {
  background: var(--accent) !important;
}

.leaflet-popup-content {
  margin: 8px 12px !important;
  font-size: 0.9rem !important;
}

.leaflet-popup-content b {
  color: var(--accent);
}

.leaflet-container a.leaflet-popup-close-button {
  color: var(--text) !important;
}

.toast {
  position: fixed;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  z-index: 1001;
  animation: fadeIn 0.3s ease;
}

/* Menu Panel */
#menu-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-width: 220px;
  z-index: 50;
}

#menu-panel h3 { text-align: center; color: var(--accent); }

/* Simulator Panel */
#simulator-panel {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-dark);
  z-index: 70;
  display: flex;
  flex-direction: column;
}

.sim-btn {
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  color: var(--text);
  border-radius: 8px;
  font-size: 1.4rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.sim-btn:active {
  background: var(--accent);
}

/* GPS Block Panel - Fullscreen Map */
#gps-block-panel {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 60;
}

#gps-map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
}

#gps-bar-normal,
#gps-bar-test {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.8rem;
  background: var(--bg-panel);
  border-top: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 100;
  pointer-events: auto;
  max-height: 35vh;
  overflow-y: auto;
}

#gps-distance-normal,
#gps-distance-test { font-size: 1rem; color: var(--text); margin: 0; }

.gps-bar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  pointer-events: auto;
}

.gps-bar-actions .ui-btn {
  pointer-events: auto;
  position: relative;
  z-index: 62;
}

#gps-code-input {
  flex: 1;
  min-width: 120px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: #000;
  color: var(--text);
  font-size: 0.95rem;
}

#btn-gps-enter {
  position: relative;
  z-index: 63;
}

/* Coordinates info badge */
.gps-coords {
  position: absolute;
  bottom: 5px; right: 5px;
  background: rgba(0,0,0,0.6);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  z-index: 10;
}

/* GPS Waiting & Fail Panels */
#gps-waiting-panel,
#gps-fail-panel {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.gps-waiting-content {
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 2.5rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.gps-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(233, 69, 96, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.gps-countdown {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: bold;
}

/* --- Editor Tabs --- */
.editor-tab {
  flex: 1;
  padding: 0.5rem 0.3rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.editor-tab:hover { color: var(--text); }
.editor-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

/* --- Editor Actions --- */
.action-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
  padding: 0.3rem;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}
.action-type {
  min-width: 130px;
  padding: 0.3rem;
  background: #000;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 0.85rem;
}
.action-param {
  flex: 1;
  padding: 0.3rem;
  background: #000;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 0.85rem;
}
.action-param-bool {
  width: auto;
  margin: 0;
}

/* --- Item Marker on Leaflet --- */
.item-marker-icon {
  width: 14px !important;
  height: 14px !important;
  background: #2ecc71;
  border: 2px solid #fff;
  border-radius: 3px;
  transform: rotate(45deg);
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.npc-marker-icon {
  width: 14px !important;
  height: 14px !important;
  background: #9b59b6;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

/* Scene property panels */
#scene-properties .editor-group {
  margin-bottom: 0.5rem;
}
#scene-properties .editor-group input,
#scene-properties .editor-group select {
  padding: 0.25rem;
  font-size: 0.85rem;
}

