px-cat, px-sprite {
  display: block;
  line-height: 0;
}

.app-header__cat { width: 36px; height: 36px; }
.auth-modal__cat { width: 36px; height: 36px; }

.village-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 4px;
}

.village-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 6px;
}

.village-panel--compact px-village { display: block; }

px-village {
  border: 1px solid var(--panel-border);
}

/* ── Home village hero ───────────────────────────────────────────────────── */
/* The home page opens on the village, full width and drawn at 2× pixels
   (px-village reads --village-height / --village-zoom), under a flat sign
   with the title, level and net asset — the sign sits above the scene, not
   over it. Tapping the village walks into the town. */
.village-hero {
  --village-height: 440px;
  --village-zoom: 2;
  --sign-border: #e7b3c2;
  position: relative;
  border-bottom: 4px solid var(--panel-border-strong);
}

.village-hero px-village { border: none; cursor: pointer; }

:root[data-theme="dark"] .village-hero {
  --sign-border: #7d6fa8;
}

.village-hero .home-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  /* content lines up with the centred column below */
  padding: 12px max(24px, calc(50% - 596px));
  background: var(--panel);
  border-bottom: 3px solid var(--sign-border);
}

.home-hero__mark {
  background: var(--panel-accent);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  box-shadow: var(--shadow-sm);
}

.home-hero__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.home-hero__lv {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.home-hero__asset {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-left: auto;
  padding-left: 18px;
  border-left: 2px dashed var(--sign-border);
}

.home-hero__asset strong {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Town page ───────────────────────────────────────────────────────────── */
/* Small chips over the map, top-left: back to Home, the level, the 圖鑑. The
   full numbers live on Home, so nothing big covers the town. */
.town-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

.town-bar__chip {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border: 2px solid #e7b3c2;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--body-text);
  font-family: var(--font-pixel);
  font-size: 13px;
  box-shadow: 0 2px 0 #d79aab;
  white-space: nowrap;
}

button.town-bar__chip { cursor: pointer; }
button.town-bar__chip:hover { background: var(--panel); }

:root[data-theme="dark"] .town-bar__chip {
  border-color: #7d6fa8;
  box-shadow: 0 2px 0 #4a4275;
}

/* "drag to look around", until the first drag */
.town-hint {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(61, 51, 38, 0.82);
  color: #fbf6ee;
  font-size: 13px;
  pointer-events: none;
}

/* the 圖鑑 modal holds Home's deck while it's open */
.dex-modal__content {
  max-width: 720px;
  padding: 2.75rem 1rem 1rem; /* clear of the close button */
}

.dex-modal__content .cat-dex {
  border: none;
  box-shadow: none;
  background: none;
  padding: 0;
}

/* ── Cat collection (圖鑑) ─────────────────────────────────────────────────── */
.cat-dex {
  --dex-border: #cdbbea;
  --dex-shadow: #b3a0d6;
  --dex-frame: #f6f0ff;
  --dex-card: #fffdfa;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 14px;
}

:root[data-theme="dark"] .cat-dex {
  --dex-border: #5e5287;
  --dex-shadow: #2a2442;
  --dex-frame: #2f2a45;
  --dex-card: #2b241a;
}

/* A fanned deck: the active card in front, the rest tilted and stacked behind
   it by distance (--d / --dist are set per card by ui/pages/home.js). */
.cat-dex__deck {
  position: relative;
  display: flex;
  align-items: center;
}

.cat-dex__stage {
  --spread: clamp(56px, 12vw, 120px);
  position: relative;
  flex: 1;
  height: 316px;
  overflow: hidden;
  /* Keep the cards' z-index (up to 100, set per card) inside the deck, so the
     front card can't rise above the phone tab bar or other fixed UI. */
  isolation: isolate;
  touch-action: pan-y;
  user-select: none;
  outline: none;
}

.cat-dex__stage:focus-visible { box-shadow: 0 0 0 2px var(--dex-border); border-radius: var(--radius-md); }

.cat-dex__stage .cat-card {
  position: absolute;
  top: 30px;
  left: 50%;
  width: 176px;
  margin-left: -88px;
  cursor: pointer;
  transform:
    translateX(calc(var(--d, 0) * var(--spread)))
    translateY(calc(var(--dist, 0) * 8px))
    rotate(calc(var(--d, 0) * 5deg))
    scale(calc(1 - var(--dist, 0) * 0.08));
  transition: transform 0.35s cubic-bezier(.2,.8,.3,1.1), opacity 0.3s, filter 0.3s;
  filter: saturate(0.75) brightness(0.97);
}

.cat-dex__stage .cat-card--active {
  cursor: default;
  filter: none;
  transform: translateY(-4px) scale(1.04);
  box-shadow: 0 5px 0 var(--dex-shadow), 0 10px 24px rgba(120, 96, 170, 0.25);
}

.cat-dex__stage .cat-card--hidden { opacity: 0; pointer-events: none; }

.cat-dex__nav {
  flex: none;
  width: 34px;
  height: 34px;
  border: 2px solid var(--dex-border);
  border-radius: 50%;
  background: var(--dex-card);
  color: var(--ink);
  font: 700 1.3rem/1 var(--font-pixel);
  cursor: pointer;
  box-shadow: 0 2px 0 var(--dex-shadow);
}

.cat-dex__nav:disabled { opacity: 0.35; cursor: default; }

.cat-dex__dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.cat-dex__dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: var(--dex-border);
  opacity: 0.45;
  cursor: pointer;
}

.cat-dex__dot--active { opacity: 1; width: 18px; }

.cat-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 10px 12px;
  background: var(--dex-card);
  border: 3px solid var(--dex-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 3px 0 var(--dex-shadow);
  min-width: 0;
}

.cat-card__no {
  position: absolute;
  top: 6px;
  left: 9px;
  font-family: var(--font-pixel);
  font-size: 0.72rem;
  color: var(--muted);
}

.cat-card__frame {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  min-height: 116px;
  padding: 10px 0 6px;
  background: var(--dex-frame);
  border-radius: var(--radius-md);
}

.cat-card__name {
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.cat-card__meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.cat-card__mass {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
  cursor: help;
}

.cat-card__mass strong {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--ink);
}

.cat-card__body {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--dex-frame);
  color: var(--muted);
  font-size: 0.72rem;
}

.cat-card__stats {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--dash-border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--body-text);
}

.cat-card__move--up { color: var(--up); }
.cat-card__move--down { color: var(--down); }
.cat-card__move--flat { color: var(--flat); }
