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

:root {
  --cream: #faf7f2;
  --parchment: #f2ece0;
  --warm-brown: #8B6914;
  --dark-brown: #3d2b1f;
  --mid-brown: #6b4c2a;
  --text: #2c1f0f;
  --text-soft: #5a4535;
  --text-muted: #8a7060;
  --border: #d9cfc0;
  --gold: #c8960a;
  --radius: 4px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--text);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 19px;
  line-height: 1.7;
  min-height: 100vh;
}

/* ===== Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Site Header ===== */
.site-header {
  position: relative;
  background:
    linear-gradient(135deg, #241709 0%, #3d2b1f 35%, #4a3525 55%, #3d2b1f 75%, #241709 100%);
  padding: 2rem 1rem 1.6rem;
  min-height: 175px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

/* Subtle embossed bird silhouettes across the header */
.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("/static/header-birds.svg");
  background-size: 640px 360px;
  pointer-events: none;
}

.site-logo {
  position: absolute;
  left: 1.25rem;
  top: 0;
  height: 100%;
  width: auto;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  z-index: 1;
}

.header-inner {
  position: relative;
  z-index: 1;
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
}

.site-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.site-title h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.4rem, 7vw, 3.4rem);
  font-weight: 600;
  color: #f5edd8;
  letter-spacing: 0.02em;
}

.site-tagline {
  font-family: 'Source Serif 4', Georgia, serif;
  font-style: italic;
  font-size: 1.15rem;
  color: #b8a888;
  letter-spacing: 0.04em;
  margin-top: 0.35rem;
}

/* ===== Date Navigator ===== */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--parchment);
  border-bottom: 1px solid var(--border);
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--mid-brown);
  font-size: 1.1rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: var(--dark-brown);
  color: #f5edd8;
  border-color: var(--dark-brown);
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.date-display {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 0.95rem;
  color: var(--text-soft);
  min-width: 12rem;
  text-align: center;
  letter-spacing: 0.03em;
}

/* ===== Loading Screen ===== */
.loading-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 4rem 1rem;
}

.loading-feather {
  animation: float 2.8s ease-in-out infinite;
  opacity: 0.7;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-12px) rotate(2deg); }
}

.loading-text {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== Error Screen ===== */
.error-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 4rem 1rem;
  text-align: center;
}

.error-msg {
  color: var(--text-soft);
  font-style: italic;
}

.retry-btn {
  background: var(--dark-brown);
  color: #f5edd8;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.retry-btn:hover { opacity: 0.85; }

/* ===== Bird Card ===== */
.bird-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ===== Hero ===== */
.hero {
  position: relative;
  width: 100%;
  height: 62vh;
  min-height: 320px;
  overflow: hidden;
  background: #1a1008;
}

/* Blurred cover backdrop fills the frame; foreground image is never cropped */
.hero-backdrop {
  position: absolute;
  inset: -32px;
  background-size: cover;
  background-position: center;
  filter: blur(24px) brightness(0.55) saturate(0.9);
}

.hero-image-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}

.hero-overlay.no-photo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e140a;
}

.no-photo-icon {
  font-size: 5rem;
  opacity: 0.25;
}

/* Day badge */
.day-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(10, 6, 2, 0.62);
  color: #e8d9b8;
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.7rem;
  border-radius: 2rem;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.1);
}

/* ===== Bird Identity ===== */
.bird-identity {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 0.5rem;
  text-align: center;
}

.bird-order {
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--warm-brown);
  margin-bottom: 0.6rem;
  font-family: 'Source Serif 4', Georgia, serif;
}

.bird-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  font-weight: 600;
  color: var(--dark-brown);
  line-height: 1.15;
  margin-bottom: 0.5rem;
}

.bird-scientific {
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.bird-family {
  font-size: 0.95rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ===== Divider ===== */
.prose-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 400px;
  margin: 1.75rem auto 0;
  padding: 0 1.5rem;
}

.divider-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}


/* ===== Prose ===== */
.bird-prose {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 1rem;
  font-size: 1.22rem;
  line-height: 1.85;
  color: var(--text-soft);
}

.bird-prose p {
  margin-bottom: 1.25em;
}

.bird-prose p:last-child {
  margin-bottom: 0;
}

/* ===== Section title ===== */
.section-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2rem;
  font-weight: 600;
  color: var(--dark-brown);
  margin-bottom: 1rem;
}

/* ===== Facts + Map row ===== */
.info-row {
  width: 100%;
  max-width: 1200px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
  align-items: stretch;
}

/* Facts — old parchment sheet */
.facts-section {
  display: flex;
  flex-direction: column;
}

/* Page-flip mechanics */
.flip-wrap {
  flex: 1;
  perspective: 1800px;
}

/* Both faces occupy the same grid cell — the card is always exactly one size,
   and a hidden face keeps its layout (visibility, not display) so it can never
   change the box when revealed. */
.flip-inner {
  height: 100%;
  display: grid;
}

.flip-front,
.flip-back {
  grid-area: 1 / 1;
}

/* The back never contributes to the card's size — Field Notes sets it */
.flip-back {
  contain: size;
  overflow: hidden;
}

.face-hidden {
  visibility: hidden;
}

/* Parchment header bar with flip arrow */
.parchment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
  padding-bottom: 0.7rem;
  border-bottom: 2px solid rgba(139, 105, 20, 0.35);
  position: relative;
  z-index: 1;
}

.parchment-title {
  font-family: 'IM Fell English', 'Playfair Display', Georgia, serif;
  font-size: 1.9rem;
  font-weight: 400;
  color: #4a3520;
  letter-spacing: 0.02em;
}

.flip-btn {
  background: rgba(139, 105, 20, 0.12);
  border: 1px solid rgba(139, 105, 20, 0.45);
  color: #6b4c2a;
  font-size: 1.15rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
}

.flip-btn:hover {
  background: rgba(139, 105, 20, 0.28);
  transform: scale(1.08);
}

/* About side */
.about-list {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 1.2em;
  row-gap: 0.55em;
  align-items: baseline;
}

.about-list {
  font-size: 1.22rem;   /* JS shrinks this if the content overflows the card */
}

.about-list dt {
  font-family: 'IM Fell English', 'Playfair Display', Georgia, serif;
  font-size: 0.86em;
  color: #6b4c2a;
  white-space: nowrap;
}

.about-list dd {
  font-family: 'IM Fell English', 'Playfair Display', Georgia, serif;
  font-size: 1em;
  color: #4a3520;
}

.about-list dd.is-sci {
  font-style: italic;
}

.about-list dd a {
  color: var(--warm-brown);
  text-decoration: underline;
  text-decoration-color: rgba(139, 105, 20, 0.45);
}

.about-list dd a + a {
  margin-left: 1.1rem;
}

.facts-parchment {
  position: relative;
  flex: 1;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(139, 105, 20, 0.14), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(107, 76, 42, 0.20), transparent 50%),
    radial-gradient(ellipse at 70% 30%, rgba(139, 105, 20, 0.08), transparent 45%),
    radial-gradient(ellipse at 8% 75%, rgba(92, 64, 28, 0.12), transparent 40%),
    linear-gradient(160deg, #efe2c2 0%, #e6d5ab 45%, #eaddb8 70%, #ddc795 100%);
  border: 1px solid #b9a070;
  /* Uneven deckled edges */
  border-radius: 12px 4px 14px 5px / 5px 13px 4px 12px;
  box-shadow:
    inset 0 0 26px rgba(92, 64, 28, 0.30),
    inset 0 0 90px rgba(107, 76, 42, 0.22),
    0 4px 18px rgba(61, 43, 31, 0.25);
  padding: 1.85rem 2rem;
  display: flex;
  flex-direction: column;
}

/* Footer bar holding the page-turn arrow, pinned to the bottom of the sheet */
.parchment-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 0.9rem;
  position: relative;
  z-index: 1;
}

/* Fibrous paper grain */
.facts-parchment::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: url("/static/parchment-grain.png");
  background-size: 256px 256px;
  pointer-events: none;
}

/* Scorched corner blots */
.facts-parchment::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 2% 3%, rgba(92, 64, 28, 0.28), transparent 14%),
    radial-gradient(circle at 97% 98%, rgba(92, 64, 28, 0.30), transparent 16%),
    radial-gradient(circle at 98% 4%, rgba(92, 64, 28, 0.18), transparent 10%),
    radial-gradient(circle at 4% 96%, rgba(92, 64, 28, 0.20), transparent 12%);
  pointer-events: none;
}

.facts-parchment > .facts-list {
  position: relative;
  z-index: 1;
}

.facts-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.facts-list li {
  position: relative;
  padding: 0.8rem 0 0.8rem 1.9rem;
  font-family: 'IM Fell English', 'Playfair Display', Georgia, serif;
  font-size: 1.22rem;
  line-height: 1.55;
  color: #4a3520;
  border-bottom: 1px solid rgba(139, 105, 20, 0.22);
}

.facts-list li:last-child { border-bottom: none; }

.facts-list li::before {
  content: '❧';
  position: absolute;
  left: 0.1rem;
  top: 0.85rem;
  color: var(--warm-brown);
  font-size: 0.95rem;
  opacity: 0.7;
}

/* Map */
.map-section {
  display: flex;
  flex-direction: column;
}

.range-summary {
  font-size: 1.12rem;
  font-style: italic;
  color: var(--text-soft);
  margin-bottom: 1rem;
  line-height: 1.6;
}

.map-frame {
  flex: 1;
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(61, 43, 31, 0.08);
}

#rangeMap {
  width: 100%;
  flex: 1;
  min-height: 380px;
  background: var(--parchment);
}

/* ===== Tale / poem ===== */
.tale-section {
  width: 100%;
  background: var(--dark-brown);
  margin-top: 3rem;
  padding: 3.5rem 1.5rem;
}

.tale-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.tale-kind {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin-bottom: 0.85rem;
}

.tale-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.4rem;
  font-weight: 600;
  color: #f5edd8;
  margin-bottom: 1.5rem;
}

.tale-text {
  font-size: 1.28rem;
  line-height: 1.95;
  color: #d9c9a8;
  white-space: pre-line;
  text-align: left;
}

.tale-text.is-poem {
  text-align: center;
  font-style: italic;
}

.tale-note {
  margin-top: 1.75rem;
  font-size: 0.95rem;
  font-style: italic;
  color: #8a7060;
}


/* ===== Site Footer ===== */
.site-footer {
  background: var(--dark-brown);
  color: #8a7060;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  padding: 1.4rem 1rem;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.ebird-link {
  font-size: 1rem;
  color: var(--gold);
  text-decoration: none;
  letter-spacing: 0.02em;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.ebird-link:hover {
  border-color: var(--gold);
}

.photo-credit {
  font-size: 0.7rem;
  color: #6b5645;
  font-style: italic;
}

/* ===== Utility ===== */
[hidden] { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .info-row {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .site-logo { height: 72px; left: 0.75rem; }
}

@media (max-width: 620px) {
  .site-logo { display: none; }
}

@media (max-width: 480px) {
  .bird-identity { padding: 1.75rem 1.25rem 0.5rem; }
  .bird-prose { padding: 1.5rem 1.25rem 0.75rem; }
  .hero { height: 48vh; min-height: 260px; }
  #rangeMap { height: 260px; }
  .tale-section { padding: 2.5rem 1.25rem; }
}
