/* ── Fonts ─────────────────────────────────────────────── */
@font-face {
  font-family: 'Press Start 2P';
  src: url('fonts/PressStart2P.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'VT323';
  src: url('fonts/VT323.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
}

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:     #f5f0e8;
  --panel:  #fdfaf4;
  --border: #8a7a6a;
  --green:  #2a5a1a;
  --gold:   #c8a820;
  --amber:  #b06820;
  --text:   #2a2018;
  --dim:    #8a7860;
  --red:    #a83020;
  --blue:   #2a4a8a;
  --dark:   #ede8e0;

  --header-h: 72px;
  --sidebar-w: 300px;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
}

/* ── CRT effects ───────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.012) 0px,
    rgba(0,0,0,0.012) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 9999;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.20) 100%);
  pointer-events: none;
  z-index: 9998;
}

/* ── App shell ─────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ── Header ────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 2px solid var(--border);
  z-index: 100;
}

.header-brand { display: flex; align-items: center; gap: 10px; }

#header-birds {
  display: flex;
  align-items: center;
  gap: 3px;
}

.header-bird {
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.brand-name {
  font-family: 'Press Start 2P', monospace;
  font-size: .88rem;
  color: var(--blue);
  letter-spacing: 1px;
}

.header-date {
  font-family: 'VT323', monospace;
  font-size: 1.45rem;
  color: var(--dim);
  letter-spacing: 1px;
}

.icon-btn {
  width: 42px; height: 42px;
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 0;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: .7rem;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* ── Layout ────────────────────────────────────────────── */
#layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
  flex: 1;
}

.sidebar-top { display: flex; flex-direction: column; gap: 8px; }

.sidebar-eyebrow {
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  letter-spacing: .1em;
  color: var(--green);
}

.sidebar-sub {
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  color: var(--dim);
  letter-spacing: .5px;
}

/* ── Species list ──────────────────────────────────────── */
.species-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
}

.species-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  opacity: 0;
  transform: translateX(-6px);
  animation: slideIn .3s ease forwards;
}
.species-item:nth-child(1) { animation-delay: .05s; }
.species-item:nth-child(2) { animation-delay: .10s; }
.species-item:nth-child(3) { animation-delay: .15s; }
.species-item:nth-child(4) { animation-delay: .20s; }
.species-item:nth-child(5) { animation-delay: .25s; }

.species-num {
  font-family: 'Press Start 2P', monospace;
  font-size: .55rem;
  color: var(--gold);
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.species-name {
  font-family: 'VT323', monospace;
  font-size: 1.15rem;
  color: var(--text);
  letter-spacing: .5px;
  line-height: 1.2;
}

@keyframes slideIn {
  to { opacity: 1; transform: translateX(0); }
}

/* ── State cards ───────────────────────────────────────── */
#sidebar-state { flex: 1; display: flex; flex-direction: column; }
.state-card { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.hidden { display: none !important; }

/* Prompt card */
#state-prompt {
  padding: 20px 12px;
  border: 2px solid var(--border);
  background: var(--bg);
  margin-top: 4px;
}
#state-prompt .prompt-icon svg { width: 44px; height: 44px; opacity: .45; }
#state-prompt p {
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  color: var(--dim);
  line-height: 1.5;
  letter-spacing: .5px;
}

/* Result card */
#state-result {
  padding: 12px 0 8px;
  border: 2px solid var(--border);
  background: var(--bg);
  margin-top: 4px;
  width: 100%;
}

.score-value {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text);
}

.result-message {
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  color: var(--text);
  line-height: 1.7;
  padding: 0 12px;
}
.distance-text {
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: var(--dim);
  letter-spacing: .5px;
}

.share-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  background: var(--panel);
  border: 2px solid var(--border);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  letter-spacing: .5px;
  cursor: pointer;
  position: relative;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.share-btn::before {
  content: '> ';
  color: var(--gold);
  opacity: 0;
  position: absolute;
  left: 6px;
  transition: opacity .15s;
}
.share-btn:hover::before { opacity: 1; }
.share-btn:hover {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.share-btn:active { transform: scale(.97); }

/* ── Stats grid ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  padding: 0 8px;
  margin-top: 12px;
}

.stat-cell {
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 14px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stat-bird {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.stat-value {
  font-family: 'Press Start 2P', monospace;
  font-size: .7rem;
  color: var(--text);
  line-height: 1.3;
  text-align: center;
  word-break: break-all;
}

.stat-label {
  font-family: 'VT323', monospace;
  font-size: .9rem;
  color: var(--dim);
  letter-spacing: .5px;
  text-align: center;
  line-height: 1.2;
}

.comeback-text {
  font-family: 'VT323', monospace;
  font-size: .9rem;
  color: var(--dim);
  letter-spacing: .5px;
}

.difficulty-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: .45rem;
  letter-spacing: .08em;
  padding: 3px 8px;
  border: 2px solid currentColor;
  line-height: 1.6;
}

/* ── History bars ──────────────────────────────────────── */
.history-bars {
  width: 100%;
  padding: 4px 8px 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-heading {
  font-family: 'Press Start 2P', monospace;
  font-size: .5rem;
  color: var(--dim);
  letter-spacing: .1em;
  margin-bottom: 5px;
}

.history-bar-row {
  height: 7px;
  background: var(--dark);
  border: 1px solid var(--border);
  overflow: hidden;
}

.history-bar {
  height: 100%;
  transition: width .5s ease-out;
}

/* ── Learn more ────────────────────────────────────────── */
.learn-more {
  width: 100%;
  border: 2px solid var(--border);
  background: var(--bg);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.learn-more-heading {
  font-family: 'Press Start 2P', monospace;
  font-size: .55rem;
  color: var(--green);
  letter-spacing: .05em;
  line-height: 1.6;
}

.learn-more-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.learn-more-list li a {
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  color: var(--blue);
  text-decoration: none;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color .15s;
}

.learn-more-list li a::before {
  content: '>';
  color: var(--gold);
  font-family: 'Press Start 2P', monospace;
  font-size: .5rem;
}

.learn-more-list li a:hover { color: var(--red); }

/* ── Footer ────────────────────────────────────────────── */
#footer-bar {
  height: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--dark);
  border-top: 2px solid var(--border);
  padding: 0 20px;
  z-index: 100;
}

.footer-text {
  font-family: 'VT323', monospace;
  font-size: .95rem;
  color: var(--dim);
  letter-spacing: .5px;
}

.footer-link {
  font-family: 'Press Start 2P', monospace;
  font-size: .55rem;
  color: var(--red);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: .5px;
  transition: color .15s;
}

.footer-link:hover { color: var(--blue); }

.footer-store {
  font-family: 'Press Start 2P', monospace;
  font-size: .5rem;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 3px 7px;
  transition: background .15s, color .15s, border-color .15s;
}

.footer-link:hover .footer-store {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* ── Map ───────────────────────────────────────────────── */
#map-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
  border-left: 2px solid var(--border);
}
#map {
  width: 100%;
  height: 100%;
  cursor: crosshair;
}
#map.guessed { cursor: default; }

#map-legend {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 400;
  background: rgba(253, 250, 244, 0.92);
  border: 2px solid var(--border);
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.legend-line {
  display: inline-block;
  width: 22px;
  border-top: 2px dashed rgba(138, 122, 106, 0.7);
}

.legend-label {
  font-family: 'Press Start 2P', monospace;
  font-size: .4rem;
  color: var(--dim);
  letter-spacing: .05em;
}

/* ── Bird explosion particles ──────────────────────────── */
.bird-particle {
  position: absolute;
  width: 42px;
  height: 42px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  z-index: 900;
  transform: translate(-50%, -50%);
  animation: birdExplode 2s ease-out forwards;
}

@keyframes birdExplode {
  0%   { opacity: 1;   transform: translate(-50%, -50%) translate(0, 0)                       scale(1.2); }
  100% { opacity: 0;   transform: translate(-50%, -50%) translate(var(--dx), var(--dy))       scale(0.4); }
}


#map-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-family: 'Press Start 2P', monospace;
  font-size: .55rem;
  letter-spacing: .5px;
  padding: 8px 16px;
  border: 2px solid var(--border);
  pointer-events: none;
  transition: opacity .4s;
  z-index: 500;
}
/* ── Custom map markers ────────────────────────────────── */
.guess-pin-outer {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}
.guess-pin {
  width: 12px; height: 12px;
  background: var(--text);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
}

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(42,32,24,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal {
  background: var(--panel);
  border: 2px solid var(--border);
  width: 100%; max-width: 440px;
  padding: 28px;
  position: relative;
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.97) translateY(6px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
.modal-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none;
  font-family: 'Press Start 2P', monospace;
  font-size: .8rem;
  color: var(--dim); cursor: pointer;
  transition: color .15s;
}
.modal-close:hover { color: var(--red); }
.modal-title {
  font-family: 'Press Start 2P', monospace;
  font-size: .75rem;
  color: var(--green);
  letter-spacing: 1px;
  margin-bottom: 18px;
}
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-body p {
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  line-height: 1.65;
  color: var(--text);
  letter-spacing: .5px;
}
.modal-body strong { color: var(--green); }
.modal-body em { color: var(--gold); font-style: normal; }

.score-guide {
  background: var(--bg);
  border: 2px solid var(--border);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.guide-row {
  display: flex; align-items: center; gap: 10px;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  letter-spacing: .5px;
}
.guide-row span:nth-child(2) { flex: 1; color: var(--dim); }
.guide-row strong {
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  color: var(--text);
}
.guide-dot { width: 10px; height: 10px; flex-shrink: 0; }

.modal-difficulty-heading {
  font-size: .85rem !important;
  color: var(--dim) !important;
  margin-top: 4px !important;
}

.difficulty-tiers {
  background: var(--bg);
  border: 2px solid var(--border);
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 7px;
}
.tier-row {
  display: flex; align-items: center; gap: 10px;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  letter-spacing: .5px;
}
.tier-dot { width: 10px; height: 10px; flex-shrink: 0; }
.tier-label { flex: 1; color: var(--dim); }
.tier-pts {
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  color: var(--text);
}

.modal-footnote {
  font-size: .95rem !important;
  color: var(--dim) !important;
  font-style: italic;
}

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-family: 'Press Start 2P', monospace;
  font-size: .6rem;
  letter-spacing: .5px;
  padding: 10px 18px;
  border: 2px solid var(--border);
  z-index: 2000;
  pointer-events: none;
  animation: toastIn .2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Test mode bar ─────────────────────────────────────── */
#test-bar {
  position: fixed;
  bottom: 52px;
  right: 16px;
  background: var(--text);
  color: var(--bg);
  border: 2px solid var(--gold);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9999;
  font-family: 'Press Start 2P', monospace;
  font-size: .5rem;
  box-shadow: 3px 3px 0 var(--gold);
}

.test-label {
  color: var(--gold);
  letter-spacing: .05em;
}

#test-date {
  min-width: 90px;
  text-align: center;
  letter-spacing: .03em;
}

#test-bar button {
  background: var(--gold);
  border: none;
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: .5rem;
  padding: 5px 8px;
  cursor: pointer;
  transition: background .15s;
}

#test-bar button:hover { background: #f5e060; }

/* ── Leaflet overrides ─────────────────────────────────── */
.leaflet-container { font-family: 'VT323', monospace; }
.leaflet-control-attribution { font-size: .65rem; }
.leaflet-control-zoom a {
  font-family: 'Press Start 2P', monospace !important;
  font-size: .65rem !important;
  color: var(--text) !important;
  background: var(--panel) !important;
  border: 2px solid var(--border) !important;
  border-radius: 0 !important;
}
.leaflet-control-zoom a:hover {
  background: var(--dark) !important;
}

/* ── Sidebar/map toggles (mobile only) ─────────────────── */
#sidebar-toggle, #map-toggle { display: none; }

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 720px) {
  #layout { flex-direction: column; }
  #sidebar {
    width: 100%; min-width: unset;
    height: auto; max-height: 44vh;
    border-right: none; border-bottom: 2px solid var(--border);
    overflow-y: auto;
    transition: max-height .25s ease, opacity .25s ease;
  }
  #sidebar.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    border-bottom: none;
  }
  #sidebar.map-hidden {
    max-height: calc(100vh - var(--header-h) - 40px);
    flex: 1;
  }
  .sidebar-inner { padding: 10px 12px; gap: 8px; }
  #map-wrapper { flex: 1; min-height: 0; border-left: none; }
  #map-wrapper.collapsed { display: none; }

  /* Species toggle — top-right of map */
  #sidebar-toggle {
    display: block;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 500;
    background: var(--panel);
    border: 2px solid var(--border);
    color: var(--text);
    font-family: 'Press Start 2P', monospace;
    font-size: .4rem;
    letter-spacing: .05em;
    padding: 6px 10px;
    cursor: pointer;
    transition: background .15s, color .15s;
  }
  #sidebar-toggle:hover {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
  }

  /* Map toggle — fixed, always visible above footer */
  #map-toggle {
    display: block;
    position: fixed;
    bottom: 50px;
    right: 10px;
    z-index: 600;
    background: var(--panel);
    border: 2px solid var(--border);
    color: var(--text);
    font-family: 'Press Start 2P', monospace;
    font-size: .4rem;
    letter-spacing: .05em;
    padding: 6px 10px;
    cursor: pointer;
    transition: background .15s, color .15s;
  }
  #map-toggle:hover {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
  }

  /* Header: shrink title and birds so nothing wraps */
  .header-date { display: none; }
  .brand-name { font-size: .6rem; }
  .header-bird { width: 26px; height: 26px; }

  /* Tighten species list */
  .species-item { padding: 6px 10px; }
  .species-name { font-size: 1rem; }

  /* Tighten state cards */
  #state-prompt { padding: 10px 8px; }
  #state-prompt .prompt-icon { display: none; }
  .stat-cell { padding: 10px 6px 8px; }

  /* Footer: single compact row */
  .footer-text { display: none; }
  #footer-bar { justify-content: center; }
}
