/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --color-navy: #2E3A4F;
  --color-slate: #63719A;
  --color-rust: #C1512E;
  --color-light-gray: #EAEAEA;
  --color-white: #FFFFFF;

  --font-heading: 'Manrope', sans-serif;
  --font-body: 'Nunito Sans', sans-serif;
  --font-size-base: 16px;

  --dim-opacity: 0.35;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-white);
  color: var(--color-navy);
  font-family: var(--font-body);
  line-height: 1.5;
}

img {
  max-width: 100%;
  display: block;
}

/* Author-origin `img { display: block }` above would otherwise beat the
   browser's default `[hidden] { display: none }` UA rule regardless of
   specificity, silently defeating the `hidden` attribute on <img> tags. */
img[hidden] {
  display: none;
}

button {
  font-family: inherit;
}

/* ==========================================================================
   Header / footer
   ========================================================================== */
.site-header {
  background: var(--color-navy);
  color: var(--color-white);
  text-align: center;
  padding: 2rem 1rem 1.5rem;
}

.site-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  margin: 0 0 0.5rem;
}

.site-tagline {
  margin: 0 0 0.5rem;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--color-white);
}

.site-subtitle {
  font-family: var(--font-body);
  color: var(--color-light-gray);
  margin: 0;
  font-size: 1rem;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--color-light-gray);
  color: var(--color-slate);
  font-size: 0.875rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--color-rust);
}

.social-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.social-links img {
  width: 24px;
  height: 24px;
  opacity: 0.8;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.social-links a:hover img,
.social-links a:focus-visible img {
  opacity: 1;
  transform: scale(1.1);
}

@media (max-width: 480px) {
  .site-footer {
    flex-direction: column;
    text-align: center;
  }
}

main {
  padding: 2rem 1rem 3rem;
  background: var(--color-white);
}

/* ==========================================================================
   Sticker stage
   ========================================================================== */

/* Scrolls horizontally on narrow viewports so creature hit-targets never
   shrink below a usable tap size; centers with breathing room on wide ones. */
.sticker-stage-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0 1rem;
}

.sticker-stage {
  position: relative;
  width: 100%;
  min-width: 900px;
  max-width: 1800px;
  margin: 0 auto;
  background: var(--color-light-gray);
  border-radius: 12px;
  overflow: hidden;
}

.sticker-stage__base-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Shown instead of the base image if full-sticker.png hasn't been added yet */
.sticker-stage__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  border: 3px dashed var(--color-slate);
  border-radius: 12px;
  color: var(--color-slate);
  font-family: var(--font-body);
  font-size: 1rem;
}

.stage-hint {
  max-width: 1800px;
  margin: 0 auto;
  text-align: center;
  color: var(--color-slate);
  font-size: 0.875rem;
}

/* Individual creature hit-targets, absolutely positioned over the base image
   using percentages derived from data/creatures.json (x/y/width/height are
   relative to the sticker's referenceWidth/referenceHeight). */
.creature-button {
  position: absolute;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.25s ease, transform 0.2s ease, filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.creature-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Desktop hover hint that a creature is clickable */
@media (hover: hover) {
  .creature-button:hover {
    transform: scale(1.04);
    filter: drop-shadow(0 0 10px rgba(193, 81, 46, 0.55));
  }
}

.creature-button:focus-visible {
  outline: 3px solid var(--color-rust);
  outline-offset: 3px;
  border-radius: 6px;
}

/* When a creature is active: dim everyone else, spotlight the active one */
.sticker-stage.has-active .creature-button {
  opacity: var(--dim-opacity);
}

.sticker-stage.has-active .creature-button.is-active {
  opacity: 1;
  transform: scale(1.05);
  filter: drop-shadow(0 0 14px rgba(193, 81, 46, 0.7));
  z-index: 5;
}

/* Placeholder box shown in place of a creature image that hasn't been added yet */
.creature-button .creature-missing {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.5rem;
  background: rgba(99, 113, 154, 0.15);
  border: 2px dashed var(--color-rust);
  border-radius: 8px;
  color: var(--color-navy);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
}

/* ==========================================================================
   Modal / popup
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(46, 58, 79, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  background: var(--color-white);
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 2rem 1.75rem 1.75rem;
  box-shadow: 0 20px 50px rgba(46, 58, 79, 0.35);
  border-top: 6px solid var(--color-rust);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 50%;
  background: var(--color-light-gray);
  color: var(--color-navy);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.modal-close:hover,
.modal-close:focus-visible {
  background: var(--color-rust);
  color: var(--color-white);
  outline: none;
}

.modal-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  margin-bottom: 1rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-weight: 800;
  color: var(--color-navy);
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

.modal-scientific-name {
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 400;
  color: var(--color-slate);
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.modal-scientific-name:empty {
  display: none;
}

.modal-description {
  font-family: var(--font-body);
  color: var(--color-navy);
  font-size: 1rem;
  margin: 0 0 1rem;
}

.modal-papers {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--color-white);
  background: var(--color-slate);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0;
}

.modal-papers:empty {
  display: none;
}

.modal-papers::before {
  content: "Learn more: ";
  font-weight: 700;
  color: var(--color-white);
}

.modal-papers ul {
  list-style: disc;
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}

.modal-papers li {
  margin-bottom: 0.5rem;
}

.modal-papers li:last-child {
  margin-bottom: 0;
}

.modal-papers a {
  color: var(--color-white);
  text-decoration: underline;
}

.modal-papers a:hover,
.modal-papers a:focus-visible {
  color: var(--color-light-gray);
}

/* ==========================================================================
   Responsive tweaks
   ========================================================================== */
@media (max-width: 600px) {
  .site-header {
    padding: 1.5rem 1rem 1rem;
  }

  main {
    padding: 1.5rem 0.75rem 2rem;
  }

  .modal-card {
    padding: 1.5rem 1.25rem 1.25rem;
  }
}
