:root {
  /* game screen (.gb) tokens - unchanged */
  --ink: #0f380f;
  --paper: #f8f8f0;
  --gb-1: #e0f8d0;
  --gb-2: #88c070;
  --gb-3: #346856;
  --gb-4: #081820;
  --hp-hi: #38b848;
  --hp-mid: #f8b800;
  --hp-lo: #e83820;
  --accent: #c8282a;
  --font: 'Press Start 2P', ui-monospace, monospace;
  /* page chrome tokens (portfolio look) */
  --primary: #6366f1;
  --secondary: #8b5cf6;
  --cyan: #06b6d4;
  --darker: #020617;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --glass: rgba(30, 41, 59, 0.5);
  --glass-border: rgba(99, 102, 241, 0.1);
  --red-accent: #ef4444;
  --gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #06b6d4);
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99, 102, 241, 0.22), transparent 70%),
    var(--darker);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
}
.shell { max-width: 760px; margin: 0 auto; padding: 16px; }

/* top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 4px 0 16px; font-family: var(--sans); }
.top h1 {
  font-family: var(--sans); font-weight: 800; font-size: 28px; line-height: 1.2; margin: 0; letter-spacing: -0.5px;
  background: var(--gradient); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.back-link {
  font-family: var(--sans); font-size: 13px; font-weight: 500; color: var(--text); text-decoration: none;
  padding: 8px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); transition: border-color 0.2s, background 0.2s;
}
.back-link:hover, .back-link:focus-visible { border-color: rgba(99, 102, 241, 0.5); background: rgba(99, 102, 241, 0.15); outline: none; }
.sub, .hint, .foot { font-family: var(--sans); color: var(--muted); font-size: 13px; line-height: 1.6; }
.sub { flex-basis: 100%; margin: 0; }
.foot { margin-top: 24px; font-size: 12px; }
.hidden { display: none !important; }

.screen { display: grid; gap: 16px; }
#setup { grid-template-columns: 1fr; }
@media (min-width: 720px) { #setup { grid-template-columns: 3fr 2fr; } }
.panel {
  font-family: var(--sans); min-width: 0;
  background: var(--glass); color: var(--text);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border); border-radius: 16px; padding: 20px;
}
.panel h2 {
  font-family: var(--mono); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--primary); margin: 0 0 8px;
}
.red-panel { border-color: rgba(239, 68, 68, 0.35); background: linear-gradient(160deg, rgba(239, 68, 68, 0.1), var(--glass) 60%); }
.red-panel h2 { color: var(--red-accent); }
.red-head { display: flex; align-items: center; gap: 12px; }
.red-pic { width: 84px; height: 84px; image-rendering: pixelated; }

.team { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.team li {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--glass-border); padding-bottom: 8px;
}
.team li > div { min-width: 0; }
.team .mini { width: 40px; height: 40px; image-rendering: pixelated; }
.team .t-name { font-size: 14px; font-weight: 600; }
.team .t-name small { font-family: var(--mono); font-weight: 400; color: var(--muted); }
.team .t-moves { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.types { display: inline-flex; gap: 4px; margin-left: 4px; vertical-align: middle; }
.type { font-family: var(--mono); font-size: 9px; padding: 2px 5px; border-radius: 4px; color: #fff; background: #777; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600; padding: 10px 18px; cursor: pointer;
  background: var(--glass); color: var(--text); border: 1px solid var(--glass-border); border-radius: 999px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn:hover, .btn:focus-visible { background: rgba(99, 102, 241, 0.15); border-color: rgba(99, 102, 241, 0.5); outline: none; }
.btn.primary { background: linear-gradient(90deg, var(--primary), var(--secondary)); border-color: transparent; color: #fff; }
.btn.primary:hover, .btn.primary:focus-visible { background: linear-gradient(90deg, var(--primary), var(--secondary)); box-shadow: 0 0 24px rgba(99, 102, 241, 0.5); }
.btn.small { font-size: 12px; padding: 8px 14px; }
.check { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--primary); }
.under { justify-content: space-between; }

/* ---------- battle screen ---------- */
.gb {
  background: var(--paper); color: var(--ink);
  border: 6px solid var(--gb-4); border-radius: 8px;
  width: 100%; max-width: 640px; margin: 0 auto; overflow: hidden;
  position: relative;
}
.field { position: relative; aspect-ratio: 160 / 96; background: linear-gradient(#f8f8f0 0 60%, #e8f0d8 60%); }
.box { position: absolute; width: 48%; font-size: clamp(8px, 2.2vw, 12px); }
.box.enemy { top: 4%; left: 3%; }
.box.player { bottom: 4%; right: 3%; }
.box .nm { display: flex; gap: 6px; align-items: center; }
.box .nm { flex-wrap: wrap; margin-bottom: 3px; }
.box .lv { font-size: 0.85em; padding: 1px 4px; border-radius: 3px; background: var(--ink); color: var(--paper); }
.st { font-size: 0.8em; padding: 1px 3px; border-radius: 2px; color: #fff; background: var(--gb-3); }
.st:empty { display: none; }
.hpwrap { display: flex; align-items: center; gap: 4px; border-bottom: 3px solid var(--ink); border-left: 3px solid var(--ink); padding: 2px 4px 4px; }
.hplabel { font-size: 0.7em; background: var(--ink); color: var(--hp-mid); padding: 0 2px; }
.hpbar { flex: 1; height: 7px; border: 2px solid var(--ink); border-radius: 4px; background: #fff; overflow: hidden; }
.hpfill { height: 100%; width: 100%; background: var(--hp-hi); transition: width 0.45s steps(24), background-color 0.2s; }
.hpnum { text-align: right; margin-top: 2px; }
.balls { display: flex; gap: 3px; margin-top: 3px; font-size: 0.7em; }
.ball { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--ink); background: var(--accent); }
.ball.out { background: #bbb; }
.sprite {
  position: absolute; width: 34%; aspect-ratio: 1; display: grid; place-items: center;
  image-rendering: pixelated; background-size: contain; background-repeat: no-repeat; background-position: center bottom;
  font-size: clamp(9px, 2.6vw, 14px); text-align: center; transition: opacity 0.3s, transform 0.3s;
}
.enemy-sprite { top: 2%; right: 6%; }
.player-sprite { bottom: 14%; left: 6%; transform: scaleX(-1); }
.player-sprite.back { transform: none; }
.sprite.placeholder { border: 3px dashed var(--gb-2); border-radius: 50%; }
.player-sprite.placeholder span { display: inline-block; transform: scaleX(-1); }
.sprite.hit { animation: hit 0.35s steps(2) 2; }
.sprite.faint { opacity: 0; transform: translateY(30%); }
@keyframes hit { 50% { opacity: 0.1; } }
.weather { position: absolute; left: 3%; bottom: 4%; font-size: 8px; color: var(--gb-3); }

.textbox {
  min-height: 74px; border-top: 6px double var(--ink); padding: 12px 14px; font-size: clamp(9px, 2.4vw, 12px);
  position: relative; cursor: pointer; background: var(--paper); line-height: 2;
}
.more { position: absolute; right: 12px; bottom: 6px; animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.menu, .moves, .party { border-top: 4px solid var(--ink); display: grid; padding: 8px; gap: 6px; background: var(--paper); }
.menu { grid-template-columns: 1fr 1fr; }
.menu button, .moves button, .party button {
  font-family: var(--font); font-size: clamp(9px, 2.4vw, 12px); text-align: left; cursor: pointer;
  background: transparent; border: 2px solid transparent; padding: 8px; color: var(--ink); border-radius: 3px;
}
.menu button:hover, .moves button:hover, .party button:hover,
.menu button:focus-visible, .moves button:focus-visible, .party button:focus-visible { border-color: var(--ink); outline: none; }
.menu button::before, .moves button::before, .party button::before { content: '▶ '; visibility: hidden; }
.menu button:hover::before, .moves button:hover::before, .party button:hover::before,
.menu button:focus-visible::before, .moves button:focus-visible::before, .party button:focus-visible::before { visibility: visible; }
.moves { grid-template-columns: 1fr 1fr; }
.moves .meta { display: block; font-size: 0.7em; color: var(--gb-3); margin-top: 4px; }
.moves button:disabled, .party button:disabled { opacity: 0.4; cursor: not-allowed; }
.party { grid-template-columns: 1fr; }
.party .pline { display: flex; justify-content: space-between; gap: 8px; }
.back-btn { grid-column: 1 / -1; }

.ai {
  background: var(--gb-4); color: var(--gb-1); font-family: var(--font); font-size: 8px; padding: 10px;
  border-radius: 4px; white-space: pre-wrap; max-width: 640px; margin: 0 auto; width: 100%;
}

/* type colours */
.t-NORMAL { background: #a8a878; } .t-FIGHTING { background: #c03028; } .t-FLYING { background: #a890f0; }
.t-POISON { background: #a040a0; } .t-GROUND { background: #b8a038; } .t-ROCK { background: #b8a038; filter: brightness(0.85); }
.t-BUG { background: #a8b820; } .t-GHOST { background: #705898; } .t-STEEL { background: #a8a8c0; color: #222; }
.t-FIRE { background: #f08030; } .t-WATER { background: #6890f0; } .t-GRASS { background: #78c850; }
.t-ELECTRIC { background: #f8d030; color: #222; } .t-PSYCHIC { background: #f85888; } .t-ICE { background: #98d8d8; color: #222; }
.t-DRAGON { background: #7038f8; } .t-DARK { background: #705848; } .t-CURSE { background: #68a090; }

/* attack visuals */
.field { position: relative; }
.field.shake { animation: shake 0.25s steps(4) 1; }
.field.shake-hard { animation: shake 0.4s steps(8) 1; --amp: 7px; }
@keyframes shake { 25% { transform: translate(calc(var(--amp, 3px) * -1), 1px); } 50% { transform: translate(var(--amp, 3px), -1px); } 75% { transform: translate(calc(var(--amp, 3px) * -1), 0); } }
.sprite.lunge-p { animation: lunge-p 0.3s steps(6) 1; }
.sprite.lunge-e { animation: lunge-e 0.3s steps(6) 1; }
@keyframes lunge-p { 50% { translate: 14% -10%; } }
@keyframes lunge-e { 50% { translate: -14% 10%; } }
.orb {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; pointer-events: none; z-index: 5;
  background: radial-gradient(circle, #fff 0 25%, var(--c) 60%, transparent 72%);
  box-shadow: 0 0 10px var(--c); transition: left 0.38s linear, top 0.38s linear;
}
.orb.burst { transition: transform 0.16s, opacity 0.16s; transform: scale(3.2); opacity: 0; }
.orb-fire { border-radius: 50% 50% 50% 0; }
.orb-electric { clip-path: polygon(50% 0, 70% 40%, 100% 40%, 60% 70%, 75% 100%, 40% 70%, 0 70%, 40% 40%); border-radius: 0; background: var(--c); }
.orb-ice, .orb-rock, .orb-steel { border-radius: 3px; transform: rotate(45deg); }
.orb-psychic, .orb-ghost { box-shadow: 0 0 18px var(--c), 0 0 30px var(--c); }
.aura {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 3px solid var(--c); border-radius: 50%;
  pointer-events: none; z-index: 5; animation: aura 0.5s steps(8) 1 forwards;
}
@keyframes aura { to { transform: scale(4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .field.shake, .field.shake-hard, .sprite.lunge-p, .sprite.lunge-e { animation: none; } }

/* Crystal battle-animation BG effects (anims.js BG_CSS) */
.field.fx-invert { filter: invert(1); }
/* at most ~2.5 flashes a second (WCAG 2.3.1 allows 3) */
.field.fx-invert-rapid { animation: fx-invert 0.4s steps(1) infinite; }
@keyframes fx-invert { 50% { filter: invert(1); } }
.field.fx-white { animation: fx-white 0.3s steps(3) 1; }
@keyframes fx-white { 0%, 66% { filter: brightness(3); } }
.fx-dark { filter: brightness(0.35); transition: filter 0.3s steps(3); }
.field.fx-shake-x { animation: fx-shake-x 0.1s steps(2) infinite; }
.field.fx-shake-y { animation: fx-shake-y 0.1s steps(2) infinite; }
@keyframes fx-shake-x { 50% { transform: translateX(4px); } }
@keyframes fx-shake-y { 50% { transform: translateY(4px); } }
.sprite.fx-hide { visibility: hidden; }
#p-sprite.fx-lunge { animation: lunge-p 0.4s steps(6) 1; }
#e-sprite.fx-lunge { animation: lunge-e 0.4s steps(6) 1; }
.sprite.fx-blink { animation: blink 0.12s steps(1) infinite; }
.sprite.fx-wobble { animation: fx-wobble 0.15s steps(2) infinite; }
@keyframes fx-wobble { 50% { translate: 4px 0; } }
#p-sprite.fx-enter { animation: fx-enter-p 0.4s steps(6) 1; }
#e-sprite.fx-enter { animation: fx-enter-e 0.4s steps(6) 1; }
@keyframes fx-enter-p { from { translate: -40% 0; opacity: 0; } }
@keyframes fx-enter-e { from { translate: 40% 0; opacity: 0; } }
.sprite.fx-return { animation: fx-return 0.4s steps(6) 1 forwards; }
@keyframes fx-return { to { scale: 0.1; opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .field.fx-invert-rapid, .field.fx-shake-x, .field.fx-shake-y, .sprite.fx-blink, .sprite.fx-wobble { animation: none; }
}

/* animation objects (animobj.js), drawn by animdraw.js */
.anim-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4;
  image-rendering: pixelated; pointer-events: none;
}
