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

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: #111;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] {
  display: none !important;
}

/* ---------- Landing / info pages ---------- */

.page {
  position: relative;
  z-index: 0; /* stacking context: keeps the ::before map above our bg, below content */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #1a2332 0%, #0d1117 100%);
}

/* Island map backdrop — sized for portrait phones (the map is ~1:2.2,
   matching tall phone screens). Capped at 560px wide so desktop gets a
   centered column fading into the gradient instead of a giant zoom. */
.page::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(13, 17, 23, 0.5), rgba(13, 17, 23, 0.65)),
    url('../assets/Island_Map.png') center top / min(100vw, 560px) auto no-repeat;
}

@media (min-width: 600px) {
  .page::before {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
  }
}

.animal-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.animal-card img {
  width: 100%;
  max-height: 52dvh;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.5));
}

.animal-card h1 {
  font-size: 1.8rem;
  text-align: center;
}

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: #f0ebe0;
  background: linear-gradient(180deg, #5d7a61 0%, #475e4b 100%);
  box-shadow: 0 4px 14px rgba(20, 35, 25, 0.4);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
  filter: brightness(0.92);
}

.btn.secondary {
  background: linear-gradient(180deg, #7d6f58 0%, #60543f 100%);
  box-shadow: 0 4px 14px rgba(40, 32, 22, 0.35);
}

.picker {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.picker a {
  padding: 14px 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #5f7261 0%, #485a4c 100%);
  color: #f0ebe0;
  text-decoration: none;
  font-weight: 600;
}

.info-body {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  line-height: 1.55;
}

.info-body ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.error-msg {
  padding: 20px;
  background: #4a1f1f;
  border-radius: 12px;
  max-width: 420px;
  line-height: 1.5;
}

/* top-left inside the centered 560px "phone zone", not the page edge.
   z-index: floats above the card, whose transparent-cornered image would
   otherwise cover the button and eat the taps on phones */
.back-btn {
  position: absolute;
  top: 16px;
  left: max(16px, calc(50% - 264px));
  z-index: 1;
}

.lang-sel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #2a3442;
  color: #fff;
  font-size: 0.9rem;
}

.habitat {
  color: #9db2cc;
  font-size: 0.95rem;
}

.info-body h2 {
  font-size: 1.1rem;
  margin-top: 4px;
}

.info-body li strong {
  color: #7db3ff;
}

/* ---------- AR pages ---------- */

.ar-page {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: transparent;
  touch-action: none;
  z-index: 900;
  pointer-events: none;
}

#camerafeed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

/* Startup gate overlay */
#ar-gate {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0d1117;
  z-index: 4000;
  padding: 24px;
  text-align: center;
  pointer-events: auto;
}

#ar-gate img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
}

#ar-gate .btn {
  max-width: 320px;
}

#ar-status {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  padding: 12px 16px;
  text-align: center;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#ar-status.hidden {
  opacity: 0;
}

/* SLAM scan overlay — shown until the map is tracked */
#ar-scan {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none;
}

#ar-scan .scan-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 28px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.95rem;
  text-align: center;
}

/* phone sweeping left↔right with a tilt, like waving it to scan */
#ar-scan .scan-phone {
  animation: scan-sweep 2.6s ease-in-out infinite;
}

@keyframes scan-sweep {
  0%   { transform: translateX(-18px) rotate(-18deg); }
  50%  { transform: translateX(18px)  rotate(18deg); }
  100% { transform: translateX(-18px) rotate(-18deg); }
}

/* AR HUD */
#ar-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  z-index: 1000;
  pointer-events: none;
}

#ar-topbar > * {
  pointer-events: auto;
}

#ar-topbar .title {
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

#ar-topbar .lang-sel {
  position: static;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

#ar-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 1000;
  pointer-events: auto;
}

#place-btn {
  padding: 14px 40px;
  border-radius: 999px;
  background: linear-gradient(180deg, #5d7a61 0%, #475e4b 100%);
  color: #f0ebe0;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 4px 16px rgba(20, 35, 25, 0.5);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-row .icon-btn {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  font-size: 1rem;
  width: 52px;
  height: 52px;
}

#shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 255, 255, 0.45);
  background-clip: padding-box;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
}

#shutter-btn:active {
  transform: scale(0.92);
}

.hidden {
  display: none !important;
}

/* ---------- Map page ---------- */

.map-page {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #1a2332 0%, #0d1117 100%);
}

/* Phone-sized frame: full-bleed column on phones; a centred
   phone-proportioned (9:19.5) panel floating on the backdrop on desktop */
.phone-frame {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100vw, 560px);
}

@media (min-width: 600px) {
  .phone-frame {
    bottom: auto;
    height: min(92dvh, 1210px);
    width: min(92vw, calc(min(92dvh, 1210px) * 9 / 19.5));
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  }
}

/* PNG-only viewer: fills the phone frame */
#map {
  position: absolute;
  inset: 0;
  /* sea tone sampled from the PNG — replaces Leaflet's default #ddd
     which washed through the image's built-in translucency */
  background: #275b74;
}

#map-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  /* extra top room clears the lang selector row — the logo gets
     its own banner row underneath */
  padding-top: 58px;
  z-index: 2000; /* above leaflet panes + controls */
  pointer-events: none;
}

#map-topbar > * {
  pointer-events: auto;
}

/* logo banner centered in the phone zone — decorative, don't eat touches */
#map-logo {
  width: 75%;
  height: auto;
  margin: 0 auto;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}


#map-controls {
  position: absolute;
  right: 12px;
  bottom: 90px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.map-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(20, 30, 25, 0.8);
  color: #f0ebe0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.map-btn.active {
  background: #5d7a61;
}

/* Leaflet zoom control — restyle the default white squares as our
   round translucent buttons (style.css loads after leaflet.css) */
.leaflet-bar {
  border: none;
  box-shadow: none;
}

.leaflet-bar a,
.leaflet-bar a:first-child,
.leaflet-bar a:last-child {
  width: 46px;
  height: 46px;
  line-height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(20, 30, 25, 0.8);
  color: #f0ebe0;
  font-size: 1.3rem;
  font-weight: 400;
  backdrop-filter: blur(4px);
}

.leaflet-bar a:hover {
  background: rgba(20, 30, 25, 0.95);
  color: #f0ebe0;
}

.leaflet-bar a.leaflet-disabled {
  background: rgba(20, 30, 25, 0.5);
  color: rgba(240, 235, 224, 0.4);
}

/* gap between the two stacked circles, like #map-controls */
.leaflet-control-zoom-in {
  margin-bottom: 10px;
}

/* the zoom control is reparented into #map-controls (see map.js) —
   drop Leaflet's 10px control margin and nudge the pair slightly
   lower toward the GPS button */
#map-controls .leaflet-control {
  margin: 0;
  transform: translateY(24px);
}

#admin-toast {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 0.9rem;
  z-index: 2000;
  white-space: nowrap;
}

/* "best on the island" notice — persistent until dismissed */
#geo-note {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.8);
  font-size: 0.85rem;
  line-height: 1.35;
  max-width: calc(100% - 48px);
  z-index: 2000;
}

#geo-note button {
  background: none;
  color: #fff;
  font-size: 0.9rem;
  opacity: 0.7;
  flex-shrink: 0;
}

/* GPS position dot */
.locate-dot {
  background: #4d9160;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(77, 145, 96, 0.35);
  animation: locate-pulse 2s ease-out infinite;
}

@keyframes locate-pulse {
  0%   { box-shadow: 0 0 0 4px rgba(77, 145, 96, 0.35); }
  70%  { box-shadow: 0 0 0 14px rgba(77, 145, 96, 0); }
  100% { box-shadow: 0 0 0 4px rgba(77, 145, 96, 0.35); }
}

/* pins */
.map-pin {
  background: #4d9160;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.pin-link {
  color: #2f6b42;
  font-weight: 700;
}

/* species pin icons: 0.1px crisp black ring — drop-shadow can't stroke,
   so 8 directional copies cover every edge + a soft lift shadow */
.animal-pin {
  filter:
    drop-shadow(0.1px 0 0 #000)
    drop-shadow(-0.1px 0 0 #000)
    drop-shadow(0 0.1px 0 #000)
    drop-shadow(0 -0.1px 0 #000)
    drop-shadow(0.1px 0.1px 0 #000)
    drop-shadow(-0.1px -0.1px 0 #000)
    drop-shadow(0.1px -0.1px 0 #000)
    drop-shadow(-0.1px 0.1px 0 #000)
    drop-shadow(0 4px 4px rgba(0, 0, 0, 0.4));
}

/* locked pins render as pure-black silhouettes — keep the lift shadow
   visible so they still read as raised */
.pin-locked {
  filter: brightness(0) drop-shadow(0 4px 4px rgba(0, 0, 0, 0.4));
}

/* ---------- Admin page ---------- */

.admin-form,
.admin-actions {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.show-pw {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #9db2cc;
}

.show-pw input {
  width: 16px;
  height: 16px;
}

/* covers type=text too — the show-password toggle flips the type */
.admin-form input[type='password'],
.admin-form input[type='text'] {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #2a3442;
  color: #fff;
  font-size: 1rem;
}

/* Photo preview toast */
#photo-toast {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 0.9rem;
  z-index: 1000;
  white-space: nowrap;
}
