/*
  Combined global styles for Random Fish Generator with hero animations and card swap transitions.
  This stylesheet merges the original design (navy and forest green palette) with enhancements for
  a clean hero section, page entrance animation, and smooth species swap animations.
*/

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');

/* Color palette and base variables */
:root {
  --navy: #002f4b;
  --forest: #013220;
  --accent: #006d77;
  --light: #f5f5f5;
  --card-bg: rgba(255, 255, 255, 0.95); /* slightly translucent card background */
  --text-color: #333333;
}

/* Reset and basic layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Montserrat', sans-serif;
  color: var(--text-color);
  background: linear-gradient(120deg, var(--navy), var(--forest));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem;
  /* Site entrance animation */
  animation: pageIn 600ms ease-out both;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

header {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--light);
}

/* Hero state: before the first fish is generated we center the header and button */
body:not(.has-result) header {
  margin: 0;
  min-height: 60vh;
  display: grid;
  place-items: center;
  gap: 14px;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

#subtitle {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

/* Generate button styling */
#generateBtn {
  background-color: var(--accent);
  color: var(--light);
  border: none;
  padding: 0.8rem 1.6rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
}

#generateBtn:hover {
  background-color: var(--forest);
  transform: scale(1.03);
}

/* Gentle pulse on the button before first click */
body:not(.has-result) #generateBtn {
  animation: floatPulse 3s ease-in-out infinite;
}

@keyframes floatPulse {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* Loading spinner */
#loading {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--light);
}

#loading.hidden {
  display: none;
}

.spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid var(--light);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 0.5rem;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Hide card and footer until the first fish is generated */
body:not(.has-result) #fishCard,
body:not(.has-result) footer {
  display: none !important;
}

/* Fish card styling */
.card {
  background-color: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  max-width: 650px;
  width: 100%;
  color: var(--text-color);
}

#fishImage {
  width: 100%;
  height: auto;
  border-radius: 8px;
  margin-bottom: 1rem;
}

#fishCommonName {
  font-size: 1.9rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--navy);
}

#fishScientificName {
  font-style: italic;
  color: var(--accent);
  margin-bottom: 1rem;
}

#fishDescription {
  margin-bottom: 1rem;
  line-height: 1.5;
}

.facts {
  list-style-type: disc;
  margin-left: 1.2rem;
  margin-bottom: 1rem;
}

.facts li {
  margin-bottom: 0.5rem;
}

.habitat {
  font-weight: 600;
  color: var(--forest);
}

/* Credit line styling. The credit line appears below the habitat when
   available. It uses a smaller font and accent color. Hidden by default
   in markup and shown when text is set. */
.credit {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 0.5rem;
  font-style: italic;
}

footer {
  margin-top: auto;
  color: var(--light);
  text-align: center;
  padding: 1rem 0;
  font-size: 0.9rem;
}

/* After first result: header margin returns to normal */
body.has-result header {
  margin-bottom: 2rem;
  transition: margin-bottom 220ms ease;
}

/* Species card swap animations */
@keyframes swapOut {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(6px) scale(0.99); }
}

@keyframes swapIn {
  0%   { opacity: 0; transform: translateY(-6px) scale(0.99); }
  100% { opacity: 1; transform: translateY(0)    scale(1); }
}

#fishCard.swapping-out {
  animation: swapOut 200ms ease forwards;
}
#fishCard.swapping-in {
  animation: swapIn 240ms cubic-bezier(.2, .7, .2, 1) forwards;
}

/* Reduce motion for users who prefer minimal animation */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}