:root {
  --bg: #0d1117;
  --surface: rgba(17, 24, 32, .72);
  --surface-2: rgba(255, 255, 255, .075);
  --surface-3: rgba(255, 255, 255, .12);
  --text: #f3f6f4;
  --muted: #91a0a8;
  --accent: #ff8a3d;
  --accent-2: #ffd0a8;
  --line: rgba(255, 255, 255, .14);
  --shadow: 0 18px 56px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 14% -8%, rgba(255, 138, 61, .24), transparent 33rem),
    radial-gradient(circle at 86% 8%, rgba(255, 208, 168, .12), transparent 30rem),
    linear-gradient(180deg, #10151c 0%, var(--bg) 52%, #090d12 100%);
  color: var(--text);
  min-height: 100vh;
}

body.modal-open {
  overflow: hidden;
}

button,
select {
  font: inherit;
}

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 0 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-items: end;
  justify-content: flex-end;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text);
  letter-spacing: .08em;
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: #17100c;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 11px;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button,
select {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 13px;
  font-weight: 800;
}

button {
  cursor: pointer;
}

button:hover,
select:hover,
.clickable:hover {
  border-color: var(--accent);
}

#refresh {
  background: var(--accent);
  border-color: var(--accent);
  color: #17100c;
}

.status {
  color: var(--muted);
  margin: 12px 0;
  min-height: 22px;
  font-size: 13px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 14px 0;
}

.stats article,
.panel,
.timeline-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .055));
  backdrop-filter: blur(18px);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats article {
  padding: 18px;
}

.stats span {
  font-size: 36px;
  font-weight: 900;
}

.stats p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.timeline-panel {
  padding: 16px 18px;
  margin: 14px 0;
}

.timeline {
  min-height: 128px;
}

.timeline-strip {
  position: relative;
  height: 100px;
  margin: 2px 12px 0;
}

.timeline-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 22px;
  height: 2px;
  background: linear-gradient(90deg, rgba(255, 138, 61, .15), rgba(255, 138, 61, .9), rgba(255, 208, 168, .2));
}

.timeline-bubble {
  position: absolute;
  bottom: 4px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid rgba(255, 138, 61, .84);
  border-radius: 50%;
  background: rgba(12, 17, 23, .92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
}

.timeline-bubble.lane-1 {
  bottom: 28px;
}

.timeline-bubble.lane-2 {
  bottom: 52px;
}

.timeline-bubble img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.timeline-bubble span {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease;
}

.timeline-bubble:hover span,
.timeline-bubble:focus-visible span {
  opacity: 1;
}

.timeline-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-meta strong {
  color: var(--accent-2);
  text-transform: uppercase;
}

.grid.two {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: 14px;
}

.panel {
  padding: 18px;
  min-height: 560px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.detections {
  display: grid;
  gap: 10px;
}

.detection {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 13px;
  align-items: center;
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  text-align: left;
}

.bird-img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-3);
}

.name {
  font-weight: 850;
  font-size: 15px;
}

.sci {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pills span {
  color: #17100c;
  background: rgba(255, 208, 168, .92);
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  font-weight: 950;
  text-transform: uppercase;
}

.species-card .pills span,
.detection .pills span {
  color: #17100c;
  font-size: 10px;
}

.badge {
  color: #17100c;
  background: var(--accent);
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
}

.species-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.species-card {
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0;
  text-align: left;
}

.species-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--surface-3);
}

.species-card div {
  padding: 12px;
}

.species-card strong {
  display: block;
}

.species-card span {
  color: var(--muted);
  font-size: 13px;
}

.species-card .recent {
  display: block;
  margin-top: 8px;
  color: var(--accent-2);
  font-weight: 800;
}

.clickable {
  cursor: pointer;
  transition: border-color .16s ease, transform .16s ease, background .16s ease;
}

.clickable:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
}

.clickable:hover {
  background: rgba(255, 138, 61, .10);
  transform: translateY(-1px);
}

.empty {
  color: var(--muted);
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 10, .74);
}

.modal-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(540px, 680px);
  overflow: hidden;
  width: min(1120px, calc(100vw - 64px));
  max-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(22, 29, 37, .92), rgba(13, 17, 23, .88));
  backdrop-filter: blur(22px);
  box-shadow: 0 24px 90px rgba(0, 0, 0, .42);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  padding: 0;
  background: rgba(13, 17, 23, .78);
  border-radius: 6px;
  font-size: 24px;
  line-height: 1;
}

.modal-image {
  width: 100%;
  height: 100%;
  min-height: 390px;
  max-height: calc(100vh - 40px);
  object-fit: cover;
  background: var(--surface-3);
}

.modal-body {
  padding: 28px 32px;
  overflow: auto;
}

.modal-body h2 {
  margin: 0;
  font-size: 30px;
}

.modal-scientific {
  margin: 8px 0 20px;
  color: var(--muted);
  font-style: italic;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 0 18px;
}

.facts div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.facts dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.facts dd {
  margin: 5px 0 0;
  font-weight: 850;
}

.wiki-summary {
  display: none;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 138, 61, .08);
}

.wiki-summary.is-visible {
  display: block;
}

.wiki-summary h3 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.wiki-summary p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.modal-note {
  color: var(--muted);
  line-height: 1.5;
}

.detection-history {
  display: none;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.detection-history.is-visible {
  display: block;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.history-head span {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.history-head strong {
  color: var(--text);
}

.history-list {
  display: grid;
  max-height: 180px;
  overflow: auto;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.history-row:last-child {
  border-bottom: 0;
}

.history-row:hover:not(:disabled) {
  background: rgba(255, 138, 61, .10);
}

.history-row:disabled {
  cursor: default;
}

.history-row strong,
.history-row small {
  display: block;
}

.history-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.history-row > span:last-child {
  color: var(--accent-2);
  font-weight: 900;
}

.audio-wrap {
  display: none;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.audio-wrap span {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.audio-wrap audio {
  display: block;
  width: 100%;
}

.waveform {
  display: block;
  width: 100%;
  height: 88px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .055);
}

.audio-wrap.is-visible {
  display: block;
}

@media (max-width: 900px) {
  .grid.two {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  h1 {
    text-align: left;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .species-grid {
    grid-template-columns: 1fr;
  }

  .timeline-bubble {
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 680px) {
  .modal-panel {
    grid-template-columns: 1fr;
  }

  .modal-image {
    min-height: 220px;
    max-height: 38vh;
  }

  .facts {
    grid-template-columns: 1fr;
  }
}

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

  .detection {
    grid-template-columns: 64px 1fr;
  }

  .badge {
    grid-column: 2;
    justify-self: start;
  }

  .bird-img {
    width: 64px;
    height: 64px;
  }
}
