/* Rarity colors used by the Field Guide chips and the round-summary tiers.
   Text always carries the rarity name too — color is never the only cue. */
:root {
  --rarity-basic: #6f664c;
  --rarity-rare: var(--pine);
  --rarity-epic: #5b4a7a;
  --rarity-legendary: var(--gold);
}

.level-scene {
  min-height: 100vh;
  padding: 32px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #24382d;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.level-back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1100;
  /* above .binocular-mask (1000) so it stays clickable even while zoomed */
}

/* ---------------------------------------------------------------
   Scene renderer (game/renderer.js — #11)
   The element passed into renderScene(container, background) gets
   .scene-root applied to it; give it real dimensions from whatever
   wraps it (level.js / #14) — it fills 100% of its parent here.
   ----------------------------------------------------------------*/
.scene-root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
}

.scene {
  position: absolute;
  inset: 0;
}

.scene-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.level-scene>.scene-root {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.scene-occlusion-layer {
  background-size: contain;
}

/* Occlusion + bird layers never intercept the pointer. Birds are collected
   by typing their name (views/level.js), not by clicking, so sprites are
   pointer-transparent too — nothing in the scene should swallow a click
   meant for the page underneath. */
.scene-occlusion-layer,
.scene-bird-layer,
.scene-bird-layer>* {
  pointer-events: none;
}

/* ---------------------------------------------------------------
   Bird sprites
   Each sprite is a direct child of a .scene-bird-layer, positioned by
   its center point (left/top = spawn point, translate(-50%,-50%) to
   center on it) and scaled via the --bird-scale custom property, which
   birdSpawner.js sets per-bird from levelConfig.birdDistanceRange.
   ----------------------------------------------------------------*/
.bird-sprite {
  position: absolute;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%) scale(var(--bird-scale, 1));
  transform-origin: center;
  opacity: 0;
  transition: opacity 300ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-sizing: content-box;
}

.bird-sprite.is-spawning,
.bird-sprite.is-visible {
  opacity: 1;
}

.bird-sprite.is-spawning,
.bird-sprite.is-reappearing {
  animation: bird-arrive 500ms ease-out forwards;
}

@keyframes bird-arrive {
  from {
    opacity: 0;
    transform:
      translate(calc(-50% + 60px), calc(-50% - 30px)) scale(var(--bird-scale, 1));
  }

  to {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(var(--bird-scale, 1));
  }
}

.bird-sprite.is-fleeing {
  opacity: 1;
  animation: bird-leave 500ms ease-in forwards;
}

@keyframes bird-leave {
  from {
    opacity: 1;
    transform:
      translate(-50%, -50%) scale(var(--bird-scale, 1));
  }

  to {
    opacity: 0;
    transform:
      translate(calc(-50% - 60px), calc(-50% - 30px)) scale(var(--bird-scale, 1));
  }
}

.bird-sprite.is-hidden {
  opacity: 0;
  cursor: default;
}

.bird-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* ---------------------------------------------------------------
   Binocular zoom mask
   .binocular-mask is a sibling of .scene inside .scene-root: an opaque
   overlay image (binocularsSilhouette.png — solid outside the two lens
   cutouts, transparent inside them) stretched to fill the scene. It's
   invisible until is-active. .scene-zoom-target (applied to .scene
   itself) is what actually scales on zoom — the mask overlay never
   scales, so the lens shapes stay put on screen while the content
   behind them zooms.
   ----------------------------------------------------------------*/
.binocular-mask {
  position: absolute;
  inset: 0;
  z-index: 1000;
  background-image: url('../assets/occlusion/binocularsSilhouette.png');
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-color: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
}

.binocular-mask.is-active {
  opacity: .8;
}

.scene-zoom-target {
  transition: transform 100ms ease;
  transform-origin: center;
}

.scene-zoom-target.is-zoomed {
  transform:
    translate(var(--pan-x, 0px), var(--pan-y, 0px)) scale(var(--zoom-scale, 2));
}

/* Level HUD */
.level-hud {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 2000;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.hud-chip {
  display: block;
  min-width: 86px;
  padding: 8px 14px;
  color: #f1ecd9;
  background: rgba(32, 42, 31, 0.92);
  border: 1px solid #f1ecd9;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  visibility: visible;
  opacity: 1;
}

[data-hud="timer"] {
  min-width: 76px;
}

/* Round summary */
.round-summary {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(231, 225, 204, 0.28), rgba(231, 225, 204, 0.28)),
    url('../assets/backgrounds/loginBG.jpg') center / cover no-repeat;
}

.summary-card {
  width: min(100%, 720px);
  padding: 36px 30px;
  color: var(--ink);
  background: rgba(241, 236, 217, 0.94);
  border: 1px solid rgba(166, 156, 124, 0.9);
  box-shadow: 0 18px 34px -22px rgba(32, 42, 31, 0.65);
  text-align: center;
}

.summary-kicker {
  margin: 0 0 8px;
  color: var(--pine);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.summary-card h1 {
  margin: 0 0 28px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 2.5rem;
  line-height: 1;
}

.summary-stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.summary-stat {
  padding: 16px 10px;
  background: rgba(231, 225, 204, 0.85);
  border: 1px solid rgba(166, 156, 124, 0.75);
}

.summary-stat-label {
  display: block;
  margin-bottom: 8px;
  color: rgba(32, 42, 31, 0.65);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.summary-stat strong {
  display: block;
  color: var(--pine-dark);
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.35rem;
}

.summary-badge {
  margin: 0 0 22px;
  padding: 10px 12px;
  color: var(--pine);
  background: rgba(51, 80, 62, 0.1);
  border-left: 3px solid var(--pine);
  font-weight: 700;
}

.summary-card [data-action="continue"] {
  min-width: 150px;
}

@media (max-width: 560px) {
  .level-hud {
    top: 12px;
  }

  .summary-card {
    padding: 28px 18px;
  }

  .summary-stat-row {
    grid-template-columns: 1fr;
  }
}

/* ---------------------------------------------------------------
   Shared scroll container (Field Guide pages, round-summary stacks)
   App-wide scrollbar look from main.css (--pine at 45%), scoped so each
   scroller keeps its wheel/touch scrolling to itself (#38, #40).
   ----------------------------------------------------------------*/
.field-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(51, 80, 62, 0.45) transparent;
}

/* Chromium/Safari builds without scrollbar-color support */
@supports not (scrollbar-color: auto) {
  .field-scroll::-webkit-scrollbar {
    width: 8px;
  }

  .field-scroll::-webkit-scrollbar-track {
    background: transparent;
  }

  .field-scroll::-webkit-scrollbar-thumb {
    background: rgba(51, 80, 62, 0.45);
    border-radius: 4px;
  }
}

/* ---------------------------------------------------------------
   Field Guide (components/fieldGuide.js — #38/#39/#40)
   A two-page spread inside a 6px dark-green rounded frame. `mini` sits
   bottom-right in the level; `large` fills the main-menu modal card.
   z-index 2000 matches .level-hud so it stays above the zoom mask (1000)
   and the Back button (1100).
   ----------------------------------------------------------------*/
.field-guide {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--card);
  border: 6px solid var(--pine);
  border-radius: 6px;
  box-shadow: 0 18px 34px -22px rgba(32, 42, 31, 0.65);
}

.field-guide--mini {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  width: min(440px, calc(100% - 32px));
  height: 250px;
  font-size: 0.78rem;
}

.field-guide--large {
  width: 100%;
  height: min(640px, 80vh);
  font-size: 1rem;
}

.fg-spread {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.fg-page {
  min-height: 0;
  padding: 8px 10px;
  background: var(--card);
}

.field-guide--large .fg-page {
  padding: 22px 26px;
}

.fg-page--left {
  border-right: 1px solid var(--rule);
}

.fg-page.can-flip {
  cursor: pointer;
}

.fg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.fg-thumb {
  flex: none;
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.field-guide--large .fg-thumb {
  width: 140px;
  height: auto;
}

.fg-titles {
  min-width: 0;
}

.fg-name {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.15em;
  line-height: 1.15;
}

.field-guide--large .fg-name {
  font-size: 1.6em;
}

.fg-scientific {
  margin: 2px 0 4px;
  color: rgba(32, 42, 31, 0.65);
  font-style: italic;
}

.fg-rarity {
  display: inline-block;
  padding: 1px 8px;
  color: #fff;
  background: var(--rarity-basic);
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 600;
}

.fg-rarity[data-rarity="rare"] {
  background: var(--rarity-rare);
}

.fg-rarity[data-rarity="epic"] {
  background: var(--rarity-epic);
}

.fg-rarity[data-rarity="legendary"] {
  color: var(--ink);
  background: var(--rarity-legendary);
}

.fg-fields {
  margin: 0;
}

.fg-fields dt {
  margin-top: 6px;
  color: var(--pine-dark);
  font-weight: 700;
}

.fg-fields dd {
  margin: 1px 0 0;
  line-height: 1.4;
}

.fg-status {
  margin: 0;
  color: rgba(32, 42, 31, 0.7);
}

.fg-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  color: var(--card);
  background: var(--pine);
}

.fg-position {
  font-size: 0.9em;
}

.fg-nav {
  padding: 2px 10px;
  font: inherit;
  font-weight: 600;
  color: inherit;
  background: transparent;
  border: 1px solid rgba(241, 236, 217, 0.55);
  border-radius: 3px;
  cursor: pointer;
}

.fg-nav:hover:not(:disabled) {
  background: var(--pine-dark);
}

.fg-nav:disabled {
  opacity: 0.4;
  cursor: default;
}

.fg-nav:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Hide / show the mini guide. `.field-guide` sets display:flex, which
   would beat the browser's [hidden] rule, so hidden is restated here. */
.field-guide[hidden],
.fg-reopen[hidden] {
  display: none;
}

.fg-close {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 24px;
  height: 24px;
  padding: 0;
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--pine-dark);
  background: var(--card);
  border: 2px solid var(--pine);
  border-radius: 50%;
  cursor: pointer;
}

.fg-close:hover {
  background: var(--paper);
}

/* Same corner the guide occupies; z-index 2000 like the guide itself. */
.fg-reopen {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--card);
  background: var(--pine);
  border: 2px solid var(--pine-dark);
  border-radius: 6px;
  box-shadow: 0 10px 22px -16px rgba(32, 42, 31, 0.65);
  cursor: pointer;
}

.fg-reopen:hover {
  background: var(--pine-dark);
}
/* ---------------------------------------------------------------
   Name textbox (views/level.js) — birds are collected by typing.
   Bottom-left so it stays clear of the mini Field Guide (bottom-right).
   ----------------------------------------------------------------*/
.collect-form {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 2000;
  width: min(340px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.collect-row {
  display: flex;
  gap: 8px;
}

.collect-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  /* placeholder stays sentence case */
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--pine);
  border-radius: 4px;
}

.collect-input::placeholder {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: rgba(32, 42, 31, 0.55);
}

.collect-input:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(185, 146, 46, 0.35);
}

.collect-input:disabled {
  opacity: 0.6;
}

.collect-feedback {
  margin: 0;
  padding: 6px 10px;
  color: var(--card);
  background: rgba(32, 42, 31, 0.92);
  border-left: 4px solid var(--rule);
  border-radius: 3px;
  font-size: 0.85rem;
  font-weight: 600;
}

.collect-feedback:empty {
  display: none;
}

.collect-feedback[data-kind="hit"] {
  border-left-color: #8fbf7a;
}

.collect-feedback[data-kind="miss"] {
  border-left-color: #d98a76;
}

@media (prefers-reduced-motion: no-preference) {
  .collect-input.is-miss {
    animation: collect-shake 260ms ease;
  }
}

@keyframes collect-shake {

  20%,
  60% {
    transform: translateX(-5px);
  }

  40%,
  80% {
    transform: translateX(5px);
  }
}

/* Not enough width to sit side by side: lift the guide above the textbox. */
@media (max-width: 820px) {
  .field-guide--mini,
  .fg-reopen {
    bottom: 96px;
  }
}

/* ---------------------------------------------------------------
   Round summary recap (views/roundSummary.js — #41)
   One row per species, rarest first: sitting image on white, then a
   fixed-height scrolling stack (name, fun fact, remaining guide fields).
   ----------------------------------------------------------------*/
.found-section {
  margin: 0 0 24px;
  text-align: left;
}

.found-heading {
  margin: 0 0 10px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.15rem;
}

.found-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.found-row {
  --tier: var(--rarity-basic);
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 12px;
  height: 132px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 6px solid var(--tier);
  border-radius: var(--radius);
}

.found-row[data-rarity="rare"] {
  --tier: var(--rarity-rare);
}

.found-row[data-rarity="epic"] {
  --tier: var(--rarity-epic);
}

.found-row[data-rarity="legendary"] {
  --tier: var(--rarity-legendary);
}

.found-logo {
  display: grid;
  place-items: center;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.found-logo img {
  display: block;
  height: 100px;
  max-height: 100px;
  max-width: 100%;
  width: auto;
  object-fit: contain;
}

.found-stack {
  min-height: 0;
  padding-right: 8px;
}

.found-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 6px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.1rem;
}

.found-count {
  color: var(--pine);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
}

.found-field {
  margin: 0 0 6px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.found-field-label {
  display: block;
  color: var(--pine-dark);
}

.found-empty {
  margin: 0;
  padding: 14px 16px;
  color: rgba(32, 42, 31, 0.75);
  background: rgba(231, 225, 204, 0.85);
  border: 1px solid rgba(166, 156, 124, 0.75);
}

@media (max-width: 560px) {
  .found-row {
    grid-template-columns: 84px 1fr;
  }
}