:root,
body[data-theme="swamp"] {
  --bg: #0f2d1f;
  --board-bg: #163f2b;
  --tile-bg: #1f5636;
  --tile-muck: #4a3826;
  --tile-golden: #d4af37;
  --text: #eafff0;
  --accent: #6be675;
  --accent-dark: #3fae4d;
  --water-a: rgba(107, 230, 117, 0.16);
  --water-b: rgba(63, 174, 77, 0.22);
}

body[data-theme="neon"] {
  --bg: #0d0221;
  --board-bg: #1a0533;
  --tile-bg: #2b0a4e;
  --tile-muck: #3d2b3a;
  --tile-golden: #f9c80e;
  --text: #f0e7ff;
  --accent: #ff2ecc;
  --accent-dark: #a916a0;
  --water-a: rgba(255, 46, 204, 0.16);
  --water-b: rgba(169, 22, 160, 0.22);
}

body[data-theme="space"] {
  --bg: #050914;
  --board-bg: #0b1226;
  --tile-bg: #14203f;
  --tile-muck: #2e2a3a;
  --tile-golden: #e8c547;
  --text: #e6efff;
  --accent: #5aa2ff;
  --accent-dark: #2c5fb8;
  --water-a: rgba(90, 162, 255, 0.16);
  --water-b: rgba(44, 95, 184, 0.22);
}

body[data-theme="candy"] {
  --bg: #ffe3ef;
  --board-bg: #ffc2dc;
  --tile-bg: #ff9fc7;
  --tile-muck: #b58a74;
  --tile-golden: #ffd166;
  --text: #5a1836;
  --accent: #ff4f9a;
  --accent-dark: #e0357f;
  --water-a: rgba(255, 79, 154, 0.16);
  --water-b: rgba(224, 53, 127, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  /* Fredoka loads from Google Fonts; ui-rounded picks SF Rounded on Apple
     devices when offline (installed PWA), so the fallback stays kid-friendly. */
  font-family: "Fredoka", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  gap: 12px;
}

.topbar {
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flies {
  font-size: 1.2rem;
  font-weight: 600;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--tile-bg);
  color: var(--text);
  font-family: inherit; /* buttons don't inherit the body font by default */
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  background: var(--accent-dark);
  font-weight: 700;
}

.board {
  --board-size: 7;
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(var(--board-size), 1fr);
  grid-template-rows: repeat(var(--board-size), 1fr);
  gap: 4px;
  border-radius: 12px;
  padding: 6px;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 25%, var(--water-a) 0%, transparent 55%),
    radial-gradient(circle at 75% 70%, var(--water-b) 0%, transparent 55%),
    var(--board-bg);
  background-size: 220% 220%, 220% 220%, 100% 100%;
  animation: pond-shimmer 14s ease-in-out infinite;
}

/* Faint diagonal streaks drifting across the gaps between tiles — the
   "running water" current. Layered above the shimmer, below the tiles
   (tiles are grid children painted after this pseudo-element). */
.board::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    115deg,
    transparent 0px,
    var(--water-a) 3px,
    transparent 7px,
    transparent 34px
  );
  background-size: 200% 100%;
  animation: pond-current 7s linear infinite;
  pointer-events: none;
}

@keyframes pond-shimmer {
  0%, 100% { background-position: 0% 0%, 100% 100%, 0 0; }
  50% { background-position: 100% 60%, 0% 40%, 0 0; }
}

@keyframes pond-current {
  from { background-position: 0% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .board { animation: none; }
  .board::before { animation: none; }
  .tile--match::before { animation: none; box-shadow: 0 0 0 2px var(--accent); }
  .tile--merge-pulse .tile__sprite,
  .tile--spawn-pop .tile__sprite { animation: none; }
}

.tile {
  --pad: var(--accent-dark);
  position: relative;
  z-index: 0; /* own stacking context so the pad's z-index:-1 can't slip behind the board */
  background: transparent;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s ease;
}

/* The lilypad: a shaded circle with a leaf notch cut out via the conic
   wedge, floating on the board's water. Sits under the tile's content
   (frog / poop emoji) but above the board background. */
.tile::before {
  content: '';
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  z-index: -1;
  background:
    radial-gradient(circle at 32% 68%, rgba(255, 255, 255, 0.22) 0%, transparent 40%),
    radial-gradient(circle at 60% 40%, rgba(0, 0, 0, 0.18) 0%, transparent 65%),
    conic-gradient(from 318deg, transparent 0deg 44deg, var(--pad) 44deg);
}

.tile--muck {
  --pad: var(--tile-muck);
}

.tile--golden {
  --pad: var(--tile-golden);
}

.tile--selected::before {
  box-shadow: 0 0 0 3px var(--accent);
}

.tile--match::before {
  animation: match-glow 1.1s ease-in-out infinite;
}

@keyframes match-glow {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent); }
  50% { box-shadow: 0 0 6px 2px var(--accent); }
}

/* Squash-and-stretch on the sprite only (not the whole tile) so the frog
   bounces while its lilypad stays put. transform-origin near the feet keeps
   the squash grounded instead of ballooning from the center. */
.tile--merge-pulse .tile__sprite {
  animation: squash-stretch 0.32s ease;
  transform-origin: 50% 88%;
}

@keyframes squash-stretch {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.35, 0.65); }
  65% { transform: scale(0.8, 1.3); }
  100% { transform: scale(1, 1); }
}

.tile--spawn-pop .tile__sprite {
  animation: spawn-boing 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 50% 88%;
}

@keyframes spawn-boing {
  0% { transform: scale(0, 0); }
  60% { transform: scale(1.2, 0.8); }
  80% { transform: scale(0.92, 1.12); }
  100% { transform: scale(1, 1); }
}

/* Still used by the discovery modal's sprite. */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.combo-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dark);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  animation: combo-pop 0.25s ease;
}

.combo-indicator[hidden] {
  display: none;
}

@keyframes combo-pop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.board--panic-flash {
  animation: panic-flash 0.35s ease;
}

@keyframes panic-flash {
  0% { box-shadow: 0 0 0 0 var(--accent); }
  50% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* Frog SVGs fill a fixed share of the tile so they sit big on the lilypad
   regardless of the tile's font-size (which now only sizes the muck emoji). */
.tile__sprite {
  pointer-events: none;
  width: 74%;
  height: 74%;
}

.tile__sprite svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Everywhere else the SVG keeps its 1em box, so the existing font-size rules
   (dex 1.8rem, discovery 3.5rem, ...) size it exactly like the old emoji. */
.dex__sprite svg,
.hof__sprite svg,
.discovery__sprite svg {
  display: block;
}

.selection-banner {
  width: 100%;
  max-width: 480px;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--tile-bg);
  color: var(--text);
}

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

.dailies,
.shop {
  width: 100%;
  max-width: 480px;
}

.dailies h2 {
  font-size: 1rem;
  margin: 4px 0;
}

#daily-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.daily--done {
  opacity: 0.6;
  text-decoration: line-through;
}

.shop {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.topbar__actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn--icon {
  padding: 8px 10px;
  font-size: 1rem;
  line-height: 1;
}

.btn__cost {
  display: block;
  font-size: 0.75rem;
  opacity: 0.8;
}

.btn--unaffordable {
  opacity: 0.5;
}

/* --- Modals --- */

.modal {
  position: fixed;
  inset: 0;
  background: #000a;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal--open {
  display: flex;
}

.modal__card {
  background: var(--board-bg);
  color: var(--text);
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal__subtitle {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.8;
}

/* --- Dex --- */

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

.dex__entry {
  background: var(--tile-bg);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  font: inherit;
  cursor: pointer;
}

.dex__entry:disabled {
  cursor: default;
}

.dex__entry--unknown {
  opacity: 0.45;
}

.dex__sprite {
  font-size: 1.8rem;
}

.dex__name {
  font-size: 0.7rem;
  line-height: 1.2;
}

/* --- Settings --- */

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.setting-row--themes {
  flex-direction: column;
  align-items: flex-start;
}

.theme-picks {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.theme-pick--active {
  outline: 2px solid var(--accent);
}

.slot-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.3;
}

.slot-pick__detail {
  font-size: 0.65rem;
  opacity: 0.75;
  font-weight: 400;
}

/* --- Discovery --- */

.modal__card--discovery {
  align-items: center;
  text-align: center;
  max-width: 320px;
}

.discovery__sprite {
  font-size: 3.5rem;
  animation: pulse 0.6s ease;
}

.modal__card--discovery h2 {
  margin: 0;
}

.modal__card--discovery p {
  margin: 0;
  opacity: 0.9;
}

.onboarding__steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  font-size: 0.95rem;
}

.welcome__earnings {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

/* --- Discovery naming --- */

.discovery__name-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  font-size: 0.85rem;
}

.discovery__name-row input {
  border-radius: 8px;
  border: none;
  padding: 8px 10px;
  font-size: 0.95rem;
  background: var(--tile-bg);
  color: var(--text);
}

/* --- Hall of Fame --- */

.hof {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hof__empty {
  opacity: 0.8;
  text-align: center;
  padding: 12px 0;
}

.hof__entry {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--tile-bg);
  border-radius: 10px;
  padding: 8px 10px;
}

.hof__sprite {
  font-size: 1.8rem;
}

.hof__nickname {
  font-weight: 700;
}

.hof__subtitle {
  font-size: 0.75rem;
  opacity: 0.8;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: #000c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 380px) {
  .tile {
    font-size: 1.3rem;
  }
}
