:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #e3350d;
  --accent-dark: #b52a0a;
  --accent-soft: #fde8e3;
  --border: #e3e6ee;
  --ok: #22a35a;
  --warn: #e8a500;
  --low: #d92d20;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; gap: 10px; min-height: 52px;
  padding: 6px 12px 6px 16px; background: var(--accent); color: #fff;
}
.sticky { position: sticky; top: 0; z-index: 10; }
/* A running battle takes the whole screen: no top bar, no banner, no step bar. */
body.in-battle header.sticky, body.in-battle .steps { display: none; }
body.in-battle main { padding: 0; }

/* Legendary event banner (events.js) */
.event-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: #f5d547; color: #1f2430; font-weight: 700; cursor: pointer; border-bottom: 2px solid #c9a200;
}
.event-banner[hidden] { display: none; }
.event-banner.active { animation: event-pulse 1.6s ease-in-out infinite; }
.event-banner.caught { background: #dcfce7; border-color: #15803d; }
.event-banner.fled { background: #eef0f5; border-color: var(--border); }
.event-banner.ping { background: #ffd8c2; border-color: #d9480f; animation: ping-pulse 1.6s ease-in-out infinite; }
@keyframes ping-pulse { 0%, 100% { background: #ffd8c2; } 50% { background: #ffe9dd; } }
.alerts-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); justify-content: space-between; }
.event-banner .text { flex: 1; font-size: 15px; line-height: 1.25; }
.event-banner .msg { font-weight: 400; font-size: 13px; }
.event-banner .more { font-size: 12px; font-weight: 600; opacity: .7; white-space: nowrap; }
.event-banner .sprite.sm { width: 36px; height: 36px; }
@keyframes event-pulse { 0%, 100% { background: #f5d547; } 50% { background: #ffe88a; } }
.event-detail { text-align: center; }
.event-detail .sprite.lg { width: 120px; height: 120px; }
.event-detail p { text-align: left; }
.event-live { border-color: #c9a200; background: #fffbe6; }
.topbar a { color: #fff; text-decoration: none; }
/* Brand = the player's team name (main.js drawTopBar); long names end in "…". */
.brand { font-weight: 800; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; max-width: 45%; }
.crumb { flex: 1 1 0; min-width: 0; opacity: .9; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { padding: 16px; max-width: 860px; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

button, .btn {
  font: inherit; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 10px 16px; cursor: pointer; text-decoration: none; display: inline-block;
  touch-action: manipulation;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
button.small { padding: 6px 10px; font-size: 14px; }
button.big { padding: 18px; font-size: 20px; width: 100%; }
button.danger { background: #fff; color: var(--low); border: 1px solid var(--low); }
button.tile {
  white-space: normal;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  padding: 14px; text-align: left; border-radius: var(--radius); width: 100%;
}
button.tile:hover { border-color: var(--accent); background: #fff; }
button.tile.selected { border-color: var(--accent); background: var(--accent-soft); }
button.tile.faint { opacity: .5; }
.tile .row { flex-wrap: nowrap; }
.tile .title { font-weight: 700; font-size: 16px; }
.tile .sub { color: var(--muted); font-size: 13px; }

input, select {
  font: inherit; font-size: 16px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; width: 100%; background: #fff;
}
label { display: block; font-weight: 600; margin-bottom: 12px; }
label input, label select { margin-top: 4px; font-weight: 400; }

/* Home */
.roles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.role {
  display: block; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 14px; text-decoration: none; color: var(--text); text-align: center;
}
.role:hover { border-color: var(--accent); }
.role .icon { font-size: 40px; display: block; margin-bottom: 6px; }
.role .name { font-weight: 700; }
.role .desc { font-size: 12px; color: var(--muted); }

/* Sprites and types */
.sprite { width: 56px; height: 56px; image-rendering: auto; object-fit: contain; flex: none; }
.sprite.lg { width: 96px; height: 96px; }
.sprite.sm { width: 40px; height: 40px; }
.sprite.fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); border-radius: 50%; font-weight: 800; font-size: 22px;
}
.sprite.silhouette { filter: brightness(0) opacity(.25); }
.type {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; color: #fff; margin-right: 4px; letter-spacing: .3px;
}
.type-normal { background: #a8a77a; } .type-fire { background: #ee8130; } .type-water { background: #6390f0; }
.type-electric { background: #e4b800; } .type-grass { background: #7ac74c; } .type-ice { background: #64c4c0; }
.type-fighting { background: #c22e28; } .type-poison { background: #a33ea1; } .type-ground { background: #d9a13c; }
.type-flying { background: #a98ff3; } .type-psychic { background: #f95587; } .type-bug { background: #a6b91a; }
.type-rock { background: #b6a136; } .type-ghost { background: #735797; } .type-dragon { background: #6f35fc; }
.type-dark { background: #705746; } .type-steel { background: #7e8fa5; }

.hpbar { height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.hpfill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.hpfill.ok { background: var(--ok); } .hpfill.warn { background: var(--warn); } .hpfill.low { background: var(--low); }
.hptext { font-size: 12px; color: var(--muted); margin-top: 2px; }

.mon { display: flex; gap: 12px; align-items: flex-start; }
.mon .body { flex: 1; min-width: 0; }
.mon .name { font-weight: 700; }
.mon.fainted .sprite { filter: grayscale(1) opacity(.5); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: #eef0f5; color: var(--muted); margin-left: 4px; }
.tag.rare { background: #fff3c4; color: #8a6d00; }
.tag.need { background: #e8f0fe; color: #1d4ed8; }
.tag.got { background: #dcfce7; color: #15803d; }
.tag.fainted { background: #fee2e2; color: var(--low); }

/* Catch difficulty meter (ui.js catchMeter) */
.catch-meter { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; white-space: nowrap; vertical-align: middle; }
.catch-meter .pips { display: inline-flex; gap: 2px; }
.catch-meter .pip { width: 8px; height: 8px; border-radius: 50%; background: #e5e7eb; border: 1px solid #d1d5db; }
.catch-meter.lvl-1 .pip.on { background: #22c55e; border-color: #15803d; }
.catch-meter.lvl-2 .pip.on { background: #84cc16; border-color: #4d7c0f; }
.catch-meter.lvl-3 .pip.on { background: #f59e0b; border-color: #b45309; }
.catch-meter.lvl-4 .pip.on { background: #ef4444; border-color: #b91c1c; }
.catch-meter.lvl-5 .pip.on { background: #8b5cf6; border-color: #6d28d9; }
.catch-meter.lvl-1 .lbl { color: #15803d; } .catch-meter.lvl-2 .lbl { color: #4d7c0f; }
.catch-meter.lvl-3 .lbl { color: #b45309; } .catch-meter.lvl-4 .lbl { color: #b91c1c; } .catch-meter.lvl-5 .lbl { color: #6d28d9; }
.dex .entry .catch-meter { margin-top: 4px; }

.order-num {
  display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex: none;
}

/* Battle */
.arena { display: grid; gap: 12px; }
.fighter { display: flex; gap: 12px; align-items: center; }
.fighter.me { flex-direction: row-reverse; text-align: right; }
.fighter .body { flex: 1; }
.fighter .sprite { width: 96px; height: 96px; }
.fighter.hit .sprite { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.moves button { padding: 14px 10px; font-size: 17px; }
.moves .pw { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.log { background: #1f2430; color: #e5e7eb; border-radius: 10px; padding: 12px; font-size: 14px; max-height: 180px; overflow-y: auto; }
.log div { padding: 2px 0; }
.log .new { color: #fff; font-weight: 600; }
.result { text-align: center; }
.result .big-text { font-size: 28px; font-weight: 800; }
.result.win .big-text { color: var(--ok); }
.result.lose .big-text { color: var(--low); }

/* Shop */
.goods .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.goods .item:first-child { border-top: none; }
.goods .info { flex: 1; min-width: 0; }
.goods .price { font-weight: 700; white-space: nowrap; }
.qty { display: inline-flex; align-items: center; gap: 6px; }
.qty button { width: 36px; height: 36px; padding: 0; font-size: 20px; }
.qty span { min-width: 2ch; text-align: center; font-weight: 700; }
.cart-bar {
  position: sticky; bottom: 0; background: var(--card); border-top: 2px solid var(--accent);
  padding: 12px 16px; margin: 0 -16px -16px; border-radius: 0 0 var(--radius) var(--radius);
}

/* Map */
.map { width: 100%; height: auto; background: #2c6331; border-radius: var(--radius); border: 1px solid var(--border); touch-action: manipulation; }
.map .pin { cursor: pointer; }
.map .art { pointer-events: none; }
.map .pin circle { fill: #fff; stroke: var(--accent); stroke-width: .6; filter: drop-shadow(0 .4px .5px rgba(0,0,0,.45)); }
.map .pin.gym circle { stroke: #e4b800; stroke-width: .9; }
.map .pin:hover circle, .map .pin.active circle { fill: var(--accent-soft); }
.map .pin text { font-size: 2.6px; font-weight: 800; fill: #1d2b1f; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #fffbea; stroke-width: .7px; stroke-linejoin: round; }
.map .pin .icon { font-size: 3.2px; stroke: none; text-anchor: middle; dominant-baseline: central; pointer-events: none; }

/* Pokedex */
.dex { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.dex .entry { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.dex .entry .num { font-size: 12px; color: var(--muted); }
.dex .entry .name { font-weight: 700; }
.dex .entry .where { font-size: 11px; color: var(--muted); margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600;
  z-index: 50; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.error { background: var(--low); }
.toast.success { background: var(--ok); }

.steps { display: flex; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.steps span.on { color: var(--accent); font-weight: 700; }

/* Logged-in person at the top right: a button that opens Switch user / Home / Help */
.who { position: relative; flex: 0 1 auto; min-width: 0; max-width: 46%; margin-left: auto; }
.who:empty { display: none; }
button.who-btn {
  display: flex; align-items: center; gap: 6px; max-width: 100%; min-height: 42px;
  padding: 4px 8px 4px 12px; border-radius: 10px; font-size: 14px; text-align: right;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.45); color: #fff;
}
button.who-btn:hover, button.who-btn[aria-expanded="true"] { background: rgba(255,255,255,.26); }
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.who-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 11px; font-weight: 600; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-caret { flex: none; font-size: 13px; }
.who-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.22); padding: 6px; display: flex; flex-direction: column;
}
.who-menu[hidden] { display: none; }
.who-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px; min-height: 48px;
  background: transparent; color: var(--text); text-align: left; border-radius: 8px; font-size: 16px;
}
.who-menu button:hover, .who-menu button:focus-visible { background: var(--accent-soft); color: var(--accent-dark); }
.help-sheet textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; font-weight: 400;
  padding: 10px; border: 1px solid var(--border); border-radius: 10px; resize: vertical;
}

/* Modal sheet (ui.js modal()) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0; width: 100%; max-width: 640px;
  max-height: 92vh; overflow-y: auto; padding: 16px; position: relative;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } .modal { border-radius: var(--radius); } }
.modal-close { position: absolute; top: 10px; right: 10px; }
body.modal-open { overflow: hidden; }

/* Map markers (mapView.js) */
.map .marker .dot { fill: #fff; stroke: #1f2430; stroke-width: .4; }
.map .marker.me .dot { fill: #2f80ed; stroke: #fff; stroke-width: .5; }
.map .marker.me .accuracy { fill: #2f80ed; fill-opacity: .15; stroke: #2f80ed; stroke-width: .25; stroke-opacity: .6; }
.map .marker.bus .dot { fill: #f5d547; stroke: #6b4a1f; }
.map .marker.player .dot { fill: #8cc66a; stroke: #1f4d26; }
.map .marker.trainer .dot { fill: #ff8a65; stroke: #7a2e0e; }
.map .marker .ring { fill: none; stroke: #ff5722; stroke-width: .5; animation: marker-ring 1.4s ease-out infinite; }
@keyframes marker-ring { 0% { r: 1.8px; opacity: .9; } 100% { r: 5px; opacity: 0; } }
.map .marker.point .dot { fill: #fff; stroke: var(--accent); stroke-width: .5; }
.map .marker .icon { font-size: 2.4px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.map .marker .label { font-size: 2.4px; font-weight: 800; fill: #1d2b1f; text-anchor: middle; paint-order: stroke; stroke: #fffbea; stroke-width: .6px; stroke-linejoin: round; pointer-events: none; }
.map.tappable { cursor: crosshair; }
