:root {
  --bg: #08111d;
  --surface: rgba(12, 19, 31, 0.82);
  --surface-strong: rgba(18, 28, 43, 0.96);
  --accent: #39d98a;
  --accent-strong: #1cb56d;
  --warning: #f7b955;
  --danger: #f87171;
  --text: #edf6ff;
  --muted: #9fb5c9;
  --shadow: rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
  min-height: 100dvh;
}

button {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

button:active {
  transform: scale(0.99);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#app {
  position: relative;
  width: min(100vw, 520px);
  height: calc(var(--vh, 1vh) * 100);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

#map {
  width: 100%;
  height: 100%;
}

.status-pill {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: 0 14px 32px var(--shadow);
  backdrop-filter: blur(10px);
  color: var(--text);
  font: inherit;
}

.status-pill .chevron {
  color: var(--muted);
  font-size: 0.7rem;
}

@keyframes pill-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-pill.loading .status-badge {
  animation: pill-pulse 1.4s ease-in-out infinite;
}

.dir-arrow {
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1;
  display: inline-block;
  transform-origin: 50% 50%;
  transition: transform 0.3s ease;
}

.recenter-button {
  position: absolute;
  right: 16px;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px));
  z-index: 550;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  box-shadow: 0 10px 24px var(--shadow);
  backdrop-filter: blur(10px);
}

.recenter-button:active {
  transform: scale(0.94);
}

.info-drawer {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 64px));
  left: 16px;
  right: 16px;
  z-index: 500;
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 14px 32px var(--shadow);
  backdrop-filter: blur(10px);
  max-height: calc(100% - 160px);
  overflow-y: auto;
}

.drawer-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 auto 12px;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.distance {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

.location-help-banner {
  position: absolute;
  top: max(72px, calc(env(safe-area-inset-top) + 72px));
  left: 16px;
  right: 16px;
  z-index: 500;
  background: rgba(247, 185, 85, 0.16);
  border: 1px solid rgba(247, 185, 85, 0.28);
  color: #f8d89d;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.72rem;
  line-height: 1.4;
  backdrop-filter: blur(10px);
}

h1 {
  margin: 0 0 8px 0;
  font-size: clamp(1.3rem, 5vw, 1.8rem);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.progress-header {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.progress-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.progress-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.progress-list li.complete {
  color: var(--text);
  background: rgba(57, 217, 138, 0.1);
  border-color: rgba(57, 217, 138, 0.2);
}

.controls {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #06120d;
}

.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ghost {
  background: rgba(8, 17, 29, 0.62);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.small {
  padding: 10px 12px;
  font-size: 0.72rem;
  line-height: 1.1;
}

.debug-panel {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 128px;
  z-index: 700;
  background: rgba(8, 17, 29, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.debug-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.debug-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.debug-row-tight {
  grid-template-columns: 1fr;
}

.debug-hint {
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--muted);
  margin: -2px 0 10px;
}

.debug-row input {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.debug-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.debug-actions .small {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hidden {
  display: none !important;
}

.intro-overlay,
.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(2, 6, 12, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.25s ease, transform 0.25s ease;
  opacity: 1;
  transform: scale(1);
}

.intro-overlay.hidden,
.victory-overlay.hidden,
.ar-overlay.hidden {
  display: flex !important;
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
}

.intro-card,
.victory-card {
  transition: transform 0.25s ease;
}

.intro-overlay.hidden .intro-card,
.victory-overlay.hidden .victory-card {
  transform: translateY(10px);
}

.intro-card,
.victory-card {
  width: min(100%, 380px);
  background: rgba(10, 18, 29, 0.96);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 22px 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}

.intro-card h2,
.victory-card h2 {
  margin: 0 0 12px 0;
  font-size: 1.8rem;
}

.intro-card p,
.victory-card p {
  margin: 0 0 18px 0;
  color: var(--muted);
  line-height: 1.5;
}

.ar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 12, 0.92);
  z-index: 1200;
  transition: opacity 0.25s ease, transform 0.25s ease;
  opacity: 1;
  transform: scale(1);
  display: flex;
  flex-direction: column;
}

.ar-camera-feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: #000;
}

.ar-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#arLabel {
  font-size: 1rem;
  font-weight: 700;
}

.mini {
  padding: 8px 10px;
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

model-viewer {
  position: relative;
  z-index: 1;
  width: 100%;
  flex: 1;
  background: transparent;
  min-height: 240px;
}

.ar-content {
  position: relative;
  z-index: 1;
  padding: 18px 16px 28px;
  background: rgba(5, 12, 18, 0.96);
}

.ar-content h2 {
  margin: 0 0 10px 0;
  font-size: 1.4rem;
}

.ar-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.map-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.marker-player {
  background: #4ec7ff;
  animation: player-pulse 2s ease-out infinite;
}

@keyframes player-pulse {
  0% { box-shadow: 0 0 0 0 rgba(78, 199, 255, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(78, 199, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(78, 199, 255, 0); }
}

.marker-target {
  width: auto;
  height: auto;
  border: none;
  border-radius: 0;
  background: none;
  position: relative;
}

.marker-pin {
  display: block;
  width: 22px;
  height: 22px;
  background: var(--warning);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.marker-target.arrived .marker-pin {
  animation: arrival-pop 0.65s ease-out;
}

@keyframes arrival-pop {
  0% { transform: rotate(-45deg) scale(1); box-shadow: 0 0 0 0 rgba(247, 185, 85, 0.55), 0 4px 10px rgba(0, 0, 0, 0.4); }
  40% { transform: rotate(-45deg) scale(1.35); }
  100% { transform: rotate(-45deg) scale(1); box-shadow: 0 0 0 24px rgba(247, 185, 85, 0), 0 4px 10px rgba(0, 0, 0, 0.4); }
}

.marker-label {
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(8, 17, 29, 0.9);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.marker-label::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(8, 17, 29, 0.9);
}
