/* ============================================================
   PETOPIA — Mobile-first Styles
   ============================================================ */

:root {
  --bg-deep:     #0A0C14;
  --bg-dark:     #10141F;
  --bg-panel:    #161C2E;
  --bg-card:     #1E2740;
  --bg-hover:    #252E4A;
  --bg-input:    #0E1220;
  --border:      rgba(255,255,255,0.08);
  --border-light:rgba(255,255,255,0.14);

  --text-primary:   #EEF0F8;
  --text-secondary: #8B9BC8;
  --text-muted:     #505878;

  --accent:      #6C7FFF;
  --accent-glow: rgba(108,127,255,0.3);
  --accent-dark: #4A5BB8;
  --gold:        #FFD700;
  --gold-glow:   rgba(255,215,0,0.25);

  --fire:        #FF6B35;
  --water:       #4A9EFF;
  --earth:       #6DB33F;
  --air:         #C8C4A0;
  --lightning:   #FFD700;

  --common:    #9BA3B8;
  --uncommon:  #4DBF70;
  --rare:      #5EA3FF;
  --legendary: #FFD700;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm:   0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:   0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:   0 8px 40px rgba(0,0,0,0.6);

  /* Safe area insets for devices with home bar */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);

  --topbar-h:   52px;
  --bnav-h:     62px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden; /* no body scroll — each screen scrolls internally */
  line-height: 1.5;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 99px; }

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 0.95rem; font-weight: 600; }
p  { color: var(--text-secondary); }
a  { color: var(--accent); text-decoration: none; }

/* ════════════════════════════════════════════════════════════
   APP SHELL — mobile-first, fixed chrome
════════════════════════════════════════════════════════════ */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport for mobile */
  position: relative;
}

/* ── Top Bar ──────────────────────────────────────────────── */
#topbar {
  flex-shrink: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-logo {
  font-size: 1rem;
  font-weight: 800;
  background: linear-gradient(135deg, #6C7FFF, #C87CFF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.topbar-spacer { flex: 1; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}
.level-badge span { color: var(--accent); font-weight: 700; }

.xp-bar-wrap {
  width: 60px;
  height: 4px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  flex-shrink: 0;
}
.xp-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #9C6FFF);
  transition: width 0.4s ease;
  width: 0%;
}

.coin-display {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Main content area ────────────────────────────────────── */
#main {
  flex: 1;
  overflow: hidden;
  position: relative;
  /* Map screen is position:absolute inside here; others scroll */
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  display: none;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.screen.active {
  display: block;
}

/* Map screen fills container with no padding/scroll */
.screen.map-screen {
  padding: 0;
  overflow: hidden;
}

/* ── Bottom Navigation ────────────────────────────────────── */
#bottom-nav {
  flex-shrink: 0;
  height: var(--bnav-h);
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}

.bnav-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
  transition: width 0.2s ease;
}

.bnav-item.active::before { width: 32px; }

.bnav-icon {
  font-size: 1.35rem;
  transition: transform 0.15s;
  line-height: 1;
}
.bnav-item.active .bnav-icon { transform: translateY(-1px); }

.bnav-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  transition: color 0.15s;
}
.bnav-item.active .bnav-label { color: var(--accent); }

/* ════════════════════════════════════════════════════════════
   BOTTOM SHEET
════════════════════════════════════════════════════════════ */

#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

#sheet-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

#sheet-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* sits above bottom nav */
  z-index: 50;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  max-height: 78vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  padding-bottom: calc(16px + var(--safe-bottom));
}

#sheet-overlay.open {
  transform: translateY(0);
}

.sheet-handle-wrap {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  background: var(--bg-panel);
  z-index: 1;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-light);
  border-radius: 99px;
}

#sheet-content {
  padding: 0 16px 8px;
}

/* ════════════════════════════════════════════════════════════
   WORLD MAP — fills the map screen completely
════════════════════════════════════════════════════════════ */

/* ── Star field animation ─────────────────────────────────── */
@keyframes starTwinkle {
  from { opacity: var(--star-op-lo, 0.15); }
  to   { opacity: var(--star-op-hi, 0.95); }
}

/* ── World Map Container ──────────────────────────────────── */
.world-map-full {
  width: 100%;
  height: 100%;
  position: relative;
  background: #020208;
  overflow: hidden;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Enable container queries so children can read both dimensions */
  container-type: size;
}

/* Globe image wrapper — always min(containerW, containerH) square.
   cqw/cqh are container query width/height units; min() picks the
   smaller axis so the globe never overflows in any orientation. */
.map-globe-wrap {
  position: relative;
  flex-shrink: 0;
  width:  min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
}

.map-globe-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Connection lines SVG (inside globe-wrap, same coord space as nodes) */
.map-connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* ── Map Nodes ────────────────────────────────────────────── */
.map-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}

.node-bubble {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.22);
  background: rgba(8, 10, 24, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow:
    0 3px 14px rgba(0,0,0,0.7),
    0 0 0 3px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.1);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  position: relative;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Element glows */
.map-node[data-element="fire"]      .node-bubble { border-color: rgba(255,110,40,0.55);  box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 16px rgba(255,100,30,0.35),  inset 0 1px 0 rgba(255,255,255,0.1); }
.map-node[data-element="water"]     .node-bubble { border-color: rgba(60,160,255,0.55);  box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 16px rgba(40,140,255,0.35),  inset 0 1px 0 rgba(255,255,255,0.1); }
.map-node[data-element="earth"]     .node-bubble { border-color: rgba(100,185,55,0.55);  box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 16px rgba(90,170,40,0.30),   inset 0 1px 0 rgba(255,255,255,0.1); }
.map-node[data-element="air"]       .node-bubble { border-color: rgba(210,205,160,0.50); box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 16px rgba(200,195,150,0.25), inset 0 1px 0 rgba(255,255,255,0.1); }
.map-node[data-element="lightning"] .node-bubble { border-color: rgba(255,215,0,0.60);   box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 18px rgba(255,210,0,0.40),   inset 0 1px 0 rgba(255,255,255,0.1); }

/* Hover */
.map-node:not(.locked):hover .node-bubble {
  transform: scale(1.14) translateY(-2px);
  box-shadow: 0 6px 22px rgba(0,0,0,0.75), 0 0 0 2px rgba(108,127,255,0.5);
}
.map-node:active .node-bubble { transform: scale(0.93); }

/* Current location */
.map-node.current .node-bubble {
  border-color: var(--accent);
  box-shadow: 0 3px 14px rgba(0,0,0,0.65), 0 0 22px rgba(108,127,255,0.55), inset 0 1px 0 rgba(255,255,255,0.12);
}
.map-node.current .node-bubble::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: currentPulse 2.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes currentPulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50%       { opacity: 0.1;  transform: scale(1.22); }
}

/* Locked */
.map-node.locked { cursor: not-allowed; }
.map-node.locked .node-bubble { filter: saturate(0.2) brightness(0.5); }

/* Node label */
.node-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  max-width: 74px;
  line-height: 1.25;
  color: #fff;
  pointer-events: none;
  background: rgba(4, 6, 16, 0.78);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 3px;
  padding: 2px 5px;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.map-node.locked .node-label { color: var(--text-muted); }

/* Lock badge */
.node-lock-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  font-size: 0.58rem;
  background: rgba(6, 8, 20, 0.92);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 50%;
  width: 17px;
  height: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Map legend */
.map-legend {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(4, 6, 18, 0.82);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.65rem;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  display: flex;
  gap: 14px;
  white-space: nowrap;
  z-index: 10;
}
.map-legend-item { display: flex; align-items: center; gap: 5px; }

/* ════════════════════════════════════════════════════════════
   LOCATION SHEET CONTENT
════════════════════════════════════════════════════════════ */

.sheet-loc-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sheet-loc-emoji { font-size: 2.4rem; flex-shrink: 0; }

.sheet-loc-title { font-size: 1.1rem; font-weight: 700; }
.sheet-loc-desc  { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }

.sheet-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 16px 0 8px;
}

.sheet-action-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ════════════════════════════════════════════════════════════
   CARDS & PANELS
════════════════════════════════════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ════════════════════════════════════════════════════════════
   BUTTONS
════════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:active { filter: brightness(0.88); transform: scale(0.97); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:active { filter: brightness(0.88); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:active { background: var(--bg-hover); }

.btn-gold {
  background: linear-gradient(135deg, #B8860B, #FFD700);
  color: #1A1200;
  font-weight: 700;
}
.btn-gold:active { filter: brightness(0.9); transform: scale(0.97); }

.btn-danger {
  background: rgba(231,76,60,0.12);
  color: #E74C3C;
  border-color: rgba(231,76,60,0.25);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-sm { padding: 6px 12px; font-size: 0.78rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; border-radius: var(--radius-lg); }
.btn-full { width: 100%; }

/* ════════════════════════════════════════════════════════════
   BADGES & TAGS
════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-common    { background: rgba(155,163,184,0.15); color: var(--common);    border: 1px solid rgba(155,163,184,0.25); }
.badge-uncommon  { background: rgba(77,191,112,0.12);  color: var(--uncommon);  border: 1px solid rgba(77,191,112,0.25);  }
.badge-rare      { background: rgba(94,163,255,0.12);  color: var(--rare);      border: 1px solid rgba(94,163,255,0.25);  }
.badge-legendary { background: rgba(255,215,0,0.12);   color: var(--legendary); border: 1px solid rgba(255,215,0,0.25);   }

.tag-fire      { background: rgba(255,107,53,0.12);  color: var(--fire);      border: 1px solid rgba(255,107,53,0.25); }
.tag-water     { background: rgba(74,158,255,0.12);  color: var(--water);     border: 1px solid rgba(74,158,255,0.25); }
.tag-earth     { background: rgba(109,179,63,0.12);  color: var(--earth);     border: 1px solid rgba(109,179,63,0.25); }
.tag-air       { background: rgba(200,196,160,0.12); color: var(--air);       border: 1px solid rgba(200,196,160,0.25); }
.tag-lightning { background: rgba(255,215,0,0.12);   color: var(--lightning); border: 1px solid rgba(255,215,0,0.25); }

/* ════════════════════════════════════════════════════════════
   STAT BARS
════════════════════════════════════════════════════════════ */

.stat-bar-wrap  { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.stat-bar-label { font-size: 0.78rem; color: var(--text-secondary); width: 90px; flex-shrink: 0; }
.stat-bar-track { flex: 1; height: 7px; background: var(--bg-input); border-radius: 99px; overflow: hidden; }
.stat-bar-fill  { height: 100%; border-radius: 99px; transition: width 0.4s ease; }
.stat-bar-fill.happiness { background: linear-gradient(90deg, #E91E8C, #FF6EC7); }
.stat-bar-fill.hunger    { background: linear-gradient(90deg, #FF9800, #FFD54F); }
.stat-bar-fill.health    { background: linear-gradient(90deg, #4CAF50, #8BC34A); }
.stat-bar-val   { font-size: 0.78rem; font-weight: 600; width: 28px; text-align: right; flex-shrink: 0; }

/* ════════════════════════════════════════════════════════════
   PET AVATAR
════════════════════════════════════════════════════════════ */

.pet-avatar {
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.pet-avatar.sz-md  { width: 72px;  height: 72px;  font-size: 2.4rem; }
.pet-avatar.sz-lg  { width: 100px; height: 100px; font-size: 3.6rem; border-radius: 22px; }
.pet-avatar.sz-xl  { width: 130px; height: 130px; font-size: 4.8rem; border-radius: 28px; }
.pet-avatar img { width: 85%; height: 85%; object-fit: contain; image-rendering: pixelated; }

.mood-indicator {
  position: absolute;
  bottom: -7px;
  right: -7px;
  font-size: 1rem;
  background: var(--bg-dark);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-panel);
}

/* ════════════════════════════════════════════════════════════
   ITEM CARDS
════════════════════════════════════════════════════════════ */

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

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s;
  text-align: center;
}

.item-card:active { background: var(--bg-hover); }
.item-card.equipped { border-color: var(--accent); }

.item-card .item-icon  { font-size: 1.7rem; }
.item-card .item-name  { font-size: 0.72rem; font-weight: 600; line-height: 1.2; }
.item-card .item-qty   { font-size: 0.68rem; color: var(--text-secondary); }
.item-card .item-rarity {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 0.55rem;
  font-weight: 800;
  text-transform: uppercase;
}
.item-card .item-price { font-size: 0.7rem; font-weight: 700; color: var(--gold); }

/* ════════════════════════════════════════════════════════════
   TABS
════════════════════════════════════════════════════════════ */

.tabs {
  display: flex;
  gap: 3px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 14px;
}

.tab-btn {
  flex: 1;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.tab-btn.active { background: var(--bg-card); color: var(--text-primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ════════════════════════════════════════════════════════════
   MODAL
════════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding-bottom: var(--safe-bottom);
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
  transform: translateY(30px);
  transition: transform 0.22s ease;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════
   TOAST
════════════════════════════════════════════════════════════ */

#toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 200;
  width: min(340px, 92vw);
  pointer-events: none;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease;
  transition: opacity 0.25s, transform 0.25s;
}

.toast.success { border-left: 3px solid #4CAF50; }
.toast.error   { border-left: 3px solid #E74C3C; }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.gold    { border-left: 3px solid var(--gold); }
.toast.hide    { opacity: 0; transform: translateY(-8px); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ════════════════════════════════════════════════════════════
   FORMS
════════════════════════════════════════════════════════════ */

.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

/* ════════════════════════════════════════════════════════════
   ACTIVITY CARD
════════════════════════════════════════════════════════════ */

.activity-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: border-color 0.15s;
}
.activity-card.done { opacity: 0.55; }
.activity-emoji { font-size: 1.7rem; flex-shrink: 0; }
.activity-info  { flex: 1; min-width: 0; }
.activity-name  { font-weight: 600; font-size: 0.88rem; }
.activity-desc  { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.activity-cd    { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ════════════════════════════════════════════════════════════
   EQUIPMENT SLOTS
════════════════════════════════════════════════════════════ */

/* Legacy grid kept for admin panel compatibility */
.equipment-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

/* ── Equipment cross grid layout ───────────────────────── */
/*
  Layout (3 cols × 3 rows, centre slot occupied per row):
    .   head  .
  hands body back
    .  boots  .
*/
.equip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    ".     head  ."
    "hands body  back"
    ".     boots .";
  gap: 12px;
  max-width: 320px;
  margin: 12px auto 4px;
}

.equip-body-slot {
  background: var(--bg-input);
  border: 2px dashed rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  padding: 10px 8px 8px;
  text-align: center;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}
.equip-body-slot.filled {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(108,127,255,0.08);
}
.equip-body-slot.has-item {
  border-color: rgba(255,215,0,0.4);
}

.equip-slot-icon { display: flex; justify-content: center; margin-bottom: 4px; }
.equip-slot-icon svg { width: 22px; height: 22px; color: var(--text-secondary); }
.equip-slot-name { font-size: 0.58rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; line-height: 1.2; }
.equip-slot-state { font-size: 0.58rem; font-weight: 600; margin-top: 2px; }
.equip-slot-state.on    { color: var(--accent); }
.equip-slot-state.has   { color: var(--gold); }
.equip-slot-state.empty { color: var(--text-muted); }

/* Legacy slot (still used by some code paths) */
.equip-slot {
  background: var(--bg-input);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 10px 6px;
  text-align: center;
  cursor: default;
}
.equip-slot.filled { border-style: solid; border-color: var(--accent); }

/* ════════════════════════════════════════════════════════════
   PET SPECIES GRID
════════════════════════════════════════════════════════════ */

.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.species-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.species-card:active { background: var(--bg-hover); }
.species-card.selected { border-color: var(--accent); background: rgba(108,127,255,0.08); }
.species-emoji { font-size: 2rem; margin-bottom: 6px; line-height: 1; }
.species-emoji img { width: 56px; height: 56px; object-fit: contain; image-rendering: pixelated; }
.species-name  { font-size: 0.78rem; font-weight: 700; margin-bottom: 4px; }

/* ════════════════════════════════════════════════════════════
   COLOR PALETTE
════════════════════════════════════════════════════════════ */

.color-palette { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
  outline: 2px solid transparent;
  outline-offset: 3px;
}
.color-swatch:active { transform: scale(0.9); }
.color-swatch.selected { outline-color: white; }

/* ════════════════════════════════════════════════════════════
   ONBOARDING
════════════════════════════════════════════════════════════ */

#onboarding-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.onboarding-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.onboarding-logo {
  font-size: 2.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, #6C7FFF, #C87CFF, #FF6EC7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.step-indicator {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 22px;
}
.step-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bg-hover);
  transition: all 0.2s;
}
.step-dot.active { background: var(--accent); width: 22px; border-radius: 99px; }
.step-dot.done   { background: var(--earth); }

/* ════════════════════════════════════════════════════════════
   MINI-GAME CONTAINER
════════════════════════════════════════════════════════════ */

.minigame-wrap {
  background: var(--bg-input);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}
.minigame-hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  flex-wrap: wrap;
}
.minigame-hud .score { font-weight: 700; color: var(--gold); }
.minigame-hud .timer { color: var(--text-secondary); }

/* ════════════════════════════════════════════════════════════
   UTILITY HELPERS
════════════════════════════════════════════════════════════ */

.flex           { display: flex; }
.flex-col       { display: flex; flex-direction: column; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-between{ justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-1         { flex: 1; }
.flex-shrink-0  { flex-shrink: 0; }
.gap-4          { gap: 4px; }
.gap-6          { gap: 6px; }
.gap-8          { gap: 8px; }
.gap-10         { gap: 10px; }
.gap-12         { gap: 12px; }
.gap-16         { gap: 16px; }
.gap-20         { gap: 20px; }
.w-full         { width: 100%; }

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }

.text-sm     { font-size: 0.8rem; }
.text-xs     { font-size: 0.72rem; }
.text-muted  { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-gold   { color: var(--gold); }
.text-accent { color: var(--accent); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.font-bold   { font-weight: 700; }
.font-semibold { font-weight: 600; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.divider { height: 1px; background: var(--border); margin: 14px 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }

/* ════════════════════════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════════════════════════ */

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-5px); }
}
.bounce { animation: bounce 1.4s ease-in-out infinite; }

@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
.legendary-shimmer {
  background: linear-gradient(90deg, #B8860B, #FFD700, #FFF3A0, #FFD700, #B8860B);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.5s linear infinite;
}

/* ════════════════════════════════════════════════════════════
   TABLET / DESKTOP — wider screens get centered content
════════════════════════════════════════════════════════════ */

@media (min-width: 600px) {
  #bottom-nav { justify-content: center; }
  .bnav-item  { max-width: 100px; }

  .screen:not(.map-screen) { padding: 20px; }

  /* On wider screens, some screens get a max-width */
  #dashboard-screen,
  #pets-screen,
  #inventory-screen,
  #games-screen,
  #profile-screen { max-width: 680px; margin: 0 auto; }

  .modal {
    border-radius: 20px;
    margin: auto;
    bottom: auto;
    max-width: 520px;
  }
  .modal-overlay { align-items: center; padding: 16px; }

  #sheet-overlay {
    max-width: 560px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border-radius: 20px 20px 0 0;
  }
  #sheet-overlay.open {
    transform: translateX(-50%) translateY(0);
  }

  .item-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

@media (min-width: 900px) {
  .species-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .equipment-row { gap: 10px; }
}

/* ============================================================
   LOCATION VIEW (full-screen scene)
   ============================================================ */

/* Outer shell */
.loc-view {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f0f2f8;
}

/* Horizontally scrollable track — fills the full viewport area */
.loc-scroll {
  position: absolute;
  inset: 0;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.loc-scroll::-webkit-scrollbar { display: none; }
.loc-scroll.dragging { cursor: grabbing; user-select: none; }

/* Scene: full height, width driven by its content (the bg image) */
.loc-scene {
  position: relative;
  height: 100%;
  display: inline-block;
  min-width: 100%;
  vertical-align: top;
  background: #e8ecf5;
}

/* BG image: fills height, auto-width preserves aspect ratio */
.loc-scene img.loc-bg-img {
  display: block;
  height: 100%;
  width: auto;
}

/* Back button — top-left of the view (not the scene) */
.loc-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 30;
  background: rgba(10,13,28,0.72);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.loc-back-btn:hover { background: rgba(20,24,44,0.9); }

/* FAB buttons — bottom-right corner of the view */
.loc-fabs {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.loc-fab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 99px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(10,13,28,0.82);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: background 0.15s, transform 0.12s;
  white-space: nowrap;
}
.loc-fab:hover { background: rgba(30,40,70,0.92); transform: translateY(-1px); }
.loc-fab.fab-activities { border-color: rgba(76,239,149,0.4); color: #4cef95; }
.loc-fab.fab-shops      { border-color: rgba(241,196,15,0.4);  color: #f1c40f; }

/* Location dialog (activities / shops list) */
.loc-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.loc-dialog {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.loc-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.loc-dialog-header h3 { font-size: 0.95rem; font-weight: 700; }
.loc-dialog-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.06);
  color: var(--text-secondary); cursor: pointer; font-size: 0.9rem;
}
.loc-dialog-body {
  padding: 12px 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================================
   GAME FULLSCREEN
   ============================================================ */

.game-fullscreen {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-deep);
}

.game-fullscreen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-dark);
  flex-shrink: 0;
}

.game-fullscreen-back {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.game-fullscreen-back:hover { background: var(--bg-hover); }

.game-fullscreen-title {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}

.game-fullscreen-area {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* Locked game card */
.game-locked-card {
  opacity: 0.45;
  filter: grayscale(0.6);
  pointer-events: none;
}
.game-locked-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}
