/* Gooville — the town progress picture on the home page (shared/town.js).
   Sky-and-ground panorama in a rounded card. No external url()s (CSP). */

.town {
  --art-h: 150px;
  --lot-w: 148px;
  --rows: 1;
  position: relative;
  font-size: 16px; /* label size; 2.4em = two label lines */
  padding-top: 14px;
  background: var(--blue-tint);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-press);
  overflow: hidden;
}
.town[hidden] { display: none; }
/* Reserve the height before games.json arrives, so nothing jumps. */
.town:not(.is-ready) { min-height: calc(14px + var(--rows) * (var(--sign-h) + 6px + var(--art-h) + 24px + 1.2em)); }

/* ---------- Street (mobile: horizontal snap strip of neighbourhoods) ---------- */
.town { --sign-h: 36px; --lot-min: 112px; }
.town__street {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.town__street::-webkit-scrollbar { display: none; }

/* A neighbourhood: its sign, then its row of lots. */
.town__block {
  --d-col: var(--goo-green-dark);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.town__sign {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--sign-h);
  max-width: calc(100% - 8px);
  margin: 0 4px 6px;
  padding: 3px 12px 3px 4px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.12);
  font-size: 0.82em;
  line-height: 1.05;
  font-weight: 700;
  color: var(--ink);
}
.town__sign-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--d-col);
}
.town__sign-icon svg { width: 20px; height: 20px; }
.town__sign-name { min-width: 0; }

.town__lots { list-style: none; margin: 0; padding: 0; display: flex; flex: 1 1 auto; }

.town__lot {
  flex: 0 0 var(--lot-w);
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  padding: 0 4px 14px;
  /* Ground: green band under the buildings, kerb in the district colour. */
  background:
    linear-gradient(to top, var(--d-col) 6px, transparent 0),
    linear-gradient(to bottom, transparent calc(var(--art-h) - 8px), var(--green-tint) 0);
}

/* ---------- Tablet and up: neighbourhoods wrap into balanced rows ---------- */
@media (min-width: 600px) {
  .town { --art-h: 140px; --rows: 2; font-size: 17px; }
  .town__street { flex-wrap: wrap; overflow: visible; }
  .town__block { flex: var(--n) 1 calc(var(--n) * var(--lot-min)); }
  .town__lots { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); }
}

/* ---------- Tablet landscape: one street when it fits ---------- */
@media (min-width: 1024px) {
  .town { --art-h: 120px; --rows: 1; --lot-min: 98px; }
}

.town__bldg,
.town__jar {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
  min-height: 64px;
  border-radius: var(--radius-inner);
  color: var(--ink-soft);
  text-decoration: none;
}
.town__bldg { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.town__bldg:focus-visible { outline-offset: -4px; }

.town__art {
  position: relative;
  isolation: isolate;
  display: block;
  width: 100%;
  height: var(--art-h);
  transition: transform 80ms ease;
}
.town__art svg { width: 100%; height: 100%; overflow: visible; }
.town__bldg:active .town__art { transform: translateY(4px); }

.town__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  min-height: 1.2em;
  margin-top: 6px;
  font-size: 1em;
  line-height: 1.2;
  font-weight: 600;
  text-align: center;
  color: var(--ink-soft);
}
.town__count {
  margin-top: 2px;
  font-size: 1.5em;
  line-height: 1;
  font-weight: 700;
  color: var(--goo-green-dark);
}

/* ---------- Desktop ---------- */
@media (min-width: 1280px) {
  .town { --art-h: 150px; font-size: 18px; }
}

/* ---------- Ambient motion (off under reduced motion via goo.css) ---------- */
.town .t-tw,
.town .t-bob,
.town .t-wave { transform-box: fill-box; transform-origin: center; }
.town .t-tw { animation: town-twinkle 2.4s ease-in-out infinite; }
.town .t-bob { animation: town-bob 3s ease-in-out infinite; }
.town .t-wave { transform-origin: left center; animation: town-wave 1.8s ease-in-out infinite; }
.town .t-flow { animation: town-flow 1.1s linear infinite; }
.town .t-d2 { animation-delay: -1.1s; }
.town .t-d3 { animation-delay: -2s; }

@keyframes town-twinkle { 50% { transform: scale(0.6) rotate(25deg); opacity: 0.6; } }
@keyframes town-bob { 50% { transform: translateY(-5px); } }
@keyframes town-wave { 50% { transform: scaleX(0.8) skewY(5deg); } }
@keyframes town-flow { to { stroke-dashoffset: -26; } }

/* ---------- "Something got better" celebration ---------- */
.town__bldg.is-celebrating .town__art svg {
  transform-origin: 50% 100%;
  animation: town-hop 900ms cubic-bezier(0.3, 1.5, 0.5, 1) both;
}
.town__bldg.is-celebrating .town__art::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 55%;
  width: min(100%, var(--art-h));
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--goo-yellow);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  animation: town-glow 1000ms ease-out both;
}
@keyframes town-hop {
  0% { transform: none; }
  20% { transform: scale(1.1, 0.88); }
  45% { transform: translateY(-14px) scale(0.94, 1.08); }
  70% { transform: translateY(0) scale(1.05, 0.96); }
  100% { transform: none; }
}
@keyframes town-glow {
  30% { opacity: 0.75; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
}

.town__burst { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.town__spark {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px;
  border-radius: 50%;
  background: var(--goo-yellow);
  opacity: 0;
  animation: town-spark 950ms cubic-bezier(0.2, 0.8, 0.4, 1) both;
}
.town__spark:nth-child(1)  { --dx: 0px;   --dy: -62px; }
.town__spark:nth-child(2)  { --dx: 40px;  --dy: -48px; background: var(--goo-pink); }
.town__spark:nth-child(3)  { --dx: 58px;  --dy: -12px; background: var(--goo-blue); }
.town__spark:nth-child(4)  { --dx: 50px;  --dy: 28px;  background: var(--goo-green); }
.town__spark:nth-child(5)  { --dx: 18px;  --dy: 50px;  background: var(--goo-purple); }
.town__spark:nth-child(6)  { --dx: -18px; --dy: 50px; }
.town__spark:nth-child(7)  { --dx: -50px; --dy: 28px;  background: var(--goo-pink); }
.town__spark:nth-child(8)  { --dx: -58px; --dy: -12px; background: var(--goo-blue); }
.town__spark:nth-child(9)  { --dx: -40px; --dy: -48px; background: var(--goo-green); }
.town__spark:nth-child(10) { --dx: 0px;   --dy: -30px; width: 10px; height: 10px; margin: -5px; background: var(--goo-purple); }
@keyframes town-spark {
  0% { opacity: 1; transform: translate(0, 0) scale(0.4); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1); }
}

/* Motion off: a still glow behind the improved building instead of a hop. */
@media (prefers-reduced-motion: reduce) {
  .town__bldg.is-celebrating .town__art { background: var(--yellow-tint); border-radius: var(--radius-inner); }
  .town__bldg.is-celebrating .town__art::before { display: none; }
}
