:root {
  --bg: #0f1c16;
  --panel: #16261e;
  --ink: #e8f5ee;
  --accent: #3fbf8a;
  --line: rgba(232, 245, 238, 0.14);
  /* UI type system ? readable at phone + desktop sizes */
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Sora", "Manrope", system-ui, sans-serif;
  --font-ui: var(--font);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 100dvh;
}
.field-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  /* Shared HUD column: burger + party slots share size & right edge */
  --field-hud-right: max(0.45rem, env(safe-area-inset-right, 0px));
  --field-hud-top: max(0.45rem, env(safe-area-inset-top, 0px));
  --field-hud-size: 2.75rem;
  --field-hud-gap: 0.4rem;
}
#field {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  touch-action: none;
}
.muted { opacity: 0.7; font-variant-numeric: tabular-nums; }
#field-fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: none;
  z-index: 5;
}

/* Emerald-style location window (top-left) */
.location-popup {
  position: absolute;
  top: max(0.55rem, env(safe-area-inset-top, 0px));
  left: 0;
  z-index: 6;
  pointer-events: none;
  max-width: min(72%, 16rem);
  padding: 0.42rem 0.85rem 0.42rem 0.7rem;
  font-family: var(--font-display);
  font-size: clamp(0.72rem, 2.2vw, 0.88rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: #181818;
  background: linear-gradient(180deg, #f4f0d8 0%, #e4d9a8 100%);
  border: 3px solid #383020;
  border-left: none;
  border-radius: 0 10px 10px 0;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translateX(-110%);
  opacity: 0;
}
.location-popup.is-in {
  animation: loc-pop-in 0.35s ease-out forwards;
}
.location-popup.is-out {
  animation: loc-pop-out 0.3s ease-in forwards;
}
@keyframes loc-pop-in {
  from { transform: translateX(-110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes loc-pop-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(-110%); opacity: 0; }
}

/* GBA-style message box over the field */
.msgbox {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 4%;
  z-index: 8;
  min-height: 4.2rem;
  padding: 0.65rem 0.85rem 0.75rem;
  background: #f8f8f0;
  color: #181818;
  border: 3px solid #585870;
  border-radius: 10px;
  box-shadow: 0 0 0 2px #f8f8f0, 0 6px 18px rgba(0, 0, 0, 0.35);
  font-family: var(--font-ui);
  font-size: clamp(0.92rem, 2.6vw, 1.1rem);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}
.msgbox.hidden { display: none !important; }
.msgbox[data-style="sign"] {
  background: #f0f4ff;
  border-color: #4050a0;
}
#dialog-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.msgbox-yesno {
  position: absolute;
  right: 0.85rem;
  bottom: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 4.5rem;
  padding: 0.25rem 0.15rem;
  background: #f8f8f0;
  border: 3px solid #585870;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #f8f8f0;
  z-index: 1;
}
.msgbox-yesno.hidden { display: none !important; }
.msgbox-choice {
  appearance: none;
  border: 0;
  background: transparent;
  color: #181818;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.3;
  text-align: left;
  padding: 0.1rem 0.45rem 0.1rem 1.1rem;
  cursor: pointer;
  position: relative;
}
.msgbox-choice.selected::before {
  content: "?";
  position: absolute;
  left: 0.15rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65em;
  color: #e05050;
}
.msgbox-continue {
  position: absolute;
  right: 0.7rem;
  bottom: 0.35rem;
  font-size: 0.7rem;
  color: #585870;
  animation: msgbox-blink 0.7s steps(1) infinite;
}
@keyframes msgbox-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  min-width: min(92vw, 340px);
  max-width: 92vw;
  padding: 1rem;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
.panel.hidden { display: none !important; }

/* ?????? Start bottom sheet (Emerald-ish) ?????? */
/* ?? Start bar (slides left out of hamburger) ?? */
.start-bar {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: block;
  pointer-events: none;
  font-family: var(--font-ui);
}
.start-bar.hidden { display: none !important; }
.start-bar-row {
  --menu-btn: 2.35rem;
  --menu-gap: 0.35rem;
  position: absolute;
  top: max(0.4rem, env(safe-area-inset-top, 0px));
  right: calc(max(0.4rem, env(safe-area-inset-right, 0px)) + var(--menu-btn) + var(--menu-gap));
  left: auto;
  z-index: 1;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  height: auto;
  min-height: var(--menu-btn);
  align-items: flex-start;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  pointer-events: none;
  transform: translateX(1.25rem);
  opacity: 0;
  transition:
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.2s ease-out;
}
.start-bar.is-open .start-bar-row {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.start-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  flex: 0 0 auto;
  width: 3rem;
  height: auto;
  min-height: var(--menu-btn);
  padding: 0.1rem 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #f4fff8;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  text-shadow:
    0 1px 0 #000,
    0 0 4px rgba(0, 0, 0, 0.85),
    0 2px 6px rgba(0, 0, 0, 0.55);
  transform: translateX(0.85rem);
  opacity: 0;
  transition:
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.2s ease-out,
    filter 0.12s ease;
}
/* Closest to hamburger slides out first (right ? left) */
.start-bar.is-open .start-bar-item {
  transform: translateX(0);
  opacity: 1;
}
.start-bar.is-open .start-bar-item:nth-child(4) { transition-delay: 0.02s; }
.start-bar.is-open .start-bar-item:nth-child(3) { transition-delay: 0.06s; }
.start-bar.is-open .start-bar-item:nth-child(2) { transition-delay: 0.1s; }
.start-bar.is-open .start-bar-item:nth-child(1) { transition-delay: 0.14s; }
.start-bar-logout { color: #ffd0d0; }
.start-bar-item:hover,
.start-bar-item:focus-visible {
  outline: none;
  filter: brightness(1.15);
}
.start-bar-item:active { transform: scale(0.94); }
.start-bar-ico {
  display: grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  line-height: 0;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 3px rgba(0, 0, 0, 0.45));
}
.start-bar-ico svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.start-bar-label {
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}
.start-bar-status {
  position: absolute;
  top: max(3.1rem, calc(env(safe-area-inset-top, 0px) + 2.7rem));
  right: max(0.5rem, env(safe-area-inset-right, 0px));
  left: auto;
  transform: none;
  margin: 0;
  padding: 0;
  font-size: 0.65rem;
  font-weight: 700;
  color: #f4fff8;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  text-align: right;
}

/* ?????? Party modal (Emerald GBA) ?????? */
.party-modal {
  --gba: var(--font-ui);
  --cream: #eef2f8;
  --edge: #1a2230;
  --inner: #5a6a82;
  --ink: #e8eef8;
  --party-bg: #0c1018;
  --party-panel: #1a2230;
  --party-slot: #243044;
  --party-slot-2: #1a2434;
  --party-line: rgba(255, 255, 255, 0.12);
  --party-accent: #5ad0ff;
  --party-muted: #9aabbf;
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  background: transparent;
  font-family: var(--gba);
  color: var(--ink);
}
.party-modal.hidden { display: none !important; }
.party-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(6, 10, 18, 0.55);
  backdrop-filter: blur(4px);
  cursor: pointer;
}
.party-modal-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(90% 60% at 10% 0%, rgba(90, 208, 255, 0.16), transparent 55%),
    radial-gradient(70% 50% at 100% 20%, rgba(255, 120, 180, 0.1), transparent 50%),
    linear-gradient(165deg, #1a2438 0%, #10161f 48%, #0a0e14 100%);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Top-right close */
.party-menu-btn {
  position: absolute;
  top: max(0.55rem, env(safe-area-inset-top, 0px));
  right: max(0.55rem, env(safe-area-inset-right, 0px));
  z-index: 6;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.party-menu-btn:hover {
  background: rgba(90, 208, 255, 0.18);
  border-color: rgba(90, 208, 255, 0.5);
}
.party-menu-icon {
  display: block;
  width: 1rem;
  height: 0.72rem;
  background:
    linear-gradient(#e8eef8, #e8eef8) 0 0 / 100% 2px no-repeat,
    linear-gradient(#e8eef8, #e8eef8) 0 50% / 100% 2px no-repeat,
    linear-gradient(#e8eef8, #e8eef8) 0 100% / 100% 2px no-repeat;
}
.party-close-x {
  display: block;
  width: 0.85rem;
  height: 0.85rem;
  position: relative;
  font-size: 0;
  color: transparent;
}
.party-close-x::before,
.party-close-x::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 1.5px;
  border-radius: 1px;
  background: #e8eef8;
}
.party-close-x::before { transform: translate(-50%, -50%) rotate(45deg); }
.party-close-x::after { transform: translate(-50%, -50%) rotate(-45deg); }

/* Party ? equal 2?3 grid */
.party-stack {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.5rem max(0.5rem, env(safe-area-inset-right, 0px)) 0.5rem max(0.5rem, env(safe-area-inset-left, 0px));
  overflow: auto;
}
.party-stack-panel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
  flex: 0 1 auto;
}
.party-stack-panel.hidden { display: none !important; }
.party-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, auto);
  gap: 0.28rem;
  width: min(100%, 26rem);
  margin: 0 auto;
  flex: 0 1 auto;
  min-height: 0;
  max-height: none;
  align-content: start;
}
.party-slot {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 0.35rem;
  align-items: center;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 0.28rem 0.4rem 0.28rem 0.28rem;
  border: 1px solid var(--party-line);
  border-radius: 10px;
  background: linear-gradient(145deg, #2a364c 0%, #1a2434 100%);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.party-slot-dragging {
  opacity: 0.4;
  z-index: 8;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  cursor: grabbing;
  pointer-events: none;
}
.party-slot-drop {
  outline: 2px solid #5ad0ff;
  outline-offset: -2px;
  background: rgba(90, 208, 255, 0.16) !important;
}
.party-slot-face {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 0;
  background: none;
  box-shadow: none;
}
.party-slot-face::before {
  content: none;
}
.party-slot-face img {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  object-fit: contain;
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
  background: none;
}
.party-slot-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  justify-content: center;
}
.party-slot-top {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  min-width: 0;
}
.party-slot.party-slot-lead {
  grid-column: auto;
  grid-row: auto;
  display: grid;
  padding: 0.28rem 0.4rem 0.28rem 0.28rem;
  border-radius: 10px;
  background: linear-gradient(145deg, #2a364c 0%, #1a2434 100%);
}
.party-slot.party-slot-lead .party-slot-face {
  width: 36px;
  height: 36px;
  border-radius: 0;
  background: none;
}
.party-slot.party-slot-lead .party-slot-face img {
  width: 36px;
  height: 36px;
}
.party-slot.party-slot-lead .party-slot-top {
  flex-direction: row;
  align-items: baseline;
}
.party-slot.party-slot-lead .party-slot-name {
  font-size: 0.7rem;
}
.party-slot.party-slot-lead .party-slot-hpwrap {
  margin-top: 0;
}
.party-slot:not(.party-slot-lead) {
  grid-column: auto;
}
.party-slot .party-exp-row {
  display: none;
}
.party-slot:hover:not(:disabled),
.party-slot.party-cursor,
.party-slot.party-selected {
  border-color: rgba(90, 208, 255, 0.7);
  box-shadow:
    inset 0 0 0 1px rgba(90, 208, 255, 0.22),
    0 0 0 2px rgba(90, 208, 255, 0.28);
  background: linear-gradient(145deg, #334560 0%, #1e2a3c 100%);
}
.party-slot.party-switch-from {
  opacity: 0.55;
  border-color: rgba(255, 255, 255, 0.08);
  filter: saturate(0.7);
}
.party-slot.party-switch-from.party-cursor {
  opacity: 1;
  filter: none;
  border-color: rgba(90, 208, 255, 0.7);
}
.party-slot:disabled,
.party-slot.empty {
  opacity: 0.38;
  cursor: default;
  background: rgba(255, 255, 255, 0.03);
}
.party-slot.fainted {
  filter: grayscale(0.7);
  opacity: 0.72;
}
.party-slot-meta,
.party-slot-name {
  min-width: 0;
  overflow: hidden;
}
.party-slot-name {
  display: block;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.02em;
  color: #f2f6fc;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 100%;
  overflow: hidden;
}
.party-slot-lv {
  display: inline-block;
  font-size: 0.52rem;
  font-weight: 650;
  color: var(--party-muted);
  flex: 0 0 auto;
}
.party-slot-hpwrap,
.party-slot-bars {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.28rem;
  min-width: 0;
  width: 100%;
}
.party-slot-hptext {
  font-size: 0.52rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--party-muted);
  line-height: 1;
  flex: 0 0 auto;
}
.party-hp-row {
  display: flex;
  align-items: center;
  gap: 0.18rem;
  flex: 1;
  min-width: 0;
}
.party-hp-tag {
  flex: 0 0 auto;
  padding: 0.05rem 0.16rem;
  font-size: 0.45rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  background: #e03870;
  border: 0;
  border-radius: 3px;
}
.party-hp-track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  border: 0;
}
.party-hp-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #4adf70, #28c050);
}
.party-hp-fill.mid { background: linear-gradient(90deg, #f0d050, #e0a020); }
.party-hp-fill.low { background: linear-gradient(90deg, #f07070, #d02828); }
.party-exp-row,
.party-sum-exp {
  display: flex;
  align-items: center;
  gap: 0.16rem;
  margin-top: 0.04rem;
}
.party-exp-tag {
  flex: 0 0 auto;
  padding: 0.05rem 0.16rem;
  font-size: 0.45rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  background: #4060c8;
  border: 0;
  border-radius: 3px;
}
.party-exp-track {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  border: 0;
}
.party-exp-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #70c8f8, #2870d0);
}
.party-sum-exp {
  margin-top: 0.35rem;
}
.party-sum-exp .party-exp-track {
  height: 7px;
}
.party-empty {
  margin: 1.2rem auto;
  padding: 0.75rem;
  max-width: 22rem;
  text-align: center;
  line-height: 1.7;
  font-size: 0.8rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--party-line);
  border-radius: 12px;
  box-shadow: none;
}
.party-empty.hidden { display: none !important; }

/* Selected mon action overlay */
.party-action-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0.65rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
}
.party-action-overlay.hidden { display: none !important; }
.party-action-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(6, 10, 18, 0.5);
  cursor: pointer;
}
.party-action-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 13.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: linear-gradient(165deg, #2a364c 0%, #171e2a 100%);
  color: #f2f6fc;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 14px 32px rgba(0, 0, 0, 0.45);
  animation: party-sheet-up 0.16s ease-out;
}
@keyframes party-sheet-up {
  from { transform: translateY(10px); opacity: 0.55; }
  to { transform: translateY(0); opacity: 1; }
}
.party-action-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0.15rem 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.party-action-card img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
}
.party-action-card strong {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 0.12rem;
  color: #f2f6fc;
}
.party-action-card .muted,
#party-action-lv {
  font-size: 0.68rem;
  color: #9aabbf;
}
.party-action-btns {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}
.party-action-btns [data-party-act].hidden,
.party-action-btns [data-party-act][hidden] {
  display: none !important;
}
.party-action-btns button,
.party-secondary {
  padding: 0.42rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  color: #f2f6fc;
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-align: left;
  box-shadow: none;
}
.party-action-btns button:hover,
.party-action-btns button.party-cursor,
.party-secondary:hover {
  outline: none;
  border-color: rgba(90, 208, 255, 0.55);
  background: rgba(90, 208, 255, 0.14);
}
.party-action-btns button:disabled {
  opacity: 0.4;
  cursor: default;
}
.party-secondary {
  width: min(100%, 22rem);
  margin: 0.25rem auto 0;
  text-align: center;
}

/* Summary ? fills floating party panel */
.party-modal.party-summary-open .party-modal-inner {
  min-height: min(26rem, 78vh);
}
.party-modal.party-summary-open .party-stack {
  /* keep layout height; summary covers it */
  pointer-events: none;
}
.party-summary-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2.6rem 0.75rem 0.75rem;
  background:
    radial-gradient(90% 60% at 10% 0%, rgba(90, 208, 255, 0.12), transparent 55%),
    linear-gradient(165deg, #1a2438 0%, #10161f 48%, #0a0e14 100%);
  backdrop-filter: none;
}
.party-summary-overlay.hidden { display: none !important; }
.party-summary-tabs {
  display: flex;
  gap: 0.25rem;
  width: min(100%, 22rem);
  margin: 0 0 0.45rem;
  flex: 0 0 auto;
}
.party-tab {
  flex: 1;
  padding: 0.35rem 0.2rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #c8d4e4;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.party-tab.active[data-sum-page="0"] {
  background: rgba(224, 56, 112, 0.28);
  color: #fff;
  border-color: rgba(240, 120, 160, 0.55);
}
.party-tab.active[data-sum-page="1"] {
  background: rgba(64, 128, 208, 0.32);
  color: #fff;
  border-color: rgba(120, 180, 255, 0.55);
}
.party-tab.active[data-sum-page="2"] {
  background: rgba(208, 160, 64, 0.28);
  color: #fff;
  border-color: rgba(240, 200, 100, 0.55);
}
.party-summary-body {
  width: min(100%, 22rem);
  flex: 1 1 auto;
  min-height: 14rem;
  max-height: none;
  padding: 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: linear-gradient(165deg, #2a364c 0%, #171e2a 100%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 16px 40px rgba(0, 0, 0, 0.45);
  overflow: auto;
  color: #e8eef8;
}
.party-summary-body[data-page="0"],
.party-summary-body[data-page="1"],
.party-summary-body[data-page="2"] {
  background: linear-gradient(165deg, #2a364c 0%, #171e2a 100%);
}
.party-sum-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.party-sum-hero {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 0.55rem;
  align-items: center;
}
.party-sum-hero .party-sum-sprite {
  width: 72px;
  height: 72px;
  object-fit: contain;
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 55%, rgba(90, 208, 255, 0.18), transparent 65%),
    rgba(0, 0, 0, 0.28);
}
.party-sum-plate {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  min-width: 0;
}
.party-sum-plate strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.15rem;
  color: #f2f6fc;
}
.party-sum-plate .party-sum-lv {
  font-size: 0.7rem;
  color: #9aabbf;
  margin-bottom: 0.25rem;
}
.party-types {
  display: flex;
  gap: 0.25rem;
  margin: 0;
}
.party-types img {
  width: auto;
  height: 12px;
  image-rendering: pixelated;
}
.party-sum-meters {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding: 0.45rem 0.5rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.party-sum-hp {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0;
}
.party-sum-hp .party-hp-track {
  flex: 1;
  height: 7px;
}
.party-sum-hpnum {
  font-size: 0.68rem;
  min-width: 3.2rem;
  text-align: right;
  color: #c8d4e4;
  font-variant-numeric: tabular-nums;
}
.party-sum-facts {
  margin: 0;
  display: grid;
  gap: 0.28rem;
}
.party-sum-facts > div {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 0.35rem;
  align-items: baseline;
  padding: 0.32rem 0.45rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.party-sum-facts dt {
  margin: 0;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #9aabbf;
}
.party-sum-facts dd {
  margin: 0;
  font-size: 0.74rem;
  color: #f2f6fc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.party-stat-list {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}
.party-stat-row {
  display: grid;
  grid-template-columns: 4.4rem 2.6rem 1fr;
  gap: 0.3rem;
  align-items: center;
  font-size: 0.7rem;
  padding: 0.28rem 0.35rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}
.party-stat-row .label {
  color: #9aabbf;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.62rem;
}
.party-stat-row .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #f2f6fc;
}
.party-stat-bar {
  height: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 0;
  border-radius: 999px;
  overflow: hidden;
}
.party-stat-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #70b8f8, #2870c8);
}
.party-move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.28rem;
}
.party-move-card {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 0.4rem;
  align-items: center;
  margin: 0;
  padding: 0.42rem 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: none;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.party-move-dragging {
  opacity: 0.55;
  z-index: 2;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  cursor: grabbing;
}
.party-move-drop {
  box-shadow: inset 0 0 0 2px #5ad0ff;
  background: rgba(90, 208, 255, 0.14);
}
.party-move-card .mv-name {
  font-size: 0.74rem;
  font-weight: 700;
  color: #f2f6fc;
  letter-spacing: 0.02em;
}
.party-move-card .mv-pp {
  font-size: 0.66rem;
  font-weight: 700;
  color: #9aabbf;
  font-variant-numeric: tabular-nums;
}
.party-move-card .mv-type {
  width: 32px;
  height: 14px;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.party-summary-overlay .party-hint {
  width: min(100%, 22rem);
  margin: 0.4rem 0 0;
}
.party-hint {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
  color: #9aabbf;
  text-align: center;
  text-shadow: none;
}
.party-switch-prompt {
  margin: 0;
  padding: 0.45rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #e8eef8;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  box-shadow: none;
  text-align: center;
}
.party-switch-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.party-switch-view .party-list {
  flex: 1;
  overflow: auto;
  margin-bottom: 0.4rem;
  align-content: start;
}
.party-switch-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: min(100%, 22rem);
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 0.15rem;
}
.party-switch-foot .party-secondary {
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.55rem;
  font-size: 0.72rem;
}

/* ?? PC BOX (HOME-inspired, polished) ????????????????????? */
.box-modal {
  --home-bg: #0e141c;
  --home-panel: #171f2c;
  --home-ink: #eef3fa;
  --home-muted: #8b9cb3;
  --home-accent: #3ecfbf;
  --home-accent-deep: #1f8f84;
  --home-select: #5ad8ff;
  --home-line: rgba(255, 255, 255, 0.08);
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top, 0px)) max(0.75rem, env(safe-area-inset-right, 0px)) max(0.75rem, env(safe-area-inset-bottom, 0px)) max(0.75rem, env(safe-area-inset-left, 0px));
  background: transparent;
  font-family: var(--font-ui);
  color: var(--home-ink);
}
.box-modal.hidden { display: none !important; }
.box-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.box-modal-inner {
  position: relative;
  z-index: 1;
  width: min(56rem, 96vw);
  max-height: min(92vh, 50rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background:
    linear-gradient(180deg, rgba(62, 207, 191, 0.07), transparent 28%),
    linear-gradient(165deg, #1a2434 0%, #121820 55%, #0a1018 100%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.45),
    0 32px 72px rgba(0, 0, 0, 0.6);
}
.box-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 18.5rem);
  gap: 0.75rem;
  padding: 0 0.85rem 0.45rem;
}
.box-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.55rem;
  flex-shrink: 0;
}
.box-top-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.box-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.85rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #48d4c4, var(--home-accent-deep));
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 2px 0 #145a54;
}
.box-count {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--home-muted);
  font-variant-numeric: tabular-nums;
}
.box-close-btn {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 999px;
  border: 1px solid var(--home-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--home-ink);
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.box-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.box-section-label {
  margin: 0 0 0.3rem;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  font-weight: 700;
  color: var(--home-muted);
}
.box-grid-section {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.box-summary {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border-radius: 16px;
  background: rgba(8, 12, 18, 0.55);
  border: 1px solid var(--home-line);
  padding: 0.85rem 0.8rem 0.9rem;
  scrollbar-width: thin;
}
.box-summary-empty {
  margin: 3rem 0.5rem;
  text-align: center;
  color: var(--home-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}
.box-summary-empty.hidden,
.box-summary-body.hidden {
  display: none !important;
}
.box-sum-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  margin: 0 0 0.75rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--home-line);
}
.box-sum-sprite-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(90, 216, 255, 0.14), transparent 65%),
    rgba(255, 255, 255, 0.03);
}
.box-sum-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
  opacity: 0;
  transition: opacity 0.12s ease;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
}
.box-sum-sprite.fp-sprite-fit {
  object-fit: fill;
  max-width: none;
  max-height: none;
}
.box-sum-id {
  min-width: 0;
  width: 100%;
}
.box-sum-id strong {
  display: block;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.1rem 0;
}
.box-sum-lv {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  color: #041018;
  background: var(--home-select);
  font-weight: 800;
}
.box-sum-types {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
}
.box-sum-types img {
  width: 36px;
  height: 16px;
  object-fit: contain;
  image-rendering: pixelated;
}
.box-sum-meters {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
}
.box-sum-hp,
.box-sum-exp {
  display: grid;
  grid-template-columns: 2.1rem 1fr auto;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--home-muted);
}
.box-sum-hp .num {
  color: var(--home-ink);
  font-variant-numeric: tabular-nums;
}
.box-sum-hp .track,
.box-sum-exp .track {
  height: 0.42rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}
.box-sum-hp .fill,
.box-sum-exp .fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #3ecf70, #6ef08a);
}
.box-sum-hp .fill.mid { background: linear-gradient(90deg, #d8a020, #f0c850); }
.box-sum-hp .fill.low { background: linear-gradient(90deg, #d03838, #f06868); }
.box-sum-exp .fill.exp { background: linear-gradient(90deg, #2aa8e0, #5ad8ff); }
.box-sum-facts {
  margin: 0 0 0.65rem;
  display: grid;
  gap: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--home-line);
  background: rgba(255, 255, 255, 0.02);
}
.box-sum-facts > div {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.4rem;
  align-items: center;
  padding: 0.38rem 0.55rem;
  font-size: 0.68rem;
  border-top: 1px solid var(--home-line);
}
.box-sum-facts > div:first-child { border-top: 0; }
.box-sum-facts dt {
  margin: 0;
  color: var(--home-muted);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.58rem;
}
.box-sum-facts dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.box-sum-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.28rem;
  margin-bottom: 0.7rem;
}
.box-sum-stats > div {
  text-align: center;
  padding: 0.35rem 0.1rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--home-line);
}
.box-sum-stats span {
  display: block;
  font-size: 0.5rem;
  color: var(--home-muted);
  font-weight: 800;
  letter-spacing: 0.04em;
}
.box-sum-stats b {
  display: block;
  margin-top: 0.18rem;
  font-size: 0.78rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.box-sum-moves-label {
  margin: 0 0 0.35rem;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--home-muted);
}
.box-sum-moves {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.28rem;
}
.box-sum-move {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.45rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--home-line);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.box-sum-move.empty {
  display: block;
  color: var(--home-muted);
  text-align: center;
  cursor: default;
  touch-action: auto;
}
.box-sum-move-dragging {
  opacity: 0.55;
  z-index: 2;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
  cursor: grabbing;
}
.box-sum-move-drop {
  border-color: var(--home-select);
  box-shadow: inset 0 0 0 1px var(--home-select);
  background: rgba(90, 216, 255, 0.12);
}
.box-sum-move img {
  width: 32px;
  height: 14px;
  object-fit: contain;
  image-rendering: pixelated;
}
.box-sum-move-pp {
  color: var(--home-muted);
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
}
.box-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: minmax(0, auto);
  gap: 0.35rem;
  padding: 0.55rem;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--home-line);
  align-content: start;
  scrollbar-width: thin;
}
.box-party-section {
  flex-shrink: 0;
  padding: 0.35rem 0.85rem 0.45rem;
}
.box-party-sheet-handle,
.box-party-sheet-head,
.box-party-collapse {
  display: none;
}
.box-party-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.4rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--home-line);
}
.box-pod {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  max-height: none;
  display: grid;
  place-items: center;
  cursor: grab;
  color: inherit;
  border-radius: 12px;
  touch-action: none;
  user-select: none;
  overflow: hidden;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.box-pod.empty {
  cursor: default;
  background: rgba(255, 255, 255, 0.025);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.box-pod:not(.empty):hover {
  background: rgba(90, 216, 255, 0.08);
}
.box-pod-ring {
  display: none;
}
.box-pod-sprite {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  image-rendering: auto;
  image-rendering: smooth;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}
.box-pod-sprite.fp-sprite-fit {
  object-fit: fill;
  max-width: none;
  max-height: none;
}
.box-pod.fainted .box-pod-sprite {
  filter: grayscale(0.75) drop-shadow(0 2px 1px rgba(0, 0, 0, 0.3));
  opacity: 0.75;
}
.box-pod-lv {
  position: absolute;
  z-index: 2;
  right: 6%;
  top: 5%;
  bottom: auto;
  font-size: 0.52rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}
.box-pod.box-cursor,
.box-pod.box-drop-target {
  outline: 2px solid var(--home-select);
  outline-offset: -2px;
  background: rgba(90, 208, 255, 0.12);
}
.box-pod.box-cursor .box-pod-ring,
.box-pod.box-drop-target .box-pod-ring {
  display: none;
}
.box-pod.box-drag-source {
  opacity: 0.35;
}
.box-pod.box-drag-source .box-pod-sprite {
  opacity: 0;
}
.box-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.2rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
  padding: 0.35rem 0.4rem 0.35rem 0.7rem;
  border-radius: 14px;
  background: rgba(10, 16, 24, 0.85);
  border: 1px solid var(--home-line);
  color: var(--home-ink);
  flex-shrink: 0;
}
.box-bar-hint {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--home-muted);
}
.box-party-toggle {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  flex-shrink: 0;
  min-width: 3.4rem;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #48d4c4, var(--home-accent-deep));
  color: #fff;
  font: inherit;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 2px 0 #145a54;
}
.box-party-toggle-ico {
  font-size: 0.7rem;
  line-height: 1;
}
.box-toast {
  position: absolute;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  z-index: 6;
  margin: 0;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.92);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.78rem;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.box-toast.hidden { display: none; }
.box-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  width: 56px;
  height: 56px;
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
}
.box-drag-ghost.hidden { display: none; }
.box-drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.box-modal.box-dragging {
  cursor: grabbing;
}
.box-modal.box-dragging .box-pod {
  cursor: grabbing;
}
@media (max-width: 720px) {
  .box-modal {
    padding: 0;
    align-items: stretch;
  }
  .box-modal-inner {
    position: relative;
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border: 0;
    overflow: hidden;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .box-top {
    padding: 0.45rem 0.6rem 0.25rem;
  }
  .box-pill {
    padding: 0.2rem 0.55rem;
    font-size: 0.68rem;
  }
  .box-count { font-size: 0.72rem; }
  .box-close-btn {
    width: 2rem;
    height: 2rem;
  }
  .box-main {
    grid-template-columns: minmax(0, 1fr) minmax(11.5rem, 13.5rem);
    gap: 0.45rem;
    padding: 0 0.45rem 0.15rem;
  }
  .box-summary {
    padding: 0.55rem 0.5rem 0.65rem;
  }
  .box-sum-sprite-wrap {
    width: 64px;
    height: 64px;
    border-radius: 14px;
  }
  .box-sum-sprite {
    width: 58px;
    height: 58px;
  }
  .box-sum-id strong {
    font-size: 0.82rem;
  }
  .box-sum-facts > div {
    grid-template-columns: 3.6rem 1fr;
    padding: 0.3rem 0.4rem;
    font-size: 0.6rem;
  }
  .box-sum-stats b {
    font-size: 0.68rem;
  }
  .box-grid {
    gap: 0.22rem;
    padding: 0.35rem;
  }
  .box-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: calc((58vw - 0.6rem) / 6);
    gap: 0;
    padding: 0.2rem 0.1rem 0.3rem;
    border-radius: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-content: start;
  }

  /* Portrait: summary onder de grid, volle breedte */
  @media (orientation: portrait) {
    .box-main {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(0, 1fr) auto;
      gap: 0.35rem;
    }
    .box-grid-section {
      min-height: 0;
    }
    .box-summary {
      width: 100%;
      max-width: none;
      max-height: min(42vh, 18rem);
    }
    .box-grid {
      grid-auto-rows: calc((100vw - 0.9rem) / 6);
    }
    .box-sum-sprite-wrap {
      width: 56px;
      height: 56px;
    }
    .box-sum-sprite {
      width: 50px;
      height: 50px;
    }
    .box-sum-id strong {
      font-size: 0.88rem;
    }
    .box-sum-hero {
      flex-direction: row;
      text-align: left;
      align-items: center;
      gap: 0.55rem;
    }
    .box-sum-types {
      justify-content: flex-start;
    }
  }
  .box-pod {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    overflow: hidden;
  }
  .box-pod-sprite {
    /* size/pos from sprite_fit.js */
  }
  .box-pod-lv {
    font-size: 0.48rem;
    right: 4%;
    top: 4%;
    bottom: auto;
  }
  .box-pod.box-cursor,
  .box-pod.box-drop-target {
    outline-width: 2px;
  }

  .box-bar {
    display: flex;
    position: relative;
    z-index: 5;
  }
  .box-party-toggle {
    display: flex;
  }
  .box-modal.box-party-open .box-party-toggle-ico {
    transform: rotate(180deg);
  }

  /* Party = bottom sheet, hidden by default */
  .box-party-section {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 8;
    margin: 0;
    padding: 0.35rem 0.55rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
    background: #151c28;
    border-radius: 16px 16px 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
    transform: translateY(110%);
    transition: transform 0.28s ease;
    pointer-events: none;
  }
  .box-modal.box-party-open .box-party-section {
    transform: translateY(0);
    pointer-events: auto;
  }
  .box-party-sheet-handle {
    display: block;
    width: 2.4rem;
    height: 0.28rem;
    margin: 0.1rem auto 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
  }
  .box-party-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
  }
  .box-party-sheet-head .box-section-label {
    margin: 0;
    font-size: 0.62rem;
  }
  .box-party-collapse {
    display: grid;
    place-items: center;
    width: 1.8rem;
    height: 1.8rem;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--home-ink);
    cursor: pointer;
    font-size: 0.7rem;
  }
  .box-party-row {
    gap: 0;
    padding: 0.25rem 0.1rem;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: calc((100vw - 1.2rem) / 6);
  }
  .box-party-row .box-pod {
    height: 100%;
    aspect-ratio: auto;
    overflow: hidden;
  }
  .box-party-row .box-pod-sprite {
    /* fitted by JS */
  }
  .box-toast {
    bottom: 4.5rem;
    font-size: 0.68rem;
  }
  .box-drag-ghost {
    width: 40px;
    height: 40px;
  }
}

/* Portrait (phone/tablet): summary onder grid; landscape/desktop blijft rechts */
@media (orientation: portrait) and (max-width: 1100px) {
  .box-modal .box-main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.4rem;
  }
  .box-modal .box-grid-section {
    min-height: 0;
    width: 100%;
  }
  .box-modal .box-summary {
    width: 100%;
    max-width: none;
    max-height: min(40vh, 20rem);
  }
  .box-modal .box-grid {
    grid-auto-rows: calc((100vw - 1.5rem) / 6);
  }
}

/* ?? Bag (floating window) ????????????????????????????????? */
.bag-modal {
  --bag-ink: #e8eef8;
  --bag-muted: #9aabbf;
  --bag-panel: #1a2230;
  --bag-panel-2: #121820;
  --bag-line: rgba(255, 255, 255, 0.1);
  --bag-accent: #5ad0ff;
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top, 0px)) max(0.75rem, env(safe-area-inset-right, 0px)) max(0.75rem, env(safe-area-inset-bottom, 0px)) max(0.75rem, env(safe-area-inset-left, 0px));
  background: transparent;
  font-family: var(--font-ui);
  color: var(--bag-ink);
}
.bag-modal.bag-battle {
  z-index: 55;
}
.bag-modal.hidden { display: none !important; }
.bag-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(6, 10, 18, 0.55);
  backdrop-filter: blur(4px);
  cursor: pointer;
}
.bag-modal-inner {
  position: relative;
  z-index: 1;
  width: min(100%, 34rem);
  max-height: min(86vh, 40rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(90, 208, 255, 0.18), transparent 55%),
    radial-gradient(90% 70% at 100% 0%, rgba(255, 120, 180, 0.12), transparent 50%),
    linear-gradient(165deg, #243044 0%, #151c28 55%, #0e141c 100%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 24px 60px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.bag-modal-inner[data-pocket="balls"] {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(96, 168, 255, 0.22), transparent 55%),
    linear-gradient(165deg, #1e2a40 0%, #121820 100%);
}
.bag-modal-inner[data-pocket="tms"] {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(160, 220, 80, 0.18), transparent 55%),
    linear-gradient(165deg, #1e2c20 0%, #121820 100%);
}
.bag-modal-inner[data-pocket="berries"] {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(255, 120, 200, 0.2), transparent 55%),
    linear-gradient(165deg, #2a1c30 0%, #121820 100%);
}
.bag-modal-inner[data-pocket="key"] {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(80, 220, 160, 0.18), transparent 55%),
    linear-gradient(165deg, #1a2c28 0%, #121820 100%);
}
.bag-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem 0.65rem;
  border-bottom: 1px solid var(--bag-line);
  flex: 0 0 auto;
}
.bag-top-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.bag-kicker {
  margin: 0;
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  color: var(--bag-muted);
  font-weight: 700;
}
.bag-top-brand h2 {
  margin: 0.1rem 0 0;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  font-weight: 800;
  color: #fff;
}
.bag-close-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #f0f4fa;
  font-size: 0.95rem;
  cursor: pointer;
  flex: 0 0 auto;
}
.bag-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}
.bag-layout {
  display: grid;
  grid-template-columns: 5.6rem minmax(0, 1fr);
  min-height: 0;
  flex: 1;
}
.bag-pockets {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding: 0.65rem 0.45rem 0.65rem 0.55rem;
  border-right: 1px solid var(--bag-line);
  overflow: auto;
  background: rgba(0, 0, 0, 0.18);
}
.bag-pocket {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 3.1rem;
  padding: 0.35rem 0.15rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--bag-muted);
  font: inherit;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.bag-pocket-ico {
  width: 1.7rem;
  height: 1.7rem;
  object-fit: contain;
  border-radius: 8px;
  background: #f4f0e8;
  padding: 0.12rem;
  opacity: 0.72;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.bag-pocket.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.bag-pocket.active .bag-pocket-ico { opacity: 1; }
.bag-pocket.active[data-pocket="items"] { color: #ffb09a; }
.bag-pocket.active[data-pocket="balls"] { color: #9accff; }
.bag-pocket.active[data-pocket="tms"] { color: #c8f070; }
.bag-pocket.active[data-pocket="berries"] { color: #ffb0e0; }
.bag-pocket.active[data-pocket="key"] { color: #7aefc0; }
.bag-body {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.65rem 0.65rem;
}
.bag-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding-right: 0.15rem;
}
.bag-row {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  text-align: left;
  cursor: pointer;
}
.bag-row-icon {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  background: #f4f0e8;
  border-radius: 8px;
  padding: 0.1rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.bag-preview-icon {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #f4f0e8;
  border-radius: 10px;
  padding: 0.15rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.bag-action-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #f4f0e8;
  border-radius: 10px;
  padding: 0.15rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.bag-row-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}
.bag-row-count {
  font-variant-numeric: tabular-nums;
  color: #9ec4ff;
  font-weight: 800;
  font-size: 0.88rem;
}
.bag-empty-list {
  margin: auto;
  padding: 1.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  color: var(--bag-muted);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  text-align: center;
  min-height: 8rem;
}
.bag-empty-list p {
  margin: 0;
  font-weight: 650;
}
.bag-empty-ico {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  background: #f4f0e8;
  border-radius: 10px;
  padding: 0.2rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
  opacity: 0.9;
}
.bag-row.bag-cursor,
.bag-row:hover {
  background: rgba(90, 208, 255, 0.14);
  border-color: rgba(90, 208, 255, 0.35);
  box-shadow: inset 0 0 0 1px rgba(90, 208, 255, 0.12);
}
.bag-footer {
  flex: 0 0 auto;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--bag-line);
}
.bag-preview {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr);
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.6rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.bag-desc {
  margin: 0;
  min-height: 2.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: #d5deea;
}
.bag-hint {
  margin: 0.45rem 0 0;
  padding: 0;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--bag-muted);
  opacity: 0.9;
}
.bag-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  background: linear-gradient(165deg, #243044 0%, #151c28 55%, #0e141c 100%);
  border-radius: inherit;
}
.bag-overlay.hidden { display: none !important; }
.bag-overlay-scrim {
  display: none;
}

/* Compact USE / GIVE / TOSS sheet over the bag (party-style) */
.bag-action-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0.65rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
  border-radius: inherit;
}
.bag-action-overlay.hidden { display: none !important; }
.bag-action-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: inherit;
  background: rgba(6, 10, 18, 0.42);
  cursor: pointer;
}
.bag-action-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 13.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: linear-gradient(165deg, #2a364c 0%, #171e2a 100%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 14px 32px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: bag-sheet-up 0.16s ease-out;
}
@keyframes bag-sheet-up {
  from { transform: translateY(10px); opacity: 0.55; }
  to { transform: translateY(0); opacity: 1; }
}
.bag-action-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.2rem 0.15rem 0.35rem;
  flex: 0 0 auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.bag-action-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #f4f0e8;
  padding: 0.15rem;
}
.bag-action-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.bag-action-meta strong {
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: #f2f6fc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bag-action-meta .muted {
  color: var(--bag-muted);
  font-size: 0.68rem;
  font-weight: 700;
}
.bag-action-btns,
.bag-msg-btns {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  flex: 0 0 auto;
}
.bag-action-btns button,
.bag-msg-btns button {
  padding: 0.42rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  color: #f2f6fc;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-align: left;
  position: relative;
}
.bag-action-btns button.bag-cursor,
.bag-action-btns button:hover,
.bag-msg-btns button.bag-cursor,
.bag-msg-btns button:hover {
  border-color: rgba(90, 208, 255, 0.55);
  background: rgba(90, 208, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(90, 208, 255, 0.18);
}

/* Bag ? party picker: same dark party look */
#bag-view-pick.bag-pick-party {
  --gba: var(--font-ui);
  --cream: #eef2f8;
  --edge: #1a2230;
  --inner: #5a6a82;
  --ink: #e8eef8;
  --party-line: rgba(255, 255, 255, 0.12);
  --party-muted: #9aabbf;
  position: fixed;
  inset: 0;
  z-index: 56;
  border-radius: 0;
  background: #0c1018;
  color: var(--ink);
  font-family: var(--gba);
}
#bag-view-pick.bag-pick-party .party-stack {
  height: 100%;
  background:
    radial-gradient(90% 60% at 10% 0%, rgba(90, 208, 255, 0.16), transparent 55%),
    radial-gradient(70% 50% at 100% 20%, rgba(255, 120, 180, 0.1), transparent 50%),
    linear-gradient(165deg, #1a2438 0%, #10161f 48%, #0a0e14 100%);
}
#bag-view-pick.bag-pick-party .party-switch-view {
  height: 100%;
}
#bag-view-pick.bag-pick-party .bag-empty-party {
  margin: 1.2rem auto;
  padding: 0.75rem;
  max-width: 22rem;
  text-align: center;
  line-height: 1.7;
  font-size: 0.8rem;
  color: #e8eef8;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: none;
}

.bag-msg-overlay {
  align-items: center;
  justify-content: center;
}
.bag-msg-sheet {
  width: min(100%, 18rem);
  justify-content: center;
  gap: 0.55rem;
}
.bag-qty-sheet {
  width: min(100%, 15rem);
  gap: 0.55rem;
  padding: 0.75rem 0.7rem 0.65rem;
}
.bag-qty-prompt {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  color: #e8eef8;
}
.bag-qty-sub {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  text-align: center;
  color: #9aabbf;
  line-height: 1.35;
}
.bag-qty-controls {
  display: grid;
  grid-template-columns: 2.6rem 1fr 2.6rem;
  align-items: center;
  gap: 0.4rem;
}
.bag-qty-controls button {
  height: 2.4rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef8;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
}
.bag-qty-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}
.bag-qty-controls button:not(:disabled):hover {
  background: rgba(90, 208, 255, 0.16);
}
#bag-qty-value {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #5ad0ff;
}
.bag-qty-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}
.bag-qty-btns button {
  padding: 0.55rem 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef8;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}
#bag-qty-ok {
  background: linear-gradient(180deg, #48d4c4, #1f8f84);
  border-color: transparent;
  color: #fff;
}
.bag-msg-sheet p {
  margin: 0;
  line-height: 1.4;
  font-size: 0.78rem;
  color: #f2f6fc;
}
.bag-msg-btns {
  flex-direction: row;
}
.bag-msg-btns button { flex: 1; text-align: center; }
.bag-empty-party {
  margin: 0.4rem;
  color: var(--bag-muted);
}

/* Full-panel subviews: replace bag chrome (no modal-in-modal) */
.bag-modal-inner.is-subview {
  min-height: min(70vh, 28rem);
}
.bag-modal-inner.is-subview > .bag-top,
.bag-modal-inner.is-subview > .bag-layout {
  display: none;
}
.bag-modal-inner.is-subview > .bag-overlay:not(.hidden) {
  position: relative;
  inset: auto;
  flex: 1;
  min-height: 0;
}
.bag-modal-inner.is-subview > #bag-view-pick.bag-pick-party:not(.hidden) {
  position: fixed;
  inset: 0;
  flex: none;
  min-height: 0;
}

/* Keep d-pad / A / B above the party / bag screens */
body.ui-party-open .engine-pad,
body.ui-bag-open .engine-pad {
  z-index: 60;
}
/* Box uses drag ? hide on-screen pad so it doesn't cover slots */
body.ui-box-open .engine-pad {
  display: none !important;
}
@media (max-width: 720px) {
  .bag-modal {
    align-items: stretch;
    padding: 0;
  }
  .bag-backdrop {
    background: rgba(6, 10, 18, 0.72);
  }
  .bag-modal-inner {
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border: 0;
  }
  .bag-layout {
    grid-template-columns: 4.6rem minmax(0, 1fr);
  }
  .bag-pocket {
    min-height: 2.7rem;
    font-size: 0.52rem;
  }
  .start-bar-row {
    --menu-btn: 2.35rem;
    gap: 0.15rem;
  }
  .start-bar-item {
    width: 2.75rem;
  }
  .start-bar-ico {
    width: 1.3rem;
    height: 1.3rem;
  }
  .start-bar-label {
    font-size: 0.42rem;
  }
  .party-modal {
    inset: 0;
    height: auto;
    padding-bottom: 0;
  }
  .party-list {
    width: min(100%, 100%);
    gap: 0.22rem;
    min-height: 0;
  }
  .party-slot {
    padding: 0.22rem 0.32rem 0.22rem 0.22rem;
  }
  .party-slot-face,
  .party-slot.party-slot-lead .party-slot-face {
    width: 32px;
    height: 32px;
  }
  .party-slot-face img,
  .party-slot.party-slot-lead .party-slot-face img {
    width: 32px;
    height: 32px;
  }
}

/* Desktop / large screens ? floating window like bag */
@media (min-width: 721px) {
  .party-modal {
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: transparent;
  }
  .party-modal-inner {
    width: min(34rem, 92vw);
    height: auto;
    max-height: min(82vh, 40rem);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.35),
      0 24px 60px rgba(0, 0, 0, 0.55),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }
  .party-modal.party-summary-open .party-modal-inner {
    min-height: min(28rem, 78vh);
  }
  .party-stack {
    padding: 2.4rem 0.85rem 0.85rem;
    justify-content: flex-start;
  }
  .party-menu-btn {
    top: 0.7rem;
    right: 0.7rem;
    width: 2.05rem;
    height: 2.05rem;
  }
  .bag-modal {
    padding: 2rem;
  }
  .bag-modal-inner {
    width: min(36rem, 92vw);
    max-height: min(82vh, 42rem);
  }
  .bag-pocket {
    font-size: 0.62rem;
  }
  .bag-row {
    font-size: 1rem;
    padding: 0.55rem 0.7rem;
  }
  .bag-desc {
    font-size: 0.88rem;
    min-height: 2.8rem;
  }
  .party-list {
    width: min(100%, 30rem);
    gap: 0.3rem;
    min-height: 0;
  }
  .party-slot {
    padding: 0.32rem 0.42rem 0.32rem 0.32rem;
  }
  .party-slot-face,
  .party-slot.party-slot-lead .party-slot-face {
    width: 40px;
    height: 40px;
  }
  .party-slot-face img,
  .party-slot.party-slot-lead .party-slot-face img {
    width: 40px;
    height: 40px;
  }
  .party-slot-name,
  .party-slot.party-slot-lead .party-slot-name {
    font-size: 0.76rem;
  }
  .party-slot-lv,
  .party-slot-hptext {
    font-size: 0.56rem;
  }
  .party-hp-tag,
  .party-exp-tag {
    font-size: 0.46rem;
  }
  .party-hp-track {
    height: 5px;
  }
  .party-exp-track {
    height: 4px;
  }
  .party-menu-btn {
    width: 2.5rem;
    height: 2.5rem;
  }
  .party-action-sheet {
    width: min(100%, 15rem);
  }
  .party-action-card img {
    width: 48px;
    height: 48px;
  }
  .party-switch-foot {
    width: min(100%, 30rem);
  }
  .party-summary-tabs,
  .party-summary-body,
  .party-summary-overlay .party-hint {
    width: min(100%, 24rem);
  }
  .party-hint {
    font-size: 0.78rem;
  }
  .start-bar-row {
    --menu-btn: 3rem;
    gap: 0.35rem;
  }
  .start-bar-item {
    width: 3.4rem;
  }
  .start-bar-ico {
    width: 1.6rem;
    height: 1.6rem;
  }
  .start-bar-label {
    font-size: 0.55rem;
  }
  .field-wrap {
    --field-hud-size: 3.5rem;
    --field-hud-gap: 0.45rem;
  }
  .field-party {
    bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }
  /* Keyboard on PC ? hide virtual pad */
  .engine-pad {
    display: none !important;
  }
}

/* Overlays inside field */
.overlay-panel {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(8, 20, 14, 0.92);
  color: #e8f5ee;
  text-align: center;
}
.overlay-panel.hidden { display: none !important; }
.overlay-panel h2 { margin: 0; font-size: 1.1rem; }
.overlay-sub { margin: 0; opacity: 0.75; font-size: 0.85rem; }

/* New-game character select ? clean UI (sprites stay pixel) */
.ng-overlay {
  background:
    radial-gradient(ellipse at 50% 18%, rgba(46, 120, 78, 0.45), transparent 52%),
    linear-gradient(165deg, #0b1612 0%, #12241c 55%, #0e1a14 100%);
  font-family: "Manrope", "Segoe UI", sans-serif;
}
.ng-card {
  width: min(100%, 28rem);
  padding: 1.35rem 1.2rem 1.25rem;
  background: rgba(248, 252, 249, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  color: #15241c;
  backdrop-filter: blur(8px);
}
.ng-kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5a7a68;
}
.ng-title {
  margin: 0.35rem 0 0.3rem;
  font-family: "Sora", "Manrope", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  color: #143628;
}
.ng-account {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #4a6558;
}
.ng-account strong {
  color: #1a4a32;
  font-weight: 700;
}
.ng-outfit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.ng-outfit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 0.45rem 0.6rem;
  border: 1.5px solid #c5d6cb;
  border-radius: 14px;
  background: #eef5f0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.ng-outfit:hover {
  background: #f5faf7;
  border-color: #8fb89a;
}
.ng-outfit.selected {
  background: #e4f6e8;
  border-color: #2f9b55;
  box-shadow: 0 0 0 3px rgba(47, 155, 85, 0.22);
  transform: translateY(-1px);
}
.ng-preview-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 7.5rem;
  background:
    linear-gradient(180deg, #9fd0f0 0%, #c8e8f8 55%, #78b048 55%, #68a038 100%);
  border: 1px solid #6a8a78;
  border-radius: 10px;
  image-rendering: pixelated;
  overflow: hidden;
}
.ng-preview-lg,
.ng-preview-sm {
  background-image: var(--sheet);
  background-repeat: no-repeat;
  background-position: 0 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.ng-preview-lg {
  width: 80px;
  height: 160px;
  background-size: 720px 160px;
  margin-bottom: -4px;
}
.ng-preview-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
}
.ng-ingame-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #5a7a68;
}
.ng-outfit.selected .ng-ingame-label {
  color: #1f5a38;
}
.ng-preview-sm {
  width: 16px;
  height: 32px;
  background-size: 144px 32px;
  flex-shrink: 0;
}
.ng-outfit-label {
  font-size: 0.92rem;
  font-weight: 700;
  color: #15241c;
}
.ng-outfit-sub {
  font-size: 0.78rem;
  color: #5a7a68;
}
.ng-outfit.selected .ng-outfit-sub {
  color: #2a6040;
}
.ng-primary,
#ng-start {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #3eb86a, #2a9a52);
  color: #f4fff8;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(34, 120, 70, 0.28);
}
.ng-primary:hover,
#ng-start:hover {
  filter: brightness(1.04);
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  width: 100%;
}
.starter-overlay {
  background:
    radial-gradient(ellipse at 50% 18%, rgba(46, 120, 78, 0.45), transparent 52%),
    linear-gradient(165deg, #0b1612 0%, #12241c 55%, #0e1a14 100%);
  font-family: var(--font-ui);
}
.starter-card-panel {
  width: min(100%, 30rem);
  padding: 1.35rem 1.2rem 1.25rem;
  background: rgba(248, 252, 249, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  color: #15241c;
}
.starter-kicker {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5a7a68;
}
.starter-title {
  margin: 0.35rem 0 0.3rem;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.2;
  color: #143628;
}
.starter-sub {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.45;
  color: #4a6558;
}
.starter-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}
.starter-tab {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.55rem 0.3rem;
  border: 1.5px solid #c5d6cb;
  border-radius: 10px;
  background: #eef5f0;
  color: #15241c;
  cursor: pointer;
}
.starter-tab.active {
  background: #2f9b55;
  border-color: #2f9b55;
  color: #f4fff8;
  box-shadow: 0 6px 14px rgba(34, 120, 70, 0.22);
}
.starter-card {
  width: auto;
  padding: 0.55rem 0.35rem 0.55rem;
  border: 1.5px solid #c5d6cb;
  border-radius: 14px;
  background: #eef5f0;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.starter-card:hover {
  background: #f5faf7;
  border-color: #2f9b55;
  box-shadow: 0 0 0 3px rgba(47, 155, 85, 0.18);
}
.starter-sprite-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 6.25rem;
  padding-bottom: 0.4rem;
  background:
    linear-gradient(180deg, #9fd0f0 0%, #c8e8f8 55%, #78b048 55%, #68a038 100%);
  border: 1px solid #6a8a78;
  border-radius: 10px;
  overflow: hidden;
}
.starter-card img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.starter-name {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.25;
}
.starter-meta {
  font-size: 0.74rem;
  font-weight: 600;
  color: #5a7a68;
  line-height: 1.3;
}
.starter-confirm-panel {
  text-align: center;
  max-width: 22rem;
}
.starter-confirm-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin: 0.85rem auto 1.1rem;
  max-width: 9.5rem;
}
.starter-confirm-preview .starter-sprite-wrap {
  width: 100%;
  height: 7rem;
}
.starter-confirm-preview img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.starter-confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}
.starter-confirm-no,
.starter-confirm-yes {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 0.7rem 0.5rem;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid transparent;
}
.starter-confirm-no {
  background: #e8eee9;
  border-color: #b8c8bc;
  color: #2a4034;
}
.starter-confirm-yes {
  background: #2f9b55;
  border-color: #248248;
  color: #f4fff8;
  box-shadow: 0 6px 14px rgba(34, 120, 70, 0.25);
}
.starter-confirm-no:hover {
  background: #dde6e0;
}
.starter-confirm-yes:hover {
  filter: brightness(1.05);
}

/* -- Auth gate (server account) -- */
body.engine-auth-required #app {
  visibility: hidden;
  pointer-events: none;
}
.engine-auth {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse at 50% 12%, rgba(52, 140, 88, 0.38), transparent 50%),
    linear-gradient(160deg, #08120e 0%, #13261c 48%, #0c1812 100%);
  font-family: "Manrope", "Segoe UI", sans-serif;
}
.engine-auth.hidden { display: none !important; }
.engine-auth-card {
  width: min(100%, 24rem);
  padding: 1.75rem 1.5rem 1.5rem;
  background: rgba(248, 252, 249, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  box-shadow: 0 28px 56px rgba(0, 0, 0, 0.4);
  color: #15241c;
  backdrop-filter: blur(10px);
}
.engine-auth-brand {
  margin: 0;
  font-family: "Sora", "Manrope", sans-serif;
  font-size: clamp(1.35rem, 4vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  color: #143628;
}
.engine-auth-sub {
  margin: 0.55rem 0 1.25rem;
  font-size: 0.95rem;
  line-height: 1.45;
  text-align: center;
  color: #4a6558;
}
.engine-auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 1rem;
  padding: 0.3rem;
  background: #e4eee8;
  border-radius: 12px;
}
.engine-auth-tabs button {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.65rem 0.4rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #3d5648;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.engine-auth-tabs button.active {
  background: #fff;
  color: #143628;
  box-shadow: 0 2px 8px rgba(20, 54, 40, 0.1);
}
.engine-auth-error {
  min-height: 1.2rem;
  margin: 0 0 0.65rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #c0392b;
}
.engine-auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.engine-auth-form.hidden { display: none !important; }
.engine-auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #3d5648;
}
.engine-auth-form input {
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  padding: 0.75rem 0.85rem;
  border: 1.5px solid #c5d6cb;
  border-radius: 12px;
  background: #fff;
  color: #15241c;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.engine-auth-form input:focus {
  border-color: #2f9b55;
  box-shadow: 0 0 0 3px rgba(47, 155, 85, 0.18);
}
.engine-auth-form button[type="submit"] {
  margin-top: 0.35rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.85rem;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #3eb86a, #2a9a52);
  color: #f4fff8;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(34, 120, 70, 0.3);
}
.engine-auth-form button[type="submit"]:hover {
  filter: brightness(1.04);
}
.engine-auth-hint {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.4;
  color: #6a8574;
}

/* Battle ??? desktop: centered GBA-like frame; mobile: fullscreen + pad below */
.battle-screen {
  --gba-font: var(--font-ui);
  --hb-cream: #f8f8d0;
  --hb-border: #486868;
  --hb-shadow: #203028;
  --hb-exp-rail: #587070;
  --hb-exp-trough: #203838;
  --hb-exp-fill: #40c8f8;
  --menu-cream: #f8f8f0;
  --menu-edge: #384868;
  --menu-inner: #90a0c0;
  --fs-name: clamp(0.72rem, 1.5cqw + 0.45rem, 1.05rem);
  --fs-body: clamp(0.68rem, 1.3cqw + 0.4rem, 0.95rem);
  --fs-small: clamp(0.58rem, 1.05cqw + 0.32rem, 0.78rem);
  --fs-tag: clamp(0.5rem, 0.85cqw + 0.28rem, 0.65rem);
  --pad: clamp(0.35rem, 1.2cqw, 0.75rem);
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 2vw, 1.25rem);
  background: rgba(6, 14, 12, 0.78);
  color: #202020;
  font-family: var(--gba-font);
}
.battle-screen.hidden { display: none !important; }

.battle-frame {
  container-type: size;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: min(720px, 92vw, calc(min(520px, 82dvh) * 3 / 2));
  max-height: min(520px, 82dvh);
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: #000;
  border: 3px solid #2a5040;
  border-radius: 6px;
  box-shadow:
    0 0 0 2px #0a1812,
    0 18px 48px rgba(0, 0, 0, 0.55);
}

.battle-stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: hidden;
  background: #68a060;
}
.battle-bg {
  position: absolute;
  inset: 0;
  background: #68a060 center / cover no-repeat;
}
.battle-anim-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 6;
  pointer-events: none;
}
.battle-anim-canvas.hidden { display: none; }

/* Mons ? no stacking context on the wrapper, or plates sit above effect canvases.
   Plates stay at z-index 1 (BG3). Sprites interleave with .rom-anim-layer 2/4/6. */
.battle-mon {
  position: absolute;
  z-index: auto;
  pointer-events: none;
}
.battle-mon.player {
  left: 8%;
  bottom: 0;
  width: min(46%, 17rem);
  height: min(64%, 17rem);
  z-index: auto;
}
.battle-mon.enemy {
  top: 4%;
  right: 14%;
  width: min(38%, 14rem);
  height: min(54%, 14rem);
  z-index: auto;
}
.battle-mon.intro-hidden,
.battle-hud.intro-hidden {
  visibility: hidden;
  pointer-events: none;
}
/* Intro: plate visible with trainer, mon sprite still hidden */
.battle-mon.sprite-hidden .battle-sprite {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.battle-mon.slide-in-enemy {
  animation: battle-slide-enemy 0.6s cubic-bezier(0.22, 0.9, 0.28, 1) forwards;
}
.battle-mon.slide-in-from-right {
  animation: battle-slide-from-right 0.55s cubic-bezier(0.22, 0.9, 0.28, 1) forwards;
}
.battle-mon.slide-in-player .battle-sprite {
  animation: battle-pop-sprite 0.35s ease-out forwards;
}
.battle-hud.slide-in {
  animation: battle-slide-hud 0.4s ease-out forwards;
}
@keyframes battle-slide-enemy {
  from { translate: -120% 0; visibility: visible; }
  to { translate: 0 0; visibility: visible; }
}
@keyframes battle-slide-from-right {
  from { translate: 110% 0; visibility: visible; }
  to { translate: 0 0; visibility: visible; }
}
@keyframes battle-slide-hud {
  from { translate: -40% 0; opacity: 0; visibility: visible; }
  to { translate: 0 0; opacity: 1; visibility: visible; }
}
.battle-hud.player.slide-in {
  animation-name: battle-slide-hud-player;
}
@keyframes battle-slide-hud-player {
  from { translate: 40% 0; opacity: 0; visibility: visible; }
  to { translate: 0 0; opacity: 1; visibility: visible; }
}
@keyframes battle-pop-sprite {
  0% { scale: 0.15; opacity: 0; visibility: visible; }
  70% { scale: 1.1; opacity: 1; visibility: visible; }
  100% { scale: 1; opacity: 1; visibility: visible; }
}

/* Player trainer back (Emerald throw sequence) ? above ground plate */
.battle-trainer {
  position: absolute;
  z-index: 4;
  left: 6%;
  bottom: 0;
  width: min(42%, 15rem);
  height: min(62%, 16rem);
  pointer-events: none;
  will-change: translate;
}
.battle-trainer.hidden { display: none !important; }
.battle-trainer.slide-in {
  animation: battle-trainer-in 0.55s cubic-bezier(0.22, 0.9, 0.28, 1) forwards;
}
.battle-trainer.slide-out {
  animation: battle-trainer-out 0.5s cubic-bezier(0.4, 0, 0.7, 0.2) forwards;
}
@keyframes battle-trainer-in {
  from { translate: 110% 0; }
  to { translate: 0 0; }
}
@keyframes battle-trainer-out {
  from { translate: 0 0; }
  to { translate: -130% 0; }
}
#battle-trainer-sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Opposing trainer (front pic) ? stands near enemy plate */
.battle-foe-trainer {
  position: absolute;
  z-index: 4;
  right: 10%;
  top: 6%;
  width: min(36%, 12.5rem);
  height: min(50%, 13rem);
  pointer-events: none;
  will-change: translate;
  transform-origin: 50% 85%;
}
.battle-foe-trainer.hidden { display: none !important; }
.battle-foe-trainer.slide-in {
  animation: battle-foe-trainer-in 0.55s cubic-bezier(0.22, 0.9, 0.28, 1) forwards;
}
.battle-foe-trainer.slide-out {
  animation: battle-foe-trainer-out 0.55s cubic-bezier(0.4, 0, 0.7, 0.2) forwards;
}
/* Fake throw beat ? front pics have no throw frames, so lean into the toss */
.battle-foe-trainer.throwing {
  animation: battle-foe-throw 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
@keyframes battle-foe-trainer-in {
  from { translate: 120% 0; }
  to { translate: 0 0; }
}
@keyframes battle-foe-trainer-out {
  from { translate: 0 0; }
  to { translate: 130% 0; }
}
@keyframes battle-foe-throw {
  0%   { translate: 0 0; rotate: 0deg; }
  35%  { translate: -10% -3%; rotate: -6deg; }
  100% { translate: -4% 0; rotate: -2deg; }
}
#battle-foe-trainer-sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Pok? Ball send-out arc */
.battle-ball {
  position: absolute;
  z-index: 5;
  width: clamp(18px, 4cqw, 28px);
  height: clamp(18px, 4cqw, 28px);
  object-fit: contain;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  pointer-events: none;
  left: 22%;
  bottom: 28%;
}
.battle-ball.hidden { display: none !important; }
.battle-ball.catch-throw {
  z-index: 8;
  width: clamp(22px, 5cqw, 34px);
  height: clamp(22px, 5cqw, 34px);
}
.battle-ball.catch-spin {
  animation: battle-ball-spin 0.55s linear both;
}
@keyframes battle-ball-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(720deg); }
}
.battle-ball.catch-hover {
  z-index: 8;
  width: clamp(22px, 5cqw, 34px);
  height: clamp(22px, 5cqw, 34px);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}
.battle-ball.catch-open {
  transform: scale(1.12);
}
.battle-ball.catch-shake {
  animation: battle-ball-shake 0.48s ease-in-out both;
}
.battle-ball.catch-click {
  animation: battle-ball-click 0.7s ease-out both;
}
@keyframes battle-ball-shake {
  0%   { transform: rotate(0deg) translateX(0); }
  15%  { transform: rotate(-28deg) translateX(-6px); }
  35%  { transform: rotate(26deg) translateX(6px); }
  55%  { transform: rotate(-18deg) translateX(-4px); }
  75%  { transform: rotate(12deg) translateX(3px); }
  100% { transform: rotate(0deg) translateX(0); }
}
@keyframes battle-ball-click {
  0%   { transform: scale(1); filter: brightness(1) drop-shadow(0 0 0 transparent); }
  20%  { transform: scale(1.4); filter: brightness(1.7) drop-shadow(0 0 8px #fff8a0); }
  45%  { transform: scale(0.9); filter: brightness(1.25); }
  70%  { transform: scale(1.15); filter: brightness(1.4) drop-shadow(0 0 6px #fff8a0); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Enemy sucked into / released from Pok? Ball */
.battle-sprite.catch-absorb {
  animation: battle-catch-absorb 0.42s ease-in forwards;
  z-index: 7;
}
.battle-sprite.catch-release {
  animation: battle-catch-release 0.38s ease-out forwards;
}
.battle-sprite.catch-inside {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none;
}
.battle-mon.enemy.catch-caught .battle-sprite {
  visibility: hidden !important;
  opacity: 0 !important;
}
.battle-mon.enemy.catch-caught .battle-plate {
  opacity: 1 !important;
}
.battle-mon.enemy.catch-dim .battle-plate {
  opacity: 0.55;
  transition: opacity 0.25s linear;
}
.battle-hud.enemy.catch-hide {
  opacity: 0 !important;
  transition: opacity 0.2s linear;
  pointer-events: none;
}
@keyframes battle-catch-absorb {
  0% {
    scale: 1;
    opacity: 1;
    filter: brightness(1);
  }
  35% {
    filter: brightness(2.2) saturate(0.2);
  }
  100% {
    scale: 0.06;
    opacity: 0;
    filter: brightness(3);
  }
}
@keyframes battle-catch-release {
  0% {
    scale: 0.08;
    opacity: 0;
    filter: brightness(2.5);
  }
  100% {
    scale: 1;
    opacity: 1;
    filter: brightness(1);
  }
}
.battle-plate {
  position: absolute;
  left: 50%;
  bottom: 0;
  translate: -50% 0;
  width: 165%;
  height: auto;
  z-index: 1;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}
.battle-mon.player .battle-plate {
  width: 185%;
  bottom: 0;
}
.battle-sprite {
  position: absolute;
  left: 50%;
  bottom: 10%;
  translate: -50% 0;
  width: 108%;
  height: 92%;
  object-fit: contain;
  object-position: bottom center;
  z-index: 3; /* above back-effect canvas (2); below mid canvas (4) */
  /* Smooth upscale ? Gen5 GIFs look chunky with nearest-neighbor */
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
  -ms-interpolation-mode: bicubic;
  will-change: translate, scale, opacity;
}
.battle-mon.player .battle-sprite {
  width: 118%;
  height: 98%;
  bottom: 6%;
}
.battle-mon.enemy .battle-sprite {
  width: 100%;
  height: 88%;
  bottom: 16%;
  z-index: 5; /* above mid-effect canvas (4); below front canvas (6) */
}
.battle-sprite.fainting {
  transform-origin: 50% 100%;
  animation: battle-faint-shrink 0.55s cubic-bezier(0.4, 0, 0.85, 0.4) forwards;
}
.battle-sprite.fainted {
  visibility: hidden;
  opacity: 0;
  scale: 0;
  pointer-events: none;
}
@keyframes battle-faint-shrink {
  0% {
    scale: 1;
    opacity: 1;
  }
  100% {
    scale: 0;
    opacity: 0;
  }
}

.hb-status {
  display: inline-block;
  margin-left: 0.12em;
  padding: 0.04em 0.28em;
  font-size: 0.55em;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  border-radius: 2px;
  color: #fff;
  background: #666;
  vertical-align: middle;
  flex-shrink: 0;
}
.hb-status[hidden] { display: none !important; }
.hb-status[data-status="SLP"] { background: #7a7a9a; }
.hb-status[data-status="PAR"] { background: #c9a84a; color: #1a1408; }
.hb-status[data-status="BRN"] { background: #c05030; }
.hb-status[data-status="PSN"],
.hb-status[data-status="TOX"] { background: #8a4aaa; }
.hb-status[data-status="FRZ"] { background: #5aa0c8; color: #0a1820; }

/* Healthboxes ? name/lv above HP card; EXP loose below */
.battle-hud {
  position: absolute;
  z-index: 4;
  box-sizing: border-box;
  color: #181818;
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  overflow: visible;
}
.battle-hud.enemy {
  top: 5%;
  left: 5%;
  width: min(34%, 11.5rem);
  padding: 0;
}
.battle-hud.player {
  right: 5%;
  bottom: 3.5%;
  width: min(38%, 12.5rem);
  padding: 0;
}

/* Battle party switch overlay ? matches overworld party menu look */
.battle-party-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #0c1018;
  font-family: var(--font-ui);
  color: #e8eef8;
}
.battle-party-overlay.hidden {
  display: none !important;
}
.battle-party-overlay-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(90% 60% at 10% 0%, rgba(90, 208, 255, 0.16), transparent 55%),
    radial-gradient(70% 50% at 100% 20%, rgba(255, 120, 180, 0.1), transparent 50%),
    linear-gradient(165deg, #1a2438 0%, #10161f 48%, #0a0e14 100%);
  color: #e8eef8;
}
.battle-party-overlay .party-stack {
  padding-top: 2.6rem;
}
.battle-party-prompt {
  width: min(100%, 32rem);
  margin: 0 auto 0.35rem;
  padding: 0 0.15rem;
  font-family: var(--font-display);
  font-size: clamp(0.72rem, 2.2cqw, 0.88rem);
  font-weight: 700;
  color: #e8eef8;
  text-shadow: none;
  letter-spacing: 0.02em;
}
.battle-party-overlay #battle-party-list .party-slot.battle-cursor,
.battle-party-overlay #battle-party-list .party-slot:hover:not(:disabled) {
  border-color: #f0d040;
  box-shadow:
    inset 0 0 0 1px #fff8c8,
    0 0 0 2px #e8c028;
  outline: none;
  filter: none;
}
.battle-party-overlay #battle-party-list .party-slot.battle-cursor::before,
.battle-party-overlay #battle-party-list .party-slot::before {
  content: none !important;
}
.battle-party-overlay #battle-party-list .party-slot.party-switch-from {
  opacity: 0.72;
  border-color: #687898;
  background: linear-gradient(180deg, #e8ecf0 0%, #d0d8e0 100%);
  box-shadow: inset 0 0 0 1px #b8c0d0;
}
.battle-party-overlay #battle-party-list .party-slot.party-switch-from.battle-cursor {
  opacity: 1;
  border-color: #f0d040;
  box-shadow:
    inset 0 0 0 1px #fff8c8,
    0 0 0 2px #e8c028;
}
.battle-party-overlay #battle-party-close[hidden] {
  display: none !important;
}

/* ROM battle_type_icons: foe left of box, player right, stacked if dual-type */
.hb-types {
  position: absolute;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.35cqh, 4px);
  pointer-events: none;
}
.battle-hud.enemy .hb-types {
  right: calc(100% + clamp(2px, 0.3cqw, 3px));
  top: 1.35em;
}
.battle-hud.player .hb-types {
  left: calc(100% + clamp(2px, 0.3cqw, 3px));
  top: 1.35em;
}
.hb-type-icon {
  display: block;
  width: clamp(12px, 2.4cqw, 18px);
  height: clamp(12px, 2.4cqw, 18px);
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Name + level sit ABOVE the HP card */
.hb-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.12em;
  padding: 0 0.08em;
  min-width: 0;
}
.hb-name {
  font-family: var(--font-display);
  font-size: clamp(0.62rem, 1.05cqw + 0.38rem, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 68%;
  color: #a81828;
  -webkit-text-stroke: 0;
  text-shadow:
    0.5px 0.5px 0 rgba(255, 255, 255, 0.95),
    -0.5px -0.5px 0 rgba(255, 255, 255, 0.95),
    0 1px 1px rgba(0, 0, 0, 0.18);
  line-height: 1.05;
}
.hb-lv {
  font-family: var(--font-display);
  font-size: clamp(0.52rem, 0.85cqw + 0.3rem, 0.66rem);
  font-weight: 700;
  flex-shrink: 0;
  color: #202028;
  text-shadow:
    0.5px 0.5px 0 rgba(255, 255, 255, 0.95),
    -0.5px -0.5px 0 rgba(255, 255, 255, 0.95);
  line-height: 1.05;
  letter-spacing: 0.02em;
}
.hb-lv.gender-male,
.hb-lv.gender-female {
  color: #202028;
}
.hb-lv .gender-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.28em;
  width: 1.05em;
  height: 1.05em;
  vertical-align: -0.12em;
  flex-shrink: 0;
  text-shadow: none;
  filter: drop-shadow(0 0.5px 0 #fff) drop-shadow(0 -0.5px 0 #fff);
}
.hb-lv .gender-mark .gender-icon {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.hb-lv .gender-mark.gender-male { color: #2a70e0; }
.hb-lv .gender-mark.gender-female { color: #e04888; }
.gender-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.9em;
  height: 0.9em;
  vertical-align: -0.05em;
  line-height: 0;
}
.gender-mark .gender-icon {
  display: block;
  width: 100%;
  height: 100%;
}
.gender-mark.gender-male { color: #2a70e0; }
.gender-mark.gender-female { color: #e04888; }
.party-slot-name .gender-mark,
.party-sum-plate .gender-mark {
  margin-left: 0.2em;
  width: 0.85em;
  height: 0.85em;
}

/* Compact HP card: bar + numbers only */
.hb-card {
  display: flex;
  flex-direction: column;
  background: #f8f8f0;
  border: 1.5px solid #181818;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.hb-hp {
  display: flex;
  align-items: center;
  gap: 0.22em;
  padding: 0.18em 0.32em 0.14em;
}
.hb-hp-tag {
  flex-shrink: 0;
  font-family: var(--font-display);
  font-size: clamp(0.4rem, 0.65cqw + 0.2rem, 0.5rem);
  font-weight: 800;
  line-height: 1;
  padding: 0.1em 0.18em;
  color: #f8f8f0;
  background: #c03838;
  border: none;
  border-radius: 1px;
  letter-spacing: 0.03em;
}
.hp-track {
  flex: 1;
  height: clamp(5px, 0.7cqh, 7px);
  background:
    repeating-linear-gradient(
      -45deg,
      #e8e8e0 0 2px,
      #f4f4ec 2px 4px
    );
  border: 1px solid #181818;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #a8a8a0;
  border-radius: 1px;
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: #48d048;
  transition: width 0.35s linear;
}
.hp-fill[data-tone="mid"] { background: #e8c820; }
.hp-fill[data-tone="low"] { background: #e84840; }
.hp-text {
  margin: 0;
  padding: 0.06em 0.38em 0.06em;
  font-family: var(--font-display);
  font-size: clamp(0.48rem, 0.8cqw + 0.26rem, 0.62rem);
  font-weight: 700;
  text-align: right;
  letter-spacing: 0.03em;
  color: #f0f0f0;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  background: #2a3038;
  border-radius: 0;
  border-top: 1px solid #181818;
}
.battle-hud.enemy .hp-text.sr-only {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

/* EXP bar: loose strip UNDER the HP card */
.hb-exp {
  display: flex;
  align-items: center;
  margin-top: 0.35em;
  padding: 0.22em 0.4em;
  background: #1a1e24;
  border: 1.5px solid #181818;
  border-radius: 3px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.exp-track {
  flex: 1;
  height: clamp(3px, 0.45cqh, 5px);
  background: #0c1014;
  border: none;
  overflow: hidden;
  border-radius: 1px;
}
.exp-fill {
  height: 100%;
  width: 0%;
  background: #40a8e8;
  min-width: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Bottom text + commands ??? fixed height so panes always match */
.battle-bottom {
  --battle-bottom-h: clamp(7.25rem, 26cqh, 9.5rem);
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  align-items: stretch;
  gap: var(--pad);
  padding: var(--pad);
  height: var(--battle-bottom-h);
  min-height: var(--battle-bottom-h);
  max-height: var(--battle-bottom-h);
  box-sizing: border-box;
  background:
    repeating-linear-gradient(90deg, #c8d4ec 0 5px, #b8c4dc 5px 10px);
  border-top: clamp(2px, 0.35cqw, 4px) solid #304060;
}
.battle-bottom.fight-open {
  --battle-bottom-h: clamp(7.25rem, 26cqh, 9.5rem);
}
.battle-bottom.fight-open > .battle-log,
.battle-bottom.fight-open > .battle-menus {
  visibility: hidden;
  pointer-events: none;
}

/* Fight menu: move cards + compact horizontal BACK */
.battle-fight {
  position: absolute;
  inset: var(--pad);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  gap: 0.4rem;
  z-index: 3;
  min-height: 0;
}
.battle-fight.hidden { display: none !important; }
.battle-fight-moves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.3em;
  align-content: stretch;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  padding: 0.28em;
  background: #2a3038;
  border: clamp(2px, 0.3cqw, 3px) solid #181818;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px #4a5058;
}
.battle-fight-moves button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 0.4em;
  border: 2px solid transparent;
  border-radius: 8px;
  background: linear-gradient(180deg, #4a5058 0%, #343a42 100%);
  color: #f8f8f0;
  font-family: inherit;
  font-size: var(--fs-body);
  font-weight: 700;
  padding: 0.35em 0.42em;
  cursor: pointer;
  text-align: left;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
  box-shadow: 0 2px 0 #181818;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.battle-fight-moves button:hover:not(:disabled),
.battle-fight-moves button:focus-visible:not(:disabled) {
  outline: none;
  filter: brightness(1.08);
}
.battle-fight-moves button.battle-cursor {
  border-color: #f0d040;
  box-shadow:
    0 0 0 2px rgba(240, 208, 64, 0.45),
    0 2px 0 #181818;
  background: linear-gradient(180deg, #585e68 0%, #3c424a 100%);
}
.battle-fight-moves button.battle-cursor::before {
  content: none;
}
.battle-fight-moves button:disabled {
  opacity: 0.42;
  cursor: default;
}
.bm-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.12em;
  min-width: 0;
  min-height: 0;
}
.bm-name {
  font-size: clamp(0.62rem, 1.85cqw, 0.82rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  line-height: 1.15;
}
.bm-pp {
  font-size: clamp(0.52rem, 1.4cqw, 0.64rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #c8d0d8;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  white-space: nowrap;
}
.bm-eff {
  font-size: clamp(0.48rem, 1.25cqw, 0.58rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #a8b0b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}
.bm-eff[data-eff="super"] { color: #ff7068; }
.bm-eff[data-eff="resist"] { color: #70b0ff; }
.bm-eff[data-eff="immune"] { color: #909098; }
.bm-eff[data-eff="status"] { color: #b0b8c8; }
.bm-eff[data-eff="neutral"] { color: #a8b0b8; }
.bm-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: center;
  min-width: 3.6em;
  max-width: 4.6em;
  padding: 0.28em 0.5em 0.28em 0.3em;
  border-radius: 4px 8px 8px 4px;
  font-size: clamp(0.42rem, 1.1cqw, 0.55rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  color: #f8f8f0;
  background: #787878;
  border: 1.5px solid rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  clip-path: polygon(0 0, calc(100% - 0.45em) 0, 100% 50%, calc(100% - 0.45em) 100%, 0 100%);
  line-height: 1.1;
}
.bm-type[data-type="normal"] { background: #a8a878; }
.bm-type[data-type="fire"] { background: #f08030; }
.bm-type[data-type="water"] { background: #6890f0; }
.bm-type[data-type="grass"] { background: #78c850; }
.bm-type[data-type="electric"] { background: #f8d030; color: #202020; text-shadow: none; }
.bm-type[data-type="ice"] { background: #98d8d8; color: #202020; text-shadow: none; }
.bm-type[data-type="fighting"] { background: #c03028; }
.bm-type[data-type="poison"] { background: #a040a0; }
.bm-type[data-type="ground"] { background: #e0c068; color: #202020; text-shadow: none; }
.bm-type[data-type="flying"] { background: #a890f0; }
.bm-type[data-type="psychic"] { background: #f85888; }
.bm-type[data-type="bug"] { background: #a8b820; }
.bm-type[data-type="rock"] { background: #b8a038; }
.bm-type[data-type="ghost"] { background: #705898; }
.bm-type[data-type="dragon"] { background: #7038f8; }
.bm-type[data-type="dark"] { background: #705848; }
.bm-type[data-type="steel"] { background: #b8b8d0; color: #202020; text-shadow: none; }
.bm-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #808890;
  font-weight: 700;
  font-size: 1.1em;
  line-height: 1;
}
.battle-fight-back {
  display: grid;
  place-items: center;
  align-self: stretch;
  width: auto;
  min-width: 3.4rem;
  max-width: 3.8rem;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0.35em 0.4em;
  border: 2px solid #203038;
  border-radius: 10px;
  background: linear-gradient(180deg, #70a8e0 0%, #4888c8 45%, #2868a0 100%);
  color: #f8f8f8;
  font-family: inherit;
  font-size: clamp(0.72rem, 2cqw, 0.88rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  transform: none;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 2px 0 #102028;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.battle-fight-back:hover,
.battle-fight-back:focus-visible {
  filter: brightness(1.08);
  outline: none;
}
.battle-log {
  padding: calc(var(--pad) * 1.1);
  background: var(--menu-cream);
  border: clamp(2px, 0.3cqw, 4px) solid var(--menu-edge);
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--menu-inner);
  white-space: pre-wrap;
  font-size: var(--fs-body);
  line-height: 1.55;
  color: #202028;
  overflow: auto;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
}
.battle-log.awaiting-a::after {
  content: "?";
  position: absolute;
  right: 0.55em;
  bottom: 0.35em;
  font-size: 0.7em;
  color: #e03848;
  animation: battle-blink 0.7s steps(1) infinite;
}
@keyframes battle-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.battle-panel.battle-busy {
  display: block;
  pointer-events: none;
  background: transparent;
  border: none;
  box-shadow: none;
  position: relative;
  min-height: 100%;
}
.battle-screen.battle-locked .battle-menus {
  opacity: 0.55;
  pointer-events: none;
}
.battle-menus {
  position: relative;
  background: var(--menu-cream);
  border: clamp(2px, 0.3cqw, 4px) solid var(--menu-edge);
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--menu-inner);
  padding: calc(var(--pad) * 0.6);
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
}
/* FR/LG-style command tray: no cream frame, colored buttons on stripe BG */
.battle-menus:has(.battle-commands:not(.hidden)) {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: calc(var(--pad) * 0.35);
}
.battle-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.15em 0.35em;
  height: 100%;
  min-height: 0;
  align-content: stretch;
}
.battle-panel.battle-commands {
  grid-template-rows: 1fr 1fr;
  gap: clamp(0.35rem, 1.2cqw, 0.65rem);
  padding: 0.15em;
}
.battle-panel.hidden { display: none !important; }
.battle-panel.battle-list {
  display: block;
  overflow: auto;
  max-height: 100%;
}
.battle-bag-panel {
  display: flex !important;
  flex-direction: column;
  gap: 0.2em;
  min-height: 0;
}
.battle-bag-panel.hidden { display: none !important; }
.battle-bag-pockets {
  display: flex;
  gap: 0.2em;
  flex: 0 0 auto;
}
.battle-bag-pocket {
  flex: 1;
  min-width: 0;
  padding: 0.28em 0.15em !important;
  text-align: center !important;
  letter-spacing: 0.04em;
  font-size: 0.62em !important;
  font-weight: 700;
  border-radius: 5px !important;
  border: 2px solid #283848 !important;
  background: #90a0b8 !important;
  color: #f8f8f8 !important;
}
.battle-bag-pocket.active[data-b-pocket="items"] {
  background: linear-gradient(180deg, #f07858, #c84830) !important;
  border-color: #882818 !important;
}
.battle-bag-pocket.active[data-b-pocket="balls"] {
  background: linear-gradient(180deg, #70b0f0, #3068c8) !important;
  border-color: #184878 !important;
}
.battle-bag-pocket.active[data-b-pocket="berries"] {
  background: linear-gradient(180deg, #e890d0, #b04898) !important;
  border-color: #681850 !important;
}
#battle-bag-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
#battle-bag-list .bag-empty {
  padding: 0.35em 0.4em;
  opacity: 0.7;
  font-size: 0.85em;
}
#battle-bag-list button[data-item] {
  display: grid;
  grid-template-columns: 1.8rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.4em;
  width: 100%;
}
.battle-bag-icon {
  width: 1.55rem;
  height: 1.55rem;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.battle-bag-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.battle-bag-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #486090;
}
.battle-panel button,
#battle-bag-list button,
#battle-party-list button {
  border: none;
  border-radius: 0;
  background: transparent;
  color: #202028;
  font-family: inherit;
  font-size: var(--fs-body);
  padding: 0.55em 0.35em 0.55em 1.15em;
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.02em;
  position: relative;
}
.battle-panel button:hover,
.battle-panel button:focus-visible,
.battle-panel button.battle-cursor {
  outline: none;
}
.battle-panel button.battle-cursor::before,
#battle-bag-list button.battle-cursor::before,
#battle-party-list button.battle-cursor::before {
  content: "?";
  position: absolute;
  left: 0.15em;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65em;
  color: #e03848;
  animation: battle-cursor-blink 0.55s steps(1) infinite;
}
@keyframes battle-cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.25; }
}
.battle-panel button:disabled { opacity: 0.35; cursor: default; }
.battle-panel button:disabled.battle-cursor::before { content: none; }

/* ?????? FireRed/LeafGreen style command buttons ?????? */
.battle-cmd {
  display: flex !important;
  align-items: center;
  justify-content: center;
  text-align: center !important;
  padding: 0.65em 0.4em !important;
  min-height: 0;
  height: 100%;
  border-radius: clamp(8px, 1.4cqw, 14px) !important;
  border: clamp(2px, 0.28cqw, 3px) solid #203038 !important;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 2px 0 #102028;
  color: #f8f8f8 !important;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  transition: filter 0.08s linear, box-shadow 0.08s linear;
}
.battle-cmd::before { content: none !important; }
.battle-cmd[data-cmd="fight"] {
  background: linear-gradient(180deg, #f09898 0%, #e07070 45%, #c84848 100%);
}
.battle-cmd[data-cmd="bag"] {
  background: linear-gradient(180deg, #f0c070 0%, #e0a040 45%, #c87820 100%);
}
.battle-cmd[data-cmd="pokemon"] {
  background: linear-gradient(180deg, #70c878 0%, #48a850 45%, #287838 100%);
}
.battle-cmd[data-cmd="run"] {
  background: linear-gradient(180deg, #70a8e0 0%, #4888c8 45%, #2868a0 100%);
}
.battle-cmd:hover,
.battle-cmd.battle-cursor {
  filter: brightness(1.12) saturate(1.08);
  /* no scale ??? keeps all 4 buttons the same size */
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 0 rgba(0, 0, 0, 0.15),
    0 0 0 3px #f8f070,
    0 2px 0 #102028;
  z-index: 1;
}
.battle-cmd.battle-cursor {
  filter: brightness(1.18) saturate(1.12);
}
.battle-cmd:active {
  filter: brightness(0.95);
}
#battle-bag-list button,
#battle-party-list button {
  display: block;
  width: 100%;
  margin-bottom: 0.15em;
}
.active-mon { outline: 2px solid #e03848; outline-offset: -2px; }
.battle-back {
  position: absolute;
  top: 0.25em;
  right: 0.25em;
  z-index: 2;
  border: 2px solid var(--menu-edge);
  background: var(--menu-cream);
  border-radius: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--fs-small);
  padding: 0.25em 0.4em;
}
.battle-back.hidden { display: none !important; }

/* ?????? On-screen HUD (transparent overlays on the field) ?????? */
.field-menu-btn {
  position: absolute;
  top: var(--field-hud-top);
  right: var(--field-hud-right);
  z-index: 10;
  width: var(--field-hud-size);
  height: var(--field-hud-size);
  padding: 0;
  border: 2px solid rgba(232, 255, 244, 0.45);
  border-radius: 10px;
  background: rgba(8, 28, 20, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: manipulation;
}
.field-menu-icon {
  display: block;
  width: 1.05rem;
  height: 0.78rem;
  background:
    linear-gradient(#e8fff4, #e8fff4) 0 0 / 100% 2px no-repeat,
    linear-gradient(#e8fff4, #e8fff4) 0 50% / 100% 2px no-repeat,
    linear-gradient(#e8fff4, #e8fff4) 0 100% / 100% 2px no-repeat;
  opacity: 0.9;
}
.field-menu-btn:active {
  transform: scale(0.96);
  background: rgba(8, 28, 20, 0.5);
}

.field-party {
  position: absolute;
  top: calc(var(--field-hud-top) + var(--field-hud-size) + var(--field-hud-gap));
  right: var(--field-hud-right);
  /* Clear A/B pad so icons never hard-clip into the face buttons */
  bottom: max(9.25rem, calc(env(safe-area-inset-bottom, 0px) + 8.5rem));
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: var(--field-hud-size);
  padding: 0 0 0.85rem;
  box-sizing: border-box;
  pointer-events: auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* Soft fade at the bottom instead of a hard cut */
  -webkit-mask-image: linear-gradient(
    to bottom,
    #000 0%,
    #000 calc(100% - 1.35rem),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    #000 0%,
    #000 calc(100% - 1.35rem),
    transparent 100%
  );
}
.field-party::-webkit-scrollbar { display: none; }
.field-party-slot {
  position: relative;
  flex: 0 0 auto;
  width: var(--field-hud-size);
  height: var(--field-hud-size);
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: rgba(8, 28, 20, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  cursor: pointer;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: pan-y;
}
.field-party-slot.empty {
  opacity: 0.35;
  cursor: default;
  background: rgba(8, 28, 20, 0.18);
}
.field-party-slot img {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
  /* size/position set by sprite_fit.js from opaque bounds */
  width: 70%;
  height: 70%;
  object-fit: contain;
  object-position: center center;
  left: 15%;
  top: 15%;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.field-party-slot img.fp-sprite-fit {
  object-fit: fill;
  object-position: center center;
  max-width: none;
  max-height: none;
}
.field-party-slot .fp-lv {
  position: absolute;
  left: 3px;
  bottom: 3px;
  font-family: var(--font-ui);
  font-size: 0.55rem;
  font-weight: 700;
  color: #f2fff8;
  text-shadow: 0 1px 0 #000, 1px 0 0 #000;
  pointer-events: none;
}
.field-party-slot .fp-hp {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
.field-party-slot .fp-hp-track,
.field-party-slot .fp-hp-fill {
  fill: none;
  stroke-width: 2.75;
}
.field-party-slot .fp-hp-track {
  stroke: rgba(0, 0, 0, 0.5);
}
.field-party-slot .fp-hp-fill {
  stroke: #40d060;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s ease;
}
.field-party-slot .fp-hp.mid .fp-hp-fill { stroke: #e0b020; }
.field-party-slot .fp-hp.low .fp-hp-fill { stroke: #e03838; }
.field-party-slot.fainted {
  filter: grayscale(0.7);
  opacity: 0.65;
}
.field-party-slot:not(.empty):active {
  transform: scale(0.96);
}

/* Transparent d-pad + A/B over the game */
.engine-pad {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 0.5rem;
  padding:
    0.5rem
    max(0.55rem, env(safe-area-inset-right, 0px))
    max(1rem, calc(env(safe-area-inset-bottom, 0px) + 0.55rem))
    max(0.55rem, env(safe-area-inset-left, 0px));
  background: transparent;
  border: 0;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.engine-dpad {
  --dpad-cell: 44px;
  /* Opaque face ? transparency via parent opacity so the cross center isn't double-dark */
  --dpad-face: #123528;
  display: grid;
  grid-template-columns: repeat(3, var(--dpad-cell));
  grid-template-rows: repeat(3, var(--dpad-cell));
  gap: 0;
  justify-self: start;
  position: relative;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  grid-column: 1;
  grid-row: 1;
  touch-action: none;
  pointer-events: auto;
  opacity: 0.55;
  isolation: isolate;
}
.engine-dpad-plate {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.engine-dpad-bar {
  position: absolute;
  display: block;
  background: var(--dpad-face);
  border: 0;
  box-shadow: none;
}
.engine-dpad-bar-v {
  left: 50%;
  top: 0;
  bottom: 0;
  width: var(--dpad-cell);
  transform: translateX(-50%);
  border-radius: 10px;
}
.engine-dpad-bar-h {
  top: 50%;
  left: 0;
  right: 0;
  height: var(--dpad-cell);
  transform: translateY(-50%);
  border-radius: 10px;
}
.engine-dpad-bar-mid {
  left: 50%;
  top: 50%;
  width: var(--dpad-cell);
  height: var(--dpad-cell);
  transform: translate(-50%, -50%);
  border-radius: 0;
  border: 0;
  /* Same opaque fill plugs the V?H junction so one solid cross */
  background: var(--dpad-face);
}
.engine-dir {
  border: 0;
  outline: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
  overflow: hidden;
  pointer-events: none; /* whole dpad captures touch; buttons are visual only */
}
.engine-dir::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-style: solid;
  z-index: 2;
  opacity: 0.85;
}
.engine-dir-up {
  grid-column: 2;
  grid-row: 1;
  border-radius: 10px 10px 0 0;
}
.engine-dir-up::after {
  border-width: 0 7px 11px 7px;
  border-color: transparent transparent rgba(200, 245, 222, 0.9) transparent;
  transform: translate(-50%, -60%);
}
.engine-dir-left {
  grid-column: 1;
  grid-row: 2;
  border-radius: 10px 0 0 10px;
}
.engine-dir-left::after {
  border-width: 7px 11px 7px 0;
  border-color: transparent rgba(200, 245, 222, 0.9) transparent transparent;
  transform: translate(-40%, -50%);
}
.engine-dir-right {
  grid-column: 3;
  grid-row: 2;
  border-radius: 0 10px 10px 0;
}
.engine-dir-right::after {
  border-width: 7px 0 7px 11px;
  border-color: transparent transparent transparent rgba(200, 245, 222, 0.9);
  transform: translate(-60%, -50%);
}
.engine-dir-down {
  grid-column: 2;
  grid-row: 3;
  border-radius: 0 0 10px 10px;
}
.engine-dir-down::after {
  border-width: 11px 7px 0 7px;
  border-color: rgba(200, 245, 222, 0.9) transparent transparent transparent;
  transform: translate(-50%, -40%);
}
.engine-dir.is-down {
  background: rgba(55, 200, 110, 0.28);
}
.engine-dir:focus,
.engine-dir:focus-visible {
  outline: 0;
  box-shadow: none;
}
.engine-face {
  position: relative;
  width: 108px;
  height: 96px;
  justify-self: end;
  grid-column: 2;
  grid-row: 1;
  pointer-events: auto;
  opacity: 0.78;
}
.engine-btn {
  position: absolute;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  color: rgba(234, 255, 244, 0.95);
  background:
    radial-gradient(circle at 32% 28%, rgba(78, 207, 143, 0.75), rgba(26, 122, 85, 0.65) 58%, rgba(15, 82, 56, 0.7) 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18),
    0 3px 0 rgba(6, 25, 18, 0.45);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
}
.engine-btn span { pointer-events: none; }
.engine-a {
  right: 0;
  top: 0;
}
.engine-b {
  left: 0;
  bottom: 0;
}
.engine-btn.is-down {
  transform: translateY(2px);
  filter: brightness(0.92);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.15),
    inset 0 -1px 0 rgba(0, 0, 0, 0.2),
    0 1px 0 rgba(6, 25, 18, 0.4);
}

/* Keep controls usable above party / start overlays */
body.ui-party-open .engine-pad,
body.ui-bag-open .engine-pad {
  z-index: 50;
}
body.ui-box-open .engine-pad {
  display: none !important;
}
body.ui-party-open .field-menu-btn,
body.ui-party-open .field-party,
body.ui-bag-open .field-menu-btn,
body.ui-bag-open .field-party,
body.ui-box-open .field-menu-btn,
body.ui-box-open .field-party {
  visibility: hidden;
  pointer-events: none;
}
body.in-battle .field-party,
body.in-battle .field-menu-btn {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 720px) {
  .engine-dpad { --dpad-cell: 42px; }
  .field-wrap {
    --field-hud-size: 2.6rem;
    --field-hud-gap: 0.35rem;
  }
  .field-party {
    bottom: max(9rem, calc(env(safe-area-inset-bottom, 0px) + 8.25rem));
  }

  .battle-screen {
    padding: 0;
    background: #000;
  }
  .battle-frame {
    width: 100%;
    max-height: none;
    height: 100%;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  /* Keep Emerald layout: text | commands side-by-side, fixed bottom height */
  .battle-bottom {
    --battle-bottom-h: clamp(7rem, 24cqh, 9rem);
    grid-template-columns: 1.25fr 1fr;
  }
  .battle-bottom.fight-open {
    --battle-bottom-h: clamp(7rem, 24cqh, 9rem);
  }
  .battle-fight {
    grid-template-columns: 1fr auto;
    gap: 0.3rem;
  }
  .battle-fight-back {
    min-width: 3.1rem;
    max-width: 3.4rem;
    font-size: 0.72rem;
  }
  .battle-hud.enemy {
    width: min(40vw, 10rem);
    left: 3%;
    top: 4%;
  }
  .battle-hud.player {
    width: min(44vw, 10.75rem);
    right: 3%;
    bottom: 2.5%;
  }
  .battle-hud .hb-name {
    font-size: clamp(0.58rem, 2.4vw, 0.72rem);
    max-width: 64%;
  }
  .battle-hud .hb-lv {
    font-size: clamp(0.48rem, 1.9vw, 0.58rem);
  }
  .battle-hud .hb-hp-tag {
    font-size: 0.4rem;
    padding: 0.08em 0.2em;
  }
  .battle-hud .hp-text {
    font-size: clamp(0.46rem, 2vw, 0.6rem);
  }
  .battle-hud .hb-exp {
    margin-top: 0.28em;
    padding: 0.18em 0.32em;
  }
  .battle-mon.enemy {
    width: min(30%, 8.5rem);
    height: min(40%, 8.5rem);
    top: 6%;
    right: 16%;
  }
  .battle-mon.player {
    width: min(36%, 10rem);
    height: min(46%, 10rem);
    left: 6%;
  }
}

@media (max-width: 720px) {
  .battle-bottom {
    --battle-bottom-h: clamp(7.25rem, 26cqh, 9.25rem);
  }
  .battle-bottom.fight-open {
    --battle-bottom-h: clamp(7.25rem, 26cqh, 9.25rem);
  }
  .battle-fight {
    grid-template-columns: 1fr auto;
  }
  .battle-fight-moves button {
    min-height: 2.7rem;
    padding: 0.28em 0.32em 0.32em;
  }
  .battle-fight-back {
    min-width: 3rem;
    max-width: 3.25rem;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
  }
  .battle-log.awaiting-a::after {
    content: "? TAP";
    font-family: var(--font-ui);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    right: 0.4em;
    bottom: 0.4em;
    padding: 0.28em 0.45em;
    border-radius: 6px;
    background: rgba(248, 248, 240, 0.95);
    border: 1.5px solid #e03848;
    color: #e03848;
    animation: battle-blink 0.9s steps(1) infinite;
  }
  .battle-panel.battle-busy::after {
    content: "TAP LEFT ?";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: #486070;
    opacity: 0.85;
    pointer-events: none;
  }
  .battle-menus {
    position: relative;
  }
}

@media (max-width: 640px) {
  .engine-dpad { --dpad-cell: 40px; }
}


/* ?? Evolution scene ?? */
.evolve-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: radial-gradient(ellipse at 50% 35%, #1a2840 0%, #070b12 70%);
  padding: 0 0 max(1rem, env(safe-area-inset-bottom));
}
.evolve-modal.hidden { display: none; }
.evolve-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 0;
}
#evolve-sprite {
  width: min(42vw, 11rem);
  height: min(42vw, 11rem);
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,0.45));
}
#evolve-sprite.evolve-pulse {
  animation: evolve-pulse 0.55s ease-in-out infinite alternate;
}
#evolve-sprite.evolve-flash {
  animation: evolve-flash 0.35s ease-out 1;
}
@keyframes evolve-pulse {
  from { transform: scale(1); filter: brightness(1) drop-shadow(0 8px 18px rgba(0,0,0,0.45)); }
  to { transform: scale(1.08); filter: brightness(1.55) drop-shadow(0 8px 22px rgba(255,255,255,0.25)); }
}
@keyframes evolve-flash {
  0% { filter: brightness(3); opacity: 0.2; transform: scale(0.92); }
  100% { filter: brightness(1); opacity: 1; transform: scale(1); }
}
.evolve-hint {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #9eb0c8;
}
.evolve-hint.hidden { display: none; }
.evolve-msgbox {
  width: min(100% - 1.5rem, 22rem);
  margin: 0 auto 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(24,36,56,0.96), rgba(12,18,30,0.98));
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}
#evolve-msg {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
  color: #f2f6fc;
  text-align: left;
}
body.ui-evolve-open { overflow: hidden; }

.party-slot-face { position: relative; }
.party-evo-badge {
  position: absolute;
  top: -0.15rem;
  right: -0.2rem;
  z-index: 2;
  padding: 0.12rem 0.28rem;
  border-radius: 6px;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #102018;
  background: linear-gradient(180deg, #7dffb0, #2ecf72);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.party-slot-evo {
  box-shadow: 0 0 0 1px rgba(70, 220, 140, 0.45), inset 0 0 0 1px rgba(70, 220, 140, 0.2);
}
.party-action-btns button.party-act-evolve {
  background: linear-gradient(180deg, #48d4a0, #1f8f5c);
  border-color: transparent;
  color: #fff;
  font-weight: 800;
  order: -1;
}

/* ?? Learn / relearn move ?? */
.learn-move-modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.75rem;
  padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
  background: rgba(4, 8, 14, 0.55);
}
.learn-move-modal.hidden { display: none !important; }
.learn-move-sheet {
  width: min(100%, 22rem);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 0.85rem 0.7rem;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(165deg, #2a364c 0%, #141b28 100%);
  box-shadow: 0 16px 36px rgba(0,0,0,0.45);
  color: #f2f6fc;
}
#learn-move-text {
  margin: 0;
  white-space: pre-line;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
}
.learn-move-yesno {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.learn-move-yesno.hidden,
.learn-move-list.hidden { display: none !important; }
.learn-move-yesno button,
.learn-move-row {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: #f2f6fc;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.learn-move-yesno button {
  padding: 0.55rem 0.4rem;
}
.learn-move-yesno button.learn-cursor,
.learn-move-row.learn-cursor {
  outline: 2px solid rgba(90, 208, 255, 0.85);
  background: rgba(90, 208, 255, 0.14);
}
.learn-move-list {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  max-height: min(42vh, 16rem);
  overflow: auto;
}
.learn-move-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.48rem 0.55rem;
  text-align: left;
}
.learn-move-row.learn-cancel { opacity: 0.75; }
.learn-move-meta {
  font-size: 0.62rem;
  font-weight: 600;
  color: #9eb0c8;
}
.learn-move-hint {
  margin: 0;
  font-size: 0.65rem;
  font-weight: 600;
  color: #9eb0c8;
  text-align: center;
}
body.ui-learn-move-open { overflow: hidden; }
.party-relearn-btn,
.box-relearn-btn {
  margin-top: 0.45rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  background: linear-gradient(180deg, #4aa7e8, #2a6fad);
  color: #fff;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.party-relearn-btn:disabled,
.box-relearn-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
