:root {
  --forest: #1f3b2c;
  --forest-soft: rgba(31, 59, 44, 0.86);
  --leaf: #5f8d4e;
  --cream: #fff7e6;
  --sun: #ffd166;
  --sun-dark: #d99a3a;
  --ink: #1d2a22;
  --pad: max(12px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9cc46e;
  color: var(--cream);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

#trail {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* The top bar while walking. */
.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: var(--pad);
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-card {
  display: grid;
  gap: 2px;
  padding: 9px 16px;
  border-radius: 16px;
  background: var(--forest-soft);
  font-size: 15px;
}
.hud-card strong { font-size: 17px; }
.hud-level { color: var(--sun); font-weight: 800; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.hud-actions { display: flex; gap: 8px; }

.round-button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--forest-soft);
  font-size: 21px;
  display: grid;
  place-items: center;
}

/* Walk buttons in the bottom corners, the camera in the middle. */
.controls {
  position: fixed;
  left: var(--pad);
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.controls > * { pointer-events: auto; }
.control-group { display: flex; gap: 14px; align-items: flex-end; }
.walk-button.jump-button { width: 96px; height: 96px; font-size: 40px; background: rgba(214, 138, 40, 0.75); }
.hud-stars { color: var(--sun); font-weight: 800; }
.hud-lives { letter-spacing: 2px; }
/* A paw for each animal in the level: gold once named right on the first try, faint until then. */
.hud-paws { max-width: 11em; font-size: 15px; line-height: 1.6; }
.paws-named { padding: 1px 3px; border-radius: 9px; background: var(--sun); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.paws-named:empty { display: none; }
.paws-left { opacity: 0.55; filter: grayscale(1) brightness(2.5); }
.walk-button {
  width: 84px;
  height: 84px;
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(31, 59, 44, 0.55);
  font-size: 32px;
  color: #fff;
}
.walk-button.held { background: rgba(31, 59, 44, 0.85); transform: scale(0.95); }
.snap-button {
  width: 78px;
  height: 78px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: rgba(31, 59, 44, 0.45);
  font-size: 32px;
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.2s;
}
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.06); } }

.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.9; } to { opacity: 0; } }

/* Confetti over everything when a level is beaten (src/confetti.js makes the pieces). */
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
.confetti i {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confetti-fall 3s linear forwards;
}
@keyframes confetti-fall { to { transform: translateY(110vh) rotate(720deg); } }

/* Panels over the trail. */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) var(--pad) max(10px, env(safe-area-inset-bottom));
  background: rgba(20, 40, 28, 0.35);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow: auto;
}
.panel {
  width: min(100%, 880px);
  max-height: 100%;
  overflow: auto;
  border-radius: 28px;
  background: var(--forest);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  padding: clamp(16px, 3.5vmin, 30px);
}
.kicker {
  margin: 0;
  color: var(--sun);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 14px;
}
h1, h2 { margin: 4px 0 8px; line-height: 1.05; }
h1 { font-size: clamp(34px, 8vmin, 60px); }
h2 { font-size: clamp(26px, 5.5vmin, 40px); }

.start-panel { width: min(100%, 1020px); text-align: center; }
.collection-count { margin: 0 0 18px; color: var(--sun); font-weight: 700; }
/* The trail map: the level you are on as a big card, then one stop per level along a dashed path. */
.trail-map { display: grid; gap: 16px; justify-items: center; }
.place-preview { width: calc(100% + 36px); height: 100px; object-fit: cover; margin: -16px -18px 8px; border-radius: 20px 20px 0 0; }
.level-now { width: min(100%, 560px); }
.place-level { color: var(--sun); font-weight: 800; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; }
.level-done {
  width: min(100%, 560px);
  text-align: center;
  background: radial-gradient(circle at 50% 0%, #e0a83a, #8a5a2b);
  box-shadow: 0 6px 0 #5a3a1b;
}
.level-done .place-level { font-size: 16px; }
.map-stops {
  position: relative;
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.5vw, 14px);
  width: 100%;
  padding-top: 4px;
}
/* The dashed path behind the stops. */
.map-stops::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 27px;
  border-top: 4px dashed rgba(255, 247, 230, 0.35);
}
.map-stop {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 5px;
  width: clamp(72px, 15vw, 130px);
  padding: 0;
  border: 0;
  background: none;
  color: var(--cream);
}
.stop-dot {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 900;
  border: 3px solid rgba(255, 247, 230, 0.5);
  background: rgba(255, 255, 255, 0.12);
}
.stop-name { font-size: 13px; font-weight: 700; line-height: 1.15; text-align: center; }
.map-stop.beaten .stop-dot { background: radial-gradient(circle at 35% 30%, #ffe39a, #e0a83a); border-color: #8a5a2b; color: #8a5a2b; }
.map-stop.beaten:active { transform: translateY(2px); }
.map-stop.now .stop-dot { background: var(--leaf); border-color: #fff; color: #fff; animation: here 1.4s ease-in-out infinite; }
@keyframes here { 50% { transform: scale(1.12); box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.15); } }
.map-stop.locked { opacity: 0.55; }
.map-stop.locked .stop-dot { background: rgba(255, 255, 255, 0.08); border-style: dotted; color: rgba(255, 247, 230, 0.7); }
.guide-filter { display: flex; gap: 12px; align-items: center; margin: 10px 0 16px; }
.guide-filter select { font: inherit; padding: 10px; border-radius: 12px; background: #fff7e6; color: #1f3b2c; max-width: 100%; }
.panel { touch-action: pan-y; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid var(--sun); outline-offset: 4px; }
.lead { font-size: clamp(16px, 3vmin, 20px); margin: 0 0 16px; }
/* Who's exploring: a big button for each player's name; one tap switches. */
.player-names { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 6px 0 12px; }
.name-button {
  min-height: 52px;
  padding: 0 24px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 22px;
  font-weight: 800;
}
.name-button.current { border-color: var(--sun); background: var(--sun); color: var(--ink); }
.place-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 16px 18px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, #5d9fb0, #4f7d3a);
  text-align: left;
  box-shadow: 0 6px 0 #2c4f33;
}
.place-card:active { transform: translateY(3px); box-shadow: 0 3px 0 #2c4f33; }
.place-name { font-size: clamp(19px, 3.5vmin, 26px); font-weight: 800; }
.place-blurb { font-size: 15px; opacity: 0.95; }
.place-count { font-size: 15px; color: var(--sun); font-weight: 700; }
.place-preview, .place-level, .place-name, .place-blurb { grid-column: 1 / -1; }
.habitat-swamp { background: linear-gradient(135deg, #4b827d, #365d4b); }
.habitat-bayou { background: linear-gradient(135deg, #5d9fb0, #4f7d3a); }
.habitat-woods { background: linear-gradient(135deg, #64894c, #3e5838); }
.habitat-backyard { background: linear-gradient(135deg, #997e47, #668547); }
.habitat-prairie { background: linear-gradient(135deg, #a2843e, #687b38); }
.habitat-gulf { background: linear-gradient(135deg, #328aa8, #4b6f8d); }
.place-go {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--sun);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}
.start-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.soft-button {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 17px;
  font-weight: 700;
}
.primary-button {
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  border-radius: 26px;
  background: var(--sun);
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 5px 0 var(--sun-dark);
}
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--sun-dark); }

/* The animal card: the real photo beside the words, stacked on a tall screen. */
.card-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(14px, 3vmin, 26px);
  align-items: center;
}
.card-photo { margin: 0; }
.card-photo img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 18px;
  display: block;
  background: #33503e;
}
.card-photo figcaption { margin-top: 6px; font-size: 12px; opacity: 0.75; }
.photo-source { color: var(--cream); font-size: 12px; }
.card-photo img { object-fit: contain; }
/* The child's own photo of an animal they saw for real: a polaroid on the reference photo, with a
   gold sticker for the day. */
.card-frame { position: relative; }
.card-seen {
  position: absolute;
  right: -4px;
  bottom: -12px;
  width: 38%;
  margin: 0;
  padding: 5px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  transform: rotate(5deg);
}
.card-photo .card-seen img { aspect-ratio: 1; object-fit: cover; border-radius: 3px; background: #ddd; }
.card-photo .card-seen figcaption {
  margin-top: 5px;
  padding: 3px 6px;
  border-radius: 10px;
  background: var(--sun);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  opacity: 1;
}
.camera-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#card-seen-button:disabled { opacity: 0.6; cursor: wait; }
#card-seen-status:empty { display: none; }
.card-words p { margin: 0 0 10px; font-size: clamp(15px, 2.6vmin, 19px); line-height: 1.35; }
.card-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  margin: 0 0 14px;
  font-size: clamp(14px, 2.4vmin, 17px);
}
.card-facts dt {
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--sun);
  font-weight: 800;
  align-self: start;
}
.card-facts dd { margin: 0; line-height: 1.3; }
.card-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* On the trail the card first asks "What animal is this?" with three names, and hides the answer. */
.card-panel:not(.guessing) .card-choices, .guessing .card-actions { display: none; }
.guessing :is(#card-name, #card-fact, #card-say, .card-facts) { display: none; }
.guessing #card-kicker { font-size: clamp(24px, 5vmin, 38px); letter-spacing: 0.02em; }
.card-choices { display: grid; gap: 10px; }
.choice-button {
  min-height: 52px;
  padding: 8px 18px;
  border: 0;
  border-radius: 18px;
  background: var(--cream);
  color: var(--ink);
  font-size: clamp(18px, 3.2vmin, 22px);
  font-weight: 800;
  box-shadow: 0 5px 0 var(--sun-dark);
}
.choice-button:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--sun-dark); }
.choice-button.wrong { opacity: 0.35; box-shadow: none; animation: wiggle 0.4s; }
@keyframes wiggle { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* Players: one row per player, with their level, count and latest finds, and Remove (tap twice). */
.players-list { display: grid; gap: 10px; margin: 12px 0 16px; }
.player-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.1);
}
.player-row.current { border-color: var(--sun); }
.player-pick { flex: 1; min-height: 48px; padding: 0; border: 0; background: none; text-align: left; font-size: 24px; font-weight: 800; }
.player-remove {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.player-remove.armed { background: #c84b4b; color: #fff; }
.players-full { margin: 0 0 12px; color: var(--sun); font-weight: 700; }
.player-form { display: flex; gap: 10px; flex-wrap: wrap; }
.player-form input {
  flex: 1 1 200px;
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  -webkit-user-select: text;
  user-select: text;
}

/* The Field Guide: found animals show their photo, the rest a dark shape and a question mark. */
.guide-head { display: flex; justify-content: space-between; align-items: flex-start; }
.guide-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.guide-slot {
  position: relative;
  border: 0;
  border-radius: 16px;
  padding: 0 0 8px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}
.guide-slot img, .guide-slot canvas {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  margin-bottom: 6px;
}
.guide-slot.missing { background: rgba(255, 255, 255, 0.06); }
.guide-slot.missing::after {
  content: "?";
  position: absolute;
  top: 6px;
  right: 10px;
  color: var(--sun);
  font-size: 22px;
  font-weight: 900;
}
/* A gold camera sticker on each animal seen for real. */
.guide-slot.seen::after {
  content: "📷";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 2px 0 var(--sun-dark);
  font-size: 16px;
}
.guide-hint { margin: 12px 0 0; font-size: 16px; min-height: 1.3em; }

.ranger-panel { width: min(100%, 460px); text-align: center; }
.badge {
  width: 120px;
  height: 120px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffe39a, #e0a83a);
  border: 6px solid #8a5a2b;
  box-shadow: 0 0 0 6px #d8b878;
  animation: bounce 1.2s ease-in-out infinite;
}
.badge span { font-size: 64px; color: #8a5a2b; }

/* Short, wide phones held sideways. */
@media (max-height: 430px) {
  .walk-button { width: 66px; height: 66px; font-size: 26px; }
  .snap-button { width: 64px; height: 64px; font-size: 27px; }
  .round-button { width: 42px; height: 42px; font-size: 18px; }
  .card-panel { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); border-radius: 22px; }
  .card-words p { margin-bottom: 6px; }
  .card-facts { margin-bottom: 8px; }
  .primary-button { min-height: 44px; font-size: 17px; }
  .lead { margin-bottom: 10px; }
  .guide-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .start-panel h1 { font-size: 32px; }
  .start-panel { padding: 16px; }
  /* The level card beside the stops, so the map fits without scrolling. */
  .start-panel .lead, .place-blurb, .collection-count { display: none; }
  .trail-map { grid-template-columns: minmax(0, 300px) minmax(0, 1fr); align-items: center; gap: 12px; }
  .level-now, .level-done { padding: 8px 12px 10px; gap: 2px; }
  .place-preview { width: calc(100% + 24px); height: 56px; margin: -8px -12px 4px; }
  .place-level { font-size: 11px; }
  .place-name { font-size: 17px; }
  .place-count { font-size: 13px; white-space: nowrap; }
  .place-go { padding: 6px 12px; font-size: 15px; }
  .map-stops { gap: 2px; }
  .map-stop { width: clamp(60px, 9vw, 86px); }
  .map-stops::before { top: 20px; }
  .stop-dot { width: 36px; height: 36px; font-size: 17px; }
  .stop-name { font-size: 11px; }
  .guide-slot { font-size: 12px; border-radius: 12px; padding-bottom: 6px; }
  .guide-slot.missing::after { font-size: 17px; top: 2px; right: 6px; }
  .guide-slot.seen::after { width: 22px; height: 22px; font-size: 12px; top: 3px; right: 3px; }
  .card-photo .card-seen figcaption { font-size: 10px; padding: 2px 4px; }
  .guide-panel h2 { font-size: 26px; margin-bottom: 10px; }
}

/* Tall, narrow screens: photo on top. */
@media (max-aspect-ratio: 4/5) {
  .place-card { grid-template-columns: 1fr; }
  .place-go { justify-self: start; }
  .place-blurb { display: none; }
  .card-panel { grid-template-columns: 1fr; }
  .guide-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Shorter screens, like a tablet held sideways: drop the intro line so all six places fit. */
@media (max-height: 790px) {
  .start-panel .lead { display: none; }
}

/* Phones held upright: the stops wrap into two rows of three. */
@media (max-width: 600px) {
  .map-stops { flex-wrap: wrap; gap: 10px 4px; }
  .map-stop { width: 30%; }
  .map-stops::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .badge, .flash.go, .map-stop.now .stop-dot, .confetti i, .choice-button.wrong { animation: none; }
}
