:root {
  --bg: #fff6f1;
  --bg2: #ffe9ef;
  --card: #ffffff;
  --ink: #4a3b47;
  --ink-soft: #8a7884;
  --line: #f1dfe6;
  --pink: #ff8fab;
  --pink-deep: #e8698c;
  --lilac: #b79cf2;
  --mint: #7fd1ae;
  --sun: #f6d55c;
  --sky: #7cc4f2;
  --danger: #ef7d7d;
  --shadow: 0 4px 14px rgba(160, 90, 120, 0.12);
  --dots: #ffffff66;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", "Nunito", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #251e2b;
    --bg2: #2f2637;
    --card: #362c3f;
    --ink: #f6eaf1;
    --ink-soft: #bba8b8;
    --line: #4a3e55;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    --dots: #ffffff0d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg2);
  background-image: radial-gradient(circle at 20% 10%, var(--dots) 0 8px, transparent 9px), radial-gradient(circle at 70% 60%, var(--dots) 0 6px, transparent 7px);
  background-size: 120px 120px, 90px 90px;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(160, 90, 120, 0.15);
  position: relative;
}

/* ---------- top bar & tabs ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  background: var(--card);
  border-bottom: 2px solid var(--line);
}
.brand { font-weight: 800; font-size: 18px; color: var(--pink-deep); letter-spacing: 0.2px; white-space: nowrap; }
.wallet { display: flex; align-items: center; gap: 6px; }
.pill { background: var(--bg2); border-radius: 999px; padding: 4px 10px; font-size: 14px; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; font-size: 20px; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; }
.icon-btn:active { background: var(--bg2); }

#view { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }

#tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--card);
  border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#tabs button {
  position: relative;
  border: 0;
  background: transparent;
  padding: 7px 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
  min-height: 56px;
}
#tabs button span { font-size: 22px; transition: transform 0.15s; }
#tabs button.active { color: var(--pink-deep); }
#tabs button.active span { transform: translateY(-2px) scale(1.12); }
.badge {
  position: absolute; top: 5px; right: calc(50% - 22px);
  background: var(--pink-deep); color: #fff; font-style: normal; font-size: 10px;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
body.in-battle #topbar, body.in-battle #tabs { display: none; }

/* ---------- generic bits ---------- */
.screen { padding: 14px 16px 24px; }
.screen h2 { margin: 6px 0 10px; font-size: 20px; }
.screen h3 { margin: 18px 0 8px; font-size: 16px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  min-height: 46px;
  font-weight: 800;
  font-size: 15px;
  background: var(--pink);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--pink-deep);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--pink-deep); }
.btn.alt { background: var(--lilac); box-shadow: 0 3px 0 #9077d6; }
.btn.mint { background: var(--mint); box-shadow: 0 3px 0 #58b28d; }
.btn.ghost { background: var(--bg2); color: var(--ink); box-shadow: 0 3px 0 var(--line); }
.btn.small { padding: 8px 12px; min-height: 40px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg2); border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; }

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--mint); border-radius: 4px; transition: width 0.3s; }

/* ---------- overlays ---------- */
#overlay-root { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }
.overlay {
  position: absolute; inset: 0; pointer-events: auto;
  background: rgba(60, 30, 50, 0.38);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade 0.15s;
}
.modal {
  background: var(--card);
  border-radius: 24px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px 18px 18px;
  box-shadow: 0 10px 40px rgba(60, 30, 50, 0.3);
  animation: pop 0.2s;
}
.modal h3 { margin: 0 0 8px; font-size: 20px; text-align: center; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal .actions .btn { flex: 1; }
.modal input[type=text], .modal textarea {
  width: 100%; font: inherit; padding: 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--ink);
}
.modal textarea { min-height: 110px; font-size: 12px; font-family: ui-monospace, monospace; user-select: text; -webkit-user-select: text; }
.modal .hero { width: 140px; height: 140px; margin: 0 auto; display: block; }

.toast {
  position: absolute; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 14px; font-weight: 700; font-size: 14px;
  animation: toast 2.4s forwards; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }

/* ---------- critters ---------- */
svg.critter { display: block; width: 100%; height: 100%; overflow: visible; }
.bob svg.critter { animation: bob 2.4s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes bob { 50% { transform: translateY(-3%) scale(1.02, 0.98); } }

/* ---------- burrow ---------- */
.greet { margin: 2px 0 10px; font-size: 18px; font-weight: 800; }
.scene {
  position: relative;
  height: 290px;
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(#cdeaff 0 38%, #bfe6a0 38% 100%);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  isolation: isolate;
}
.scene.night { background: linear-gradient(#3b3d6e 0 38%, #6f9c6a 38% 100%); }
.scene .deco { position: absolute; pointer-events: none; }
.roamer {
  position: absolute; width: 84px; height: 84px; margin: -60px 0 0 -42px;
  transition: left 3.2s ease-in-out, top 3.2s ease-in-out;
  cursor: pointer; z-index: 2;
}
.roamer .nm { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); font-size: 11px; font-weight: 800; background: #ffffffcc; color: #4a3b47; border-radius: 8px; padding: 1px 6px; white-space: nowrap; }
.roamer .body { width: 100%; height: 100%; transition: transform 0.3s; }
.roamer.flip .body { transform: scaleX(-1); }
.roamer.pet svg.critter { animation: squish 0.35s; }
@keyframes squish { 40% { transform: scale(1.12, 0.88); } }
.say {
  position: absolute; left: 50%; bottom: calc(100% - 6px); transform: translateX(-50%);
  width: max-content; max-width: 150px; padding: 5px 10px; border-radius: 12px;
  background: #fff; color: #4a3b47; font-size: 12px; font-weight: 700; line-height: 1.25; text-align: center;
  box-shadow: 0 2px 6px rgba(80, 40, 60, 0.18); pointer-events: none; animation: pop 0.18s;
}
.say::after { content: ''; position: absolute; left: 50%; top: 100%; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; }
.say.think { background: #fffaf0; font-style: italic; font-weight: 600; }
.say.think::after { border-top-color: #fffaf0; }
.say.edge-l { left: 0; transform: none; }
.say.edge-l::after { left: 30px; }
.say.edge-r { left: auto; right: 0; transform: none; }
.say.edge-r::after { left: auto; right: 24px; }
.heart { position: absolute; font-size: 20px; pointer-events: none; animation: floatUp 1s forwards; z-index: 5; }
@keyframes floatUp { to { transform: translateY(-50px) scale(1.3); opacity: 0; } }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.quick .card { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.quick .card b { font-size: 15px; }
.glow { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px #ffd1de, var(--shadow); } }

/* ---------- adventure ---------- */
.region-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font-size: 17px; font-weight: 800; }
.region-h:first-child { margin-top: 4px; }
.map-card { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.map-card .num { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-weight: 900; font-size: 18px; background: var(--bg2); flex: none; }
.map-card.done .num { background: var(--mint); color: #fff; }
.map-card.locked { opacity: 0.5; cursor: default; }
.map-card .info { flex: 1; min-width: 0; }
.map-card .info b { display: block; }
.map-card .friend { width: 46px; height: 46px; flex: none; }
.map-card .friend.mystery { filter: brightness(0) opacity(0.25); }

.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.pick { border: 3px solid transparent; background: var(--bg); border-radius: 16px; padding: 6px 4px 6px; text-align: center; cursor: pointer; position: relative; }
.pick .art { width: 64px; height: 64px; margin: 0 auto; }
.pick .nm { font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .sub { font-size: 11px; color: var(--ink-soft); }
.pick.sel { border-color: var(--pink); background: var(--bg2); }
.pick.sel::after { content: '✓'; position: absolute; top: 4px; right: 6px; background: var(--pink); color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: grid; place-items: center; font-weight: 900; }
.pick.busy { opacity: 0.45; pointer-events: none; }

/* ---------- wardrobe ---------- */
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin: 0 -2px; scrollbar-width: thin; }
.strip .pick { flex: none; width: 82px; }
.strip .pick .art { width: 56px; height: 56px; }
.dress { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center; }
.dress .stage { width: 150px; height: 150px; background: radial-gradient(circle at 50% 70%, var(--bg2) 0 55%, transparent 56%); border-radius: 20px; }
.dress .name { font-size: 19px; font-weight: 900; display: flex; align-items: center; gap: 6px; }
.dress .name button { border: 0; background: var(--bg2); border-radius: 10px; padding: 4px 8px; cursor: pointer; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 8px; text-align: center; }
.stats div { background: var(--bg); border-radius: 10px; padding: 4px 0; font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.stats b { display: block; font-size: 16px; color: var(--ink); }
.stats b.up { color: #3fa877; }
.stats b.down { color: var(--danger); }
.stars { color: #f2b632; letter-spacing: 1px; }
.tabset { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0 10px; }
.tabset button { border: 0; border-radius: 12px; padding: 8px 2px; min-height: 44px; background: var(--card); font-weight: 800; font-size: 12px; cursor: pointer; box-shadow: var(--shadow); }
.tabset button.on { background: var(--pink); color: #fff; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.item { background: var(--card); border: 3px solid transparent; border-radius: 16px; padding: 4px 4px 6px; text-align: center; cursor: pointer; box-shadow: var(--shadow); position: relative; }
.item .art { width: 64px; height: 64px; margin: 0 auto; }
.item .nm { font-size: 11px; font-weight: 800; line-height: 1.15; min-height: 2.3em; display: flex; align-items: center; justify-content: center; }
.item.on { border-color: var(--pink); }
.item .tag { position: absolute; top: 4px; left: 5px; font-size: 13px; }
.item .none { width: 64px; height: 64px; margin: 0 auto; display: grid; place-items: center; font-size: 26px; opacity: 0.5; }
.dyes { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0 4px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--pink-deep); }

/* ---------- errands & boutique ---------- */
.errand { display: flex; gap: 12px; align-items: center; }
.errand .ico { font-size: 30px; width: 46px; text-align: center; flex: none; }
.errand .info { flex: 1; min-width: 0; }
.crew { display: flex; gap: 2px; }
.crew .art { width: 38px; height: 38px; }
.shop-item { display: flex; gap: 10px; align-items: center; }
.shop-item .art { width: 70px; height: 70px; flex: none; background: var(--bg); border-radius: 14px; }
.shop-item .info { flex: 1; min-width: 0; }
.shop-item .info b { display: block; }

/* ---------- battle ---------- */
.battle { height: 100%; display: flex; flex-direction: column; background: var(--bg); }
.bbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px;
  background: var(--card); border-bottom: 2px solid var(--line);
}
.bbar .title { flex: 1; text-align: center; font-weight: 800; font-size: 14px; line-height: 1.15; }
.bbar .title small { display: block; font-weight: 700; color: var(--ink-soft); font-size: 12px; }
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 6px 8px; min-height: 0; }
.board {
  position: relative;
  width: min(100%, calc((100dvh - 250px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 0.75));
  aspect-ratio: 6 / 8;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: manipulation;
  isolation: isolate;
}
.tile { position: relative; cursor: pointer; }
.tile .tile-art { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tile::after { content: ''; position: absolute; inset: 2px; border-radius: 8px; pointer-events: none; }
.tile.mv::after { background: rgba(102, 170, 255, 0.42); box-shadow: inset 0 0 0 2px rgba(80, 140, 240, 0.6); }
.tile.atk::after { background: rgba(255, 170, 200, 0.22); box-shadow: inset 0 0 0 2px rgba(240, 90, 130, 0.55); }
.tile.tgt::after { background: rgba(255, 90, 110, 0.5); box-shadow: inset 0 0 0 3px #ff5d73; animation: pulse 0.9s infinite; }
.tile.heal::after { background: rgba(110, 220, 160, 0.5); box-shadow: inset 0 0 0 3px #3fbf83; animation: pulse 0.9s infinite; }
.tile.danger::after { background: rgba(190, 120, 255, 0.28); }
.tile.sel::after { box-shadow: inset 0 0 0 3px #fff; }
@keyframes pulse { 50% { opacity: 0.55; } }

.units { position: absolute; inset: 0; pointer-events: none; }
.unit {
  position: absolute; width: calc(100% / 6); height: calc(100% / 8);
  transition: left 0.11s linear, top 0.11s linear, opacity 0.5s, filter 0.3s;
  display: flex; align-items: flex-end; justify-content: center;
}
.unit .art { position: absolute; left: 4%; right: 4%; top: -14%; bottom: 10%; }
.unit::before { content: ''; position: absolute; left: 14%; right: 14%; bottom: 6%; height: 16%; border-radius: 50%; background: rgba(80, 140, 240, 0.45); }
.unit.e::before { background: rgba(200, 80, 140, 0.45); }
.unit.e svg.critter { transform: scaleX(-1); }
.unit.boss .art { left: -6%; right: -6%; top: -30%; }
.unit.acted { filter: grayscale(0.7) brightness(0.92); }
.unit.out { opacity: 0; }
.unit .hp { position: absolute; left: 12%; right: 12%; bottom: 2%; height: 9%; min-height: 4px; background: #00000030; border-radius: 3px; overflow: hidden; z-index: 2; }
.unit .hp i { display: block; height: 100%; background: #5ccf91; transition: width 0.35s; }
.unit.e .hp i { background: #f07aa0; }
.unit .shield { position: absolute; top: -6%; left: 2%; font-size: 13px; z-index: 3; }
.unit.hurt .art { animation: hurt 0.35s; }
@keyframes hurt { 20%, 60% { transform: translateX(-8%); } 40%, 80% { transform: translateX(8%); } }
.unit.lunge .art { animation: lunge 0.3s; }
@keyframes lunge { 50% { transform: translateY(-14%) scale(1.08); } }
.float {
  position: absolute; z-index: 10; font-weight: 900; font-size: 18px; color: #ff4d6d;
  text-shadow: 0 2px 0 #fff, 0 0 4px #fff; pointer-events: none;
  transform: translate(-50%, -50%); animation: floatNum 0.9s forwards; white-space: nowrap;
}
.float.heal { color: #23a86b; }
.float.miss { color: #8a7884; font-size: 15px; }
.float.crit { font-size: 23px; color: #ff7a00; }
@keyframes floatNum { to { transform: translate(-50%, -150%); opacity: 0; } }

.dice {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 20; width: 112px; text-align: center; pointer-events: none; animation: pop 0.15s;
}
.dice .d { width: 86px; height: 86px; margin: 0 auto; position: relative; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25)); }
.dice .d svg { width: 100%; height: 100%; }
.dice .d b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; font-weight: 900; color: #fff; padding-top: 4px; }
.dice .lbl { margin-top: 4px; background: #000a; color: #fff; border-radius: 10px; padding: 3px 8px; font-weight: 800; font-size: 13px; display: inline-block; }
.dice.rolling .d { animation: spin 0.45s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel {
  background: var(--card); border-top: 2px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  min-height: 150px;
}
.uinfo { display: flex; gap: 10px; align-items: center; }
.uinfo .art { width: 54px; height: 54px; flex: none; }
.uinfo .meta { flex: 1; min-width: 0; }
.uinfo .meta b { font-size: 15px; }
.uinfo .meta .bar { margin: 4px 0 3px; height: 9px; }
.uinfo .meta .bar i { background: #5ccf91; }
.uinfo.e .meta .bar i { background: #f07aa0; }
.mini { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.acts { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.acts .btn { padding: 8px 6px; font-size: 14px; }
.fc { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; text-align: center; }
.fc .side { background: var(--bg); border-radius: 12px; padding: 6px 4px; }
.fc .side b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc .big { font-size: 16px; font-weight: 900; }
.fc .vs { font-weight: 900; color: var(--ink-soft); }
.adv { font-size: 11px; font-weight: 800; }
.adv.good { color: #3fa877; }
.adv.bad { color: var(--danger); }
.phase-banner {
  position: absolute; left: 0; right: 0; top: 40%; z-index: 30; text-align: center; pointer-events: none;
  font-size: 26px; font-weight: 900; color: #fff; padding: 12px 0;
  background: linear-gradient(90deg, transparent, rgba(232, 105, 140, 0.9), transparent);
  animation: banner 1.1s forwards;
}
.phase-banner.e { background: linear-gradient(90deg, transparent, rgba(140, 100, 200, 0.9), transparent); }
@keyframes banner { 0% { opacity: 0; transform: scaleY(0.2); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- shinies ---------- */
svg.critter .twinkle { animation: twinkle 1.6s ease-in-out infinite; transform-origin: 50% 50%; }
svg.critter .shine { animation: shine 2.4s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: 0.25; } }
@keyframes shine { 50% { opacity: 0.55; } }
.shiny-tag { color: #e0a800; font-weight: 900; }

/* ---------- burrow extras ---------- */
.decor { position: absolute; transform: translate(-50%, -100%); pointer-events: none; }
.decor svg { display: block; width: 100%; height: auto; overflow: visible; }
.scene.decorating .decor { pointer-events: auto; cursor: grab; outline: 2px dashed #ffffffaa; outline-offset: 2px; border-radius: 6px; touch-action: none; }
.scene.decorating .decor.picked { outline: 3px solid var(--lilac); }
.scene.decorating .decor.dragging { cursor: grabbing; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25)); transform: translate(-50%, -104%) scale(1.06); z-index: 200 !important; }
.decor-x {
  position: absolute; top: -12px; right: -12px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #fff; background: var(--danger); color: #fff; font-size: 13px; font-weight: 900;
  display: grid; place-items: center; cursor: pointer; padding: 0; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.scene.decorating .roamer { opacity: 0.35; pointer-events: none; }
.scene.decorating { box-shadow: 0 0 0 3px var(--lilac), var(--shadow); cursor: crosshair; }
.tray { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; }
.tray .ti { flex: none; width: 76px; background: var(--card); border: 3px solid transparent; border-radius: 14px; padding: 4px; text-align: center; font-size: 11px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow); }
.tray .ti svg { width: 48px; height: 48px; }
.tray .ti.on { border-color: var(--lilac); }
.tray .ti.none { opacity: 0.4; pointer-events: none; }
.nest { position: absolute; left: 3%; bottom: 3%; display: flex; align-items: flex-end; gap: 2px; z-index: 120; padding: 0 6px 2px; }
.nest::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 14px; border-radius: 50%; background: #b8875a; box-shadow: inset 0 3px 0 #9b6b4e; z-index: -1; }
.egg { width: 34px; height: 42px; cursor: pointer; animation: wobble 2.8s ease-in-out infinite; transform-origin: 50% 90%; }
.egg.ready { animation: wobble 0.7s ease-in-out infinite; filter: drop-shadow(0 0 6px #fff6b0); }
@keyframes wobble { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-8deg); } 88% { transform: rotate(8deg); } }
.particle { position: absolute; top: -10%; font-size: 16px; pointer-events: none; z-index: 110; animation: fall linear infinite; opacity: 0.85; }
@keyframes fall { to { transform: translate(40px, 340px) rotate(300deg); } }
.toolrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: -2px 0 12px; }
.toolrow .btn { padding: 8px 4px; font-size: 13px; }
.season-chip { font-size: 13px; font-weight: 800; margin-left: 6px; color: var(--ink-soft); }

/* ---------- chats ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.chat .line { display: flex; gap: 8px; align-items: flex-end; }
.chat .line.r { flex-direction: row-reverse; }
.chat .line .art { width: 48px; height: 48px; flex: none; }
.chat .bubble { background: var(--bg2); border-radius: 16px 16px 16px 4px; padding: 8px 12px; font-size: 14px; max-width: 78%; }
.chat .line.r .bubble { border-radius: 16px 16px 4px 16px; background: var(--bg); border: 2px solid var(--line); }
.chat .bubble b { display: block; font-size: 11px; color: var(--ink-soft); }
.friends { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.friend-chip { display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: 999px; padding: 2px 10px 2px 2px; font-size: 12px; font-weight: 800; box-shadow: var(--shadow); cursor: pointer; border: 0; }
.friend-chip .art { width: 30px; height: 30px; }
.rank { background: var(--pink); color: #fff; border-radius: 6px; padding: 0 5px; font-size: 11px; }

/* ---------- letter ---------- */
.letter {
  background: #fffaf0; color: #5a4636; border-radius: 6px; padding: 16px 16px 14px;
  box-shadow: 0 2px 0 #ead9c4, inset 0 0 0 1px #f1e3cc;
  font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  background-image: repeating-linear-gradient(transparent 0 23px, #f3e6d3 23px 24px);
}
.letter .sig { text-align: right; font-weight: 800; margin-top: 8px; }

/* ---------- dex ---------- */
.dexgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.dexcard { background: var(--card); border-radius: 16px; padding: 6px; text-align: center; box-shadow: var(--shadow); font-size: 12px; }
.dexcard .pair { display: flex; justify-content: center; }
.dexcard .art { width: 44px; height: 44px; }
.unseen svg.critter { filter: brightness(0) opacity(0.18); }
.unseen.shiny-slot svg.critter { filter: brightness(0) opacity(0.1); }
.milestone { display: flex; align-items: center; gap: 10px; }
.milestone .info { flex: 1; min-width: 0; }

/* ---------- contest ---------- */
.judges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.judge { text-align: center; background: var(--card); border-radius: 16px; padding: 6px 4px 8px; box-shadow: var(--shadow); }
.judge .art { width: 56px; height: 56px; margin: 0 auto; }
.judge .nm { font-size: 11px; font-weight: 800; }
.judge .score { font-size: 26px; font-weight: 900; color: var(--pink-deep); min-height: 32px; }
.judge .says { font-size: 11px; color: var(--ink-soft); min-height: 2.6em; }
.runway { height: 170px; border-radius: 20px; background: linear-gradient(#ffe6ee, #fff6f1); position: relative; overflow: hidden; box-shadow: var(--shadow); margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { .runway { background: linear-gradient(#4a3550, #2f2637); } }
.runway::after { content: ''; position: absolute; left: 20%; right: 20%; bottom: 10px; height: 18px; border-radius: 50%; background: #ff8fab55; }
.runway .art { position: absolute; left: 50%; bottom: 14px; width: 130px; height: 130px; transform: translateX(-50%); z-index: 1; }
.runway .spot { position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, #fff8 0 30%, transparent 55%); }
.score-pop { animation: pop 0.3s; }

/* ---------- happenings ---------- */
.ev-icon { font-size: 44px; text-align: center; line-height: 1; }
.need { text-align: center; font-weight: 800; margin: 8px 0; }
.bigdie { width: 96px; height: 96px; margin: 8px auto; position: relative; }
.bigdie svg { width: 100%; height: 100%; }
.bigdie b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; font-weight: 900; color: #fff; padding-top: 4px; }
.bigdie.rolling { animation: spin 0.5s linear infinite; }

@media (max-width: 430px) {
  .brand { font-size: 0; }
  .brand::before { content: '🐾'; font-size: 22px; }
  .pill { padding: 4px 8px; font-size: 13px; }
}

/* Laptop / landscape: give the battle board room beside the panel. */
@media (min-width: 900px) and (min-height: 560px) {
  #app { max-width: 600px; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .battle { display: grid; grid-template-columns: 1fr minmax(240px, 40%); grid-template-rows: auto 1fr; }
  .bbar { grid-column: 1 / -1; }
  .board { width: min(100%, calc((100dvh - 70px) * 0.75)); }
  .panel { border-top: 0; border-left: 2px solid var(--line); overflow-y: auto; }
  #app { max-width: 900px; }
}
