:root {
  --ink: #0b1d22; --deep: #0f2a2c; --teal: #1d5a5c; --teal2: #2f7f7b; --sage: #a9c7a4;
  --silver: #dbe9ef; --mist: #9fc3cf; --gold: #f2c64d; --gold2: #e3a72f; --text: #eef6f3; --dim: #a9c4c0;
  --r: 18px; --ease: cubic-bezier(.22, 1, .36, 1);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; color: var(--text); background: var(--ink);
  font: 16px/1.5 Rubik, system-ui, sans-serif; overflow-x: hidden;
}
.bg {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, rgba(11, 29, 34, .25), rgba(11, 29, 34, .78) 55%, rgba(11, 29, 34, .94)),
    url(img/bg.webp) center top / cover no-repeat, var(--ink);
}
button, a { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--mist); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 8px; }

.top { text-align: center; padding: max(14px, env(safe-area-inset-top)) 16px 4px; }
.logo { width: min(440px, 86vw); height: auto; display: block; margin: 0 auto -4px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .55)); }
.logo-text { font: 400 clamp(34px, 11vw, 54px)/1.1 "Secular One", sans-serif; letter-spacing: .04em; color: var(--silver); text-shadow: 0 3px 0 #23465a, 0 6px 14px rgba(0,0,0,.6); }
.sub { margin: 2px 0 0; color: var(--silver); font-size: 15px; text-shadow: 0 1px 6px #000; }

.tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; justify-content: center;
  margin: 10px auto 0; padding: 8px; max-width: 560px;
}
.tabs::before {
  content: ""; position: absolute; inset: 4px 6px; border-radius: 999px; z-index: -1;
  background: rgba(11, 29, 34, .82); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(159, 195, 207, .25);
}
.tabs button {
  flex: 1 1 auto; min-height: 40px; padding: 6px 8px; border-radius: 999px; font-weight: 500; font-size: 15px; white-space: nowrap; color: var(--dim);
  transition: background .2s var(--ease), color .2s;
}
.tabs button[aria-selected="true"] { background: var(--teal); color: #fff; box-shadow: inset 0 0 0 1px rgba(219, 233, 239, .35); }

main { max-width: 560px; margin: 0 auto; padding: 8px 14px 24px; }

/* ---------- card ---------- */
.card {
  position: relative; padding: 6px 4px 10px;
  border-style: solid; border-color: transparent;
  border-width: min(58px, 11vw) min(57px, 11vw) min(66px, 12.5vw) min(57px, 11vw);
  border-image: url(img/frame.webp) 115 115 133 114 stretch;
  background: radial-gradient(120% 80% at 50% 0%, #1d4b4c, #0d2326 70%) border-box;
  border-radius: 22px; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55));
}
.card.in { animation: cardIn .45s var(--ease); }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.photo {
  position: relative; aspect-ratio: 1 / .86; overflow: hidden; border-radius: 10px; background: #08171a;
  box-shadow: 0 0 0 1px rgba(159, 195, 207, .35), 0 6px 16px rgba(0, 0, 0, .45);
}
.photo iframe { border: 0; width: 100%; height: 100%; display: block; background: #08171a; }
.photo.loading::after {
  content: ""; position: absolute; left: 50%; top: 50%; margin: -19px; width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(159, 195, 207, .25); border-top-color: var(--mist); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.names { text-align: center; margin-top: 8px; }
.names h1 {
  margin: 0; font: 400 clamp(26px, 7.5vw, 38px)/1.1 "Secular One", Rubik, sans-serif; color: var(--gold);
  text-shadow: 0 2px 0 #7a4f12, 0 4px 12px rgba(0, 0, 0, .6);
}
.names .en { margin: 2px 0 0; color: var(--dim); font-size: 15px; direction: ltr; }

.iucn {
  display: inline-flex; align-items: center; gap: 8px; margin: 8px 0 0; padding: 4px 12px 4px 4px; border-radius: 999px;
  font-size: 14px; font-weight: 500; background: rgba(11, 29, 34, .7); box-shadow: inset 0 0 0 1px var(--c, #6fae7a);
}
.iucn b { display: inline-grid; place-items: center; min-width: 34px; height: 26px; border-radius: 999px; background: var(--c); color: var(--fg, #0b1d22); font-weight: 700; font-size: 13px; direction: ltr; }
.iucn-mini { font-style: normal; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--c); color: var(--fg, #0b1d22); vertical-align: 2px; }
.s-LC { --c: #6fae7a; } .s-NT { --c: #c8d36a; } .s-VU { --c: #f2c64d; } .s-EN { --c: #ef8a3c; }
.s-CR { --c: #e2503f; --fg: #fff; } .s-EW, .s-EX { --c: #1b1b1b; --fg: #fff; } .s-DD { --c: #9aa5a8; }
.ask, .reveal { margin-top: 12px; text-align: center; }
.q { margin: 0 0 8px; font-weight: 500; color: var(--silver); }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; direction: ltr; }
@media (max-width: 520px) { .scale { grid-template-columns: repeat(5, 1fr); gap: 6px; } .f { aspect-ratio: auto; height: 54px; } }
.f {
  position: relative; aspect-ratio: 1 / 1.35; min-height: 44px; border-radius: 10px; padding: 0;
  background: rgba(159, 195, 207, .08); box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .22);
  transition: transform .18s var(--ease), background .18s;
}
.f img { position: absolute; inset: 6% 8% 26%; width: 84%; height: 68%; object-fit: contain; opacity: .38; transition: opacity .18s, filter .18s; }
.f span { position: absolute; bottom: 3px; left: 0; right: 0; font-weight: 700; font-size: 14px; }
.f.lit { background: rgba(47, 127, 123, .45); }
.f.lit img { opacity: 1; filter: drop-shadow(0 0 6px rgba(219, 233, 239, .8)); }
.f:active { transform: scale(.92); }
.f.picked { background: var(--gold2); color: var(--ink); }
.f.picked img { opacity: 1; }
@media (hover: hover) { .f:hover { transform: translateY(-3px); } }

.row { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.ghost { padding: 10px 14px; min-height: 44px; display: inline-flex; align-items: center; border-radius: 999px; color: var(--mist); text-decoration: none; font-size: 15px; }
.ghost:active { background: rgba(159, 195, 207, .12); }
.gold {
  min-height: 48px; padding: 10px 26px; border-radius: 999px; font-weight: 700; font-size: 17px; color: var(--ink);
  background: linear-gradient(180deg, var(--gold), var(--gold2)); box-shadow: 0 4px 0 #8a5b14, 0 8px 18px rgba(0, 0, 0, .4);
  transition: transform .12s var(--ease), box-shadow .12s;
}
.gold:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5b14, 0 4px 10px rgba(0, 0, 0, .4); }

.verdict { display: flex; gap: 10px; justify-content: center; }
.stat { flex: 1; max-width: 190px; padding: 10px; border-radius: 16px; background: rgba(159, 195, 207, .08); box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .2); }
.stat .lbl { display: block; color: var(--dim); font-size: 14px; }
.stat b { display: block; font: 400 44px/1.05 "Secular One", sans-serif; }
.stat small { color: var(--dim); font-size: 13px; }
.stat.crowd b { color: var(--gold); }
.line { margin: 10px 0 0; color: var(--silver); }
.reveal.pop .stat { animation: pop .5s var(--ease) both; }
.reveal.pop .stat.crowd { animation-delay: .12s; }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
.counter { text-align: center; color: var(--dim); font-size: 14px; margin: 12px 0 0; }

/* ---------- lists ---------- */
.h { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0 0; font: 400 28px/1.2 "Secular One", sans-serif; color: var(--gold); text-shadow: 0 2px 8px #000; }
.ico { width: 42px; height: 42px; object-fit: contain; }
.note { text-align: center; color: var(--dim); margin: 2px 0 12px; }
.empty { text-align: center; color: var(--silver); padding: 24px 8px; }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 8px; align-items: end; }
.p {
  display: flex; flex-direction: column; align-items: center; text-decoration: none; color: var(--text);
  background: rgba(11, 29, 34, .85); border-radius: 16px; padding: 8px 6px 10px; box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .25);
}
.p1 { box-shadow: inset 0 0 0 2px var(--gold), 0 0 24px rgba(242, 198, 77, .25); padding-bottom: 16px; }
.place { font: 400 22px/1 "Secular One", sans-serif; color: var(--gold); }
.pimg { width: 100%; aspect-ratio: 1; border-radius: 10px; overflow: hidden; margin: 6px 0; pointer-events: none; }
.pimg iframe { border: 0; width: 100%; height: 100%; }
.p .nm { font-weight: 700; text-align: center; line-height: 1.2; }
.p .sc { font: 400 24px/1.1 "Secular One", sans-serif; color: var(--gold); }
.p .cnt { font-size: 12px; color: var(--dim); }

.list { list-style: none; padding: 0; margin: 14px 0 0; counter-reset: n; }
.list[start="4"] { counter-reset: n 3; }
.list li {
  counter-increment: n; display: grid; grid-template-columns: 28px 1fr auto; grid-template-areas: "i a s" "i a u"; align-items: center;
  column-gap: 8px; padding: 10px 12px; margin-bottom: 6px; border-radius: 14px; background: rgba(11, 29, 34, .82); box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .15);
}
.list li::before { content: counter(n); grid-area: i; color: var(--mist); font-weight: 700; text-align: center; }
.list a { grid-area: a; text-decoration: none; color: var(--text); min-width: 0; }
.list .nm { display: block; font-weight: 700; }
.list .nm { direction: ltr; text-align: right; }
.list .en { direction: ltr; text-align: right; font-style: italic; display: block; font-size: 13px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sc { grid-area: s; font: 400 22px/1 "Secular One", sans-serif; color: var(--gold); text-align: left; }
.list .sub { grid-area: u; font-size: 12px; color: var(--dim); text-align: left; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0 0; }
.seg button { padding: 8px 14px; min-height: 40px; border-radius: 999px; background: rgba(11, 29, 34, .8); color: var(--dim); box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .25); }
.seg button[aria-pressed="true"] { background: var(--teal); color: #fff; }

.fun { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.fact { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 6px; border-radius: 14px; background: rgba(11, 29, 34, .82); text-decoration: none; color: var(--text); box-shadow: inset 0 0 0 1px rgba(159, 195, 207, .15); }
.fact span { font-size: 12px; color: var(--dim); }
.fact b { font-weight: 700; line-height: 1.25; margin: 2px 0; }
.fact small { font-size: 12px; color: var(--mist); }

.foot { max-width: 560px; margin: 0 auto; padding: 8px 18px max(24px, env(safe-area-inset-bottom)); text-align: center; font-size: 12px; color: var(--dim); }

.view[hidden], [hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- phones: the whole bird on one screen ---------- */
@media (max-width: 520px) {
  .top { padding: max(8px, env(safe-area-inset-top)) 12px 0; }
  .logo { width: min(300px, 70vw); margin-bottom: 0; }
  .logo-text { font-size: 30px; }
  .sub { font-size: 13px; line-height: 1.35; margin-top: 2px; }
  .tabs { margin-top: 4px; padding: 6px 8px; gap: 2px; }
  .tabs::before { inset: 3px 6px; }
  .tabs button { min-height: 38px; font-size: 14px; padding: 4px 6px; }
  main { padding: 4px 10px 16px; }

  .card {
    border-width: min(42px, 8.6vw) min(41px, 8.4vw) min(48px, 9.8vw) min(41px, 8.4vw);
    padding: 2px 0 6px; border-radius: 18px;
  }
  .photo { width: min(100%, calc(31dvh / .86)); margin: 0 auto; border-radius: 8px; }
  .names { margin-top: 6px; }
  .names h1 { font-size: clamp(22px, 6.6vw, 30px); }
  .names .en { font-size: 13px; margin: 0; }
  .iucn { margin-top: 5px; font-size: 13px; padding: 2px 10px 2px 3px; }
  .iucn b { height: 22px; min-width: 30px; font-size: 12px; }

  .ask, .reveal { margin-top: 8px; }
  .q { margin-bottom: 6px; font-size: 15px; }
  .scale { gap: 5px; }
  .f { width: 100%; height: 46px; aspect-ratio: auto; border-radius: 9px; }
  .f img { inset: 4px 18% 16px; width: 64%; height: calc(100% - 20px); }
  .f span { bottom: 2px; font-size: 13px; }
  .row { margin-top: 6px; gap: 4px; }
  .ghost { font-size: 14px; padding: 8px 10px; }
  .gold { min-height: 46px; font-size: 16px; padding: 8px 22px; }
  .stat { padding: 8px; }
  .stat b { font-size: 36px; }
  .line { margin-top: 6px; font-size: 14px; }
  .counter { margin-top: 8px; font-size: 13px; }

  .h { font-size: 24px; }
  .ico { width: 34px; height: 34px; }
  .podium { gap: 6px; }
  .p { padding: 6px 4px 8px; }
  .p .nm { font-size: 13px; direction: ltr; }
  .p .sc { font-size: 20px; }
  .fun { gap: 6px; }
  .fact b { font-size: 13px; direction: ltr; }
  .list li { padding: 8px 10px; }
  .seg button { min-height: 38px; padding: 6px 12px; font-size: 14px; }
}
/* short phones (iPhone SE and similar): drop the tagline */
@media (max-width: 520px) and (max-height: 700px) {
  .sub { display: none; }
  .logo { width: min(240px, 60vw); }
  .photo { width: min(100%, calc(27dvh / .86)); }
  .names h1 { font-size: 22px; }
  .q { display: none; }
  .f { height: 42px; }
  .stat { padding: 6px; } .stat b { font-size: 30px; } .stat .lbl, .stat small { font-size: 12px; }
}
html, body { overflow-x: clip; }

/* ---------- motion + touch feedback ---------- */
:root {
  --dur-instant: 90ms; --dur-fast: 160ms; --dur-base: 240ms; --dur-medium: 360ms;
  --ease-out: cubic-bezier(.16, 1, .3, 1); --ease-in: cubic-bezier(.55, 0, 1, .45); --ease-pop: cubic-bezier(.34, 1.36, .64, 1);
  --dir: 1;
}
[dir="rtl"] { --dir: -1; }

/* tabs: one indicator slides to the chosen tab */
.tabs .ind {
  position: absolute; top: 8px; bottom: 8px; left: 0; width: 0; border-radius: 999px; z-index: 0;
  background: var(--teal); box-shadow: inset 0 0 0 1px rgba(219, 233, 239, .35);
  transition: transform var(--dur-base) var(--ease-out), width var(--dur-base) var(--ease-out);
}
@media (max-width: 520px) { .tabs .ind { top: 6px; bottom: 6px; } }
.tabs button { position: relative; z-index: 1; }
.tabs button[aria-selected="true"] { background: none; box-shadow: none; }
.tabs button:active { transform: scale(.96); transition: transform var(--dur-instant); }

/* views arrive with a short rise */
.view.enter { animation: viewIn var(--dur-medium) var(--ease-out) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } }

/* the card: leaves forward, the next bird arrives from behind */
.card.in { animation: cardIn var(--dur-medium) var(--ease-out) both; }
.card.out { animation: cardOut 200ms var(--ease-in) both; pointer-events: none; }
@keyframes cardIn { from { opacity: 0; transform: translateX(calc(var(--dir) * -36px)) rotate(calc(var(--dir) * -1.5deg)); } }
@keyframes cardOut { to { opacity: 0; transform: translateX(calc(var(--dir) * 44px)) rotate(calc(var(--dir) * 2deg)); } }

/* photo fades in when the embed has loaded */
.photo iframe { opacity: 0; transition: opacity var(--dur-medium) var(--ease-out); }
.photo.ready iframe { opacity: 1; }

/* threatened birds: one glow when they arrive */
.card.in .iucn:is(.s-VU, .s-EN, .s-CR, .s-EW, .s-EX) { animation: glow 1.1s var(--ease-out) .35s both; }
@keyframes glow { 0% { box-shadow: inset 0 0 0 1px var(--c), 0 0 0 0 var(--c); } 40% { box-shadow: inset 0 0 0 1px var(--c), 0 0 18px 2px var(--c); } 100% { box-shadow: inset 0 0 0 1px var(--c), 0 0 0 0 transparent; } }

/* feathers: press, fill up to the score, the chosen one pops */
.f { transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast); touch-action: manipulation; }
.f:active { transform: scale(.9); transition-duration: var(--dur-instant); }
.f.fill { animation: fill var(--dur-base) var(--ease-pop) var(--d, 0ms) both; }
.f.fill img { opacity: 1; filter: drop-shadow(0 0 6px rgba(219, 233, 239, .8)); transition-delay: var(--d, 0ms); }
.f.picked { animation: pick 420ms var(--ease-pop) var(--d, 0ms) both; }
@keyframes fill { 0% { transform: scale(1); background: rgba(159, 195, 207, .08); } 50% { transform: scale(1.1); } 100% { transform: scale(1); background: rgba(47, 127, 123, .55); } }
@keyframes pick { 0% { transform: scale(1); } 45% { transform: scale(1.22) rotate(calc(var(--dir) * -4deg)); background: var(--gold); } 100% { transform: scale(1.04); background: var(--gold2); } }
.fx-feather { position: fixed; z-index: 60; pointer-events: none; filter: drop-shadow(0 0 6px rgba(219, 233, 239, .7)); will-change: transform, opacity; }

/* the question gives way to the verdict */
.ask.leave { opacity: 0; transform: translateY(6px); transition: opacity 150ms var(--ease-in), transform 150ms var(--ease-in); }
.ask.back { animation: viewIn var(--dur-base) var(--ease-out) both; }
.reveal.pop .line { animation: viewIn var(--dur-medium) var(--ease-out) .3s both; }
.reveal.pop .row { animation: viewIn var(--dur-medium) var(--ease-out) .42s both; }

/* buttons answer the touch */
.ghost, .seg button, .fact, .list a { transition: transform var(--dur-instant) var(--ease-out); }
.ghost:active, .seg button:active, .fact:active { transform: scale(.96); }

/* lists and podium */
.view.enter .list li, .list.fresh li { animation: rowIn var(--dur-medium) var(--ease-out) calc(var(--i, 0) * 40ms) both; }
@keyframes rowIn { from { opacity: 0; transform: translateY(8px); } }
.view.enter .p { animation: rise 480ms var(--ease-out) both; }
.view.enter .p2 { animation-delay: 60ms; } .view.enter .p3 { animation-delay: 140ms; }
.view.enter .p1 { animation: rise 560ms var(--ease-pop) 220ms both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } }
.view.enter .fact { animation: rowIn var(--dur-medium) var(--ease-out) .35s both; }
.f.fill { background: rgba(47, 127, 123, .55); }
.f.picked { background: var(--gold2); }

/* ---------- first-visit intro ---------- */
.intro-cover { display: none; }
html.intro .intro-cover {
  display: grid; place-items: center; position: fixed; inset: 0; z-index: 50; background: rgba(11, 29, 34, 1);
}
.intro-bg { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,29,34,.15), rgba(11,29,34,.75)), url(img/bg.webp) center / cover; }
.intro-cover img { position: relative; width: min(82vw, 560px); height: auto; opacity: 0; filter: drop-shadow(0 6px 18px rgba(0,0,0,.6)); }
html.intro .top .logo { opacity: 0; }
html.intro body { overflow: hidden; }

/* ---------- maker logo ---------- */
.maker { display: block; width: fit-content; margin: 14px auto 0; opacity: .6; transition: opacity var(--dur-fast), transform var(--dur-instant) var(--ease-out); }
.maker img { display: block; width: 54px; height: auto; }
.maker:hover, .maker:focus-visible { opacity: 1; }
.maker:active { transform: scale(.94); }

/* ---------- install suggestion ---------- */
.install {
  position: fixed; z-index: 40; inset-inline: 10px; bottom: max(10px, env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 8px;
  border-radius: 20px; background: rgba(15, 42, 44, .96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(0,0,0,.55), inset 0 0 0 1px rgba(159,195,207,.3);
}
.install img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.install .txt { flex: 1; min-width: 0; line-height: 1.3; }
.install .txt b { display: block; font-size: 15px; }
.install .txt span { display: block; font-size: 13px; color: var(--dim); }
.gold.sm { min-height: 40px; padding: 6px 16px; font-size: 15px; box-shadow: 0 3px 0 #8a5b14; flex: none; }
.install .x { width: 40px; height: 40px; border-radius: 50%; color: var(--dim); font-size: 16px; flex: none; }
.install .x:active { background: rgba(159,195,207,.12); }
.install.in { animation: sheetIn var(--dur-medium) var(--ease-out) both; }
.install.out { animation: sheetOut 230ms var(--ease-in) both; pointer-events: none; }
@keyframes sheetIn { from { opacity: 0; transform: translateY(24px); } }
@keyframes sheetOut { to { opacity: 0; transform: translateY(24px); } }

.credit { margin: 14px 0 0; font-size: 13px; color: var(--silver); }
.credit a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(219,233,239,.4); }
.maker { margin-top: 8px; }

/* iNaturalist photos: a picture that links to the species page, credit on the photo */
.photo .inat { position: absolute; inset: 0; display: block; color: #fff; text-decoration: none; }
.photo img, .pimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo img { opacity: 0; transition: opacity var(--dur-medium) var(--ease-out); }
.photo.ready img { opacity: 1; }
.inat-credit {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 10px 6px; font-size: 11px; line-height: 1.3; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72)); color: rgba(255, 255, 255, .9);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
