/* dexieworks: "morning aviary" palette, light by default, dusk in dark mode. */
:root {
  color-scheme: light dark;
  --bg-top: #fff6e6;
  --bg-bottom: #fde3c3;
  --ink: #2a2733;
  --muted: #5f5a68;
  --soft: #857f8c;
  --card: rgba(255, 255, 255, 0.72);
  --card-border: rgba(42, 39, 51, 0.1);
  --sun: #f6c343;
  --sun-ink: #2a2108;
  --cheek: #ef7d3c;
  --teal: #1f7f75;
  --teal-hover: #196a62;
  --cloud: rgba(255, 255, 255, 0.85);
  --feather: #b9b2a6;
  --focus: #1f7f75;
  --shadow: 0 24px 48px -28px rgba(80, 50, 20, 0.45);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #141a2e;
    --bg-bottom: #2b2847;
    --ink: #f6f0e6;
    --muted: #c9c2d6;
    --soft: #a39cb3;
    --card: rgba(255, 255, 255, 0.07);
    --card-border: rgba(255, 255, 255, 0.12);
    --teal: #63d0c1;
    --teal-hover: #86ddd1;
    --cloud: rgba(255, 255, 255, 0.07);
    --feather: #7e7897;
    --focus: #ffd66b;
    --shadow: 0 24px 48px -28px rgba(0, 0, 0, 0.8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* No grey/blue flash over tapped elements on mobile browsers. */
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100svh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%) fixed;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: rgba(246, 195, 67, 0.45); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }

/* ---------------------------------------------------------------- ambience */
.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.cloud {
  position: absolute;
  width: 180px;
  height: 56px;
  border-radius: 999px;
  background: var(--cloud);
  filter: blur(1px);
  animation: drift-x linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}
.cloud::before { width: 84px; height: 84px; left: 26px; top: -38px; }
.cloud::after { width: 64px; height: 64px; left: 88px; top: -26px; }
.c1 { top: 12%; animation-duration: 70s; animation-delay: -10s; }
.c2 { top: 34%; animation-duration: 95s; animation-delay: -60s; transform: scale(0.7); }
.c3 { top: 70%; animation-duration: 120s; animation-delay: -30s; transform: scale(0.85); }

@keyframes drift-x {
  from { left: -240px; }
  to { left: 110vw; }
}

.feather {
  position: absolute;
  top: -40px;
  width: 14px;
  height: 30px;
  border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
  background: var(--feather);
  opacity: 0;
  animation: fall linear infinite;
}
.f1 { left: 8%; animation-duration: 21s; animation-delay: 1s; }
.f2 { left: 36%; animation-duration: 26s; animation-delay: 9s; transform: scale(0.7); }
.f3 { left: 64%; animation-duration: 23s; animation-delay: 4s; }
.f4 { left: 90%; animation-duration: 29s; animation-delay: 14s; transform: scale(0.6); }

@keyframes fall {
  0% { opacity: 0; transform: translate3d(0, 0, 0) rotate(0deg); }
  10% { opacity: 0.45; }
  50% { transform: translate3d(40px, 55vh, 0) rotate(160deg); }
  90% { opacity: 0.3; }
  100% { opacity: 0; transform: translate3d(-10px, 115vh, 0) rotate(320deg); }
}

/* ------------------------------------------------------------------ layout */
.page {
  position: relative;
  z-index: 1;
  width: min(68rem, 100%);
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3rem) clamp(1rem, 4vw, 2.5rem) 2rem;
  display: grid;
  gap: clamp(2rem, 5vw, 3.5rem);
}

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  align-items: center;
  gap: clamp(1rem, 4vw, 3rem);
  min-height: min(38rem, 78svh);
}

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; text-align: center; min-height: 0; }
  .stage { order: -1; }
  .actions { justify-content: center; }
}

.reveal { animation: rise 800ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.r1 { animation-delay: 0ms; }
.r2 { animation-delay: 90ms; }
.r3 { animation-delay: 180ms; }
.r4 { animation-delay: 270ms; }
.r5 { animation-delay: 360ms; }

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------------- text */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--cheek);
  box-shadow: 0 0 0 0 rgba(239, 125, 60, 0.6);
  animation: pulse 2.2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 125, 60, 0.55); }
  80%, 100% { box-shadow: 0 0 0 10px rgba(239, 125, 60, 0); }
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 5.5rem);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
}
h1 .accent {
  background: linear-gradient(100deg, var(--sun) 10%, var(--cheek) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.quip {
  max-width: 32rem;
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2.4vw, 1.3rem);
  text-wrap: balance;
  min-height: 3.2em;
}
@media (max-width: 760px) { .quip { margin-inline: auto; } }

.quip .caret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--cheek);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.lead { margin: 0.6rem 0 0; color: var(--soft); font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.6rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.5rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 180ms ease, background-color 180ms ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary {
  background: var(--sun);
  color: var(--sun-ink);
  box-shadow: 0 14px 26px -14px rgba(239, 125, 60, 0.95);
}
.btn-primary:hover { box-shadow: 0 20px 32px -16px rgba(239, 125, 60, 1); }
.btn-ghost {
  background: var(--card);
  color: var(--teal);
  border: 1.5px solid var(--card-border);
}
.btn-ghost:hover { color: var(--teal-hover); }

/* -------------------------------------------------------------------- bird */
.stage { position: relative; display: grid; justify-items: center; }

.bird-button {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.bird {
  display: block;
  width: clamp(13rem, 34vw, 21rem);
  height: auto;
  overflow: visible;
  filter: drop-shadow(var(--shadow));
}
.bird-body { transform-origin: 110px 236px; animation: breathe 4.8s ease-in-out infinite; }
.head { transform-box: view-box; transform-origin: 104px 122px; transition: transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.crest { transform-box: view-box; transform-origin: 104px 70px; animation: crest-idle 7s ease-in-out infinite; }
.wing { transform-box: view-box; transform-origin: 118px 132px; }
.tail { transform-box: view-box; transform-origin: 124px 212px; animation: tail-idle 5s ease-in-out infinite; }
.lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); animation: blink-eye 5.5s infinite; }

@keyframes breathe {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.012, 0.992); }
}
@keyframes crest-idle {
  0%, 80%, 100% { transform: rotate(0deg); }
  86% { transform: rotate(-4deg); }
  92% { transform: rotate(2deg); }
}
@keyframes tail-idle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-2deg); }
}
@keyframes blink-eye {
  0%, 94%, 100% { transform: scaleY(0); }
  96% { transform: scaleY(1); }
}

/* excited: crest straight up, wings flutter, head bob (added by app.js on tap) */
.bird-button.excited .crest { animation: crest-up 900ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.bird-button.excited .wing { animation: flutter 600ms ease-in-out; }
.bird-button.excited .bird-body { animation: hop 600ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.bird-button.excited .cheek { animation: blush 900ms ease; }

@keyframes crest-up {
  0% { transform: rotate(0deg) scale(1); }
  30% { transform: rotate(-14deg) scale(1.08); }
  70% { transform: rotate(-10deg) scale(1.05); }
  100% { transform: rotate(0deg) scale(1); }
}
@keyframes flutter {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-16deg); }
  40% { transform: rotate(4deg); }
  60% { transform: rotate(-12deg); }
  80% { transform: rotate(2deg); }
}
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
}
@keyframes blush {
  50% { transform: scale(1.15); filter: saturate(1.4); }
}
.cheek { transform-box: fill-box; transform-origin: center; }

.scritches { margin: 0.4rem 0 0; color: var(--soft); font-size: 0.9rem; font-weight: 600; }

.bubble {
  position: absolute;
  top: 2%;
  left: 2%;
  z-index: 2;
  max-width: 13rem;
  margin: 0;
  padding: 0.55rem 0.9rem;
  border-radius: 16px 16px 16px 4px;
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  font-weight: 700;
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  transition: opacity 220ms ease, transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.bubble.show { opacity: 1; transform: none; }

.sparks { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.spark {
  position: absolute;
  font-size: 1.4rem;
  animation: spark-up 1100ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes spark-up {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5) rotate(0deg); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 0), -110px) scale(1.2) rotate(var(--rot, 0deg)); }
}

/* ------------------------------------------------------------------- facts */
.facts {
  width: min(44rem, 100%);
  margin: 0 auto;
  padding: clamp(1.1rem, 3vw, 1.6rem);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.facts-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.facts h2 { margin: 0; font-size: 1.05rem; letter-spacing: 0.02em; }
.fact-count { color: var(--soft); font-weight: 600; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--sun); border-color: var(--sun); color: var(--sun-ink); }

.fact-card { margin: 1rem 0 0; min-height: 7.5rem; touch-action: pan-y; }
.fact-text {
  margin: 0;
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  font-weight: 600;
  line-height: 1.5;
  text-wrap: pretty;
}
.fact-source { margin-top: 0.6rem; color: var(--soft); font-size: 0.85rem; }
.fact-source a { color: var(--teal); text-underline-offset: 0.2em; }
.fact-card.swap-out { animation: fact-out 220ms ease forwards; }
.fact-card.swap-in { animation: fact-in 380ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes fact-out { to { opacity: 0; transform: translateX(var(--swap-dir, -16px)); } }
@keyframes fact-in { from { opacity: 0; transform: translateX(calc(var(--swap-dir, -16px) * -1)); } }

.fact-controls { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; }
.progress {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--card-border);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--sun), var(--cheek));
  transform-origin: left;
  transform: scaleX(0);
}
.progress span.run { animation: progress var(--fact-ms, 12000ms) linear forwards; }
.progress span.paused { animation-play-state: paused; }
@keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--card-border);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 150ms ease;
}
.icon-btn:hover { transform: scale(1.08); }
#fact-pause { font-size: 0.7rem; letter-spacing: -0.1em; }

/* ------------------------------------------------------------------ footer */
.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--soft);
  font-size: 0.85rem;
}
.foot p { margin: 0; }
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--teal);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* -------------------------------------------------------------------- game */
.game {
  width: min(26rem, calc(100vw - 1rem));
  max-height: calc(100svh - 1rem);
  padding: 0.75rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--bg-top);
  color: var(--ink);
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.6);
}
.game[open] { animation: pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.game::backdrop { background: rgba(20, 16, 30, 0.55); backdrop-filter: blur(4px); }
@keyframes pop { from { opacity: 0; transform: scale(0.92); } }

.game-bar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.game-bar h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.game-best { margin: 0; color: var(--muted); font-size: 0.9rem; }
.game canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100svh - 8rem);
  aspect-ratio: 360 / 640;
  object-fit: contain;
  border-radius: 14px;
  background: #bfe6f2;
  touch-action: none;
  cursor: pointer;
  /* Rapid taps must not select, highlight or open a callout on the canvas. */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.game { -webkit-user-select: none; user-select: none; }
.game-help { margin: 0.5rem 0 0; color: var(--soft); font-size: 0.8rem; text-align: center; }
kbd {
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--card-border);
  border-radius: 5px;
  font: inherit;
  font-size: 0.75rem;
}

/* ---------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .cloud, .feather { display: none; }
  .progress span.run { animation: none; transform: scaleX(0); }
}
