/* The home page's title, tagline and Start button fonts: Fredoka and Nunito,
   both under the SIL Open Font License (public/fonts/*-OFL.txt). They're kept
   here rather than loaded from Google Fonts, so the page doesn't wait on, or
   tell, another site. Until they load, the page uses its usual font. */
@font-face {
  font-family: Fredoka;
  font-weight: 600;
  font-display: swap;
  src: url(./fonts/fredoka-600.woff2) format('woff2');
}

@font-face {
  font-family: Fredoka;
  font-weight: 700;
  font-display: swap;
  src: url(./fonts/fredoka-700.woff2) format('woff2');
}

@font-face {
  font-family: Nunito;
  font-weight: 700;
  font-display: swap;
  src: url(./fonts/nunito-700.woff2) format('woff2');
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ccfbf1;
  color: #134e4a;
  font-family: system-ui, sans-serif;
  text-align: center;
  padding-top: 3rem;
}

.friends {
  display: flex;
  flex-wrap: wrap; /* on narrow screens, pals wrap onto a second row */
  justify-content: center;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0 1rem;
}

.pal {
  width: 120px;
}

/* Tap a pal on the home page and she divides in two (game/split.js). The
   daughters can drift past the edge of her drawing while she's split. */
.splittable .pal {
  cursor: pointer;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom when tapping twice */
  user-select: none;
  -webkit-user-select: none;
}

.pal .cell {
  transform-box: fill-box;
  transform-origin: center;
}

.bob {
  animation: bob 2.4s ease-in-out infinite;
}

.squish {
  animation: squish 2s ease-in-out infinite 0.5s;
  transform-origin: bottom center;
}

@keyframes wobble {
  0%,
  100% {
    transform: rotate(-4deg);
  }

  50% {
    transform: rotate(4deg);
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

@keyframes squish {
  0%,
  100% {
    transform: scale(1, 1);
  }

  50% {
    transform: scale(1.08, 0.92);
  }
}

/* Elia is a spirochete: she wiggles like a corkscrew. */
@keyframes slither {
  0%,
  100% {
    transform: skewX(-8deg);
  }

  50% {
    transform: skewX(8deg);
  }
}

.slither {
  animation: slither 1.6s ease-in-out infinite;
}

/* The game's name on the home page, big and round like a game logo. */
.logo {
  margin: 1.6rem 0 0.4rem;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: clamp(3.2rem, 15vw, 5.2rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
}

/* What the game is, in a few words, under its name. */
.tagline {
  margin: 0 0 1.4rem;
  padding: 0 1rem;
  font-family: Nunito, system-ui, sans-serif;
  font-size: clamp(1.05rem, 4.6vw, 1.3rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #0f766e;
}

/* A sentence or two under the Start button saying what the game is, for
   new players (and search engines). */
.about {
  max-width: 34rem;
  margin: 2rem auto 0;
  padding: 0 1.25rem;
  line-height: 1.5;
  opacity: 0.85;
}

.start-btn {
  margin-top: 1rem;
  padding: 0.8rem 2rem;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: white;
  background: #0f766e;
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 0 #134e4a;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.start-btn:hover {
  background: #14b8a6;
}

.start-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #134e4a;
}

.start-btn:disabled {
  cursor: wait;
  opacity: 0.8;
}

.picker-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  /* Keep the card and the signature under it together in the middle, even
     on a page whose card is short (like choose-mode.html). */
  align-content: center;
  padding: 2rem 1rem;
}

.picker-shell {
  width: min(760px, 100%);
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(19, 78, 74, 0.15);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: 0 20px 40px rgba(19, 78, 74, 0.08);
}


/* The pal picker is wider than the other cards, to fit four pals across. */
.picker-wide {
  width: min(1000px, 100%);
  position: relative; /* for the microscope button in its corner */
}

/* Microscope mode (game/pal-picker.js): a button in the picker's corner that
   shows every pal as she'd look after a Gram stain, purple or pink. */
.scope-btn {
  position: absolute;
  top: 1.75rem;
  right: 1.75rem;
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.45em 0.85em;
  border: 2px solid #99f6e4;
  border-radius: 999px;
  background: #f0fdfa;
  color: #0f766e;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.scope-btn:hover {
  background: #ccfbf1;
}

.scope-btn[aria-pressed='true'] {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
}

.scope-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.scope-caption {
  margin: -0.5rem 0 1rem;
  text-align: center;
  font-size: 0.9rem;
  color: #475569;
}

.scope-caption b {
  white-space: nowrap;
}

.scope-caption .gram-positive {
  color: #6d28d9;
}

.scope-caption .gram-negative {
  color: #db2777;
}

/* On a phone or small tablet, where the corner is too close to the heading,
   the button sits under it instead. */
@media (max-width: 760px) {
  .scope-btn {
    position: static;
    margin: -0.5rem auto 1rem;
  }
}

/* Stained, each pal sits on a white slide. Her stain colors themselves are
   set on her drawing by game/stain.js; here they just fade in and out. */
.stained .pal-icon {
  background: radial-gradient(circle, #fff 0 58%, #f1f5f9 72%, #e2e8f0 100%);
  box-shadow: inset 0 0 0 2px #cbd5e1;
}

.pal-icon svg * {
  transition: fill 0.4s ease, stroke 0.4s ease;
}

.stain-note {
  display: none;
}

.stained .stain-note {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #db2777;
}

@media (prefers-reduced-motion: reduce) {
  .pal-icon svg * {
    transition: none;
  }
}

/* A heading at the very top of the card sits on the card's own padding,
   without the browser's extra margin on top. */
.picker-shell > h1:first-child {
  margin-top: 0;
}

/* Four across on a computer (two rows of four), two on a tablet, one on a
   phone, where the Select buttons wouldn't fit side by side. */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

@media (max-width: 900px) {
  .picker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .picker-grid {
    grid-template-columns: 1fr;
  }
}

.pal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.5);
  border: 2px solid rgba(15, 118, 110, 0.2);
  border-radius: 18px;
  padding: 1rem;
}

/* Line the Select buttons up along the bottom, however long the name above. */
.pal-card .pick-btn {
  margin-top: auto;
  white-space: nowrap;
}

/* Each pal's name, with her species right under it. */
.picker-grid .pal-card h2 {
  margin: 0.35rem 0 0.2rem;
  line-height: 1.2;
}

/* Her species, right under her name. Every card keeps room for two lines,
   so a long one that wraps (Streptococcus pneumoniae) doesn't make her card
   look different from the rest. */
.picker-grid .species {
  margin: 0 0 1rem;
  line-height: 1.3;
  min-height: 2.6em;
}

.pal-icon {
  width: 110px;
  height: 110px;
  margin: 0 auto 0.75rem;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 0 0 2px rgba(19, 78, 74, 0.06);
}

.pal-icon svg {
  width: 90px;
  height: 90px;
  display: block;
}

.mona {
  background: rgba(134, 239, 172, 0.45);
}

.goldie {
  background: rgba(253, 230, 138, 0.45);
}

.scarlett {
  background: rgba(252, 165, 165, 0.45);
}

.elia {
  background: rgba(216, 180, 254, 0.45);
}

.penny {
  background: rgba(165, 180, 252, 0.45);
}

.ana {
  background: rgba(249, 168, 212, 0.4);
}

.coco {
  background: rgba(212, 176, 140, 0.45);
}

.vi {
  background: rgba(253, 186, 116, 0.45);
}

.pick-btn {
  margin-top: 0.75rem;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 999px;
  background: #0f766e;
  color: white;
  font-weight: 700;
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
}

.pick-btn:hover {
  background: #14b8a6;
}

.back-link {
  display: inline-block;
  margin-top: 1.5rem;
  color: #0f766e;
  font-weight: 700;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.dish-shell {
  width: min(760px, 100%);
}

/* The agar keeps itself square (below) and the glass rim wraps around it.
   Don't size the agar from the dish's height instead: Safari (so every
   browser on an iPhone) can ignore a percentage height when the parent's
   height only comes from aspect-ratio, which squashes the agar into an oval. */
.petri-dish {
  position: relative;
  width: min(600px, 100%);
  margin: 0 auto;
  padding: 18px;
  border-radius: 50%;
  /* glass rim */
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid rgba(15, 118, 110, 0.35);
  box-shadow:
    0 18px 36px rgba(19, 78, 74, 0.15),
    inset 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.agar {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  /* agar gel with a soft glass highlight */
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75), transparent 32%),
    radial-gradient(circle at 50% 50%, #fef9c3, #e7eeab);
  border: 2px solid rgba(180, 83, 9, 0.2);
  /* Touch and hold on the agar to steer (game/touch.js): don't scroll or zoom
     the page, select text, or pop up the long-press menu instead. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Positioned by petri-dish.js; the pal's own idle animation stays on the SVG. */
/* The mode screen after picking a pal. */
.mode-shell h1 {
  margin: 0.75rem 0 0;
}

.mode-pal {
  display: flex;
  justify-content: center;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.mode-card h2 {
  margin: 0.25rem 0 0.5rem;
}

.mode-card p {
  margin: 0 0 1rem;
  line-height: 1.45;
}

.pal-mover {
  grid-area: 1 / 1; /* stack in the dish center, even after dividing into two */
  width: 18%;
  position: relative;
  z-index: 1; /* swim over the nutrients */
  will-change: transform;
}

/* Nutrient flecks scattered on the agar; placed by petri-dish.js. */
.nutrient {
  position: absolute;
  width: 2.2%;
  aspect-ratio: 1;
  border-radius: 45% 55% 50% 40%;
  /* Each fleck gets a random --hue (set in game/nutrients.js), so the agar is
     sprinkled with every color of the rainbow. The faint dark ring keeps the
     yellow ones visible against the yellow agar. */
  background: hsl(var(--hue, 20) 85% 52%);
  box-shadow: 0 0 0 1px rgba(19, 78, 74, 0.25);
  opacity: 0.9;
  transform: translate(-50%, -50%);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.nutrient.small {
  width: 1.5%;
}

.nutrient.eaten {
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
}

.dish-pal {
  width: 100%;
  height: auto;
  display: block;
}

.dish-pal[hidden] {
  display: none;
}

.wobble {
  animation: wobble 3s ease-in-out infinite;
}

.species {
  font-size: 0.95rem;
}

/* The pal's name and species above the dish. */
.dish-title {
  margin-bottom: 1.25rem;
}

.dish-title .pal-name {
  margin: 0;
  font-size: 2rem;
}

.dish-title .species {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
}

.win-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: min(320px, 85%);
  padding: 1.25rem 1.5rem 1.5rem;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(15, 118, 110, 0.25);
  border-radius: 20px;
  box-shadow: 0 16px 36px rgba(19, 78, 74, 0.2);
  animation: pop-in 0.35s ease-out;
}

.win-banner[hidden] {
  display: none;
}

.win-banner h2 {
  margin: 0 0 0.5rem;
}

.win-banner p {
  margin: 0;
}

/* The "Did you know?" fact about your pal when you win. */
.win-banner .fun-fact {
  margin-top: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: rgba(15, 118, 110, 0.08);
  font-size: 0.92rem;
  line-height: 1.4;
}

.win-banner .fun-fact[hidden] {
  display: none;
}

.win-banner .fun-fact strong {
  color: #0f766e;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.banner-buttons {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.banner-buttons .pick-btn {
  margin-top: 0;
  font: inherit;
  font-weight: 700;
}

.banner-buttons .pick-btn[hidden] {
  display: none;
}

/* The second choice in the pop-up: outlined instead of filled. */
.start-over {
  background: white;
  color: #0f766e;
  box-shadow: inset 0 0 0 2px #0f766e;
}

.start-over:hover {
  background: #ccfbf1;
}

/* The group the player steers stays on top, in full color with a soft halo;
   the offspring left behind are paler and a little washed out. */
.pal-mover.player {
  z-index: 2;
  filter:
    drop-shadow(0 0 2px #fff)
    drop-shadow(0 0 3px #fff)
    drop-shadow(0 0 7px rgba(15, 118, 110, 0.45));
}

/* The rival's pal in mixed culture mode: a soft dark outline instead of the
   player's white glow, so you can tell who's who. */
.pal-mover.rival {
  z-index: 2;
  filter:
    drop-shadow(0 0 1.5px rgba(30, 41, 59, 0.55))
    drop-shadow(0 0 5px rgba(30, 41, 59, 0.25));
}

.pal-mover.offspring {
  opacity: 0.75;
  filter: saturate(0.45) brightness(1.08);
}

/* Elia's offspring are a touch paler still: her purple stays strong even
   washed out, so they stood out more than the others'. */
.pal-mover.offspring .dish-pal[data-pal="elia"] {
  opacity: 0.85;
  filter: saturate(0.8) brightness(1.05);
}

/* Only the player's pal has a face. */
.pal-mover.offspring .face {
  display: none;
}

/* Offspring sit still on the agar, without the idle wiggle. That also keeps
   a dish full of 64 cells smooth. */
.pal-mover.offspring .dish-pal {
  animation: none;
}

.cell-count {
  margin: 1rem 0 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.how-to-play {
  margin: 0.75rem 0 0;
  line-height: 1.6;
  color: #334155;
}

/* Arrow-key directions on a computer, touch directions on a phone or tablet.
   The media query picks from the device before any script runs (a finger is a
   "coarse" pointer); then game/touch.js switches them to match whatever the
   player actually uses, for devices with both. */
.for-touch {
  display: none;
}

@media (pointer: coarse) {
  .for-keys {
    display: none;
  }

  .for-touch {
    display: inline;
  }
}

html.input-touch .for-keys,
html.input-keys .for-touch {
  display: none;
}

html.input-touch .for-touch,
html.input-keys .for-keys {
  display: inline;
}

/* The antibiotic disk: a small white paper disk with the drug's code on it,
   like the disks used in the lab. Placed by game/antibiotic.js. */
.antibiotic {
  position: absolute;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #f1f5f9);
  border: 2px solid #cbd5e1;
  box-shadow: 0 2px 4px rgba(19, 78, 74, 0.2);
  color: #475569;
  font-size: clamp(8px, 1.3vw, 14px);
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* The zone of inhibition around each disk: clear agar where the drug has
   soaked in and nothing can grow. Sized by game/antibiotic.js. */
.zone {
  position: absolute;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  /* Real zones are clear, slightly glassy agar with a soft, hazy edge where
     the growth thins out, not a crisp ring. Each zone also gets a slightly
     uneven shape (set in game/antibiotic.js). */
  border-radius: 50%;
  /* The disk covers the inner ~65%, so the visible ring is the outer third:
     clear agar, then a thin hazy rim right at the outside. The rim has to
     sit at the very edge, because that's where touching it ends the game
     (see touchesDisk in game/antibiotic.js); a rim that faded out early
     made the game end with a gap still showing. */
  background: radial-gradient(
    closest-side,
    rgba(255, 255, 252, 0.85) 0%,
    rgba(255, 255, 252, 0.8) 88%,
    rgba(255, 255, 248, 0.65) 93%,
    rgba(206, 192, 110, 0.4) 97%,
    rgba(206, 192, 110, 0.3) 99%,
    rgba(206, 192, 110, 0) 100%
  );
  filter: blur(0.5px);
  pointer-events: none;
}

/* Hover over a disk to see which antibiotic it is. */
.antibiotic::after {
  content: attr(data-name);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  padding: 0.25rem 0.55rem;
  border-radius: 8px;
  background: #134e4a;
  color: white;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: normal;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.antibiotic:hover {
  z-index: 4; /* above the pals, so the label isn't hidden behind them */
}

.antibiotic:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* The player's pal after touching the antibiotic. */
.pal-mover.killed {
  filter: grayscale(1);
  opacity: 0.45;
  transition: filter 0.4s ease, opacity 0.4s ease;
}

/* Freeze her mid-wiggle rather than turning the animation off: switching it
   off snaps her back to her resting pose (up to 10px away for a bob), so she
   would look like she never touched the zone. */
.pal-mover.killed .dish-pal {
  animation-play-state: paused;
}

/* Jess's signature at the foot of every page. */
.signature {
  margin: 2rem 0 1.5rem;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

.picker-page .signature {
  margin: 1rem 0 0;
}

/* On the home page, push it down to the bottom of the screen instead of
   right under the start button. */
body:not(.picker-page) {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

body:not(.picker-page) .signature {
  margin-top: auto;
  padding-top: 2rem;
}

/* On a phone, give the dish as much of the screen as we can: less padding
   around the card and a thinner glass rim. */
@media (max-width: 600px) {
  .picker-page:has(.dish-shell) {
    padding: 0.75rem 0.5rem;
  }

  .dish-shell {
    padding: 1rem 0.5rem;
  }

  .dish-shell .petri-dish {
    padding: 8px;
  }
}

/* An offspring cell popping in an antibiotic zone (game/colony.js): a ring
   in the pal's color that bursts outward and fades. */
.pop {
  position: absolute;
  aspect-ratio: 1;
  border: 3px solid;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pop 0.35s ease-out forwards;
}

@keyframes pop {
  from {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.7);
  }

  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.8);
    border-width: 1px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pop {
    animation-duration: 0.01s;
  }
}
