:root {
  --bg: #0b0c0f;
  --surface: #14161b;
  --surface-2: #1a1d24;
  --line: #2a2e38;
  --text: #e8e6e1;
  --muted: #9a968c;
  --gold: #c4a46b;
  --danger: #b45a4a;
  --ok: #6f8f7a;
}

* { box-sizing: border-box; }

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  min-height: 100dvh;
}

#app.mode-battle {
  max-width: 920px;
  padding: 8px 10px 10px;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app.mode-battle .screen.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", "Noto Sans TC", sans-serif;
}

body {
  min-height: 100dvh;
  height: 100dvh;
  background-image:
    radial-gradient(1000px 520px at 50% -15%, #161922 0%, transparent 55%);
}

/* allow scroll only on non-battle screens */
#app:not(.mode-battle) {
  overflow: auto;
  height: auto;
  min-height: 100dvh;
}

.screen { display: none; animation: fade .28s ease; }
.screen.active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  color: var(--gold);
  letter-spacing: .18em;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

h1, h2, .serif {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-weight: 600;
  letter-spacing: .02em;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(36px, 6vw, 54px);
}

h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 4vw, 32px);
}

.lede {
  color: var(--muted);
  line-height: 1.65;
  max-width: 42ch;
  margin: 0 0 22px;
}

.panel {
  border: 1px solid var(--line);
  background: rgba(20, 22, 27, .92);
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.topbar strong { color: var(--text); font-weight: 500; }

.layout {
  display: grid;
  grid-template-columns: 1.4fr .9fr;
  gap: 14px;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

/* Pokemon-style battle scene — fits one screen, no scroll */
.battle {
  border: 1px solid var(--line);
  background: #0b0c0f;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.battle-field {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
  background-image: url("../assets/images/battle-arena.png");
  background-size: cover;
  background-position: center;
}

.battle-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 4px 2px 6px;
  color: var(--muted);
  font-size: 12px;
  flex: 0 0 auto;
}
.battle-top strong { color: var(--text); font-weight: 500; }

.hud-card {
  position: absolute;
  z-index: 3;
  min-width: 140px;
  max-width: 42%;
  padding: 7px 9px;
  border: 1px solid #3a3f4c;
  background: rgba(20, 22, 27, .92);
}
.hud-card .who {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 15px;
  margin: 0 0 4px;
  color: var(--text);
}
.hud-card .meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 3px;
}
.hud-card .bar {
  height: 8px;
  border: 1px solid #3a3f4c;
  background: #1a1d24;
  overflow: hidden;
}

.battle-msg {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 10px;
  min-height: 0;
  max-height: 52px;
  font-size: 13px;
  line-height: 1.35;
  flex: 0 0 auto;
  overflow: hidden;
}
.battle-msg .hint {
  margin: 0 0 2px;
  font-size: 11px;
}

.battle-cmds {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: #12141a;
  flex: 0 0 auto;
}
.battle-cmds-scroll {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-height: 28vh;
  overflow-y: auto;
  flex: 0 1 auto;
}
.battle-cmds .btn {
  min-height: 44px;
  padding: 8px 8px;
}
.battle-cmds .btn .label {
  display: block;
  font-size: 13px;
}
.battle-cmds .btn .tiny {
  font-size: 10px;
}

.layout.battle-layout {
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  display: flex;
}
.layout.battle-layout .side {
  display: none;
}

.battler.enemy {
  top: auto;
  bottom: 44%;
  right: 7%;
  left: auto;
  width: min(30%, 160px);
  height: 38%;
}
.battler.player {
  top: auto;
  bottom: 3%;
  left: 5%;
  right: auto;
  width: min(34%, 180px);
  height: 44%;
}

@media (max-width: 720px) {
  .battle-cmds { grid-template-columns: 1fr 1fr; }
  .battler.enemy { width: 38%; }
  .battler.player { width: 42%; }
}

@media (max-height: 700px) {
  .battle-field { flex-basis: 0; }
  .hud-card.enemy { top: 8px; left: 8px; }
  .hud-card.player { right: 8px; bottom: 8px; }
  .battle-cmds .btn { min-height: 40px; }
}

.battle-field::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11,12,15,.15), rgba(11,12,15,.55));
  pointer-events: none;
}

.battler {
  position: absolute;
  z-index: 2;
  transition: transform .18s ease, filter .18s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.battler img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  object-position: bottom center;
  background: transparent;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.45));
}

.battler.enemy {
  top: auto;
  bottom: 46%;
  right: 8%;
  left: auto;
  width: min(34%, 200px);
  height: 42%;
}
.battler.player {
  top: auto;
  bottom: 4%;
  left: 6%;
  right: auto;
  width: min(40%, 230px);
  height: 48%;
}

.battler.hit {
  animation: hit-generic .38s ease;
}
.battler.attacking {
  animation: atk-generic .34s ease;
}

/* Player attack styles by axis */
.battler.player.atk-violence { animation: atk-violence .42s ease; }
.battler.player.atk-shadow { animation: atk-shadow .36s steps(2, end); }
.battler.player.atk-faith { animation: atk-faith .4s ease; }
.battler.player.atk-abyss { animation: atk-abyss .45s ease; }
.battler.player.atk-luck { animation: atk-luck .4s ease; }
.battler.player.atk-charm { animation: atk-charm .38s ease; }
.battler.player.atk-wisdom { animation: atk-wisdom .32s ease; }
.battler.player.pose-defend { animation: pose-defend .5s ease; }
.battler.player.pose-heal { animation: pose-heal .5s ease; }

/* Enemy hit / attack by id */
.battler.enemy.hit-slime { animation: hit-slime .42s ease; }
.battler.enemy.hit-rat { animation: hit-rat .36s ease; }
.battler.enemy.hit-knight { animation: hit-knight .4s ease; }
.battler.enemy.hit-whisper { animation: hit-whisper .45s ease; }
.battler.enemy.hit-boss { animation: hit-boss .5s ease; }
.battler.enemy.atk-slime { animation: enemy-atk-bounce .4s ease; }
.battler.enemy.atk-rat { animation: enemy-atk-lunge .34s ease; }
.battler.enemy.atk-knight { animation: enemy-atk-heavy .42s ease; }
.battler.enemy.atk-whisper { animation: enemy-atk-fade .4s ease; }
.battler.enemy.atk-boss { animation: enemy-atk-boss .48s ease; }

@keyframes atk-generic {
  0%, 100% { transform: translate(0,0); }
  45% { transform: translate(22px, -12px) scale(1.04); }
}
@keyframes atk-violence {
  0% { transform: translate(0,0) rotate(0); }
  35% { transform: translate(36px, -8px) rotate(4deg) scale(1.08); }
  55% { transform: translate(28px, -4px) rotate(-2deg); }
  100% { transform: translate(0,0) rotate(0); }
}
@keyframes atk-shadow {
  0% { transform: translate(0,0); opacity: 1; filter: none; }
  40% { transform: translate(50px, -16px); opacity: .15; filter: brightness(1.8); }
  70% { transform: translate(30px, -8px); opacity: 1; }
  100% { transform: translate(0,0); }
}
@keyframes atk-faith {
  0%, 100% { transform: translate(0,0); filter: none; }
  40% { transform: translate(14px, -18px); filter: brightness(1.35) drop-shadow(0 0 10px rgba(196,164,107,.55)); }
}
@keyframes atk-abyss {
  0%, 100% { transform: translate(0,0) scale(1); filter: none; }
  25% { transform: translate(8px, 4px) scale(1.05); filter: hue-rotate(-10deg); }
  55% { transform: translate(32px, -14px) scale(1.12); filter: brightness(1.2) contrast(1.15); }
}
@keyframes atk-luck {
  0% { transform: translate(0,0) rotate(0); }
  30% { transform: translate(16px, -20px) rotate(-8deg); }
  60% { transform: translate(28px, -6px) rotate(6deg) scale(1.06); }
  100% { transform: translate(0,0) rotate(0); }
}
@keyframes atk-charm {
  0%, 100% { transform: translate(0,0) scaleX(1); }
  40% { transform: translate(18px, -10px) scaleX(1.05); filter: brightness(1.2); }
}
@keyframes atk-wisdom {
  0%, 100% { transform: translate(0,0); }
  50% { transform: translate(16px, -6px) scale(1.02); }
}
@keyframes pose-defend {
  0%, 100% { transform: translate(0,0) scale(1); }
  40% { transform: translate(-6px, 2px) scale(.96); filter: brightness(.9); }
}
@keyframes pose-heal {
  0%, 100% { filter: none; transform: translateY(0); }
  40% { filter: brightness(1.4) drop-shadow(0 0 12px rgba(111,143,122,.7)); transform: translateY(-8px); }
}

@keyframes hit-generic {
  0%, 100% { transform: translate(0,0); filter: none; }
  25% { transform: translate(10px, -2px); filter: brightness(2); }
  50% { transform: translate(-8px, 2px); filter: brightness(.75); }
}
@keyframes hit-slime {
  0%, 100% { transform: scale(1,1); filter: none; }
  30% { transform: scale(1.25, .72) translateX(8px); filter: brightness(1.8); }
  60% { transform: scale(.85, 1.18) translateX(-6px); }
}
@keyframes hit-rat {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(12px, -4px) rotate(6deg); filter: brightness(2); }
  45% { transform: translate(-14px, 2px) rotate(-8deg); }
  70% { transform: translate(8px, 0) rotate(3deg); }
}
@keyframes hit-knight {
  0%, 100% { transform: translate(0,0); filter: none; }
  30% { transform: translate(6px, 0); filter: brightness(1.6) contrast(1.2); }
  55% { transform: translate(-4px, 3px); filter: brightness(.8); }
}
@keyframes hit-whisper {
  0%, 100% { opacity: 1; filter: none; transform: translate(0,0); }
  25% { opacity: .2; filter: blur(2px) brightness(2); transform: translate(16px, -8px); }
  55% { opacity: .85; transform: translate(-10px, 4px); }
}
@keyframes hit-boss {
  0%, 100% { transform: translate(0,0) scale(1); }
  20% { transform: translate(14px, -4px) scale(1.04); filter: brightness(2); }
  40% { transform: translate(-12px, 4px) scale(1.02); filter: brightness(.7); }
  65% { transform: translate(8px, -2px); filter: brightness(1.4); }
}

@keyframes enemy-atk-bounce {
  0%, 100% { transform: translate(0,0) scale(1); }
  40% { transform: translate(-28px, 18px) scale(1.1); }
}
@keyframes enemy-atk-lunge {
  0%, 100% { transform: translate(0,0); }
  45% { transform: translate(-34px, 14px) rotate(-6deg); }
}
@keyframes enemy-atk-heavy {
  0%, 100% { transform: translate(0,0); }
  30% { transform: translate(-8px, -6px); }
  55% { transform: translate(-30px, 16px) scale(1.06); }
}
@keyframes enemy-atk-fade {
  0%, 100% { opacity: 1; transform: translate(0,0); }
  35% { opacity: .25; transform: translate(-40px, 20px); }
  70% { opacity: 1; }
}
@keyframes enemy-atk-boss {
  0%, 100% { transform: translate(0,0) scale(1); }
  40% { transform: translate(-36px, 18px) scale(1.08); filter: brightness(1.25); }
}

.battle-fx {
  position: absolute;
  z-index: 4;
  width: min(28%, 150px);
  height: auto;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}
.battle-fx.show-slash {
  top: 22%;
  right: 14%;
  animation: fx-slash .45s ease forwards;
}
.battle-fx.show-hit {
  top: 24%;
  right: 16%;
  animation: fx-hit .4s ease forwards;
}
.battle-fx.show-skill {
  top: 18%;
  right: 12%;
  width: min(34%, 180px);
  animation: fx-skill .55s ease forwards;
}
.battle-fx.show-heal {
  left: 12%;
  bottom: 18%;
  right: auto;
  top: auto;
  mix-blend-mode: screen;
  animation: fx-heal .55s ease forwards;
}

@keyframes fx-slash {
  0% { opacity: 0; transform: scale(.5) rotate(-20deg); }
  35% { opacity: 1; transform: scale(1.05) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.25) rotate(8deg) translate(10px, -8px); }
}
@keyframes fx-hit {
  0% { opacity: 0; transform: scale(.4); }
  40% { opacity: 1; transform: scale(1.1); }
  100% { opacity: 0; transform: scale(1.35); }
}
@keyframes fx-skill {
  0% { opacity: 0; transform: scale(.4) rotate(0); }
  40% { opacity: 1; transform: scale(1.15) rotate(8deg); }
  100% { opacity: 0; transform: scale(1.4) rotate(-6deg); }
}
@keyframes fx-heal {
  0% { opacity: 0; transform: translateY(12px) scale(.7); }
  40% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-18px) scale(1.2); }
}

.dmg-float {
  position: absolute;
  z-index: 5;
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 28px;
  font-weight: 600;
  color: #f0d9a4;
  text-shadow: 0 2px 0 #000;
  pointer-events: none;
  animation: dmg-up .7s ease forwards;
}
.dmg-float.player { color: #e8a39a; }
@keyframes dmg-up {
  0% { opacity: 0; transform: translateY(8px) scale(.8); }
  20% { opacity: 1; transform: translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateY(-36px) scale(1); }
}

.hud-card.enemy {
  top: 10px;
  left: 10px;
}
.hud-card.player {
  right: 10px;
  bottom: 10px;
}
.hud-card .bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8a3d36, #c4a46b);
}
.hud-card .bar.player > i {
  background: linear-gradient(90deg, #3d6b52, #6f8f7a);
}

.seal {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.stage .blurb {
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  margin: 0;
}

.stage .enemy-name {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 28px;
  margin: 0 0 8px;
  color: var(--gold);
}

.side {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
}

.statline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid #22262f;
  color: var(--muted);
}

.statline span:last-child { color: var(--text); }

.axes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin-top: 10px;
}

.axis {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.axis b { color: var(--text); font-weight: 500; }

.cmds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 2px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--gold);
  background: #1e2230;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn.primary {
  background: transparent;
  border-color: var(--gold);
  color: var(--gold);
  text-align: center;
  letter-spacing: .08em;
}

.btn.primary:hover:not(:disabled) {
  background: rgba(196, 164, 107, .08);
}

.btn.ghost {
  background: transparent;
}

.log {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  max-height: 120px;
  overflow: auto;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .06em;
}

.field input {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 12px;
  outline: none;
}

.field input:focus { border-color: var(--gold); }

.contract-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 18px;
}

.contract-row {
  display: grid;
  grid-template-columns: 28px 56px minmax(120px, 1.3fr) 84px 84px minmax(110px, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.contract-row:hover { background: var(--surface-2); }
.contract-row.selected {
  box-shadow: inset 2px 0 0 var(--gold);
  border-color: #3a3f4c;
}

.contract-row .name {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank { font-weight: 600; letter-spacing: .04em; }
.rank.F, .rank.E, .rank.D { color: #8d9098; }
.rank.C, .rank.B { color: #b7b2a6; }
.rank.A, .rank.S { color: #c4a46b; }
.rank.SS, .rank.SSS { color: #f0d9a4; }

.muted { color: var(--muted); }
.gold { color: var(--gold); }
.danger { color: var(--danger); }

.path-list {
  display: grid;
  gap: 8px;
}

.path-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 14px;
  cursor: pointer;
}

.path-row:hover { border-color: var(--gold); }
.path-row .t {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 20px;
  margin-bottom: 4px;
}
.path-row .d { color: var(--muted); font-size: 13px; }

.center {
  min-height: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.title-hero {
  width: 100%;
  max-width: 560px;
  max-height: 28vh;
  aspect-ratio: 16/9;
  object-fit: cover;
  border: 1px solid var(--line);
  margin: 0 0 14px;
  display: block;
}

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

.side .skill-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.goal {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.goal strong { color: var(--gold); font-weight: 500; }

.hint {
  color: var(--gold);
  font-size: 13px;
  margin: 0 0 10px;
  line-height: 1.5;
}

.reward-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.hpbar {
  height: 8px;
  background: #22262f;
  border: 1px solid var(--line);
  margin-top: 10px;
  overflow: hidden;
}
.hpbar > span {
  display: block;
  height: 100%;
  background: var(--danger);
}

.playstyle {
  display: inline-block;
  border: 1px solid #3a3f4c;
  color: var(--gold);
  padding: 2px 8px;
  font-size: 12px;
  margin-left: 6px;
}

.steps {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
  margin: 0 0 18px;
  padding-left: 18px;
}

.tiny {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .contract-row {
    grid-template-columns: 24px 40px 1fr;
    grid-template-areas:
      "mark rank name"
      "mark a b"
      "mark c c";
  }
  .contract-row > :nth-child(1) { grid-area: mark; }
  .contract-row > :nth-child(2) { grid-area: rank; }
  .contract-row > :nth-child(3) { grid-area: name; }
  .contract-row > :nth-child(4) { grid-area: a; }
  .contract-row > :nth-child(5) { grid-area: b; }
  .contract-row > :nth-child(6) { grid-area: c; }
}

/* ═══════════════════════════════════════════
   Battle UI v2 — Pokémon-like clarity
   Soft motion only (no flash / harsh filters)
   ═══════════════════════════════════════════ */

.battle-v2 {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  background: #0c0e13;
}

.battle-v2 .battle-field {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  background: #0c0e13;
  overflow: hidden;
}

/* Current street-view scene as real <img>, blurred behind battlers */
.battle-v2 .battle-field > .battle-scene-bg {
  position: absolute;
  inset: -28px;
  z-index: 0;
  width: calc(100% + 56px);
  height: calc(100% + 56px);
  object-fit: cover;
  object-position: center;
  filter: blur(14px) saturate(0.85) brightness(0.5);
  pointer-events: none;
  user-select: none;
}

.battle-v2 .battle-field::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8,10,14,.35) 0%, rgba(8,10,14,.12) 42%, rgba(8,10,14,.55) 100%);
}

.battle-v2 .battle-field > .battler,
.battle-v2 .battle-field > .bui-hud {
  z-index: 2;
}

.bui-hud {
  position: absolute;
  z-index: 5;
  width: min(46%, 240px);
  padding: 8px 10px 9px;
  border-radius: 4px 12px 4px 12px;
  border: 1px solid rgba(196, 164, 107, .35);
  background:
    linear-gradient(145deg, rgba(28, 32, 42, .94), rgba(16, 18, 24, .92));
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

/* Pokémon layout: HUD opposite the sprite so faces stay clear */
.bui-hud.enemy { top: 10px; left: 10px; right: auto; width: min(42%, 220px); }
.bui-hud.player { right: 10px; bottom: 10px; left: auto; }

.bui-hud .who-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.bui-hud .who {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 16px;
  color: var(--text);
  margin: 0;
  letter-spacing: .02em;
}
.bui-hud .lv {
  font-size: 12px;
  color: var(--gold);
  white-space: nowrap;
}

.bui-hud.enemy .bar-row.stam-row,
.bui-hud.enemy .bar-row.mana-row {
  display: none;
}

.bui-hud .xp-row {
  margin-top: 4px;
}
.bui-hud .xp-track {
  height: 4px;
  border-radius: 99px;
  background: #1a1d24;
  border: 1px solid #333845;
  overflow: hidden;
}
.bui-hud .xp-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #6b5a2e, #c4a46b);
}

.bui-hud .type-line {
  font-size: 11px;
  color: var(--gold);
  margin-bottom: 6px;
  opacity: .9;
}

.bui-hud .bar-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
  font-size: 10px;
  color: var(--muted);
}

.bui-hud .bar-track {
  height: 8px;
  border-radius: 99px;
  background: #1a1d24;
  border: 1px solid #333845;
  overflow: hidden;
}

.bui-hud .bar-track.hp { height: 10px; }

.bui-hud .hp-fill,
.bui-hud .stam-fill,
.bui-hud .mana-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transform-origin: left center;
}

.bui-hud .hp-fill[data-band="ok"] {
  background: linear-gradient(90deg, #3d8f5c, #6fbf88);
}
.bui-hud .hp-fill[data-band="mid"] {
  background: linear-gradient(90deg, #a68b2c, #d4b84a);
}
.bui-hud .hp-fill[data-band="low"] {
  background: linear-gradient(90deg, #8a3d36, #c45a4a);
}

.bui-hud .stam-fill {
  background: linear-gradient(90deg, #5a6b3d, #9aaf6a);
}
.bui-hud .mana-fill {
  background: linear-gradient(90deg, #3d4f7a, #6a8fc4);
}

.bui-hud .hp-num,
.bui-hud .stam-num,
.bui-hud .mana-num {
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  text-align: right;
  color: var(--text);
  font-size: 11px;
}

.bui-hud .status-line {
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
  min-height: 1.2em;
}

.battle-v2 .battler {
  transition: transform .45s cubic-bezier(.22,.7,.2,1);
  will-change: transform;
}
.battle-v2 .battler img {
  filter: drop-shadow(0 12px 18px rgba(0,0,0,.4));
}

/* Soft poses — no brightness flash */
.battle-v2 .battler.player.atk-soft {
  animation: bui-lunge-player .55s cubic-bezier(.2,.8,.2,1);
}
.battle-v2 .battler.enemy.hit-soft {
  animation: bui-hit-enemy .55s cubic-bezier(.2,.8,.2,1);
}
.battle-v2 .battler.enemy.atk-soft {
  animation: bui-lunge-enemy .55s cubic-bezier(.2,.8,.2,1);
}
.battle-v2 .battler.player.hit-soft {
  animation: bui-hit-player .55s cubic-bezier(.2,.8,.2,1);
}
.battle-v2 .battler.player.pose-guard {
  animation: bui-guard .6s ease;
}

@keyframes bui-lunge-player {
  0%, 100% { transform: translate(0, 0); }
  40% { transform: translate(28px, -10px); }
  55% { transform: translate(18px, -4px); }
}
@keyframes bui-lunge-enemy {
  0%, 100% { transform: translate(0, 0); }
  40% { transform: translate(-26px, 8px); }
}
@keyframes bui-hit-enemy {
  0%, 100% { transform: translate(0, 0); opacity: 1; }
  25% { transform: translate(10px, -2px); opacity: .85; }
  50% { transform: translate(-6px, 0); opacity: .7; }
  75% { transform: translate(4px, 0); opacity: .9; }
}
@keyframes bui-hit-player {
  0%, 100% { transform: translate(0, 0); opacity: 1; }
  30% { transform: translate(-10px, 2px); opacity: .8; }
  60% { transform: translate(4px, 0); opacity: .9; }
}
@keyframes bui-guard {
  0%, 100% { transform: translate(0, 0) scale(1); }
  40% { transform: translate(-6px, 0) scale(.97); }
}

.bui-float {
  position: absolute;
  z-index: 8;
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: 28px;
  font-weight: 600;
  pointer-events: none;
  animation: bui-float-up 1.05s cubic-bezier(.2,.7,.2,1) forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,.55);
}
.bui-float.is-enemy { top: 28%; right: 22%; color: #f0e6d2; }
.bui-float.is-player { bottom: 34%; left: 22%; color: #e8b4aa; }
.bui-float-heal { color: #8fd4a4 !important; }
.bui-float-info { font-size: 15px; color: var(--gold) !important; }

@keyframes bui-float-up {
  0% { opacity: 0; transform: translateY(12px) scale(.92); }
  18% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1); }
}

.bui-msg {
  flex: 0 0 auto;
  min-height: 72px;
  max-height: 88px;
  padding: 12px 14px 10px;
  border-top: 2px solid rgba(196, 164, 107, .45);
  background:
    linear-gradient(180deg, #1a1e28 0%, #12151c 100%);
  cursor: pointer;
  position: relative;
  user-select: none;
}

.bui-msg-body {
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  min-height: 2.9em;
  opacity: 0;
  transform: translateY(4px);
}
.bui-msg-body.is-in {
  animation: bui-msg-in .28s ease forwards;
}
@keyframes bui-msg-in {
  to { opacity: 1; transform: none; }
}

.bui-msg-cue {
  position: absolute;
  right: 14px;
  bottom: 8px;
  color: var(--gold);
  font-size: 12px;
  opacity: 0;
  transition: opacity .2s;
}
.bui-msg-cue.show { opacity: 1; animation: bui-cue-blink 1s ease infinite; }
@keyframes bui-cue-blink {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

.battle-cmds.fight-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background: #0e1016;
  border-top: 1px solid var(--line);
  max-height: 34vh;
  overflow-y: auto;
}

.fight-menu .btn {
  min-height: 52px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.fight-menu .btn:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: rgba(196, 164, 107, .55);
}
.fight-menu .btn:disabled {
  opacity: .45;
  cursor: wait;
}
.fight-menu .btn .label { font-size: 14px; }
.fight-menu .btn .tiny { color: var(--muted); }

.battle-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  background: #0a0c10;
  border-bottom: 1px solid #1c2028;
  flex: 0 0 auto;
}
.battle-toolbar .btn {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
}

/* Stats sheet */
.stats-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 40;
}
.stats-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.stats-sheet {
  position: fixed;
  top: 0;
  right: 0;
  width: min(400px, 94vw);
  height: 100dvh;
  z-index: 41;
  background: linear-gradient(180deg, #161922, #0e1016);
  border-left: 1px solid rgba(196,164,107,.35);
  padding: 16px 16px 28px;
  overflow-y: auto;
  transform: translateX(104%);
  transition: transform .32s cubic-bezier(.22,.7,.2,1);
  box-shadow: -12px 0 40px rgba(0,0,0,.4);
}
.stats-sheet.open { transform: translateX(0); }

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.sheet-head h2 { margin: 0; font-size: 28px; }

.sheet-aff {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.02);
  border-radius: 8px;
}
.sheet-aff > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.sheet-aff b { color: var(--text); font-weight: 500; }

.sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin-bottom: 14px;
}
.sheet-stat {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 8px;
  font-size: 12px;
  color: var(--muted);
  background: #14171f;
  border-radius: 6px;
  border: 1px solid #22262f;
}
.sheet-stat b { color: var(--text); font-weight: 500; }

.sheet-skills {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}
.sheet-skills li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #22262f;
  font-size: 13px;
}
.sheet-skills span { color: var(--muted); font-size: 11px; }
.sheet-hint { margin-top: 12px; color: var(--muted); }

/* Explore side panel polish */
.side.stats-card {
  border-radius: 10px;
  padding: 14px;
  background: linear-gradient(180deg, #171a22, #12151c);
}
.side .aff-badge {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}
.side .aff-badge span {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--gold);
  background: rgba(196,164,107,.08);
}

@media (max-width: 720px) {
  .bui-hud { width: min(64%, 220px); padding: 8px 10px; }
  .bui-hud .who { font-size: 15px; }
  .fight-menu { grid-template-columns: 1fr 1fr; }
  .bui-msg { min-height: 64px; }
}

/* ═══ Top-down tile map ═══ */
#app.mode-map {
  max-width: none;
  width: 100%;
  height: 100dvh;
  padding: 0;
  margin: 0;
  overflow: hidden;
}
.map-screen {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: #0a0c10;
  overflow: hidden;
}
#tile-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #0a0c10;
}
.map-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(6,8,12,.75), transparent);
}
.map-hud-left, .map-hud-right {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  pointer-events: auto;
}
.map-hud span, .map-hud strong {
  font-size: 12px;
  padding: 4px 8px;
  background: rgba(10,12,18,.65);
  border: 1px solid rgba(255,255,255,.14);
}
.map-quest { color: #e8d296; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-quest.muted { color: rgba(200,200,200,.5); }
.map-hud .btn {
  padding: 4px 10px;
  font-size: 12px;
  background: rgba(14,16,22,.8);
  border-color: rgba(255,255,255,.22);
  color: #f2efe6;
}
.map-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  margin: 0;
  font-size: 11px;
  color: rgba(230,230,230,.45);
  pointer-events: none;
}
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: #0a0c10;
  color: rgba(232,210,150,.85);
  font-size: 16px;
}
.map-pad {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 6;
  display: none;
  grid-template-rows: auto auto auto;
  justify-items: center;
  gap: 4px;
}
.map-pad-mid { display: flex; gap: 4px; }
.map-pad button {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(10,12,18,.7);
  color: #f2efe6;
  font-size: 16px;
  border-radius: 10px;
  touch-action: none;
}
@media (max-width: 900px), (pointer: coarse) {
  .map-pad { display: grid; }
  .map-hint { display: none; }
}

/* ═══ Mistlamp street-view VN (legacy) ═══ */
#app.mode-vn {
  max-width: none;
  width: 100%;
  padding: 0;
  margin: 0;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}
#app.mode-vn .vn-screen {
  min-height: 100dvh;
  height: 100dvh;
  padding: 0;
  margin: 0;
}
.sv-stage {
  position: relative;
  height: 100dvh;
  color: #f2efe6;
  overflow: hidden;
  background: #07080c;
}
.sv-stage.is-arrive .sv-bg { opacity: 0; transform: scale(1.08); }
.sv-stage.is-in .sv-bg {
  opacity: 1;
  transform: scale(1.02);
  transition: opacity .45s ease, transform .7s ease;
}
.sv-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  user-select: none;
}
.sv-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(6,8,12,.5) 0%, transparent 22%, transparent 58%, rgba(6,8,12,.75) 100%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.35) 100%);
}
.sv-hotspots {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.sv-hz {
  pointer-events: auto;
  position: absolute;
  border: 0;
  background: transparent;
  color: #f4f0e6;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: .55;
  transition: opacity .2s ease, transform .2s ease;
}
.sv-hz:hover { opacity: 1; }
.sv-hz-arrow {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(8,10,14,.45);
  border: 1px solid rgba(255,255,255,.35);
  backdrop-filter: blur(6px);
  font-size: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.sv-hz:hover .sv-hz-arrow {
  border-color: rgba(232, 210, 150, .85);
  background: rgba(16,18,24,.7);
  transform: scale(1.06);
}
.sv-hz-label {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(8,10,14,.55);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .2s ease, transform .2s ease;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sv-hz:hover .sv-hz-label,
.sv-hz:focus .sv-hz-label { opacity: 1; transform: none; }
.sv-hz-forward { left: 50%; top: 18%; transform: translateX(-50%); width: 40%; height: 28%; }
.sv-hz-back { left: 50%; bottom: 10%; transform: translateX(-50%); width: 36%; height: 18%; }
.sv-hz-left { left: 0; top: 28%; width: 18%; height: 44%; }
.sv-hz-right { right: 0; top: 28%; width: 18%; height: 44%; }
.sv-hz-up { right: 18%; top: 10%; width: 14%; height: 16%; }
.sv-hz-down { right: 18%; bottom: 14%; width: 14%; height: 16%; }

.sv-hud {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  pointer-events: none;
}
.sv-floor {
  font-size: 11px;
  letter-spacing: .14em;
  color: rgba(232, 210, 150, .85);
}
.sv-title {
  margin: 2px 0 0;
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 600;
  line-height: 1.1;
  text-shadow: 0 2px 16px rgba(0,0,0,.7);
}
.sv-stats {
  display: flex;
  gap: 6px;
  height: fit-content;
}
.sv-stats span {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(10,12,18,.5);
  backdrop-filter: blur(6px);
}
.sv-blurb {
  position: absolute;
  z-index: 4;
  left: 16px;
  right: 16px;
  bottom: 88px;
  margin: 0;
  max-width: 520px;
  font-size: 15px;
  line-height: 1.45;
  text-shadow: 0 1px 12px rgba(0,0,0,.85);
  pointer-events: none;
}
.sv-pins {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 52px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: min(92vw, 640px);
}
.sv-pin {
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(10,12,18,.55);
  color: #f2efe6;
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.sv-pin:hover { border-color: rgba(232,210,150,.7); }
.sv-people {
  position: absolute;
  z-index: 4;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 55%;
}
.sv-npc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(10,12,18,.62);
  color: inherit;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.sv-npc img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  object-position: top center;
  border-radius: 4px;
}
.sv-fab {
  position: absolute;
  z-index: 5;
  right: 14px;
  bottom: 14px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.28);
  background: rgba(10,12,18,.7);
  color: #f2efe6;
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.sv-menu {
  position: absolute;
  z-index: 5;
  right: 14px;
  bottom: 66px;
  display: none;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
}
.sv-menu.is-open { display: flex; }
.sv-menu .btn {
  background: rgba(14,16,22,.82);
  border-color: rgba(255,255,255,.22);
  color: #f2efe6;
}
@media (max-width: 720px) {
  .sv-hz-left, .sv-hz-right { width: 22%; }
  .sv-blurb { font-size: 14px; bottom: 96px; }
  .sv-people { max-width: 70%; }
}
.npc-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.npc-card {
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.npc-card img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  object-position: top center;
  border-radius: 6px;
  background: #111;
}
.npc-card .t { font-size: 14px; }
.npc-card .d { font-size: 11px; color: var(--muted); }

.talk-layout {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  align-items: start;
}
.talk-portrait {
  width: 120px;
  height: 160px;
  object-fit: cover;
  object-position: top center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #111;
}
.journal-list { display: flex; flex-direction: column; gap: 8px; }
.journal-line {
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid #22262f;
  border-radius: 6px;
  background: #14171f;
  color: var(--muted);
}
@media (max-width: 720px) {
  .talk-layout { grid-template-columns: 1fr; }
  .talk-portrait { width: 96px; height: 128px; }
}
