:root {
  --bg: #0f1410;
  --bg-soft: #161d18;
  --surface: #1c2620;
  --surface-2: #223029;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f3f6f2;
  --text-dim: #aebbb1;
  --text-faint: #7d8d83;
  --gold: #d9b15f;
  --gold-soft: #e8cf9b;
  --green: #4fae74;
  --green-deep: #1f6b43;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
  --shadow-hover: 0 28px 60px -20px rgba(0, 0, 0, 0.8);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
body { overflow-x: hidden; }

/* Twemoji renders emojis as crisp, consistent flat SVGs across all devices. */
img.emoji {
  height: 1.1em;
  width: 1.1em;
  margin: 0 0.05em 0 0.05em;
  vertical-align: -0.18em;
  display: inline-block;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(79, 174, 116, 0.18), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(217, 177, 95, 0.10), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------------- HERO ---------------- */
.hero {
  position: relative;
  overflow: hidden;
  padding: 72px 24px 88px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.hero__inner {
  position: relative;
  z-index: 2;
  max-width: 820px;
  margin: 0 auto;
}

.hero__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(6px);
  margin-bottom: 26px;
}
.hero__mark { font-size: 18px; }
.hero__brandname {
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold-soft);
}

.hero__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  line-height: 1.02;
  margin: 0 0 18px;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 0%, #d6e4da 60%, var(--gold-soft) 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__subtitle {
  font-size: clamp(1rem, 2.2vw, 1.18rem);
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0 auto 34px;
  max-width: 620px;
}

.hero__stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}
.stat {
  min-width: 104px;
  padding: 14px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}
.stat__num {
  font-family: "Fraunces", serif;
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--gold-soft);
  line-height: 1;
}
.stat__label {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.hero__glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(600px 280px at 50% 120%, rgba(79, 174, 116, 0.28), transparent 70%);
  z-index: 1;
}

/* ---------------- TOOLBAR ---------------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 20, 16, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.toolbar__inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 24px;
}

.search {
  position: relative;
  max-width: 520px;
  margin: 0 auto 16px;
}
.search__icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.7;
}
.search__input {
  width: 100%;
  padding: 13px 16px 13px 42px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search__input::placeholder { color: var(--text-faint); }
.search__input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(79, 174, 116, 0.18);
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  justify-content: flex-start;
}
.chips::-webkit-scrollbar { height: 6px; }
.chips::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s var(--ease);
}
.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
  transform: translateY(-1px);
}
.chip__icon { font-size: 15px; }
.chip__count {
  font-size: 11px;
  color: var(--text-faint);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 7px;
  border-radius: 999px;
}
.chip.is-active {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-deep) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(79, 174, 116, 0.7);
}
.chip.is-active .chip__count {
  background: rgba(0, 0, 0, 0.25);
  color: #eafff2;
}

/* ---------------- CONTENT ---------------- */
.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: 36px 24px 60px;
}
.results-bar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 24px;
}
.results-bar__title {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.7rem;
  margin: 0;
  letter-spacing: -0.01em;
}
.results-bar__count {
  font-size: 13px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(262px, 1fr));
  gap: 22px;
}

/* ---------------- FLIP CARD ---------------- */
.card {
  perspective: 1400px;
  height: 440px;
  cursor: pointer;
  border-radius: var(--radius);
  outline: none;
  animation: cardIn 0.5s var(--ease) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.card:focus-visible { box-shadow: 0 0 0 3px var(--gold); }

.card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.7s var(--ease);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}
.card.is-flipped .card__inner { transform: rotateY(180deg); }

.card__face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  /* Belt-and-suspenders: swap face visibility at the flip's edge-on midpoint
     so the front never shows through mirrored on top of the back. */
  transition: opacity 0s linear 0.34s, visibility 0s linear 0.34s;
}

/* Front is visible at rest, hidden once flipped. Back is the reverse. */
.card__front { opacity: 1; visibility: visible; }
.card__back { opacity: 0; visibility: hidden; }
.card.is-flipped .card__front { opacity: 0; visibility: hidden; }
.card.is-flipped .card__back { opacity: 1; visibility: visible; }

/* ---- FRONT ---- */
.card__front {
  background: var(--surface);
}
.card__photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background:
    linear-gradient(135deg, var(--surface-2), var(--surface));
  transition: transform 0.9s var(--ease);
}
.card:hover .card__photo { transform: scale(1.06); }
.card.is-fallback .card__photo { display: none; }

.card__shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(7, 11, 8, 0.92) 0%, rgba(7, 11, 8, 0.35) 42%, rgba(7, 11, 8, 0) 70%);
}
.card__loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(110deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s infinite linear;
}
.card__loader-emoji {
  font-size: 64px;
  opacity: 0.4;
}
@keyframes shimmer {
  from { background-position: 180% 0; }
  to { background-position: -80% 0; }
}
.card__loader.is-hidden { display: none; }
/* When the photo can't load, the loader stays as a clean emoji tile (no shimmer). */
.card.is-fallback .card__loader {
  animation: none;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(79, 174, 116, 0.18), transparent 60%),
    linear-gradient(165deg, var(--surface-2), var(--bg-soft));
}
.card.is-fallback .card__loader-emoji { opacity: 0.9; }
.card.is-fallback .card__loader-emoji img.emoji { width: 76px; height: 76px; }

.card__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 20px 18px;
  z-index: 2;
}
.card__cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 8px;
  font-weight: 600;
}
.card__name {
  font-family: "Fraunces", serif;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
  color: #fff;
}
.card__sci {
  font-style: italic;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 3px;
}
.card__fliphint {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(7, 11, 8, 0.55);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(4px);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s, transform 0.25s;
}
.card:hover .card__fliphint { opacity: 1; transform: none; }

/* ---- BACK ---- */
.card__back {
  transform: rotateY(180deg);
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(79, 174, 116, 0.16), transparent 55%),
    linear-gradient(165deg, var(--surface-2), var(--bg-soft));
  display: flex;
  flex-direction: column;
  padding: 22px 20px 18px;
  min-height: 0;
}
.back__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.back__name {
  font-family: "Fraunces", serif;
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.15;
}
.back__sci {
  font-style: italic;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 2px;
}
.back__emoji {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  font-size: 26px;
  line-height: 1;
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(79, 174, 116, 0.32), rgba(217, 177, 95, 0.14));
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.back__emoji img.emoji { width: 28px; height: 28px; vertical-align: 0; }

.back__meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.meta {
  min-width: 0;
}
.meta__label {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.meta__value {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  margin-top: 2px;
  line-height: 1.3;
}

.back__facts-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.back__facts {
  list-style: none;
  margin: 0;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 14px 0 4px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.back__facts::-webkit-scrollbar { display: none; }

.back__scrollbar {
  flex: 0 0 7px;
  position: relative;
  margin: 14px 0 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  touch-action: none;
}
.back__scrollbar-thumb {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  min-height: 32px;
  border-radius: 999px;
  background: rgba(217, 177, 95, 0.7);
  cursor: grab;
  touch-action: none;
}
.back__scrollbar-thumb:active { cursor: grabbing; }
.back__scrollbar.is-static .back__scrollbar-thumb {
  background: rgba(217, 177, 95, 0.45);
  cursor: default;
}
.fact {
  position: relative;
  padding: 0 0 12px 22px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-dim);
}
.fact::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
}
.fact:last-child { padding-bottom: 0; }

.back__foot {
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  letter-spacing: 0.04em;
}

/* ---------------- EMPTY ---------------- */
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty__icon { font-size: 46px; display: block; margin-bottom: 12px; }
.empty__text { font-size: 16px; margin: 0 0 18px; }
.empty__reset {
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.empty__reset:hover { border-color: var(--green); color: #fff; }

/* ---------------- FOOTER ---------------- */
.footer {
  border-top: 1px solid var(--line);
  text-align: center;
  padding: 32px 24px 48px;
  color: var(--text-faint);
  font-size: 13px;
}
.footer p { margin: 4px 0; }
.footer__note { font-size: 12px; opacity: 0.8; }

@media (max-width: 560px) {
  .hero { padding: 52px 18px 60px; }
  .hero__title { font-size: clamp(2rem, 10vw, 3.1rem); }
  .hero__subtitle { font-size: 1rem; }
  .stat { min-width: 92px; padding: 12px 16px; }
  .stat__num { font-size: 1.45rem; }
  .grid { grid-template-columns: 1fr; gap: 18px; }
  .card { height: 500px; }
  .chips { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .hero__stats { gap: 10px; }
  .stat { min-width: 84px; padding: 11px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .card__inner, .card__photo, .chip, .search__input, .card__face { transition: none; }
  .card { animation: none; }
  .card__loader { animation: none; }
}
