/* Emerald Nuzlocke Simulator — site styles. No build step. */

:root {
  --bg: #0b111d;
  --bg2: #0f1727;
  --panel: #131c2e;
  --panel2: #1a2540;
  --line: #26334f;
  --ink: #e8eefc;
  --dim: #93a1bd;
  --faint: #5d6b88;
  --accent: #2fd69a;
  --accent-ink: #04261a;
  --gold: #f5c451;
  --danger: #ff6b6b;
  --warn: #ffb454;
  --radius: 12px;
  --pixel: "Silkscreen", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font: 14px/1.45 var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(47, 214, 154, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(86, 130, 255, .10), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
img { image-rendering: pixelated; }

/* ── header ── */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.gem {
  width: 34px; height: 34px; flex: none; transform: rotate(45deg); border-radius: 7px;
  background: linear-gradient(135deg, #7af5c9, var(--accent) 45%, #0e8f63);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .08) inset, 0 0 24px rgba(47, 214, 154, .45);
}
.brand h1 { font: 700 19px/1.1 var(--pixel); letter-spacing: .5px; }
.tag { color: var(--dim); font-size: 13px; margin-top: 3px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.view { max-width: 1400px; margin: 0 auto; padding: 0 24px 24px; }

/* ── shared pieces ── */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font: 700 13px/1 var(--pixel); letter-spacing: 1px; text-transform: uppercase; color: var(--dim); }
.hint { color: var(--dim); font-size: 12.5px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 9px;
  padding: 7px 12px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { border-color: #3a4c75; background: #213056; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: #4ae3ad; }
.btn.big { font: 700 15px/1 var(--pixel); padding: 14px 22px; letter-spacing: .5px; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--dim); font-size: 12px;
}
.type {
  display: inline-block; padding: 1px 7px; border-radius: 5px; font: 700 10px/1.6 var(--sans);
  letter-spacing: .4px; text-transform: uppercase; color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  background: var(--t, #666);
}

/* A Pokémon sprite, with a fallback tile if the image cannot load. */
.spr {
  width: var(--s, 64px); height: var(--s, 64px); flex: none; position: relative;
  display: grid; place-items: center;
}
/* The sprite files have a wide transparent margin: draw them a little larger than the box. */
.spr img { width: 100%; height: 100%; object-fit: contain; transform: scale(1.3); }
.spr.missing {
  border-radius: 50%; font: 700 calc(var(--s, 64px) * .3) / 1 var(--pixel); color: #fff;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .35), transparent 45%), var(--t, #50607f);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18); text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
  transform: scale(.72);
}

/* ── builder ── */
#view-builder { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; gap: 16px; align-items: start; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

.slots { display: grid; gap: 8px; }
.slot {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  min-height: 82px;
}
.slot.empty {
  grid-template-columns: 1fr; place-items: center; color: var(--faint);
  border-style: dashed; background: transparent; font-size: 13px;
}
.slot .who { min-width: 0; display: grid; gap: 4px; }
.slot .nick {
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 2px 6px; margin-left: -6px;
  font-weight: 700; font-size: 15px; width: 100%; min-width: 0;
}
.slot .nick::placeholder { color: var(--ink); opacity: 1; }
.slot .nick:hover { border-color: var(--line); }
.slot .nick:focus { border-color: var(--accent); outline: none; background: var(--bg2); }
.slot .meta { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; color: var(--dim); font-size: 12px; }
.slot .evo { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.slot .evo select { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; font-size: 12px; max-width: 100%; }
.slot .x { background: none; border: 0; color: var(--faint); cursor: pointer; font-size: 18px; padding: 4px 6px; border-radius: 6px; }
.slot .x:hover { color: var(--danger); background: rgba(255, 107, 107, .1); }
.evo-line { display: inline-flex; align-items: center; gap: 2px; }
.evo-line .arrow { color: var(--faint); font-size: 11px; }

.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; color: var(--dim); font-size: 13px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.rules { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.rule { display: grid; gap: 4px; }
.rule > .k { font: 700 10.5px/1 var(--pixel); letter-spacing: .8px; color: var(--faint); text-transform: uppercase; }
.rule .desc { color: var(--faint); font-size: 12px; }
.rule select, .rule input[type=number], .rule input[type=text] {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 100%;
}
.rule.wide { grid-column: 1 / -1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--bg2); }
.seg button { background: none; border: 0; padding: 6px 11px; cursor: pointer; font-weight: 600; color: var(--dim); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seed-row { display: flex; gap: 6px; }

.go { margin-top: 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.picker-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#search { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; width: 230px; }
.types { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 12px; }
.types button { border: 0; cursor: pointer; opacity: .5; }
.types button.on, .types button:hover { opacity: 1; }
.types button.on { box-shadow: 0 0 0 2px #fff; }
.picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px;
  max-height: calc(100vh - 230px); min-height: 320px; overflow: auto; padding-right: 4px;
}
.pick {
  display: grid; justify-items: center; gap: 2px; padding: 6px 4px 8px; cursor: pointer;
  background: var(--panel2); border: 1px solid transparent; border-radius: 10px; text-align: center;
}
.pick:hover { border-color: var(--accent); background: #1f2d50; }
.pick .n { font-weight: 600; font-size: 12px; line-height: 1.2; }
.pick .ts { display: flex; gap: 3px; }
.pick .type { font-size: 8.5px; padding: 0 4px; }
.picker .none { grid-column: 1 / -1; color: var(--faint); padding: 30px; text-align: center; }

/* ── run: bar ── */
#view-run { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.runbar { display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px; }
.runbar-main { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.run-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.run-title h2 { font: 700 16px/1 var(--pixel); }
.badges { display: flex; gap: 4px; align-items: center; }
.badge { width: 30px; height: 30px; display: grid; place-items: center; transition: filter .4s, opacity .4s, transform .4s; filter: brightness(.22) saturate(0); opacity: .75; }
.badge svg { width: 100%; height: 100%; display: block; overflow: visible; }
.badge.on { filter: drop-shadow(0 0 5px rgba(245, 196, 81, .55)); opacity: 1; }
.badge.new { animation: badge-in .9s cubic-bezier(.2, 1.6, .4, 1) 1; }
@keyframes badge-in { 0% { transform: scale(.2) rotate(-40deg); filter: brightness(3); } 60% { transform: scale(1.5) rotate(8deg); } 100% { transform: none; } }
.runbar-stats { display: flex; gap: 18px; }
.stat { display: grid; gap: 2px; }
.stat .k { font: 700 9.5px/1 var(--pixel); letter-spacing: .8px; color: var(--faint); text-transform: uppercase; }
.stat .v { font: 700 16px/1 var(--pixel); }
.runbar-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ctl { display: inline-flex; gap: 6px; align-items: center; color: var(--dim); font-size: 12.5px; }
.ctl select { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

/* ── run: timeline ── */
.timeline-panel { padding: 12px 16px 8px; }
.timeline { display: flex; align-items: center; gap: 3px; overflow-x: auto; padding: 8px 2px 10px; scrollbar-width: thin; }
.tick {
  flex: none; width: 12px; height: 12px; border-radius: 50%; padding: 0; cursor: default;
  border: 2px solid var(--line); background: var(--bg2); position: relative; transition: all .25s;
}
.tick.boss { width: 22px; height: 22px; border-radius: 6px; transform: rotate(45deg); margin: 0 5px; }
.tick.boss > span { position: absolute; inset: 0; display: grid; place-items: center; transform: rotate(-45deg); font: 700 9px/1 var(--pixel); color: var(--faint); }
.tick.sim { border-color: #3d5080; background: #24345a; }
.tick.done { cursor: pointer; }
.tick.won { background: var(--accent); border-color: var(--accent); }
.tick.won.boss > span { color: var(--accent-ink); }
.tick.bloody { background: var(--warn); border-color: var(--warn); }
.tick.bloody.boss > span { color: #3b2300; }
.tick.lost { background: var(--danger); border-color: var(--danger); }
.tick.lost.boss > span { color: #3a0606; }
.tick.now { box-shadow: 0 0 0 3px rgba(255, 255, 255, .85); }
.tick.done:hover { filter: brightness(1.25); }
.tick-gap { flex: none; width: 10px; height: 2px; background: var(--line); border-radius: 1px; }
.timeline-foot { display: flex; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 12.5px; min-height: 19px; }
.sim-status { color: var(--faint); white-space: nowrap; }
.sim-status.busy::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px;
  background: var(--accent); animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

/* ── run: main grid ── */
.run-grid { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 12px; align-items: start; }
.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.stage-panel { padding: 0; overflow: hidden; position: relative; min-height: 420px; }

/* prep */
.prep { display: grid; place-items: center; gap: 12px; padding: 70px 24px; text-align: center; }
.prep h3 { font: 700 17px/1.2 var(--pixel); }
.prep .hint { max-width: 520px; }
.prep .bar { width: min(460px, 90%); height: 12px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.prep .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #1a9d6f, var(--accent)); transition: width .5s; }
.prep-ball {
  width: 54px; height: 54px; border-radius: 50%; border: 3px solid #0a0f1a; position: relative;
  background: linear-gradient(#ef5350 0 46%, #0a0f1a 46% 54%, #f4f6fb 54%);
  animation: wobble 1.1s ease-in-out infinite;
}
.prep-ball::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -10px;
  border-radius: 50%; background: #f4f6fb; border: 3px solid #0a0f1a;
}
@keyframes wobble { 0%, 100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }

/* map */
.map-wrap { position: relative; }
#map { display: block; width: 100%; height: auto; background: radial-gradient(900px 500px at 60% 40%, #16335c, #0c1d38 70%); }
#map .land { fill: #2c7a57; stroke: #1c5a3f; stroke-width: 3; stroke-linejoin: round; }
#map .land.hi { fill: #3a916a; stroke: none; }
#map .rock { fill: #6b7a66; stroke: #4c5a4a; stroke-width: 2; }
#map .lake { fill: #1d4f86; }
#map .wave { stroke: rgba(255, 255, 255, .07); stroke-width: 2; fill: none; stroke-linecap: round; }
#map .route { fill: none; stroke: rgba(255, 255, 255, .22); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; stroke-linejoin: round; }
#map .walked { fill: none; stroke: var(--gold); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 4px rgba(245, 196, 81, .55)); }
#map .place circle.dot { fill: #0c1526; stroke: #c9d6f2; stroke-width: 2; transition: all .3s; }
#map .place.visited circle.dot { fill: var(--accent); stroke: #fff; }
#map .place.gym circle.dot { stroke: var(--gold); stroke-width: 3; }
#map .place.here circle.dot { fill: #fff; }
#map .place text { fill: #dfe8fb; font: 600 11px var(--sans); paint-order: stroke; stroke: rgba(8, 16, 30, .85); stroke-width: 3px; stroke-linejoin: round; }
#map .place.todo text { fill: #8ea0c4; }
#map .place .count { font: 700 9px var(--pixel); fill: var(--gold); }
#map .marker { transition: transform .9s cubic-bezier(.5, 0, .3, 1); }
#map .marker .ring { fill: none; stroke: #fff; stroke-width: 2; opacity: .7; animation: ring 1.6s ease-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes ring { from { transform: scale(.6); opacity: .9; } to { transform: scale(2.1); opacity: 0; } }
#map .grave { font-size: 15px; }

.toast {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(9, 15, 28, .92); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; display: flex; gap: 12px; align-items: center; max-width: 92%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); animation: rise .25s ease-out;
}
.toast strong { font: 700 13px/1.3 var(--pixel); }
.toast .sub { color: var(--dim); font-size: 12.5px; }
.toast.good { border-color: var(--accent); }
.toast.bad { border-color: var(--danger); }
.toast.warn { border-color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* battle stage */
.stage { display: grid; }
.stage-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 12px 16px; flex-wrap: wrap; }
.stage-head .kind { font: 700 10px/1 var(--pixel); letter-spacing: 1px; text-transform: uppercase; color: var(--gold); margin-right: 6px; }
.stage-head strong { font: 700 15px/1.2 var(--pixel); }
.stage-sub { color: var(--dim); font-size: 12.5px; }
.scene {
  position: relative; aspect-ratio: 16 / 8.2; overflow: hidden;
  background:
    radial-gradient(ellipse 30% 9% at 73% 47%, rgba(0, 0, 0, .28) 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 86%, rgba(0, 0, 0, .3) 0 60%, transparent 62%),
    radial-gradient(ellipse 30% 9% at 73% 46%, #9fd68a 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 85%, #9fd68a 0 60%, transparent 62%),
    linear-gradient(#bfe6ff 0 30%, #dff3d2 30% 34%, #77c267 34%);
}
.scene.cave {
  background:
    radial-gradient(ellipse 30% 9% at 73% 46%, #8d8271 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 85%, #8d8271 0 60%, transparent 62%),
    linear-gradient(#3c3a45 0 32%, #55505c 32% 36%, #6b6258 36%);
}
.scene.gym {
  background:
    radial-gradient(ellipse 30% 9% at 73% 46%, #e9e2cf 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 85%, #e9e2cf 0 60%, transparent 62%),
    linear-gradient(#56608a 0 32%, #8a93b8 32% 36%, #c4b9a0 36%);
}
.scene.league {
  background:
    radial-gradient(ellipse 30% 9% at 73% 46%, #e8d9ff 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 85%, #e8d9ff 0 60%, transparent 62%),
    linear-gradient(#2a1d4d 0 32%, #5b3fa0 32% 36%, #8f78c9 36%);
}
.scene.sea {
  background:
    radial-gradient(ellipse 30% 9% at 73% 46%, #7fd3ff 0 60%, transparent 62%),
    radial-gradient(ellipse 36% 11% at 27% 85%, #7fd3ff 0 60%, transparent 62%),
    linear-gradient(#bfe6ff 0 30%, #9ad7ff 30% 34%, #3f8fd6 34%);
}

.mons { position: absolute; display: flex; align-items: flex-end; justify-content: center; gap: 1%; pointer-events: none; }
.mons.foe { left: 53%; width: 40%; top: 4%; height: 44%; }
/* Your Pokémon run off the bottom edge, as in the games: the box hangs a sixth of itself below it. */
.mons.you { left: 4%; width: 46%; top: 53.3%; height: 56%; }
.mons.double .mon { height: 76%; }
.mons.foe.double .mon { height: 68%; }
.mon { height: 100%; aspect-ratio: 1; display: grid; place-items: end center; transition: opacity .3s, transform .3s; }
.mons.foe .mon { height: 82%; }
.mon img { width: 100%; height: 100%; object-fit: contain; object-position: bottom; }
.mon .ball { width: 28%; aspect-ratio: 1; border-radius: 50%; --t: #50607f; }
.mon.missing { place-items: center; }
.mon.missing .tile {
  width: 46%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  font: 700 18px/1 var(--pixel); color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .4), transparent 45%), var(--t, #50607f);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, .18), 0 6px 10px rgba(0, 0, 0, .25);
}
.mon.out { opacity: 0; transform: translateY(18%) scale(.6); }
.mon.fainted { opacity: 0; transform: translateY(40%); transition: opacity .5s, transform .5s ease-in; }
.mon.hit { animation: hit .35s steps(2, jump-none) 1; }
@keyframes hit { 0%, 100% { opacity: 1; } 50% { opacity: .1; } }
.mon.enter { animation: enter .35s ease-out 1; }
@keyframes enter { from { opacity: 0; transform: scale(.3); filter: brightness(3); } }

.hpboxes { position: absolute; display: grid; gap: 5px; width: 36%; min-width: 190px; }
.hpboxes.foe { left: 3%; top: 6%; }
.hpboxes.you { right: 3%; bottom: 7%; }
.hpbox {
  background: #f6f3e4; color: #2b2b33; border: 3px solid #39414f; border-radius: 10px 4px 10px 4px;
  padding: 5px 9px 6px; box-shadow: 0 3px 0 rgba(0, 0, 0, .25); transition: opacity .3s;
}
.hpbox.empty { opacity: 0; }
.hpbox .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.hpbox .nm { font: 700 12px/1.2 var(--pixel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hpbox .lv { font: 700 11px/1.2 var(--pixel); white-space: nowrap; }
.hpbox .hp { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.hpbox .hp b { font: 700 9px/1 var(--pixel); color: #f0a020; background: #39414f; padding: 2px 4px; border-radius: 3px; }
.hpbox .track { flex: 1; height: 8px; border-radius: 4px; background: #39414f; padding: 1.5px; }
.hpbox .fill { height: 100%; width: 100%; border-radius: 3px; background: #3bd16f; transition: width calc(.45s / var(--spd, 1)) linear, background .2s; }
.hpbox .fill.mid { background: #f2c230; }
.hpbox .fill.low { background: #ef4d43; }
.hpbox .num { font: 700 10px/1 var(--pixel); margin-top: 3px; text-align: right; color: #4a4a55; }
.status { font: 700 9px/1 var(--pixel); color: #fff; padding: 2px 4px; border-radius: 3px; margin-left: 4px; }
.status.slp { background: #8b8fa3; } .status.psn, .status.tox { background: #a44fc4; }
.status.brn { background: #e8632c; } .status.frz { background: #4fb6d8; } .status.par { background: #d6a700; }

.pips { position: absolute; display: flex; gap: 4px; }
.pips.foe { left: 3%; top: 1.5%; }
.pips.you { right: 3%; bottom: 2%; }
.pip { width: 11px; height: 11px; border-radius: 50%; border: 2px solid #20242e; background: linear-gradient(#ef5350 0 50%, #f4f6fb 50%); }
.pip.dead { background: #4a4f5c; opacity: .7; }
.pip.gap { border: 0; background: none; width: 4px; }

.turn { position: absolute; left: 50%; top: 2%; transform: translateX(-50%); font: 700 10px/1 var(--pixel); color: #fff; background: rgba(12, 18, 30, .72); padding: 4px 9px; border-radius: 99px; }
.turn:empty { display: none; }

.vs {
  position: absolute; inset: 0; z-index: 3; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 4% 5%; background: linear-gradient(115deg, #101a30 0 49.6%, #fff 49.6% 50.4%, #2a1320 50.4%); animation: fade .25s;
}
.vs .col { display: grid; gap: 10px; justify-items: center; text-align: center; }
.vs .who { font: 700 15px/1.2 var(--pixel); }
.vs .cls { font: 700 10px/1 var(--pixel); color: var(--gold); letter-spacing: 1px; text-transform: uppercase; }
.vs .mid { font: 700 30px/1 var(--pixel); color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .5); background: #0b111d; border: 3px solid #fff; border-radius: 50%; width: 64px; height: 64px; display: grid; place-items: center; }
.vs .line { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; max-width: 340px; }
.vs .trainer { height: 96px; }
.vs .trainer img { height: 100%; }
.vs .lvl { font-size: 11px; color: var(--dim); }
@keyframes fade { from { opacity: 0; } }

.banner {
  position: absolute; left: 0; right: 0; top: 38%; z-index: 2; text-align: center; padding: 14px;
  font: 700 22px/1.2 var(--pixel); color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .45);
  background: linear-gradient(90deg, transparent, rgba(8, 14, 26, .88) 20% 80%, transparent); animation: fade .3s;
}
.banner small { display: block; font: 600 13px/1.4 var(--sans); color: #d6def0; text-shadow: none; margin-top: 4px; }
.banner.win { color: #9bffd8; } .banner.loss { color: #ff9d9d; }

.msg {
  margin: 0; padding: 14px 18px; min-height: 56px; font: 700 15px/1.5 var(--pixel);
  background: #1d2a4a; border-top: 4px solid #39414f; color: #fff;
}

/* ending */
.ending { padding: 44px 24px; display: grid; gap: 16px; justify-items: center; text-align: center; }
.ending h3 { font: 700 26px/1.2 var(--pixel); }
.ending.win h3 { color: var(--gold); text-shadow: 0 0 24px rgba(245, 196, 81, .5); }
.ending.loss h3 { color: var(--danger); }
.ending .lineup { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.ending .hof { display: grid; justify-items: center; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); min-width: 96px; }
.ending .hof.dead { opacity: .55; filter: grayscale(1); }
.ending .hof .n { font-weight: 700; font-size: 13px; }
.ending .hof .f { font-size: 11.5px; color: var(--dim); }
.ending .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ending .facts { color: var(--dim); max-width: 560px; }

/* party */
.party { display: grid; gap: 6px; }
.member {
  display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px;
}
.member.dead { opacity: .6; background: transparent; border-style: dashed; }
.member.dead .spr { filter: grayscale(1) brightness(.7); }
.member.fresh-dead { animation: flashbad 1.2s 1; }
.member.evolved { animation: flashgood 1.4s 1; }
@keyframes flashbad { 0%, 60% { background: rgba(255, 107, 107, .35); border-color: var(--danger); } }
@keyframes flashgood { 0%, 60% { background: rgba(47, 214, 154, .3); border-color: var(--accent); } }
.member .info { min-width: 0; display: grid; gap: 2px; }
.member .l1 { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.member .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .sp { color: var(--dim); font-size: 12px; white-space: nowrap; }
.member .l2 { color: var(--dim); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .moves { display: flex; gap: 3px; flex-wrap: wrap; }
.member .mv { font-size: 10.5px; padding: 0 5px; border-radius: 4px; background: var(--bg2); border-left: 3px solid var(--t, #666); color: #cfd8ee; line-height: 1.7; }
.member .rip { color: var(--danger); font-size: 11.5px; }
.member details { grid-column: 1 / -1; font-size: 11.5px; color: var(--dim); }
.member summary { cursor: pointer; color: var(--faint); }

/* log */
.log-panel { min-height: 0; }
.log { max-height: 340px; overflow: auto; font-size: 12.5px; display: grid; gap: 1px; scrollbar-width: thin; }
.log .t { font: 700 9.5px/1 var(--pixel); color: var(--faint); letter-spacing: 1px; margin: 8px 0 3px; text-transform: uppercase; }
.log .x { color: #dbe4f8; }
.log .x.foe { color: #f3b7b7; }
.log .x.faint { color: var(--danger); font-weight: 700; }
.log .d { color: var(--faint); padding-left: 12px; font-size: 11.5px; }
.log .sep { margin: 8px 0; border-top: 1px dashed var(--line); padding-top: 6px; color: var(--gold); font: 700 10px/1.2 var(--pixel); }
.log .empty { color: var(--faint); }

.foot { max-width: 1400px; margin: 0 auto; padding: 8px 24px 28px; color: var(--faint); font-size: 12px; }
.err { background: rgba(255, 107, 107, .12); border: 1px solid var(--danger); color: #ffd0d0; border-radius: 10px; padding: 10px 14px; margin: 0 24px 12px; max-width: 1352px; }

/* ── battle feedback: layers, damage numbers, shake ── */
.hpboxes, .pips, .turn { z-index: 2; }
.vs { z-index: 6; }
.banner { z-index: 5; }
.pops { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.pop {
  position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 2px;
  white-space: nowrap; animation: pop calc(1s / min(var(--spd, 1), 4)) ease-out forwards;
}
.pop b {
  font: 700 22px/1 var(--pixel); color: #fff;
  text-shadow: -2px 0 #1b1f2a, 2px 0 #1b1f2a, 0 -2px #1b1f2a, 0 2px #1b1f2a, 0 4px 0 rgba(0, 0, 0, .35);
}
.pop span {
  font: 700 10px/1 var(--pixel); letter-spacing: .5px; padding: 3px 6px; border-radius: 4px;
  background: #1b1f2a; color: #fff;
}
.pop.dmg b { color: #ffe9e4; }
.pop.dmg.heavy b { font-size: 30px; color: #ffd24a; }
.pop.dmg.super span { background: #d8442f; }
.pop.dmg.weak b { font-size: 17px; color: #cfd6e6; }
.pop.dmg.weak span { background: #5d6b88; }
.pop.dmg.crit span:first-of-type { background: #f0a020; color: #2a1800; }
.pop.heal b { color: #8dffb2; }
.pop.miss b { font-size: 16px; color: #dfe6f7; }
.pop.st b { font-size: 13px; padding: 4px 7px; border-radius: 4px; background: #1b1f2a; text-shadow: none; }
.pop.st.brn b { color: #ff9a62; } .pop.st.par b { color: #ffe066; } .pop.st.psn b, .pop.st.tox b { color: #d58cf0; }
.pop.st.slp b { color: #c3c8d8; } .pop.st.frz b { color: #8fe3ff; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); }
  14% { opacity: 1; transform: translate(-50%, -62%) scale(1.15); }
  28% { transform: translate(-50%, -55%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -85%); }
  100% { opacity: 0; transform: translate(-50%, -105%); }
}
.scene.shake { animation: shake calc(.28s / min(var(--spd, 1), 4)) steps(6, jump-none) 1; }
.scene.shake-big { animation: shake-big calc(.42s / min(var(--spd, 1), 4)) steps(9, jump-none) 1; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translate(-4px, 2px); } 50% { transform: translate(4px, -2px); } 75% { transform: translate(-2px, 0); } }
@keyframes shake-big {
  0%, 100% { transform: none; } 15% { transform: translate(-9px, 4px); } 30% { transform: translate(9px, -5px); }
  45% { transform: translate(-7px, -3px); } 60% { transform: translate(6px, 4px); } 80% { transform: translate(-3px, 1px); }
}

/* ── with juice.js: it moves the sprites and trails the HP bar itself ── */
.scene.juice .mon { transition: none; }
.scene.juice .hpbox .fill { transition: background .2s; }

/* ── genders, conditions ── */
.g { font: 700 1em/1 var(--sans); margin-left: 3px; }
.g.m { color: #5aa9ff; } .g.f { color: #ff7fb0; }
.hpbox .g.m { color: #1f6fd6; } .hpbox .g.f { color: #d83a7c; }
.gbtn { border: 1px solid var(--line); background: var(--bg2); border-radius: 6px; padding: 0 6px; cursor: pointer; font: 700 13px/1.5 var(--sans); }
.gbtn.m { color: #5aa9ff; } .gbtn.f { color: #ff7fb0; }
.gbtn:hover { border-color: var(--accent); }
.hpbox .conds { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.hpbox .conds:empty { display: none; }
.cond { font: 700 8.5px/1 var(--pixel); padding: 2px 4px; border-radius: 3px; color: #fff; background: #6a5a9c; white-space: nowrap; }
.cond.up { background: #2f9e62; } .cond.down { background: #c9483a; }
.pip.st-psn, .pip.st-tox { box-shadow: 0 0 0 2px #a44fc4; } .pip.st-brn { box-shadow: 0 0 0 2px #e8632c; }
.pip.st-par { box-shadow: 0 0 0 2px #d6a700; } .pip.st-slp { box-shadow: 0 0 0 2px #8b8fa3; } .pip.st-frz { box-shadow: 0 0 0 2px #4fb6d8; }
.pips { align-items: center; flex-wrap: wrap; }
.sidec { font: 700 8.5px/1 var(--pixel); padding: 2px 5px; border-radius: 3px; background: rgba(20, 30, 52, .85); color: #cfe0ff; margin-left: 4px; white-space: nowrap; }
.pop.stat b { font-size: 13px; padding: 3px 6px; border-radius: 4px; text-shadow: none; }
.pop.stat.up b { background: #2f9e62; } .pop.stat.down b { background: #c9483a; }

/* ── live party ── */
.member { transition: border-color .2s, background .2s, opacity .2s; }
.member .live { display: flex; align-items: center; gap: 6px; }
.member .lbar { flex: 1; height: 7px; border-radius: 4px; background: #0d1424; border: 1px solid var(--line); overflow: hidden; }
.member .lbar i { display: block; height: 100%; background: #3bd16f; transition: width calc(.45s / var(--spd, 1)) linear, background .2s; }
.member .lbar i.mid { background: #f2c230; } .member .lbar i.low { background: #ef4d43; }
.member .lhp { font: 700 9.5px/1 var(--pixel); color: var(--dim); white-space: nowrap; min-width: 62px; text-align: right; }
.member .lst .status { margin-left: 0; }
.member.on-field { border-color: var(--accent); background: linear-gradient(90deg, rgba(47, 214, 154, .16), var(--panel2) 60%); }
.member.down { border-color: var(--danger); background: rgba(255, 107, 107, .08); }
.member.down .spr { filter: grayscale(1) brightness(.7); }
.member.down .lhp { color: var(--danger); }
.member.benched { opacity: .55; }
.member .mv.new { box-shadow: 0 0 0 1px var(--accent); color: #fff; }
.member .newitem { color: var(--accent); font-weight: 700; }

/* ── AI thinking ── */
.think { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 18px; padding: 10px 16px 12px; background: #101829; border-top: 1px solid var(--line); min-height: 112px; align-content: start; }
.think:empty::before { content: "AI thinking: the options it weighs appear here each turn."; color: var(--faint); font-size: 12.5px; }
.think-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 5px; flex-wrap: wrap; }
.think-head b { font: 700 11px/1.2 var(--pixel); color: var(--gold); }
.think-head span { color: var(--dim); font-size: 12px; }
.think-opts { display: grid; gap: 3px; }
.opt { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(40px, 1fr) 74px; gap: 8px; align-items: center; font-size: 12.5px; color: var(--dim); padding: 1px 6px; border-left: 3px solid var(--t); border-radius: 3px; }
.opt.chosen { color: var(--ink); font-weight: 700; background: rgba(47, 214, 154, .12); }
.opt .lab { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt .bar { height: 6px; border-radius: 3px; background: #1d2740; overflow: hidden; }
.opt .bar i { display: block; height: 100%; background: #5b6b8f; border-radius: 3px; }
.opt.chosen .bar i { background: var(--accent); }
.opt .out { text-align: right; font-variant-numeric: tabular-nums; }
.opt .out small { color: var(--faint); font-weight: 400; }
.log .ai { color: #8fb7ff; font-size: 11.5px; padding-left: 12px; }
.btn.off { color: var(--faint); }

/* ── run recap ── */
.recap { text-align: left; max-width: 760px; width: 100%; display: grid; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.recap-head { display: flex; justify-content: space-between; align-items: center; }
.recap h4 { margin: 0; font: 700 13px/1 var(--pixel); letter-spacing: 1px; text-transform: uppercase; color: var(--gold); }
.recap p { color: #d5def2; font-size: 14px; line-height: 1.55; }
.recap-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.recap-table th { text-align: left; font: 700 9.5px/1 var(--pixel); letter-spacing: .8px; color: var(--faint); text-transform: uppercase; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.recap-table td { padding: 3px 8px; border-bottom: 1px solid rgba(38, 51, 79, .6); vertical-align: middle; }
.recap-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.recap-table td.nm { font-weight: 700; }
.recap-table td.nm small { display: block; font-weight: 400; color: var(--dim); font-size: 11.5px; }
.recap-table td.fate { color: var(--dim); font-size: 12px; }
.recap-table tr.dead td.fate { color: #f3a0a0; }
.recap-table tr.dead .spr { filter: grayscale(1) brightness(.75); }
.recap .recap-foot { color: var(--faint); font-size: 12px; }

@media (max-width: 1000px) {
  #view-builder { grid-template-columns: minmax(0, 1fr); }
  .run-grid { grid-template-columns: minmax(0, 1fr); }
  .picker { max-height: 60vh; }
}
@media (max-width: 620px) {
  .top, .view, .foot { padding-left: 12px; padding-right: 12px; }
  .brand h1 { font-size: 15px; }
  .rules { grid-template-columns: 1fr; }
  .scene { aspect-ratio: 1 / 1.08; }
  .hpboxes { min-width: 0; width: 52%; }
  .hpbox { padding: 3px 6px 4px; border-width: 2px; }
  .hpbox .nm { font-size: 10px; }
  .hpbox .lv { font-size: 9px; }
  .mons.foe { left: 46%; width: 50%; top: 14%; height: 34%; }
  .mons.you { left: 0; width: 56%; top: 57.3%; height: 44%; }
  .hpboxes.you { bottom: 9%; }
  .msg { font-size: 12px; padding: 10px 12px; min-height: 48px; }
  .vs {
    grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; padding: 3%; gap: 4px;
    background: linear-gradient(170deg, #101a30 0 49.4%, #fff 49.4% 50.6%, #2a1320 50.6%);
  }
  .vs .col { gap: 4px; }
  .vs .mid { width: 40px; height: 40px; font-size: 15px; justify-self: center; border-width: 2px; }
  .vs .trainer { height: 52px; }
  .vs .who { font-size: 12px; }
  .vs .line .spr { --s: 40px !important; }
  .banner { font-size: 17px; }
  .runbar { gap: 12px; }
  .stage-head strong { font-size: 13px; }
  .pop b { font-size: 16px; }
  .pop.dmg.heavy b { font-size: 21px; }
  .pop span { font-size: 8px; }
  .think { min-height: 0; padding: 8px 12px; }
  .recap-table th:nth-child(5), .recap-table td:nth-child(5) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
