:root {
  --bg: #1a2332;
  --panel: #243447;
  --text: #f0f4f8;
  --muted: #9bb0c4;
  --accent: #4fc3f7;
  --danger: #e57373;
  --ok: #81c784;
  --gold: #ffd54f;
  --border: #3a5169;
  /*
   * Boss silhouette: 4 cardinal 1px drops (literal values — calc/var inside
   * drop-shadow breaks on some mobile browsers and the whole filter vanishes).
   * JS syncBossOutlineHairline() rewrites these to the same literals at boot.
   */
  --boss-outline:
    drop-shadow(-1px 0 0 #ff6b6b)
    drop-shadow(1px 0 0 #ff6b6b)
    drop-shadow(0 -1px 0 #ff6b6b)
    drop-shadow(0 1px 0 #ff6b6b);
  --boss-outline-sm: var(--boss-outline);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  /* Disable double-tap zoom; keep clicks/scrolls working */
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: radial-gradient(ellipse at top, #2a3f55, var(--bg));
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: absolute;
  inset: 0;
  width: auto;
  max-width: none;
  margin: 0;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 12px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 16px;
}

.top-bar h1 {
  font-size: 1.35rem;
  margin: 0;
}

.status {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}

.status-metrics {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.status-metric {
  background: none;
  border-radius: 0;
  padding: 0;
  line-height: 1.1;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

#coin-display { color: var(--gold); }
#fruit-display { color: #b2ebf2; }
#twin-key-display { color: #ce93d8; }
#charm-display { color: #e1bee7; }

.coin-icon {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.28em;
  vertical-align: -0.08em;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #fff59d 0%, #ffd54f 42%, #f9a825 72%, #ef6c00 100%);
  box-shadow:
    inset 0 -1px 1px rgba(93, 64, 0, 0.35),
    0 0 0 1px rgba(255, 213, 79, 0.35);
}

.screen.hidden, .hidden { display: none !important; }

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#screen-select {
  flex-direction: row;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.split-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#screen-select .split-pane:first-child {
  flex: 2 1 0;
}

#screen-select .split-pane:last-child {
  flex: 1 1 0;
}

.split-pane > h2 {
  flex-shrink: 0;
}

.pane-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #4a6580 transparent;
}

.pane-scroll::-webkit-scrollbar {
  width: 8px;
}

.pane-scroll::-webkit-scrollbar-thumb {
  background: #4a6580;
  border-radius: 999px;
}

.screen:not(#screen-select) > .panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4a6580 transparent;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.map-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.map-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #1c2a3a;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.map-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.map-card.rift {
  border-color: #7c4dff;
}

.map-card.locked {
  opacity: 0.72;
}

.map-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}

.map-card .meta {
  padding: 10px 12px;
}

.map-card .meta strong {
  display: block;
  margin-bottom: 4px;
}

.map-card .meta span {
  color: var(--muted);
  font-size: 0.85rem;
}

.shop {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  overflow: auto;
  min-height: 0;
  flex: 1;
  margin: 8px 0 12px;
}

.shop-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  background: #1c2a3a;
}

.shop-item img {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
}

.shop-item .price {
  color: var(--gold);
  font-size: 0.9rem;
  margin: 4px 0 8px;
}

.party-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.party-head-title {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.party-head .maze-info-btn {
  margin-left: auto;
  align-self: center;
}

#party-count {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

#party-count.full {
  color: var(--danger);
}

/* —— Party pane: compact horizontal rails —— */
#screen-select .split-pane.party-pane:last-child,
#screen-select .party-pane {
  flex: 0 0 auto;
  max-height: none;
}

/* Desktop is a row layout: keep party as a side column, rail scrolls inside it. */
@media (min-width: 721px) {
  #screen-select .split-pane.party-pane:last-child {
    flex: 1 1 0;
  }
}

.party-list {
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: #4a6580 transparent;
  overscroll-behavior-x: contain;
}

#screen-select .party-list {
  grid-template-columns: unset;
}

/* Pick-party: wrapping grid of tile cards */
#pick-party.party-list {
  flex-wrap: wrap;
  overflow: visible;
  margin-bottom: 12px;
}

#pick-party .party-card {
  flex: 0 0 auto;
}

/* 精灵球瓷砖：方卡，立绘为主、等级角标、名字一行 */
.party-card {
  position: relative;
  cursor: pointer;
  box-sizing: border-box;
  flex: 0 0 auto;
  width: 88px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #1c2a3a;
  color: var(--text);
  font: inherit;
}

.party-card.selectable:hover,
.party-card:hover {
  border-color: var(--accent);
}

.party-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.party-card .sprite-frame {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 70%, rgba(255, 255, 255, 0.12), transparent 55%),
    linear-gradient(160deg, #2a4058, #1a2838);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.25);
}

.party-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

.party-card.shiny img {
  filter: hue-rotate(160deg) saturate(1.4) drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

.party-card.boss .sprite-frame {
  overflow: visible;
}

.party-card.boss img {
  filter: var(--boss-outline-sm) drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

.party-card.shiny.boss img {
  filter:
    hue-rotate(160deg) saturate(1.4)
    var(--boss-outline-sm)
    drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

.party-card > strong {
  width: 100%;
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.party-card > .meta {
  position: absolute;
  top: 4px;
  right: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--gold);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.2;
}

.party-card.in-battle {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 10px rgba(79, 195, 247, 0.35);
}

/* Popover overlays its own card: parents scroll/clip (overflow), so "above the card" would be cut off. */
.party-popover {
  position: absolute;
  inset: 0;
  z-index: 5;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: rgba(12, 20, 30, 0.96);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  cursor: default;
}

.party-popover button {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 22px;
  padding: 2px 4px;
  font-size: 0.72rem;
  line-height: 1.1;
  border-radius: 999px;
  white-space: nowrap;
}

.party-card .sell {
  margin-top: 0;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.party-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag.battle {
  background: #0d47a1;
  color: #e3f2fd;
}

.shop-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}

.shop-dialog {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#shop-modal .shop-dialog > h2,
#shop-modal .shop-dialog > button,
#dex-modal .shop-dialog > h2,
#dex-modal .shop-dialog > button,
#dex-detail-modal .shop-dialog > h2,
#dex-detail-modal .shop-dialog > button {
  flex-shrink: 0;
}

#shop-modal .shop-dialog > button,
#dex-modal .shop-dialog > button,
#dex-detail-modal .shop-dialog > button {
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  font-size: 1.05rem;
}

.dex-dialog {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.dex-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  min-height: 0;
  flex: 1;
  margin: 8px 0 12px;
}

.dex-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 4px;
  flex-shrink: 0;
}

.dex-filter {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.dex-filter.active {
  background: #1565c0;
  border-color: #90caf9;
}

.dex-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1e2a38;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dex-row:hover {
  border-color: #90caf9;
  background: #243447;
}

.dex-row img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
}

.dex-row .name {
  flex: 1;
  font-weight: 600;
}

.dex-detail-modal {
  z-index: 40;
}

.dex-detail-dialog {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow: auto;
}

.dex-detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0 12px;
  align-items: center;
  text-align: center;
}

.dex-hero-wrap {
  display: grid;
  place-items: center;
}

.dex-detail .hero {
  width: 120px;
  height: 120px;
  object-fit: contain;
  image-rendering: pixelated;
}

.dex-anim-btn {
  margin-top: 2px;
}

.dex-detail .meta,
.dex-detail .stats,
.dex-detail .moves,
.dex-detail .extra {
  width: 100%;
  text-align: left;
  line-height: 1.45;
}

.dex-detail .moves li {
  margin-left: 1.2em;
}

.dex-detail .individual {
  width: 100%;
  text-align: left;
  line-height: 1.45;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.reset-dialog {
  width: min(420px, 100%);
}

.reset-dialog p {
  margin: 0 0 4px;
  line-height: 1.5;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: #334;
}

.tag.boss { background: #5c1a1a; color: #ff8a80; }
.tag.shiny { background: #4a148c; color: #e1bee7; }
.tag.mega { background: #5d4037; color: #ffe082; }
.tag.type { background: #A8A878; color: #1a1a1a; }
.tag.type.type-normal { background: #A8A878; color: #1a1a1a; }
.tag.type.type-fire { background: #F08030; color: #fff; }
.tag.type.type-water { background: #6890F0; color: #fff; }
.tag.type.type-electric { background: #F8D030; color: #1a1a1a; }
.tag.type.type-grass { background: #78C850; color: #1a1a1a; }
.tag.type.type-ice { background: #98D8D8; color: #1a1a1a; }
.tag.type.type-fighting { background: #C03028; color: #fff; }
.tag.type.type-poison { background: #A040A0; color: #fff; }
.tag.type.type-ground { background: #E0C068; color: #1a1a1a; }
.tag.type.type-flying { background: #A890F0; color: #fff; }
.tag.type.type-psychic { background: #F85888; color: #fff; }
.tag.type.type-bug { background: #A8B820; color: #1a1a1a; }
.tag.type.type-rock { background: #B8A038; color: #fff; }
.tag.type.type-ghost { background: #705898; color: #fff; }
.tag.type.type-dragon { background: #7038F8; color: #fff; }
.tag.type.type-dark { background: #705848; color: #fff; }
.tag.type.type-steel { background: #B8B8D0; color: #1a1a1a; }
.tag.type.type-fairy { background: #EE99AC; color: #1a1a1a; }

button {
  border: 1px solid var(--border);
  background: #2f455c;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}

button:hover { border-color: var(--accent); }
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: #1565c0;
  border-color: #42a5f5;
}

button.danger {
  background: #5c2121;
  border-color: var(--danger);
}

.battle-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
}

.move-buttons {
  display: flex;
  gap: 8px;
  width: 100%;
}

.move-buttons button.move-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  text-align: left;
}

.move-btn-name {
  font-weight: 600;
  line-height: 1.2;
}

.move-btn-tags {
  margin-top: 0;
}

.move-btn-tags .tag.power {
  background: #37474f;
  color: #eceff1;
}

.move-btn-tags .tag.effect {
  background: #2e7d32;
  color: #e8f5e9;
}

.flee-btn {
  min-height: 40px;
}

/* 方案1：列表 */
.battle-actions[data-layout="list"] .move-buttons {
  flex-direction: column;
}

.battle-actions[data-layout="list"] .move-btn {
  width: 100%;
  min-height: 52px;
}

.battle-actions[data-layout="list"] .flee-btn {
  align-self: flex-end;
  min-width: 88px;
  background: #37474f;
  border-color: #546e7a;
}

/* 方案2：棋盘（技能 + 逃跑同一网格、同尺寸） */
.battle-actions[data-layout="grid"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-actions[data-layout="grid"] .move-buttons {
  display: contents;
}

.battle-actions[data-layout="grid"] .move-btn,
.battle-actions[data-layout="grid"] .flee-btn {
  min-height: 76px;
  width: 100%;
}

.battle-actions[data-layout="grid"] .flee-btn {
  background: #37474f;
  border-color: #546e7a;
}

/* 方案3：主招 */
.battle-actions[data-layout="primary"] .move-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-actions[data-layout="primary"] .move-btn:first-child {
  grid-column: 1 / -1;
  min-height: 64px;
}

.battle-actions[data-layout="primary"] .move-btn {
  min-height: 56px;
  width: 100%;
}

.battle-actions[data-layout="primary"] .flee-btn {
  align-self: flex-end;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.72);
  min-height: 32px;
  padding: 4px 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.battle-actions[data-layout="primary"] .flee-btn:hover {
  color: #fff;
  border: none;
}

.move-prompt {
  width: 100%;
  margin: 8px 0 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.item-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
}

.item-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
}

.item-row .item-icon {
  font-size: 1.2rem;
}

.item-row .item-effect {
  color: var(--muted);
  font-size: 0.85rem;
}

.item-row .item-owned {
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.item-row:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

.items-dialog {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.items-dialog .item-list,
.items-dialog #items-target-list {
  overflow: auto;
  min-height: 0;
  max-height: 55vh;
  margin: 8px 0 12px;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(420px, calc(100% - 24px));
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(18, 12, 28, 0.92);
  border: 1px solid #8b6bb0;
  color: #f2e9ff;
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.app-toast.hidden { display: none; }

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.map-stage {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.map-stage img#map-bg {
  width: 100%;
  display: block;
  image-rendering: pixelated;
}

#map-markers {
  position: absolute;
  inset: 0;
}

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(20, 28, 40, 0.88);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: center;
  min-width: 88px;
  transition: transform 0.12s ease;
}

.marker:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

.marker.trainer { border-color: #ffb74d; }
.marker.cleared {
  opacity: 0.35;
  pointer-events: none;
}

.marker img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  margin: 0 auto 4px;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}

.marker.shiny img {
  filter: hue-rotate(160deg) saturate(1.4) drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}

.marker.boss img {
  filter: var(--boss-outline-sm) drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}

.marker.shiny.boss img {
  filter:
    hue-rotate(160deg) saturate(1.4)
    var(--boss-outline-sm)
    drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}

.marker .label {
  font-size: 0.75rem;
  line-height: 1.2;
}

.battle-field {
  display: grid;
  gap: 16px;
}

.battle-field.dual {
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.battle-field.dual #ally-row {
  display: none;
}

.battle-cmd-hint {
  margin: 0 0 8px;
  font-size: 0.95rem;
  opacity: 0.9;
}
.move-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.move-buttons button {
  text-align: left;
}
.fighter.targetable {
  outline: 2px solid #f5d76e;
  cursor: pointer;
}
.fighter.target-dim {
  opacity: 0.45;
  pointer-events: none;
}
.fighter.cmd-ready::after {
  content: '就绪';
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 12px;
}
.battle-field.dual .fighter.player {
  position: relative;
}

.map-card.twin {
  border-color: #c9a227;
}

.party-card.selected {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 2px rgba(90, 180, 255, 0.35);
}

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

.ally-chip {
  position: relative;
  background: #15202b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  font-size: 0.75rem;
}

.ally-chip img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.ally-chip.fainted {
  opacity: 0.4;
}

.foe-skills {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 2px 0 6px;
}

.fighter .name-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.hp-bar {
  height: 12px;
  background: #111;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #333;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #66bb6a, #a5d6a7);
  transition: width 0.55s ease-out;
}

.hp-fill.low { background: linear-gradient(90deg, #ef5350, #ff8a80); }

.sprite-wrap {
  min-height: 160px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  padding-bottom: 8px;
  background: linear-gradient(180deg, rgba(135, 200, 255, 0.15), transparent 55%);
  border-radius: 12px;
}

.sprite-wrap img {
  width: 144px;
  height: 144px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  position: relative;
  z-index: 1;
  animation: idle-bob 2.4s ease-in-out infinite;
}

.fighter.foe .sprite-wrap img {
  animation-delay: 0.4s;
}

@keyframes idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.sprite-wrap.shiny img {
  filter: hue-rotate(160deg) saturate(1.45);
}

.sprite-wrap.boss img {
  filter: var(--boss-outline);
}

.sprite-wrap.shiny.boss img {
  filter: hue-rotate(160deg) saturate(1.45) var(--boss-outline);
}

/* Battle FX POC */
.sprite-wrap.fx-face-right img:not(.fx-strip) {
  transform: scaleX(-1);
}

.sprite-wrap.fx-lunge-right img {
  animation: fx-lunge-right 160ms ease-out;
}

.sprite-wrap.fx-lunge-left img {
  animation: fx-lunge-left 160ms ease-out;
}

.sprite-wrap.fx-hit img {
  animation: fx-hit 220ms steps(2, end);
}

@keyframes fx-lunge-right {
  0% { transform: translate(0, 0); }
  45% { transform: translate(18px, -6px); }
  100% { transform: translate(0, 0); }
}

@keyframes fx-lunge-left {
  0% { transform: translate(0, 0); }
  45% { transform: translate(-18px, -6px); }
  100% { transform: translate(0, 0); }
}

@keyframes fx-hit {
  0%, 100% { transform: translate(0, 0); filter: brightness(1); }
  25% { transform: translate(-5px, 0); filter: brightness(2.2); }
  50% { transform: translate(5px, 0); filter: brightness(1.4); }
  75% { transform: translate(-3px, 0); filter: brightness(1.8); }
}

.fx-burst {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  box-shadow: 0 0 0 0 var(--fx-tint, #fff);
}

.fx-burst.play {
  animation: fx-burst 320ms ease-out forwards;
}

@keyframes fx-burst {
  0% { opacity: 0.95; width: 12px; height: 12px; box-shadow: 0 0 0 0 var(--fx-tint, #fff); }
  70% { opacity: 0.55; width: 96px; height: 96px; box-shadow: 0 0 18px 6px var(--fx-tint, #fff); }
  100% { opacity: 0; width: 110px; height: 110px; box-shadow: 0 0 0 0 transparent; }
}

.fx-strip {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 96px;
  height: 96px;
  transform: translate(-50%, -50%);
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
}

.fx-strip.show {
  opacity: 1;
}

.ally-chip.fx-chip-flash {
  animation: fx-chip-flash 140ms ease-out;
}

@keyframes fx-chip-flash {
  0%, 100% { filter: brightness(1); }
  40% { filter: brightness(1.8); }
}

.fx-num {
  position: absolute;
  left: calc(50% + var(--fx-num-shift, 0px));
  top: 6px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 1px #1a1208;
  paint-order: stroke fill;
  text-shadow: 0 2px 0 #1a1208;
  animation: fx-num-float 720ms ease-out forwards;
}

.fx-num-value {
  font-size: 1.45rem;
}

.fx-num.super {
  color: #ffd24a;
}

.fx-num.super .fx-num-value {
  font-size: 1.7rem;
}

.fx-num.resist {
  color: #9bb0c9;
}

.fx-num.resist .fx-num-value {
  font-size: 1.15rem;
}

.fx-num.crit {
  color: #fff6c2;
}

.fx-num.crit .fx-num-value {
  font-size: 2rem;
}

.fx-num.super.crit {
  color: #ffb020;
}

.fx-num-tag {
  margin-top: 2px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: #ffe08a;
  -webkit-text-stroke: 0;
}

.fx-num.heal {
  color: #7dff8a;
}

.fx-num.heal .fx-num-value {
  font-size: 1.5rem;
}

.fx-num.still {
  animation: fx-num-still 420ms ease-out forwards;
}

@keyframes fx-num-float {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
  18% { opacity: 1; transform: translate(-50%, -4px) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

@keyframes fx-num-still {
  0%, 65% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .sprite-wrap.fx-lunge-right img,
  .sprite-wrap.fx-lunge-left img,
  .sprite-wrap.fx-hit img,
  .fx-burst.play,
  .ally-chip.fx-chip-flash {
    animation-duration: 1ms !important;
  }

  .fx-num {
    animation: fx-num-still 420ms ease-out forwards;
  }
}

.battle-log {
  background: #15202b;
  border-radius: 8px;
  padding: 10px;
  min-height: 90px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.9rem;
  margin: 12px 0 0;
  border: 1px solid var(--border);
}

.battle-log p {
  margin: 0 0 6px;
}

.ball-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.ball-option {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #1c2a3a;
  cursor: pointer;
  text-align: center;
  min-width: 84px;
}

.ball-option.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.35);
}

.ball-option img {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
}

.ball-option .count {
  font-size: 0.8rem;
  color: var(--muted);
}

.ball-option .tag {
  min-height: 1em;
  font-size: 0.72rem;
  color: var(--gold);
}

.ball-option:disabled {
  opacity: 0.45;
  cursor: default;
}

.catch-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.catch-head h2 {
  margin: 0;
}

.catch-outlook {
  font-weight: 700;
  color: var(--gold);
}

.settings-dialog {
  width: min(420px, 100%);
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 12px 0 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-label {
  color: var(--muted);
  flex-shrink: 0;
}

.style-toggle {
  display: inline-flex;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.style-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 16px;
  cursor: pointer;
}

.style-toggle button.selected {
  background: var(--accent);
  color: #10202c;
  font-weight: 700;
}

.style-toggle button:disabled {
  cursor: default;
  opacity: 0.6;
}

#catch-canvas {
  width: 100%;
  max-width: 640px;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  touch-action: none;
  cursor: grab;
  display: block;
  background: #87ceeb;
}

.catch-result {
  margin: 10px 0;
  min-height: 1.4em;
  font-weight: 600;
}

.catch-result.ok { color: var(--ok); }
.catch-result.fail { color: var(--danger); }
.catch-result.soft { color: var(--muted); font-weight: 500; }

/* —— Mobile portrait: playable layout —— */
@media (max-width: 720px) {
  #app {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    gap: 8px;
  }

  .top-bar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 12px;
  }

  .top-bar h1 {
    font-size: 1.05rem;
    line-height: 1.2;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .status button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.85rem;
    flex: 0 0 auto;
  }

  .status-metrics {
    gap: 10px;
  }

  .status-metric {
    min-height: 0;
    padding: 0;
    font-size: 0.78rem;
    line-height: 1.1;
  }

  button {
    min-height: 44px;
    padding: 10px 14px;
  }

  .maze-info-btn {
    width: 1.125rem;
    height: 1.125rem;
    min-width: 1.125rem;
    min-height: 1.125rem;
    max-width: 1.125rem;
    max-height: 1.125rem;
    padding: 0;
  }

  .panel {
    padding: 12px;
    border-radius: 12px;
  }

  #screen-select {
    flex-direction: column;
    gap: 10px;
  }

  #screen-select .split-pane.party-pane:last-child {
    flex: 0 0 auto;
    max-height: none;
  }

  #screen-select .split-pane:first-child {
    flex: 1 1 0;
    min-height: 0;
  }

  #pick-party .party-card {
    flex-basis: calc(50% - 4px);
  }

  .map-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .map-card img {
    height: 100px;
  }

  .row-actions {
    gap: 10px;
  }

  .row-actions button {
    flex: 1 1 auto;
  }

  .map-stage {
    max-width: none;
  }

  .marker {
    min-width: 72px;
    padding: 8px 6px;
    border-width: 2px;
  }

  .marker img {
    width: 48px;
    height: 48px;
  }

  .marker .label {
    font-size: 0.7rem;
  }

  .sprite-wrap {
    min-height: 112px;
    padding-bottom: 12px;
  }

  .sprite-wrap img {
    width: 112px;
    height: 112px;
  }

  .ally-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .ally-chip {
    padding: 4px;
    font-size: 0.68rem;
  }

  .ally-chip img {
    width: 40px;
    height: 40px;
  }

  .battle-log {
    min-height: 72px;
    max-height: 120px;
    font-size: 0.85rem;
    margin: 8px 0 0;
  }

  .battle-panel .row-actions {
    position: sticky;
    bottom: 0;
    padding-top: 4px;
    background: linear-gradient(180deg, transparent, var(--panel) 28%);
  }

  .battle-panel .row-actions button {
    flex: 1 1 0;
  }

  .ball-picker {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .ball-picker::-webkit-scrollbar {
    display: none;
  }

  .ball-option {
    flex: 0 0 auto;
    min-width: 76px;
    min-height: 72px;
    padding: 10px 8px;
  }

  .style-toggle {
    width: auto;
    display: inline-flex;
  }

  .style-toggle button {
    flex: 1;
    min-height: 44px;
    padding: 10px 12px;
  }

  #catch-canvas {
    max-width: none;
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .catch-head {
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  .shop {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .shop-modal {
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    align-items: end;
  }

  .shop-dialog {
    width: 100%;
    max-height: min(88vh, 100%);
    border-radius: 14px 14px 10px 10px;
  }

  .reset-dialog {
    width: 100%;
    align-self: center;
    border-radius: 14px;
  }
}

/* Spirit hall: no drag-selection highlight while exploring */
#screen-maze,
#screen-maze * {
  -webkit-user-select: none;
  user-select: none;
}

.maze-panel { display: flex; flex-direction: column; gap: 0.75rem; }
.maze-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.maze-top #maze-title { margin: 0; }
.maze-info-btn {
  box-sizing: border-box;
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  min-height: 1.125rem;
  max-width: 1.125rem;
  max-height: 1.125rem;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid #C7C7CC;
  background: transparent;
  color: #E5E5EA;
  font: 600 0.68rem/1 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-style: normal;
  letter-spacing: 0;
  cursor: pointer;
  flex: 0 0 1.125rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.maze-info-btn:hover,
.maze-info-btn:focus-visible {
  border-color: #F2F2F7;
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}
.maze-info-btn:active {
  opacity: 0.7;
}
.maze-viewport {
  --maze-tile: 56px;
  --maze-view-w: 11;
  --maze-view-h: 9;
  position: relative;
  width: calc(var(--maze-tile) * var(--maze-view-w));
  height: calc(var(--maze-tile) * var(--maze-view-h));
  max-width: min(96vw, 640px);
  max-height: min(70vh, 520px);
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  border: 2px solid #5a3f78;
  background: #0c0812;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.55);
}
.maze-world {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  transition: transform 120ms ease-out;
}
.maze-tile {
  position: absolute;
  width: var(--maze-tile);
  height: var(--maze-tile);
  image-rendering: pixelated;
  background-size: cover;
  background-repeat: no-repeat;
}
.maze-tile.wall { background-image: url('../assets/maze/wall.png'); }
.maze-tile.floor { background-image: url('../assets/maze/floor.png'); }
.maze-tile.stairs { background-image: url('../assets/maze/stairs.png'); }
.maze-tile.walkable { cursor: pointer; }
.maze-tile.walkable:hover { filter: brightness(1.08); }
.maze-dest {
  position: absolute;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid rgba(125, 255, 179, 0.9);
  background: rgba(125, 255, 179, 0.22);
  pointer-events: none;
  z-index: 1;
}
.maze-entity {
  position: absolute;
  width: calc(var(--maze-tile) * 0.82);
  height: calc(var(--maze-tile) * 0.82);
  margin: calc(var(--maze-tile) * 0.09);
  image-rendering: pixelated;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.65));
  z-index: 2;
}
.maze-entity.player {
  z-index: 4;
  outline: 2px solid #7dffb3;
  outline-offset: 1px;
  border-radius: 6px;
  background: rgba(20, 40, 30, 0.35);
}
.maze-entity.roamer { z-index: 3; }
.maze-entity.boss {
  z-index: 3;
  filter: var(--boss-outline-sm);
}
.maze-crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.28) 100%);
  z-index: 5;
}
.maze-minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 104px;
  height: 104px;
  z-index: 8;
  pointer-events: none;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  background: rgba(10, 12, 18, 0.72);
  image-rendering: pixelated;
}
@media (max-width: 720px) {
  .maze-minimap {
    width: 88px;
    height: 88px;
  }
}
.maze-stick {
  position: absolute;
  left: 10px;
  top: 50%;
  z-index: 9;
  width: 112px;
  height: 112px;
  margin-top: -56px;
  border-radius: 50%;
  background: rgba(18, 14, 24, 0.42);
  border: 2px solid rgba(255, 255, 255, 0.32);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
}
.maze-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(176, 176, 184, 0.78);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4), 0 2px 6px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.maze-stick-arrow {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0.8;
  pointer-events: none;
}
.maze-stick-arrow.n {
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 11px solid rgba(255, 255, 255, 0.8);
}
.maze-stick-arrow.s {
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 11px solid rgba(255, 255, 255, 0.8);
}
.maze-stick-arrow.w {
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 11px solid rgba(255, 255, 255, 0.8);
}
.maze-stick-arrow.e {
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid rgba(255, 255, 255, 0.8);
}
.maze-stick[data-dir="n"] .maze-stick-arrow.n,
.maze-stick[data-dir="s"] .maze-stick-arrow.s,
.maze-stick[data-dir="w"] .maze-stick-arrow.w,
.maze-stick[data-dir="e"] .maze-stick-arrow.e {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.95));
}
.maze-toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 8;
  max-width: calc(100% - 24px);
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(18, 12, 28, 0.92);
  border: 1px solid #8b6bb0;
  color: #f2e9ff;
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.maze-toast.hidden { display: none; }
.map-card.spirit { border-color: #8b6bb0; }

@media (max-width: 640px) {
  .maze-viewport {
    --maze-tile: 44px;
    --maze-view-w: 9;
    --maze-view-h: 9;
  }
  .maze-stick {
    width: 96px;
    height: 96px;
    margin-top: -48px;
  }
}
