:root {
  --bg: #0c1020;
  --bg2: #151b32;
  --card: #1c2442;
  --card2: #242c4e;
  --line: #333c66;
  --text: #f4f1ea;
  --muted: #9aa3c7;
  --gold: #f0c14b;
  --gold2: #ffd978;
  --danger: #ef6b6b;
  --good: #4fd48a;
  --ember: #ff6b35;
  --tide: #3d9ee8;
  --grove: #3ecf6e;
  --volt: #f0d24a;
  --stone: #c4a07a;
  --gust: #b7d9f7;
  --plain: #c9c3b5;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --radius: 14px;
  --btn-h: 50px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}
button, input { font: inherit; }
button {
  min-height: var(--btn-h);
  border: 0;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  background: var(--card2);
  cursor: pointer;
  letter-spacing: 0.01em;
}
button:disabled { opacity: 0.4; cursor: default; }
button:active:not(:disabled) { transform: scale(0.98); }
.btn-gold {
  background: linear-gradient(180deg, #f6d56a, #d7a52a);
  color: #2a1d00;
}
.btn-good { background: linear-gradient(180deg, #4fd48a, #2aa863); color: #062014; }
.btn-danger { background: linear-gradient(180deg, #ef7a7a, #c44545); color: #2a0b0b; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-block { width: 100%; }

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 50% -10%, #2a1f5a 0%, transparent 60%),
    radial-gradient(800px 400px at 100% 100%, #132a3a 0%, transparent 50%),
    var(--bg);
}
.screen { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }
.screen.active { display: flex; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.pad { padding: 16px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Title */
.brand {
  text-align: center;
  padding: 28px 16px 8px;
}
.logo-mark { width: 96px; height: 96px; margin: 0 auto 8px; }
.logo-mark svg { width: 100%; height: 100%; }
h1.title {
  margin: 0;
  font-size: 2.15rem;
  letter-spacing: 0.14em;
  font-weight: 800;
  background: linear-gradient(90deg, #ff6b35, #f0d24a, #3ecf6e, #3d9ee8, #b7d9f7);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.tag {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 0.95rem;
}
.title-actions { padding: 12px 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); font-size: 0.85rem; text-align: center; line-height: 1.4; padding: 0 16px 20px; }
.sparkle-line {
  height: 2px;
  margin: 18px 40px 0;
  background: linear-gradient(90deg, transparent, #f0c14b, #7ec8f5, transparent);
  opacity: 0.7;
}

/* Starter select */
.starter-grid { display: flex; flex-direction: column; gap: 12px; }
.starter-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: left;
  min-height: 108px;
  width: 100%;
}
.starter-card .art { width: 88px; height: 88px; flex: 0 0 88px; }
.starter-card .art svg { width: 100%; height: 100%; }
.starter-card h3 { margin: 0 0 4px; font-size: 1.15rem; }
.starter-card p { margin: 0; color: var(--muted); font-size: 0.88rem; font-weight: 500; }
.type-chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 4px;
  color: #111;
}
.chip-Ember { background: var(--ember); }
.chip-Tide { background: var(--tide); }
.chip-Grove { background: var(--grove); }
.chip-Volt { background: var(--volt); }
.chip-Stone { background: var(--stone); }
.chip-Gust { background: var(--gust); }
.chip-Plain { background: var(--plain); }
.screen-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 4px;
}
.screen-head h2 { margin: 0; flex: 1; font-size: 1.15rem; }
.icon-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  background: var(--card);
  border: 1px solid var(--line);
}

/* Map */
.map-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.map-hud .stat { color: var(--gold2); font-weight: 800; font-size: 0.95rem; }
.map-canvas {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 8px 24px;
  position: relative;
}
.map-rows { display: flex; flex-direction: column-reverse; gap: 28px; position: relative; z-index: 1; }
.map-row { display: flex; justify-content: space-evenly; align-items: center; position: relative; }
.map-node {
  width: 72px;
  min-height: 72px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--card);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  position: relative;
  z-index: 2;
  box-shadow: 0 6px 0 #0a0e1c;
}
.map-node .sym { font-size: 1.25rem; line-height: 1; }
.map-node .lbl { font-size: 0.62rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.map-node.available {
  border-color: var(--gold);
  animation: pulse 1.6s ease-in-out infinite;
}
.map-node.available.wild { border-color: #7ec8f5; }
.map-node.available.trainer { border-color: #ef8a6b; }
.map-node.available.shop { border-color: var(--gold); }
.map-node.available.rest,
.map-node.available.camp { border-color: var(--good); }
.map-node.available.boss { border-color: #e8d48a; background: #3a2a12; width: 88px; min-height: 88px; }
.map-node.done { opacity: 0.45; }
.map-node.locked { opacity: 0.28; }
.map-node.current { outline: 2px solid #fff; }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 0 #0a0e1c, 0 0 0 0 rgba(240,193,75,0.5); }
  50% { transform: scale(1.05); box-shadow: 0 6px 0 #0a0e1c, 0 0 0 8px rgba(240,193,75,0); }
}
@media (prefers-reduced-motion: reduce) {
  .map-node.available { animation: none; }
  button:active:not(:disabled) { transform: none; }
}
.map-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Battle */
.battle-field { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 12px; gap: 6px; }
.battler {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}
.battler.foe { background: linear-gradient(180deg, #24203a, var(--card)); }
.battler.you { background: linear-gradient(180deg, var(--card), #162832); }
.battler .art { width: 92px; height: 92px; }
.battler .art svg { width: 100%; height: 100%; }
.battler.hit .art { animation: hitflash 0.28s ease; }
@keyframes hitflash {
  0%, 100% { filter: none; transform: none; }
  30% { filter: brightness(2.2); transform: translateX(4px); }
}
.battler.catching .art { animation: swirl 0.6s ease; }
@keyframes swirl {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.3) rotate(40deg); opacity: 0.3; }
  100% { transform: scale(0); opacity: 0; }
}
.battler-meta h3 { margin: 0; font-size: 1rem; display: flex; justify-content: space-between; gap: 8px; }
.lv { color: var(--muted); font-weight: 700; font-size: 0.85rem; }
.hp-track {
  height: 12px;
  background: #0a0e1c;
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0 3px;
  border: 1px solid #2a3358;
}
.hp-fill { height: 100%; width: 100%; background: var(--good); border-radius: 99px; transition: width 0.35s ease, background 0.3s; }
.hp-fill.mid { background: var(--gold); }
.hp-fill.low { background: var(--danger); }
.hp-num { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.battle-log {
  flex: 0 0 auto;
  min-height: 64px;
  max-height: 88px;
  overflow-y: auto;
  background: #0a0e1c;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  line-height: 1.35;
  color: #e6e3d8;
}
.battle-log .line { margin: 0 0 4px; }
.battle-actions { padding: 8px 12px calc(8px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.move-btn {
  text-align: left;
  padding: 8px 10px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border: 2px solid var(--line);
  background: var(--card);
}
.move-btn .mn { font-size: 0.95rem; }
.move-btn .ms { font-size: 0.72rem; font-weight: 700; color: #111; align-self: flex-start; padding: 1px 6px; border-radius: 99px; }
.move-btn.eff-super { box-shadow: inset 0 0 0 1px #4fd48a; }
.move-btn.eff-weak { opacity: 0.85; }
.tip {
  background: #2a2448;
  color: #efe8c8;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  line-height: 1.35;
  margin: 0 12px 6px;
}

/* Shop / bag / party */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  text-align: left;
  width: 100%;
  min-height: 64px;
}
.list-item .grow { flex: 1; }
.list-item h3 { margin: 0; font-size: 1rem; }
.list-item p { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; font-weight: 500; }
.price { color: var(--gold2); font-weight: 800; white-space: nowrap; }
.qty { color: var(--muted); font-size: 0.8rem; }
.party-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  width: 100%;
  text-align: left;
  min-height: 80px;
}
.party-card.fainted { opacity: 0.55; }
.party-card .art { width: 72px; height: 72px; }
.party-card .art svg { width: 100%; height: 100%; }
.rest-art { text-align: center; padding: 20px 0 8px; }
.campfire {
  width: 140px; height: 140px; margin: 0 auto;
}
.end-wrap { text-align: center; padding: 32px 20px 16px; }
.end-wrap h2 { font-size: 1.8rem; margin: 8px 0 10px; }
.end-wrap p { color: var(--muted); line-height: 1.45; }
.badge {
  width: 120px; height: 120px; margin: 0 auto 8px;
}
.muted { color: var(--muted); }
.center { text-align: center; }
.tiny { font-size: 0.78rem; color: var(--muted); }
.footer-actions { padding: 8px 16px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.overlay-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8,10,20,0.72); z-index: 20; padding: 24px;
}
.overlay-msg .panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; text-align: center; width: 100%; max-width: 320px;
}
.hidden { display: none !important; }
.type-Ember { color: var(--ember); }
.type-Tide { color: var(--tide); }
.type-Grove { color: var(--grove); }
.type-Volt { color: var(--volt); }
.type-Stone { color: var(--stone); }
.type-Gust { color: var(--gust); }

html.test-mode *, html.test-mode *::before, html.test-mode *::after {
  animation: none !important;
  transition: none !important;
}
