:root {
  --bg: #0d0b1e;
  --panel: #1a1633;
  --panel-2: #241e45;
  --border: #4a3f8c;
  --text: #e8e4ff;
  --dim: #9a90c9;
  --gold: #ffd23f;
  --red: #ff4d6d;
  --green: #4ade80;
  --ink: #0a0818;            /* darkest wells: inputs, bars, panels-in-panels */
  --shade: #362d66;          /* subtle inner borders */
  --accent2: #6d5ae0;        /* secondary accent: stat bars, alt buttons */
  --glow: #2d2461;           /* ambient radial glows */
  --title-shadow: #7c2d92;   /* hard drop shadow behind gold headings */
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-body: 'VT323', 'Courier New', monospace;
}

/* Website Brawl wears the same retro suit in deep-sea teal. */
html[data-brand="site"] {
  --bg: #06181d;
  --panel: #0e2a30;
  --panel-2: #14383f;
  --border: #2e7f86;
  --text: #e2f8fb;
  --dim: #8fc3cc;
  --ink: #051317;
  --shade: #1c4d54;
  --accent2: #2dd4bf;
  --glow: #0f4a52;
  --title-shadow: #0c6157;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% -20%, var(--glow) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.15) 3px 4px);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 60px;
}

header { text-align: center; margin-bottom: 24px; }

h1 {
  font-family: var(--font-pixel);
  font-size: clamp(20px, 4vw, 38px);
  margin: 0 0 12px;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--title-shadow), 6px 6px 0 rgba(0,0,0,.5);
  letter-spacing: 2px;
}

.tagline { color: var(--dim); margin: 0; font-size: 22px; }

.cross-link {
  display: inline-block;
  margin-top: 14px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--gold);
  text-decoration: none;
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
  transition: transform .1s;
}

.cross-link:hover { transform: translateY(-2px); border-color: var(--gold); }

/* Each brand hides the other mode's scan explanation. */
html[data-brand="domain"] .hiw-site-scan { display: none; }

/* ---------- setup ---------- */
#setup {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(720px, 100%);
  box-shadow: 0 8px 0 rgba(0,0,0,.35);
}

.mode-hint { color: var(--dim); margin: 0 0 16px; }

.input-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }

.input-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 22px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 8px;
  outline: none;
}

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

.vs-badge {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--red);
  text-shadow: 2px 2px 0 rgba(0,0,0,.6);
  flex-shrink: 0;
}

#fight-btn, #begin-battle-btn, #rematch-btn, #new-battle-btn {
  display: block;
  width: 100%;
  font-family: var(--font-pixel);
  font-size: 16px;
  padding: 16px;
  background: linear-gradient(180deg, #ff6b8a, var(--red));
  color: #fff;
  border: 3px solid #8c1d3f;
  border-radius: 10px;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0,0,0,.4);
  box-shadow: 0 5px 0 #8c1d3f;
  transition: transform .08s;
}

#fight-btn:active, #begin-battle-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8c1d3f; }
#fight-btn:disabled { opacity: .5; cursor: wait; }

.error { color: var(--red); margin: 12px 0 0; }
.hidden { display: none !important; }

/* ---------- how it works ---------- */
#how-it-works {
  width: min(720px, 100%);
  margin-top: 16px;
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 0 rgba(0,0,0,.35);
}

#how-it-works summary {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--dim);
  padding: 16px 20px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

#how-it-works summary::-webkit-details-marker { display: none; }
#how-it-works summary:hover { color: var(--gold); }
#how-it-works[open] summary { color: var(--gold); border-bottom: 2px dashed var(--border); }

.hiw-body { padding: 6px 20px 18px; }

.hiw-block h4 {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--gold);
  margin: 18px 0 6px;
}

.hiw-block p { margin: 0 0 8px; color: var(--text); line-height: 1.45; }
.hiw-block strong { color: var(--gold); font-weight: normal; }

.hiw-ring { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--dim); }

.el {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 4px 8px;
  border-radius: 12px;
  color: #0a0818;
}

.el-flame { background: #ff6b35; }
.el-flora { background: #4ade80; }
.el-terra { background: #c98d4a; }
.el-volt { background: #ffd23f; }
.el-aqua { background: #38bdf8; }
.el-cyber { background: #a78bfa; }
.el-spectre { background: #94a3b8; }

/* ---------- loading ---------- */
#loading { text-align: center; margin-top: 40px; }

.loading-orb {
  width: 60px; height: 60px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold), #b8860b);
  animation: orbit 1s ease-in-out infinite alternate;
  box-shadow: 0 0 30px var(--gold);
}

@keyframes orbit { from { transform: scale(.85); } to { transform: scale(1.1); } }

/* ---------- reveal cards ---------- */
#reveal { width: min(1000px, 100%); margin-top: 28px; }

.card-row { display: flex; gap: 16px; align-items: stretch; justify-content: center; flex-wrap: wrap; }

.card-vs {
  font-family: var(--font-pixel);
  font-size: 28px;
  color: var(--red);
  align-self: center;
  text-shadow: 3px 3px 0 rgba(0,0,0,.6);
}

.monster-card {
  flex: 1;
  min-width: 300px;
  max-width: 430px;
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  animation: cardIn .5s ease-out backwards;
}

#card-b { animation-delay: .2s; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(30px) scale(.9); }
  to { opacity: 1; transform: none; }
}

.monster-card .portrait {
  background: radial-gradient(ellipse at 50% 80%, var(--glow), var(--ink));
  border: 2px solid var(--border);
  border-radius: 10px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.monster-card .portrait svg { height: 180px; width: auto; filter: drop-shadow(0 6px 8px rgba(0,0,0,.5)); }

.monster-card h3 {
  font-family: var(--font-pixel);
  font-size: 16px;
  margin: 0 0 2px;
  color: var(--gold);
}

.monster-card .host { color: var(--dim); margin: 0 0 8px; font-size: 18px; }

.element-chip {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 5px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
  color: #0a0818;
}

.pedigree { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }

.ped-chip {
  font-size: 15px;
  background: var(--ink);
  border: 1px solid var(--shade);
  border-radius: 12px;
  padding: 3px 9px;
  color: var(--dim);
  cursor: default;
}

.tier-uncommon { border-color: #4ade80; color: #4ade80; }
.tier-rare { border-color: #38bdf8; color: #38bdf8; }
.tier-epic { border-color: #c084fc; color: #c084fc; }
.tier-legendary { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 10px rgba(255, 210, 63, .35); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin-bottom: 10px; }

.stat-row { display: flex; align-items: center; gap: 8px; font-size: 18px; }

.stat-row .label { width: 46px; color: var(--dim); font-family: var(--font-pixel); font-size: 9px; }

.stat-row .bar {
  flex: 1; height: 10px;
  background: var(--ink);
  border-radius: 5px;
  overflow: hidden;
}

.stat-row .bar > div { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--accent2), var(--gold)); }

.stat-row .val { width: 36px; text-align: right; }

.moves-list { margin: 8px 0 0; padding: 0; list-style: none; font-size: 18px; }
.moves-list li { padding: 2px 0; border-top: 1px dashed var(--shade); }
.moves-list .mv-power { color: var(--gold); float: right; }

.origin { color: var(--dim); font-size: 16px; margin-top: 10px; }

#begin-battle-btn { max-width: 420px; margin: 24px auto 0; }

/* ---------- lighthouse gym ---------- */
.train-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 12px 8px;
  background: linear-gradient(180deg, #3f9fff, #1d5fd6);
  color: #fff;
  border: 3px solid #123c8c;
  border-radius: 10px;
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(0,0,0,.4);
  box-shadow: 0 4px 0 #123c8c;
}

.train-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #123c8c; }
.train-btn:disabled { cursor: default; opacity: .85; }
.train-btn:disabled:not(.working) { background: linear-gradient(180deg, #ffd23f, #d4a017); border-color: #8c6d12; box-shadow: 0 4px 0 #8c6d12; color: #2b2103; }

.train-panel {
  margin-top: 12px;
  background: var(--ink);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  animation: cardIn .4s ease-out;
}

.lh-scores { display: flex; gap: 10px; justify-content: center; }

.lh-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid;
}

.lh-score.good { border-color: #4ade80; color: #4ade80; background: rgba(74,222,128,.08); }
.lh-score.ok { border-color: #fbbf24; color: #fbbf24; background: rgba(251,191,36,.08); }
.lh-score.bad { border-color: #f87171; color: #f87171; background: rgba(248,113,113,.08); }

.lh-num { font-family: var(--font-pixel); font-size: 13px; }
.lh-label { font-size: 12px; opacity: .8; }

.train-gains { text-align: center; margin: 10px 0 0; color: var(--green); font-size: 17px; }
.train-bonus { text-align: center; margin: 6px 0 0; color: var(--gold); font-size: 18px; }
.train-error { color: var(--red); margin: 0; text-align: center; }

/* ---------- arena ---------- */
#arena { width: min(1000px, 100%); margin-top: 28px; }

.battle-stage {
  position: relative;
  background:
    radial-gradient(ellipse at 50% 105%, #45348c55 0%, transparent 60%),
    linear-gradient(180deg, #141030, #1d1740 70%, #2a2158 70%, #221b49);
  border: 3px solid var(--border);
  border-radius: 12px;
  height: 340px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 40px 30px;
  overflow: hidden;
}

.fighter { position: relative; width: 300px; display: flex; flex-direction: column; align-items: center; }

.fighter .sprite-box { transition: transform .18s ease-out; }
.fighter .sprite-box svg { height: 190px; width: auto; filter: drop-shadow(0 10px 10px rgba(0,0,0,.55)); }

#fighter-a .sprite-box { animation: idleA 2.2s ease-in-out infinite; }
#fighter-b .sprite-box { animation: idleB 2.6s ease-in-out infinite; }

@keyframes idleA { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes idleB { 0%,100% { transform: translateY(-6px); } 50% { transform: translateY(2px); } }

.fighter.lunge-right .sprite-box { animation: none; transform: translateX(70px) scale(1.06); }
.fighter.lunge-left .sprite-box { animation: none; transform: translateX(-70px) scale(1.06); }
.fighter.hurt .sprite-box { animation: hurtShake .35s linear; }
.fighter.fainted .sprite-box { animation: none; transform: rotate(100deg) translateY(40px); opacity: .25; transition: all .8s; }

@keyframes hurtShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-12px); filter: brightness(2.4); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-8px); filter: brightness(1.8); }
  80% { transform: translateX(6px); }
}

.hp-plate {
  width: 100%;
  background: rgba(10, 8, 24, .85);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 2;
}

.hp-name { font-family: var(--font-pixel); font-size: 10px; color: var(--gold); white-space: nowrap; }

.hp-bar { flex: 1; height: 14px; background: var(--ink); border-radius: 7px; overflow: hidden; border: 1px solid var(--shade); }

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  border-radius: 7px;
  transition: width .5s ease, background .5s;
}

.hp-fill.mid { background: linear-gradient(90deg, #eab308, #facc15); }
.hp-fill.low { background: linear-gradient(90deg, #dc2626, #f87171); }

.hp-num { font-size: 16px; color: var(--dim); min-width: 70px; text-align: right; }

.dmg-pop {
  position: absolute;
  top: 40%;
  left: 50%;
  font-family: var(--font-pixel);
  font-size: 22px;
  color: var(--red);
  text-shadow: 2px 2px 0 #000;
  animation: dmgFloat 1s ease-out forwards;
  pointer-events: none;
  z-index: 5;
}

.dmg-pop.heal { color: var(--green); }
.dmg-pop.crit { color: var(--gold); font-size: 28px; }
.dmg-pop.miss { color: var(--dim); }

@keyframes dmgFloat {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -70px); }
}

.battle-controls { display: flex; gap: 10px; margin-top: 12px; justify-content: flex-end; }

.battle-controls button {
  font-family: var(--font-body);
  font-size: 18px;
  background: var(--panel-2);
  color: var(--dim);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}

#commentary {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 12px;
  margin-top: 12px;
  padding: 14px 18px;
  height: 190px;
  overflow-y: auto;
  font-size: 21px;
  line-height: 1.45;
}

#commentary p { margin: 0 0 6px; animation: lineIn .25s ease-out; }
#commentary p.turn-marker { color: var(--gold); font-family: var(--font-pixel); font-size: 10px; margin-top: 10px; }
#commentary p.effective { color: var(--green); }
#commentary p.weak { color: var(--dim); }
#commentary p.ko { color: var(--red); font-size: 24px; }

@keyframes lineIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

#result-banner {
  text-align: center;
  margin-top: 18px;
  animation: cardIn .6s ease-out;
}

#result-text {
  font-family: var(--font-pixel);
  font-size: clamp(16px, 3vw, 26px);
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--title-shadow);
}

.result-buttons { display: flex; gap: 12px; max-width: 560px; margin: 0 auto; }
.result-buttons button { flex: 1; }

#new-battle-btn { background: linear-gradient(180deg, #6d5ae0, #4a3f8c); border-color: #2d2461; box-shadow: 0 5px 0 #2d2461; }

footer { margin-top: 40px; color: var(--dim); font-size: 16px; text-align: center; max-width: 600px; }

/* ---------- Website Brawl (teal) composite overrides ---------- */
html[data-brand="site"] .battle-stage {
  background:
    radial-gradient(ellipse at 50% 105%, #2e7f8655 0%, transparent 60%),
    linear-gradient(180deg, #0a2227, #103238 70%, #175058 70%, #12424a);
}

html[data-brand="site"] .hp-plate { background: rgba(5, 19, 23, .85); }

html[data-brand="site"] #new-battle-btn {
  background: linear-gradient(180deg, #2dd4bf, #117f74);
  border-color: #0b5850;
  box-shadow: 0 5px 0 #0b5850;
}

/* Each cross-link badge wears the sister site's color as a preview. */
html[data-brand="domain"] .cross-link { border-color: #2e7f86; }
html[data-brand="site"] .cross-link { border-color: #6d5ae0; }

@media (max-width: 720px) {
  .battle-stage { height: auto; flex-direction: column; align-items: center; gap: 12px; padding-bottom: 16px; }
  .fighter .sprite-box svg { height: 130px; }
  .card-vs { display: none; }
}
