:root {
  color-scheme: light;
  --forest: #173f35;
  --forest-deep: #0d2b24;
  --moss: #587d68;
  --fern: #dce7d8;
  --paper: #f3f0e6;
  --cream: #fffdf6;
  --ochre: #d89032;
  --ink: #18231f;
  --muted: #66716b;
  --line: rgba(23, 63, 53, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 8%, rgba(216, 144, 50, 0.17), transparent 24rem),
    linear-gradient(135deg, #f8f5ea 0%, var(--paper) 65%, #e8eadc 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
  pointer-events: none;
}

button, a { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(1080px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--forest);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 700;
  text-decoration: none;
}

.brand svg { width: 42px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.5; }
.brand svg path:first-child { fill: currentColor; stroke: none; }
.brand svg circle { fill: var(--paper); stroke: none; }
.region { color: var(--moss); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.header-actions, .result-actions { display: flex; gap: 12px; align-items: center; }
.language-button, .clear-button {
  color: var(--forest);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.language-button { width: 42px; height: 36px; }
.clear-button { padding: 10px 13px; }
.language-button:hover, .clear-button:hover { background: rgba(255, 253, 246, 0.7); }
.language-button:focus-visible, .clear-button:focus-visible { outline: 3px solid rgba(216, 144, 50, 0.5); outline-offset: 2px; }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 24px;
  align-items: center;
  min-height: 220px;
  padding: 18px 4%;
}

.eyebrow { margin: 0 0 7px; color: var(--ochre); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.18em; }
h1, h2 { margin: 0; color: var(--forest-deep); font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { max-width: 680px; font-size: clamp(2.25rem, 4vw, 3.35rem); line-height: 0.97; letter-spacing: -0.045em; }
.intro { max-width: 620px; margin: 10px 0 0; color: #4e5d56; font-family: Georgia, "Times New Roman", serif; font-size: 0.94rem; line-height: 1.4; }

.listener { position: relative; display: grid; min-height: 170px; place-items: center; }
.rings, .rings i { position: absolute; inset: 50%; border: 1px solid rgba(23, 63, 53, 0.14); border-radius: 50%; transform: translate(-50%, -50%); }
.rings { width: 150px; height: 150px; }
.rings i:nth-child(1) { width: 74%; height: 74%; }
.rings i:nth-child(2) { width: 48%; height: 48%; }
.rings i:nth-child(3) { width: 122%; height: 122%; }

.listen-button {
  position: relative;
  z-index: 2;
  display: grid;
  width: 84px;
  height: 84px;
  padding: 12px;
  color: #fffdf7;
  background: var(--forest);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 12px 30px rgba(13, 43, 36, 0.24);
  cursor: pointer;
  place-content: center;
  transition: transform 180ms ease, background 180ms ease;
}

.listen-button:hover { background: #205648; transform: translateY(-3px); }
.listen-button:focus-visible { outline: 4px solid rgba(216, 144, 50, 0.5); outline-offset: 6px; }
.listen-button svg { width: 24px; margin: 0 auto 3px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }
.listen-button span { font-size: 0.59rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }

.listener.active .listen-button { background: #a94836; }
.listener.active .rings i { animation: pulse 2.4s ease-out infinite; }
.listener.active .rings i:nth-child(2) { animation-delay: 0.6s; }
.listener.active .rings i:nth-child(3) { animation-delay: 1.2s; }

@keyframes pulse {
  0% { opacity: 0.8; transform: translate(-50%, -50%) scale(0.78); }
  75%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
}

.status-panel {
  display: flex;
  gap: 15px;
  align-items: center;
  padding: 12px 16px;
  color: var(--forest-deep);
  background: rgba(255, 253, 246, 0.75);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(31, 52, 44, 0.05);
}

.status-dot { flex: 0 0 auto; width: 10px; height: 10px; background: var(--moss); border-radius: 50%; box-shadow: 0 0 0 5px rgba(88, 125, 104, 0.12); }
.status-panel strong { font-size: 0.92rem; }
.status-panel p { margin: 3px 0 0; color: var(--muted); font-size: 0.82rem; }
.status-panel.listening .status-dot { background: var(--ochre); box-shadow: 0 0 0 5px rgba(216, 144, 50, 0.14); }
.status-panel.error .status-dot { background: #a94836; box-shadow: 0 0 0 5px rgba(169, 72, 54, 0.12); }

.results-section { margin-top: 20px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 14px; }
.section-heading h2 { font-size: clamp(1.65rem, 3vw, 2.35rem); letter-spacing: -0.035em; }
.count { display: grid; width: 44px; height: 44px; color: var(--cream); background: var(--forest); border-radius: 50%; font-family: Georgia, serif; font-size: 1.15rem; place-items: center; }

.empty-state { display: grid; min-height: 220px; color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); place-content: center; text-align: center; }
.empty-state svg { width: 120px; margin: 0 auto 12px; fill: none; stroke: var(--moss); stroke-linecap: round; stroke-width: 2; }
.empty-state p { max-width: 340px; margin: 0; font-family: Georgia, serif; font-size: 1.05rem; }
.empty-state.hidden { display: none; }

.results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.bird-card { display: grid; grid-template-columns: 152px minmax(0, 1fr); min-height: 178px; overflow: hidden; background: var(--cream); border: 1px solid var(--line); animation: reveal 350ms ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(12px); } }
.bird-photo { position: relative; min-height: 178px; overflow: hidden; background: var(--fern); }
.bird-photo img { width: 100%; height: 100%; object-fit: cover; }
.bird-photo .fallback { display: grid; width: 100%; height: 100%; color: var(--moss); place-items: center; }
.bird-photo .fallback svg { width: 58px; fill: currentColor; }
.bird-info { display: flex; flex-direction: column; padding: 19px 20px 17px; }
.confidence { align-self: flex-start; margin-bottom: auto; padding: 5px 8px; color: var(--forest); background: var(--fern); border-radius: 2px; font-size: 0.72rem; font-weight: 800; }
.bird-info h3 { margin: 16px 0 4px; color: var(--forest-deep); font-family: Georgia, serif; font-size: 1.34rem; font-weight: 500; line-height: 1.08; }
.scientific { margin: 0; color: var(--muted); font-size: 0.8rem; font-style: italic; }
.last-seen { margin: 7px 0 0; color: var(--ochre); font-size: 0.67rem; font-weight: 700; }
.source { margin-top: 10px; color: var(--moss); font-size: 0.68rem; text-decoration: none; }
.source:hover { text-decoration: underline; }
.bird-card.updated { animation: result-refresh 650ms ease; }
@keyframes result-refresh {
  0% { border-color: var(--ochre); box-shadow: 0 0 0 0 rgba(216, 144, 50, 0.34); }
  100% { border-color: var(--line); box-shadow: 0 0 0 9px rgba(216, 144, 50, 0); }
}

footer { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 72px; padding-top: 24px; color: #6d756f; border-top: 1px solid var(--line); font-size: 0.72rem; line-height: 1.55; }
footer p { margin: 0; }

.continue-dialog {
  width: min(460px, calc(100% - 32px));
  padding: 34px;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(13, 43, 36, 0.35);
}
.continue-dialog::backdrop { background: rgba(13, 43, 36, 0.72); backdrop-filter: blur(4px); }
.dialog-mark { margin-bottom: 22px; color: var(--ochre); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.16em; }
.continue-dialog h2 { font-size: 2.2rem; line-height: 1; }
.continue-dialog p { margin: 18px 0 28px; color: var(--muted); line-height: 1.6; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-actions button { padding: 12px 16px; border: 1px solid var(--forest); cursor: pointer; font: inherit; font-size: 0.8rem; font-weight: 800; }
.dialog-primary { color: var(--cream); background: var(--forest); }
.dialog-secondary { color: var(--forest); background: transparent; }

@media (max-width: 760px) {
  .shell { width: min(100% - 28px, 620px); padding-top: 17px; }
  .region { max-width: 130px; text-align: right; }
  .header-actions { gap: 7px; }
  .hero { grid-template-columns: minmax(0, 1fr) 112px; gap: 10px; min-height: 190px; padding: 20px 0 14px; }
  h1 { font-size: clamp(2rem, 9.5vw, 3rem); }
  .intro { margin-top: 10px; font-size: 0.86rem; line-height: 1.35; }
  .listener { min-height: 140px; }
  .rings { width: 108px; height: 108px; }
  .listen-button { width: 72px; height: 72px; padding: 9px; }
  .listen-button svg { width: 21px; }
  .listen-button span { font-size: 0.52rem; }
  .results-section { margin-top: 20px; }
  .results { grid-template-columns: 1fr; }
  .section-heading { align-items: center; }
  .clear-button { max-width: 92px; padding: 8px; }
  footer { grid-template-columns: 1fr; gap: 12px; }
}

@media (max-width: 420px) {
  .bird-card { grid-template-columns: 118px minmax(0, 1fr); }
  .bird-info { padding-inline: 15px; }
  .bird-info h3 { font-size: 1.18rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
