/* Retro console look, drawn entirely in the Sweetie 16 palette: dark screen,
   blue RPG-style windows with hard white borders, pixel type, no curves. */
:root {
  --bg: #1a1c2c;
  --panel: #29366f;
  --panel-dim: #333c57;
  --ink: #f4f4f4; /* text and window borders */
  --muted: #94b0c2;
  --dark: #1a1c2c; /* text on bright fills */
  --shadow: #0d0e17;
  --green: #38b764;
  --lime: #a7f070;
  --yellow: #ffcd75;
  --orange: #ef7d57;
  --red: #b13e53;
  --blue: #3b5dc9;
  --cyan: #73eff7;
  --slate: #566c86; /* backdrop that keeps sprite outlines visible */
  --panel-hi: var(--blue); /* lit top edge of a window */
  --dot: #242a44; /* the faint dot grid behind screens */
  --dither: repeating-conic-gradient(var(--panel-dim) 0 25%, var(--panel) 0 50%) 0 0 / 4px 4px;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --border: 3px solid var(--ink);
  --pop: 4px 4px 0 var(--shadow);
  --pixel: 'Press Start 2P', 'VT323', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: 'VT323', ui-monospace, 'Courier New', monospace;
  font-size: 21px;
  line-height: 1.15;
  color: var(--ink);
  background: var(--shadow);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

h1, h2, h3, p { margin: 0; }
h1 { font-family: var(--pixel); font-size: 20px; line-height: 1.3; color: var(--yellow); text-shadow: 3px 3px 0 var(--shadow); }
h2 { font-family: var(--pixel); font-size: 13px; line-height: 1.5; }
h3 { font-family: var(--pixel); font-size: 11px; margin: 18px 0 10px; color: var(--cyan); text-transform: uppercase; }
b { font-weight: 400; }
small { font-size: 18px; color: var(--muted); }
button, input, select { font: inherit; color: inherit; border-radius: 0; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

/* Faint CRT scanlines over everything. */
#app::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 40;
  background: repeating-linear-gradient(0deg, rgba(13, 14, 23, 0.16) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(14px + var(--safe-top)) 16px 24px;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  background:
    linear-gradient(90deg, var(--bg) 14px, transparent 14px) 0 0 / 16px 16px,
    linear-gradient(var(--bg) 14px, var(--dot) 14px) 0 0 / 16px 16px;
}

.screen > * { flex-shrink: 0; }

/* ---------- Tab bar ---------- */

.tabbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: var(--panel);
  border-top: var(--border);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 56px;
  font-family: var(--pixel);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--muted);
}

.tabbar a[aria-current] { color: var(--dark); background: var(--yellow); box-shadow: inset 0 -4px 0 var(--orange); }

/* ---------- Shared pieces ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

/* Title card: a stepped yellow/orange bar under each screen title. */
.topbar h1 {
  padding-bottom: 12px;
  background:
    linear-gradient(var(--yellow), var(--yellow)) 0 calc(100% - 4px) / 40px 4px no-repeat,
    linear-gradient(var(--orange), var(--orange)) 8px 100% / 40px 4px no-repeat;
}

.balance, .record-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px 6px 6px;
  background: var(--panel);
  border: var(--border);
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--yellow);
  white-space: nowrap;
}

.record-pill { gap: 0; padding: 0; font-size: 10px; color: var(--dark); }
.record-pill span { padding: 10px 12px; }
.record-pill .is-win { background: var(--lime); }
.record-pill .is-loss { background: var(--orange); border-left: 3px solid var(--ink); }
.point-icon { width: 18px; height: 18px; flex: none; }
.px-icon { width: 16px; height: 16px; flex: none; }
.coin-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 3px solid var(--yellow);
  border-radius: 50%;
  color: var(--yellow);
  font-family: var(--pixel);
  font-size: 12px;
}

.topbar-balances {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.balance-diamonds {
  color: var(--cyan);
}

.diamond-icon { width: 28px; height: 28px; flex: none; image-rendering: pixelated; }
.balance .diamond-icon { width: 18px; height: 18px; }
.coin-balance .diamond-icon { width: 40px; height: 40px; }
.coin-pack-art .diamond-icon { width: 42px; height: 42px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 12px 4px 4px;
  background: var(--panel);
  border: var(--border);
  box-shadow: var(--pop);
  text-align: left;
  min-width: 0;
}

.chip-text { display: flex; flex-direction: column; line-height: 1; min-width: 0; }
.chip-text b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--orange);
  border: 2px solid var(--ink);
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--dark);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 18px;
  border: var(--border);
  background: var(--panel);
  box-shadow: var(--pop);
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1.4;
  text-transform: uppercase;
}

.btn:active:not(:disabled) { transform: translate(4px, 4px); box-shadow: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--green); color: var(--dark); }
.btn-pink { background: var(--orange); color: var(--dark); }
.btn-ghost { box-shadow: none; border-color: var(--panel-dim); color: var(--muted); background: none; }
.btn-block { width: 100%; }
.btn-xl { min-height: 64px; font-size: 15px; }
.btn-small { min-height: 44px; padding: 6px 10px; font-size: 10px; }
/* Can't afford it yet: dithered and flat, so it reads as a goal, not a broken button. */
.btn.is-short { background: var(--dither); color: var(--muted); border-style: dashed; border-color: var(--muted); box-shadow: none; }
.btn.is-short:active { transform: none; }
.btn-icon { align-self: flex-end; width: 44px; padding: 0; }
.btn-icon .px-icon { width: 20px; height: 20px; }
.btn.is-loading { animation: blink 0.5s steps(1) infinite; }

/* Hazard stripes top and bottom, clear label in the middle. */
.btn-demo {
  color: var(--dark);
  background:
    linear-gradient(var(--yellow), var(--yellow)) center / 100% 56% no-repeat,
    repeating-linear-gradient(-45deg, var(--yellow) 0 8px, var(--dark) 8px 16px);
}

.bar { height: 16px; background: var(--shadow); border: 2px solid var(--ink); overflow: hidden; }

/* Filled in chunks, like a health bar. */
.bar i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--lime) 0 8px, var(--green) 8px 10px);
  transition: width 0.3s steps(6);
}

.stat-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s3); }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--panel);
  border: var(--border);
}

.stat small { display: flex; align-items: center; gap: 6px; color: var(--cyan); }
.stat small .point-icon { width: 16px; height: 16px; }
.stat b { font-family: var(--pixel); font-size: 22px; }
.hint { font-size: 19px; color: var(--muted); text-align: center; text-wrap: pretty; }
.hint-top { text-align: left; }
.empty, .muted { color: var(--muted); text-align: center; padding: 24px 8px; text-wrap: pretty; }
.status { min-height: 24px; text-align: center; color: var(--cyan); }
.eyebrow { font-family: var(--pixel); font-size: 11px; text-transform: uppercase; color: var(--cyan); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 60;
  width: max-content;
  max-width: min(340px, calc(100vw - 32px));
  padding: 10px 16px;
  background: var(--panel);
  border: var(--border);
  box-shadow: var(--pop);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.15s steps(2), transform 0.15s steps(2);
  pointer-events: none;
}

#toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
#toast[data-kind='good'] { background: var(--green); color: var(--dark); border-color: var(--dark); }
#toast[data-kind='warn'] { background: var(--red); }

.confetti { position: fixed; inset: 0; z-index: 80; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Buddy ---------- */

/* Sprites move in whole pixels (1px = one sprite pixel) and without easing. */
.buddy { display: block; width: 100%; height: auto; }
.buddy-body { transform-box: view-box; }
.buddy.is-idle .buddy-body { animation: bounce 0.9s steps(1) infinite; }
.buddy.is-sleepy .buddy-body { animation-duration: 2.4s; }
.buddy.is-happy .buddy-body { animation: hop 0.4s steps(1) 3; }

@keyframes bounce { 50% { transform: translateY(-1px); } }

@keyframes hop {
  25% { transform: translateY(-2px); }
  50% { transform: translateY(-3px); }
  75% { transform: translateY(-1px); }
}

@keyframes blink { 50% { opacity: 0.5; } }

/* ---------- Login ---------- */

.login {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  text-align: center;
  overflow-y: auto;
}

.login h1 { font-size: 28px; }
.login > p { color: var(--muted); }
.login form, .sheet form { width: 100%; display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
label, legend { display: block; text-align: left; color: var(--cyan); }
label input:not([type='radio']), label select { display: block; margin-top: 6px; }

input, select {
  min-height: 52px;
  padding: 8px 14px;
  background: var(--shadow);
  border: var(--border);
  font-size: 24px;
  width: 100%;
}

input::placeholder { color: var(--slate); }

/* ---------- Home ---------- */

.stage-card { position: relative; border: var(--border); overflow: hidden; box-shadow: var(--pop); background: var(--shadow); }

.bubble {
  position: relative;
  z-index: 2;
  align-self: center;
  max-width: 100%;
  margin-bottom: -2px;
  padding: 8px 14px;
  background: var(--ink);
  color: var(--dark);
  border: 3px solid var(--dark);
  box-shadow: 0 0 0 3px var(--ink);
  text-align: center;
}

/* On home the bubble floats over the scene, so the page doesn't jump when the buddy talks. */
.home-bubble {
  position: absolute;
  top: 48px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  animation: bubble-in 0.25s steps(3);
}
.home-bubble[hidden] { display: none; }

@keyframes bubble-in {
  from { transform: translateX(-50%) scale(0.8); opacity: 0; }
}

.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 9px;
  height: 9px;
  margin-left: -4px;
  background: var(--ink);
}

.nameplate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border-top: var(--border);
}

.nameplate > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.nameplate > div:first-child { flex: 1; }
.nameplate > .nameplate-stats { flex-direction: row; gap: var(--s1); flex: none; }

/* Game HUD in the corners of the scene. */
.scene-hud {
  position: absolute;
  top: var(--s2);
  left: var(--s2);
  right: var(--s2);
  z-index: 1;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.hud-badge, .stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--dark);
  border: 2px solid var(--ink);
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--ink);
}

.hud-level { color: var(--yellow); }
.stat-badge { padding: 4px 6px; border-color: var(--panel-dim); }
.stat-badge .px-icon { width: 12px; height: 12px; }
.stat-badge.is-attack .px-icon { color: var(--orange); }
.stat-badge.is-evasion .px-icon { color: var(--cyan); }
.nameplate b { font-family: var(--pixel); font-size: 12px; color: var(--yellow); }
.nameplate span { font-size: 18px; color: var(--ink); }
/* The beast itself is the talk button. */
.beast-tap { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.home-bubble.is-thinking .dots { animation: blink 0.6s steps(1) infinite; }
.traits { color: var(--muted); }
.stage-card .evolve { padding: 0 var(--s3) var(--s3); background: var(--panel); }
.evolve .bar { height: 20px; }
.evolve-text { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 19px; color: var(--muted); }
.evolve .bar i { background: repeating-linear-gradient(90deg, var(--cyan) 0 8px, var(--blue) 8px 10px); }
.upgrades {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--panel);
  border: var(--border);
  box-shadow: var(--pop);
}

/* One training window, three stations. Affordable ones light up with an orange bevel. */
.upgrade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 88px;
  padding: var(--s2) var(--s1) var(--s1);
  background: var(--yellow);
  color: var(--dark);
  border: 0;
  box-shadow: inset 0 -4px 0 var(--orange);
}

.upgrade + .upgrade { border-left: 3px solid var(--ink); }
.upgrade .px-icon { width: 16px; height: 16px; }
.upgrade:active:not(.is-short) { box-shadow: inset 0 4px 0 var(--orange); }
.upgrade.is-short { background: var(--dither); color: var(--muted); box-shadow: none; }
.upgrade-label { font-family: var(--pixel); font-size: 8px; line-height: 1.4; text-transform: uppercase; }
.upgrade-detail { font-size: 17px; line-height: 1; }

.cost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
  padding: 0 8px 0 4px;
  background: var(--dark);
  color: var(--yellow);
  font-size: 17px;
  white-space: nowrap;
}

.upgrade.is-short .cost { padding: 0 8px; color: var(--muted); }

.cost .point-icon, .btn-small .point-icon { width: 16px; height: 16px; }

/* Up to six beasts in a row; the one walking with the player is lit. */
.team { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s2); }

.team-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 2px 2px 4px;
  background: var(--panel);
  border: var(--border);
  border-color: var(--panel-dim);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.team-slot.is-walking { border-color: var(--yellow); color: var(--yellow); }
.team-slot.is-tired .buddy { opacity: 0.45; }
.team-slot.is-tired { color: var(--orange); }
.edge a { text-decoration: underline; }
.team-slot:active { transform: translate(2px, 2px); }

/* The wardrobe: slot tabs along the bottom of the beast's card, and a shelf of
   what the player owns for the open slot. */
.wardrobe { background: var(--panel); border-top: 2px solid var(--panel-dim); }
.wardrobe .segmented-sub { border: 0; }
.wardrobe-shelf { display: flex; gap: var(--s2); padding: var(--s2) var(--s3) var(--s3); overflow-x: auto; }

.wardrobe-item {
  flex: none;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  padding: 0;
  background: var(--slate);
  border: var(--border);
  border-color: var(--dark);
  overflow: hidden;
}

.wardrobe-item.is-equipped { border-color: var(--yellow); }
.wardrobe-item.is-taken { opacity: 0.4; }
.wardrobe-item:active { transform: translate(2px, 2px); }
.wardrobe-empty { padding: var(--s3); font-size: 19px; color: var(--muted); text-align: center; }
.wardrobe-empty a { color: var(--yellow); text-decoration: underline; }

/* ---------- Walk ---------- */

.ring-card { position: relative; width: min(100%, 300px); margin: 4px auto; }
.ring { display: block; width: 100%; }
.ring-track { fill: var(--panel); stroke: var(--shadow); stroke-width: 20; }
.ring-fill { fill: none; stroke: var(--lime); stroke-width: 20; transition: stroke-dashoffset 0.4s steps(8); }
.ring-fill.is-done { stroke: var(--yellow); }
/* Cuts the ring into 30 chunks, like a health meter. */
.ring-notches { fill: none; stroke: var(--shadow); stroke-width: 22; }
.ring-buddy { width: 72px; }
.buddy.is-walking .buddy-body { animation: hop 0.4s steps(1) infinite; }
.btn.is-walking { animation: border-blink 1s steps(1) infinite; }

@keyframes border-blink { 50% { border-color: var(--yellow); } }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ring-center b { font-family: var(--pixel); font-size: 28px; color: var(--ink); text-shadow: 3px 3px 0 var(--shadow); }
.ring-center span { color: var(--muted); }

/* ---------- Map ---------- */

.screen[data-tab='map'] { position: relative; padding: 0; overflow: hidden; }
/* Google Maps puts inline position/size styles on its own element, so the
   map lives in an inner div and this wrapper does the positioning. */
/* A pixel street grid, seen only until (or unless) the Google map covers it. */
.map {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--panel-dim) 4px, transparent 4px) 0 0 / 96px 96px,
    linear-gradient(90deg, var(--panel-dim) 4px, transparent 4px) 0 0 / 96px 96px,
    linear-gradient(var(--dot) 2px, transparent 2px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--dot) 2px, transparent 2px) 0 0 / 32px 32px,
    var(--bg);
}

.map-empty { position: absolute; top: 50%; left: 50%; z-index: 1; width: 160px; transform: translate(-50%, -60%); pointer-events: none; }
.map-empty[hidden] { display: none; }
.map > div { width: 100%; height: 100%; }

/* The characters' own canvas in the retro look, laid over the whole map. */
.map-buddy { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
.map-buddy[hidden] { display: none; }

.map-card {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 12px;
  z-index: 2;
  display: grid;
  grid-auto-flow: column;
  justify-content: space-between;
  gap: var(--s3);
  width: 264px;
  padding: var(--s2) var(--s3);
  background: var(--panel);
  border: var(--border);
}

.map-card div { display: flex; flex-direction: column; gap: 4px; }
.map-card small { color: var(--cyan); }
.map-card b { display: flex; align-items: center; gap: 4px; font-family: var(--pixel); font-size: 11px; color: var(--ink); }
.map-card div:last-child b { color: var(--yellow); }
.map-card .point-icon { width: 14px; height: 14px; }

.map-avatars {
  position: absolute;
  top: calc(76px + var(--safe-top));
  left: 12px;
  z-index: 2;
  display: flex;
  width: 264px;
  background: var(--panel);
  border: var(--border);
}

.map-avatars button {
  flex: 1;
  min-height: 44px;
  padding: 4px 10px;
  border: 0;
  background: none;
  font-family: var(--pixel);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--muted);
}

.map-avatars button[aria-pressed='true'] { background: var(--yellow); color: var(--dark); }

.map-credit {
  position: absolute;
  top: calc(132px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 2;
  font-size: 15px;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--dark), -1px -1px 0 var(--dark), 1px -1px 0 var(--dark), -1px 1px 0 var(--dark);
}

.map-credit[hidden] { display: none; }

.map-status {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 104px;
  z-index: 2;
  padding: var(--s2) var(--s3);
  background: var(--panel);
  border: var(--border);
  text-align: center;
}

.map-status[hidden] { display: none; }

/* A problem reads as a dialog box with an alert badge. */
.map-status.is-alert { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3); text-align: left; }
.map-status.is-alert::before {
  content: '!';
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: var(--yellow);
  color: var(--dark);
  font-family: var(--pixel);
  font-size: 12px;
}

.map-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 40px; /* leaves the Google logo and terms visible underneath */
  z-index: 2;
  display: flex;
  gap: 10px;
}

.map-controls .btn { flex: 1; padding-inline: 8px; }
.map-controls[hidden] { display: none; }

/* Zoom buttons, top right, clear of the stats card. */
.map-zoom {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: var(--border);
}
.map-zoom button {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  font-family: var(--pixel);
  font-size: 16px;
  color: var(--ink);
}
.map-zoom button + button { border-top: 3px solid var(--ink); }

/* Shown once the map has been dragged away from the buddy. */
.map-recenter {
  position: absolute;
  top: calc(122px + var(--safe-top));
  right: 12px;
  z-index: 2;
  width: 50px;
  height: 50px;
  background: var(--yellow);
  border: var(--border);
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--dark);
}
.map-recenter .px-icon { width: 24px; height: 24px; }
.map-recenter[hidden] { display: none; }

/* Name tags sit in their own layer over the characters, so none is ever covered. */
.map-tags { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }

/* A nearby player's tap area: feet on their map position, up past their head,
   name tag on top (the height is set from how tall they are drawn). */
.map-player {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 56px;
  height: 72px;
  pointer-events: auto;
  padding: 0;
  border: 0;
  background: none;
  transform: translate(-50%, -100%);
  cursor: pointer;
}
.map-player span {
  /* Just above the head, however small the character is drawn. */
  position: absolute;
  bottom: calc(var(--head, 48px) + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 4px 2px;
  background: var(--dark);
  border: 2px solid var(--ink);
  color: var(--yellow);
  font-family: var(--pixel);
  font-size: 7px;
  white-space: nowrap;
}

/* The player being looked at: their profile, over the walk controls. */
.map-profile {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 40px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3);
  background: var(--panel);
  border: var(--border);
}
.map-profile[hidden] { display: none; }
.map-profile-head { display: flex; align-items: center; gap: var(--s3); }
.map-profile-head .opponent-art { width: 64px; }
.map-profile-stats { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.map-profile-actions { display: flex; align-items: center; gap: 10px; }
.map-profile-actions .btn { flex: 1; padding-inline: 8px; }

/* ---------- Store ---------- */

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; background: var(--panel); border: var(--border); }

.segmented button {
  min-height: 44px;
  border: 0;
  background: none;
  font-family: var(--pixel);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
}

.segmented button[aria-selected='true'] { background: var(--yellow); color: var(--dark); }
/* Filters under the main tabs: lighter, underlined instead of filled. */
.segmented-sub { padding: 0; border-width: 2px; background: none; }
.segmented-sub button { font-size: 9px; }
.segmented-sub button[aria-selected='true'] { background: none; color: var(--yellow); box-shadow: inset 0 -3px 0 var(--yellow); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: var(--s3); }

.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--panel);
  border: var(--border);
  text-align: center;
}

.item .btn { width: 100%; }
.item-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  background: repeating-conic-gradient(rgba(244, 244, 244, 0.08) 0 25%, transparent 0 50%) 0 0 / 16px 16px, var(--slate);
  border: 2px solid var(--dark);
  overflow: hidden;
}

.price-tag, .stamp {
  position: absolute;
  top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 3px;
  border: 2px solid var(--ink);
  font-family: var(--pixel);
  font-size: 10px;
}

.price-tag { left: 6px; background: var(--dark); color: var(--yellow); }
.price-tag .point-icon { width: 14px; height: 14px; }
.stamp { right: 6px; padding: 3px 6px; background: var(--lime); color: var(--dark); font-size: 8px; text-transform: uppercase; }
.item.is-owned { border-color: var(--lime); }
.item-art .buddy { width: 76%; }
.price-tag .diamond-icon { width: 14px; height: 14px; }
.rarity { font-family: var(--pixel); font-size: 8px; text-transform: uppercase; color: var(--muted); }
.rarity[data-rarity='uncommon'] { color: var(--lime); }
.rarity[data-rarity='rare'] { color: var(--cyan); }
.rarity[data-rarity='legendary'] { color: var(--yellow); }
.cosmetic-icon { width: 76%; height: 76%; }
.cosmetic-icon.is-bg { width: 100%; height: 100%; }
.owned { min-height: 44px; display: grid; place-items: center; color: var(--lime); }
.item-tap { box-shadow: var(--pop); min-height: 44px; }
.item-tap:active { transform: translate(4px, 4px); box-shadow: none; }
.item-tap .owned { min-height: 0; font-size: 18px; color: var(--muted); }
.item-tap.is-equipped { border-color: var(--yellow); }
.item-tap.is-equipped .owned { color: var(--yellow); }

.coin-hero {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3);
  background: var(--panel);
  border: var(--border);
}
.coin-balance { display: flex; align-items: center; gap: var(--s3); color: var(--yellow); }
.coin-balance .coin-icon { width: 40px; height: 40px; font-size: 16px; }
.coin-balance span { display: flex; flex-direction: column; gap: 4px; }
.coin-balance small { color: var(--muted); }
.coin-balance b { font-family: var(--pixel); font-size: 16px; }
.coin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.coin-pack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--panel);
  border: var(--border);
  text-align: center;
}
.coin-pack.is-popular { border-color: var(--yellow); }
.coin-pack-art { display: grid; place-items: center; width: 64px; height: 64px; background: var(--dark); border: 2px solid var(--yellow); }
.coin-pack-art .coin-icon { width: 42px; height: 42px; }
.coin-pack strong { color: var(--yellow); }
.coin-pack .btn { width: 100%; min-height: 44px; font-size: 10px; }
.popular { position: absolute; top: -12px; padding: 3px 6px; background: var(--yellow); color: var(--dark); font-family: var(--pixel); font-size: 8px; text-transform: uppercase; }

/* ---------- Battle ---------- */

.opponents { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.opponent { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); background: var(--panel); border: var(--border); }
.opponent-art { position: relative; flex: none; width: 80px; border: 2px solid var(--ink); overflow: hidden; }
.art-level {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 3px 4px 2px;
  background: var(--dark);
  color: var(--yellow);
  font-family: var(--pixel);
  font-size: 8px;
}
.opponent-info { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; line-height: 1; }
.opponent-info b { font-family: var(--pixel); font-size: 12px; color: var(--yellow); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.opponent-actions { flex: none; display: flex; flex-direction: column; align-items: stretch; gap: 6px; text-align: center; }
.add-friend { margin-top: var(--s2); }
.add-friend > div { display: flex; gap: 8px; margin-top: 6px; }

/* Your buddy delivers the empty-state line. */
.empty-buddy { display: flex; flex-direction: column; align-items: center; gap: var(--s4); padding-top: var(--s4); }
.empty-buddy .bubble { max-width: 300px; text-wrap: pretty; }
.empty-buddy .buddy { width: 140px; margin-top: -40px; }

/* The top three on a podium: 2nd, 1st, 3rd. */
.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: var(--s2); padding-top: var(--s2); }
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; text-align: center; }
.podium-col b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--pixel); font-size: 9px; color: var(--yellow); }
.podium-col small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.podium-art { width: 72px; }
.place-1 .podium-art { width: 92px; }

.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-top: var(--s1);
  padding-top: var(--s2);
  border: var(--border);
  color: var(--dark);
}

.podium-step span { font-family: var(--pixel); font-size: 18px; }
.podium-step em { font-style: normal; font-size: 19px; }
.place-1 .podium-step { height: 96px; background: var(--yellow); box-shadow: inset 0 4px 0 var(--ink); }
.place-2 .podium-step { height: 72px; background: var(--muted); }
.place-3 .podium-step { height: 56px; background: var(--orange); }
.podium-col.is-me .podium-step { border-color: var(--lime); }
.add-friend input { flex: 1; min-width: 0; margin: 0; }
.add-friend .btn { min-height: 52px; }

.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.board li { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3) var(--s2) var(--s2); background: var(--panel); border: var(--border); }
.board li.is-me { border-color: var(--yellow); }
.board-art { flex: none; width: 44px; border: 2px solid var(--ink); }
.board-value { margin-left: auto; font-family: var(--pixel); font-size: 11px; color: var(--ink); }
.rank { flex: none; display: grid; place-items: center; width: 30px; height: 30px; font-family: var(--pixel); font-size: 10px; background: var(--panel-dim); }
.rank-1 { background: var(--yellow); color: var(--dark); }
.rank-2 { background: var(--muted); color: var(--dark); }
.rank-3 { background: var(--orange); color: var(--dark); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(13, 14, 23, 0.8);
}

.overlay.arena, .overlay.evolution { align-items: center; padding: 16px; }

.arena-card, .evolution-card, .sheet {
  width: 100%;
  max-width: 430px;
  background: var(--panel);
  border: var(--border);
  box-shadow: 0 0 0 3px var(--dark), var(--pop);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.arena-card, .evolution-card { text-align: center; max-width: 398px; }
.announcement { font-size: 24px; line-height: 1.25; white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; }
.fighters { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 4px; }
.versus { align-self: center; font-family: var(--pixel); font-size: 14px; color: var(--orange); }
.fighter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fighter-name { display: flex; flex-direction: column; gap: 2px; }
.fighter-name b { font-family: var(--pixel); font-size: 11px; color: var(--yellow); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp { position: relative; height: 24px; background: var(--shadow); border: 2px solid var(--ink); overflow: hidden; }

.hp i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--lime) 0 8px, var(--green) 8px 10px);
  transition: width 0.25s steps(4);
}

.hp span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--dark), -1px -1px 0 var(--dark), 1px -1px 0 var(--dark), -1px 1px 0 var(--dark);
}

.fighter-art { position: relative; background: var(--slate); border: 2px solid var(--dark); transition: transform 0.15s steps(3); }
.fighter[data-side='a'].is-lunging .fighter-art { transform: translateX(40%); z-index: 2; }
.fighter[data-side='b'].is-lunging .fighter-art { transform: translateX(-40%); z-index: 2; }
.fighter.is-hit .fighter-art { animation: shake 0.3s steps(1); }
.fighter.is-hit .buddy-body { animation: blink 0.1s steps(1) 3; }
.fighter.is-winner .buddy-body { animation: hop 0.4s steps(1) infinite; }
.fighter.is-loser .buddy { opacity: 0.4; }

@keyframes shake {
  0%, 50% { transform: translateX(-6px); }
  25%, 75% { transform: translateX(6px); }
}

.float {
  position: absolute;
  left: 50%;
  top: 8%;
  z-index: 3;
  transform: translateX(-50%);
  font-family: var(--pixel);
  font-size: 18px;
  color: var(--orange);
  text-shadow: 2px 2px 0 var(--dark), -2px -2px 0 var(--dark), 2px -2px 0 var(--dark), -2px 2px 0 var(--dark);
  white-space: nowrap;
  pointer-events: none;
  animation: float-up 0.8s steps(6) forwards;
}

.float.is-miss { color: var(--ink); font-size: 13px; }
.float.is-strong { color: var(--yellow); font-size: 22px; }

/* Element tags, shown wherever a beast is. */
.element { flex: none; align-self: center; padding: 3px 6px; font-family: var(--pixel); font-size: 8px; text-transform: uppercase; color: var(--dark); }
.element.is-fire { background: var(--orange); }
.element.is-water { background: var(--blue); color: var(--ink); }
.element.is-nature { background: var(--lime); }
.element.is-sky { background: var(--cyan); }
.edge { font-size: 17px; }
.edge.is-strong { color: var(--lime); }
.edge.is-weak { color: var(--orange); }

/* Energy: three pips, a special spends two. */
.energy { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; height: 8px; }
.energy i { background: var(--shadow); border: 2px solid var(--ink); }
.energy i.is-on { background: var(--yellow); }

.moves { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }

.move {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 84px;
  padding: var(--s2) 2px;
  background: var(--yellow);
  color: var(--dark);
  border: var(--border);
  box-shadow: var(--pop);
}

.move .px-icon { width: 18px; height: 18px; }
.move b { font-family: var(--pixel); font-size: 9px; text-transform: uppercase; }
.move small { font-size: 15px; line-height: 1; color: inherit; text-wrap: balance; }
.move:active:not(:disabled) { transform: translate(4px, 4px); box-shadow: none; }
.move:disabled { background: var(--dither); color: var(--muted); box-shadow: none; cursor: default; }

@keyframes float-up {
  from { transform: translate(-50%, 12px); }
  to { transform: translate(-50%, -30px); opacity: 0.2; }
}

.arena-result { min-height: 64px; display: flex; flex-direction: column; gap: 8px; }
.arena-result h2 { font-size: 20px; }
.arena-result h2.is-win { color: var(--lime); }
.arena-result h2.is-loss { color: var(--orange); }
.arena-result h2.is-draw { color: var(--yellow); }
.arena-result p { color: var(--muted); }

/* After the battle: the buddy reacts and says its line. */
.arena-card.aftermath { animation: pop-in 0.3s steps(3); }
.aftermath-title { font-size: 22px; }
.aftermath-title.is-win { color: var(--lime); }
.aftermath-title.is-loss { color: var(--orange); }
.aftermath-title.is-draw { color: var(--yellow); }
.aftermath-detail { color: var(--muted); }
.aftermath-bubble { min-height: 44px; display: grid; place-items: center; animation: pop-in 0.25s steps(3) 0.2s backwards; }
.aftermath-bubble.is-thinking .dots { animation: blink 0.6s steps(1) infinite; }
.aftermath-buddy { width: 60%; margin: 6px auto 0; background: var(--slate); border: 2px solid var(--dark); }
.aftermath-buddy.is-win .buddy-body { animation: hop 0.4s steps(1) infinite; }
.aftermath-buddy.is-loss .buddy-body { animation: slump 1.6s steps(1) infinite; }
.aftermath-buddy.is-draw .buddy-body { animation: bounce 0.9s steps(1) infinite; }

@keyframes pop-in {
  from { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.04); }
}

@keyframes slump {
  0%, 100% { transform: translateY(2px); }
  50% { transform: translateY(3px) rotate(-3deg); }
}

/* ---------- Evolution ---------- */

.evolution-stage { position: relative; width: 70%; margin: 0 auto; aspect-ratio: 1; background: var(--slate); border: 2px solid var(--dark); }
.evolution-stage .buddy { position: absolute; inset: 0; height: 100%; }
/* The old form strobes white, then the new one snaps in. */
.evo-from { animation: evo-out 1s steps(1) forwards; }
.evo-to { opacity: 0; animation: evo-in 0.4s steps(1) 0.9s forwards; }

@keyframes evo-out {
  0%, 30%, 50%, 70% { filter: none; }
  20%, 40%, 60%, 80% { filter: brightness(0) invert(1); }
  90% { filter: brightness(0) invert(1); opacity: 1; }
  100% { opacity: 0; }
}

@keyframes evo-in {
  0% { opacity: 1; filter: brightness(0) invert(1); }
  50% { opacity: 1; filter: none; }
  75% { opacity: 1; filter: brightness(0) invert(1); }
  100% { opacity: 1; filter: none; }
}

/* ---------- Profile sheet ---------- */

.sheet { max-height: 92dvh; overflow-y: auto; border-bottom: 0; padding-bottom: calc(20px + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { color: var(--yellow); }
.sheet h3 { margin: 6px 0 0; }
.sheet form { margin-top: 0; }
.sheet .stat { background: var(--bg); }
.icon-btn { width: 44px; height: 44px; border: var(--border); background: var(--red); font-family: var(--pixel); font-size: 12px; }
.record { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.record-4 { grid-template-columns: repeat(4, 1fr); }
/* Four beast numbers side by side need smaller figures. */
.record-4 .stat { gap: var(--s1); padding: var(--s2) var(--s1); min-width: 0; text-align: center; }
.record-4 .stat b { font-size: 12px; }
/* The profile reads top to bottom: a heading, then one thing per line, with room between sections. */
.profile, .sheet-section { display: flex; flex-direction: column; gap: 14px; }
.profile h3 { margin: var(--s4) 0 0; padding-top: var(--s4); border-top: 2px solid var(--panel-dim); }
.profile .sheet-section > h3:first-child { margin-top: 0; }
.stat-list { list-style: none; margin: 0; padding: 0; background: var(--bg); border: 2px solid var(--panel-dim); }
.stat-list li { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: var(--s3); font-size: 21px; }
.stat-list li + li { border-top: 2px solid var(--panel-dim); }
.stat-list span { color: var(--muted); }
.stat-list b { font-weight: normal; color: var(--ink); text-align: right; }
.profile .history li { padding: var(--s3); }
.profile #signout { margin-top: var(--s4); }
.profile .chart-card { background: var(--bg); border-width: 2px; border-color: var(--panel-dim); }
.beast-card { display: grid; grid-template-columns: 112px 1fr; gap: var(--s3); align-items: center; }
.beast-card b { font-family: var(--pixel); font-size: 11px; color: var(--yellow); }
.beast-card > div:last-child { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.stat.is-win b { color: var(--lime); }
.stat.is-loss b { color: var(--orange); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg); border: 2px solid var(--panel-dim); }
.history li.muted { justify-content: center; }
.history-who { flex: 1; min-width: 0; }
.history-who b { color: var(--yellow); }
.history-score { font-family: var(--pixel); font-size: 10px; }
.tag { flex: none; padding: 4px 8px; font-family: var(--pixel); font-size: 8px; text-transform: uppercase; background: var(--panel-dim); }
.tag.is-win { background: var(--lime); color: var(--dark); }
.tag.is-loss { background: var(--red); }

/* ---------- Stats ---------- */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.tile { display: flex; flex-direction: column; gap: 6px; padding: var(--s3); background: var(--panel); border: var(--border); }
.tile-wide { grid-column: 1 / -1; }
.tile small { display: flex; align-items: center; gap: 6px; color: var(--cyan); }
.tile b { font-family: var(--pixel); font-size: 15px; line-height: 1.3; }
.tile-wide b { font-size: 26px; color: var(--lime); }
.tile span { font-size: 18px; color: var(--muted); text-wrap: pretty; }
.tile .bar { height: 20px; margin-top: 6px; }
.chart-card { display: flex; flex-direction: column; gap: 6px; padding: var(--s3) var(--s3) var(--s2); background: var(--panel); border: var(--border); }
.chart-card h2 { color: var(--yellow); }
.readout { min-height: 24px; color: var(--muted); }
.readout b { color: var(--ink); }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.axis-text { font-family: 'VT323', monospace; font-size: 13px; fill: var(--muted); }
.goal-text { fill: var(--yellow); }
.grid-line { stroke: var(--panel-dim); stroke-width: 1; shape-rendering: crispEdges; }
.goal-line { stroke: var(--yellow); stroke-width: 2; stroke-dasharray: 4 4; shape-rendering: crispEdges; }
.bar-mark { fill: var(--cyan); shape-rendering: crispEdges; }
.bar-cap { fill: var(--ink); shape-rendering: crispEdges; }
.bar-slot.is-today .bar-mark { fill: var(--yellow); }
.bar-slot.is-active .bar-mark { fill: var(--ink); }
.bar-slot.is-active .axis-text { fill: var(--ink); }

/* ---------- Window frame ---------- */

/* Every panel is an RPG window: a lit top edge and a dark inner line inside the white border. */
.tile, .item:not(.item-tap), .opponent, .chart-card, .stat, .board li, .map-card, .map-status {
  background-image: linear-gradient(var(--panel-hi) 0 4px, transparent 4px);
  box-shadow: inset 0 0 0 2px var(--dark);
}

.nameplate { background-image: linear-gradient(var(--panel-hi) 0 4px, transparent 4px); }

@media (min-width: 431px) {
  #app { border-inline: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .evo-from { display: none; }
  .evo-to { opacity: 1; }
}

/* Profile: a setting that applies on tap, outside the Save form. */
.setting { display: grid; gap: 6px; margin-bottom: var(--s3); }
.setting-label { color: var(--cyan); text-align: left; }
.volume { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s2); color: var(--muted); }
.volume input[type='range'] { flex: 1; width: auto; min-width: 0; min-height: 44px; margin: 0; padding: 0; border: 0; background: none; accent-color: var(--yellow); }
.volume input:disabled { opacity: 0.4; }
