:root {
  --accent: #ff2d55;
  --warn: #ffcc00;
  --bg: #0a0a0a;
  --fg: #ededed;
  --muted: #9a9a9a;
  --glow: 0 0 20px var(--accent), 0 0 40px rgba(255, 45, 85, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Courier New', ui-monospace, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
}

.view.active { display: block; }

#camera,
#preview-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 0;
}

.overlay-root {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.overlay-root > * { pointer-events: auto; }

#view-nav {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 100;
  display: flex;
  gap: 4px;
}

#view-nav button {
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

#view-nav button.active {
  border-color: var(--accent);
  color: var(--accent);
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

/* True monochrome over CartoDB Dark Matter — grayscale strips residual
   blue tint, contrast bump keeps roads readable. */
.leaflet-tile-pane {
  filter: grayscale(1) contrast(1.1) brightness(0.92);
}

.leaflet-container {
  background: #0a0a0a;
  font-family: inherit;
  /* Contain Leaflet's internal z-index stack (up to ~400) so it doesn't
     fight the app chrome (#view-nav, #debug-hud, overlay-root, …). */
  isolation: isolate;
}

.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.65) !important;
  color: var(--muted) !important;
  font-size: 9px !important;
  padding: 2px 6px !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.leaflet-control-attribution a {
  color: var(--muted) !important;
}

/* --- Checkpoint marker --- */
.cp-marker {
  position: relative;
}

.cp-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent), 0 0 22px rgba(255, 45, 85, 0.45);
}

.cp-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: cp-pulse 2.4s ease-out infinite;
  opacity: 0;
  pointer-events: none;
}

@keyframes cp-pulse {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0.8; }
  100% { transform: translate(-50%, -50%) scale(3);   opacity: 0;   }
}

.cp-label {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 7px;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--fg);
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

/* --- User location + compass --- */
.user-marker {
  position: relative;
  width: 40px;
  height: 40px;
}

.user-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}

/* Triangular "heading cone" rendered via CSS borders on a rotated wrapper.
   The wrapper's rotation is driven by --heading (set by setHeading()). */
.user-dir {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%) rotate(var(--heading, 0deg));
  transform-origin: 50% 50%;
  pointer-events: none;
}

.user-dir::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-bottom: 26px solid rgba(255, 45, 85, 0.55);
  filter: blur(0.5px) drop-shadow(0 0 6px rgba(255, 45, 85, 0.8));
}

/* --- Route line --- */
.route-line {
  stroke-dasharray: 6 10;
  animation: route-flow 1.2s linear infinite;
  filter: drop-shadow(0 0 4px rgba(255, 45, 85, 0.55));
}

@keyframes route-flow {
  to { stroke-dashoffset: -16; }
}

#permission-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.perm-card {
  max-width: 320px;
  width: 100%;
  padding: 20px;
  border: 1px solid var(--accent);
  background: #000;
  box-shadow: var(--glow);
  text-align: center;
}

.perm-title {
  color: var(--accent);
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.perm-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  margin-bottom: 16px;
}

#perm-retry {
  padding: 10px 16px;
  background: var(--accent);
  color: #000;
  border: none;
  font-family: inherit;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

#debug-hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 150;
  padding: 4px 8px;
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-family: 'Courier New', ui-monospace, monospace;
  pointer-events: none;
  white-space: nowrap;
}

/* --- Engine mode: hide dev-only surfaces --- */
body.engine-mode #dev-bar,
body.engine-mode #debug-hud,
body.engine-mode #view-nav {
  display: none !important;
}

/* --- Engine-start overlay --- */
#engine-start {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: pointer;
}

.engine-start-card {
  max-width: 360px;
  width: 100%;
  padding: 28px 24px;
  border: 1px solid var(--accent);
  background: #000;
  box-shadow: var(--glow);
  text-align: center;
}

.engine-start-title {
  color: var(--accent);
  font-size: 15px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.engine-start-sub {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hidden { display: none !important; }

#border-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 transparent;
  transition: box-shadow 400ms ease, opacity 400ms ease;
  opacity: 0;
}

#border-highlight.active {
  opacity: 1;
  box-shadow:
    inset 0 0 60px var(--accent),
    inset 0 0 140px rgba(255, 45, 85, 0.35);
  animation: border-pulse 2.2s ease-in-out infinite;
}

@keyframes border-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

#hint {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  max-width: 80%;
  text-align: center;
}

#banner {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 22px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 16px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  box-shadow: var(--glow);
  animation: banner-in 300ms ease-out;
  white-space: nowrap;
}

@keyframes banner-in {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#scan {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-prompt {
  position: absolute;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

#effect-canvas,
#scan-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#zone-hit {
  position: absolute;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
}

#zone-hit:focus { outline: none; }

#tooltip {
  position: absolute;
  max-width: 80vw;
  width: 280px;
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid var(--accent);
  padding: 14px 14px 12px;
  box-shadow: var(--glow);
  animation: tooltip-in 220ms ease-out;
}

.tooltip-title {
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.tooltip-body {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 8px;
}

.tooltip-annotation {
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 12px;
}

.tooltip-cta {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #000;
  border: none;
  font-family: inherit;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.tooltip-cta:active { opacity: 0.75; }

@keyframes tooltip-in {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

#message-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
}

.message-card {
  width: 100%;
  max-width: 640px;
  padding: 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.92);
  border-top: 1px solid var(--accent);
  animation: message-in 320ms ease-out;
}

@keyframes message-in {
  0%   { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0);    opacity: 1; }
}

.message-speaker {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.message-text {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 10px;
}

.message-annotation {
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 14px;
}

.message-hint {
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
  opacity: 0.55;
}

#dev-bar {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 24px);
}

#dev-bar button {
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

#dev-bar button:active { background: rgba(255, 45, 85, 0.25); }

#dev-bar button.active {
  border-color: var(--accent);
  color: var(--accent);
}
