:root {
  --ink: #14121f;
  --bg: #1a1730;
  --bg2: #221e3d;
  --panel: #2b2650;
  --panel2: #362f63;
  --line: #4a4282;
  --text: #f2f0ff;
  --muted: #a79fd6;
  --blue: #4cc9ff;
  --red: #ff5470;
  --yellow: #ffd23f;
  --green: #7dff7a;
  --purple: #b77cff;
  --px: 3px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.025) 75%),
    linear-gradient(45deg, rgba(255,255,255,.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.025) 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
  color: var(--text);
  font-family: 'VT323', monospace; font-size: 21px; line-height: 1.15;
  -webkit-font-smoothing: none;
}
h1, h2, h3, button, .btn, .tag, label.small, .pix { font-family: 'Silkscreen', monospace; letter-spacing: .5px; }
h1 { font-size: 30px; margin: 0; }
h2 { font-size: 20px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--yellow); }
a { color: var(--blue); }
img.icon, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
img.icon { vertical-align: middle; }

#app { max-width: 1180px; margin: 0 auto; padding: 14px 16px 60px; }

/* pixel border */
.panel, .btn, button, input, select, textarea, .card {
  box-shadow: 0 calc(var(--px) * -1) 0 var(--ink), 0 var(--px) 0 var(--ink), calc(var(--px) * -1) 0 0 var(--ink), var(--px) 0 0 var(--ink);
  border: none; border-radius: 0;
}
.panel { background: var(--panel); padding: 14px; margin: var(--px); position: relative; }
.panel.inset { background: var(--bg2); }
.panel + .panel { margin-top: 16px; }

button, .btn {
  font-size: 13px; color: var(--text); background: var(--panel2); padding: 9px 13px 8px; cursor: pointer;
  margin: var(--px); display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  box-shadow: 0 calc(var(--px) * -1) 0 var(--ink), 0 var(--px) 0 var(--ink), calc(var(--px) * -1) 0 0 var(--ink), var(--px) 0 0 var(--ink), inset 0 calc(var(--px) * -1) 0 rgba(0,0,0,.35), inset 0 var(--px) 0 rgba(255,255,255,.12);
}
button:hover, .btn:hover { background: #443b7a; }
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 calc(var(--px) * -1) 0 var(--ink), 0 var(--px) 0 var(--ink), calc(var(--px) * -1) 0 0 var(--ink), var(--px) 0 0 var(--ink), inset 0 var(--px) 0 rgba(0,0,0,.35); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.primary { background: #2f8f4a; } button.primary:hover { background: #38a857; }
button.danger { background: #8e2236; } button.danger:hover { background: #a82a42; }
button.gold { background: #b07a14; color: #fff; } button.gold:hover { background: #c98d1a; }
button.small { font-size: 11px; padding: 6px 9px 5px; }
button.on { background: #2269a8; }

input, select, textarea {
  background: var(--bg2); color: var(--text); font-family: 'VT323', monospace; font-size: 20px; padding: 5px 8px; margin: var(--px);
}
input[type=color] { padding: 0; width: 44px; height: 32px; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--yellow); box-shadow: none; background: none; padding: 0; }
textarea.code { width: 100%; min-height: 380px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; line-height: 1.45; tab-size: 2; white-space: pre; color: #d9f7ff; background: #120f22; resize: vertical; }
label { display: block; }
label.small { font-size: 11px; color: var(--muted); margin: 6px 0 2px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.split { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.split.wide { grid-template-columns: minmax(0, 1fr) 380px; }
.muted { color: var(--muted); }
.warn { color: var(--yellow); }
.bad { color: var(--red); }
.good { color: var(--green); }
.center { text-align: center; }

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; }

/* home */
.home { text-align: center; padding-top: 10px; }
.logo { width: min(560px, 92%); image-rendering: pixelated; display: block; margin: 0 auto 6px; }
.home .tagline { color: var(--muted); margin-bottom: 22px; font-size: 24px; }
.menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; max-width: 900px; margin: 0 auto; }
.menu button { flex-direction: column; padding: 18px 10px 14px; font-size: 15px; gap: 10px; }
.menu button small { font-family: 'VT323', monospace; font-size: 18px; color: var(--muted); letter-spacing: 0; }
.menu button.big { grid-column: 1 / -1; background: #2f8f4a; font-size: 20px; }
.home-ball { display: block; margin: 0 auto 10px; }

/* lists & cards */
.list { display: flex; flex-direction: column; gap: 8px; max-height: 620px; overflow-y: auto; padding: 4px; }
.item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: var(--bg2); cursor: pointer; box-shadow: 0 0 0 2px var(--ink); }
.item:hover { background: #2d2852; }
.item.sel { background: #3c3470; box-shadow: 0 0 0 2px var(--yellow); }
.item img { width: 36px; height: 36px; image-rendering: pixelated; }
.item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 9px; padding: 2px 5px; background: var(--ink); color: var(--muted); }
.tag.y { color: var(--yellow); } .tag.b { color: var(--blue); } .tag.g { color: var(--green); } .tag.r { color: var(--red); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card { background: var(--panel); padding: 12px; margin: var(--px); display: flex; flex-direction: column; gap: 6px; }
.card .thumb { height: 90px; display: flex; align-items: center; justify-content: center; background: var(--bg2); }
.card .thumb img, .card .thumb canvas { image-rendering: pixelated; max-height: 84px; }
.card .t { font-family: 'Silkscreen', monospace; font-size: 13px; }

/* stat sliders */
.stat { display: grid; grid-template-columns: 90px 1fr 40px; gap: 8px; align-items: center; }
.pips { display: flex; gap: 3px; }
.pip { flex: 1; height: 14px; background: var(--bg2); box-shadow: 0 0 0 2px var(--ink); cursor: pointer; }
.pip.on { background: var(--yellow); }
.param { display: grid; grid-template-columns: 140px 1fr 56px; gap: 8px; align-items: center; }
.param .v { text-align: right; color: var(--yellow); }

.meter { height: 14px; background: var(--bg2); box-shadow: 0 0 0 3px var(--ink); position: relative; margin: 8px 3px; }
.meter > div { height: 100%; background: var(--green); }
.meter.over > div { background: var(--red); }

.part { background: var(--bg2); padding: 10px; margin: 10px 3px; box-shadow: 0 0 0 3px var(--ink); }
.part-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.part-h .t { font-family: 'Silkscreen', monospace; font-size: 14px; flex: 1; }
.rule { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; background: var(--bg2); padding: 6px; margin: 8px 3px; box-shadow: 0 0 0 3px var(--ink); }
.rule .kw { font-family: 'Silkscreen', monospace; font-size: 11px; color: var(--yellow); padding: 0 4px; }
.rule input[type=number] { width: 66px; }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }

/* arena */
.arena-wrap { position: relative; width: 100%; max-width: 640px; margin: 0 auto; background: var(--ink); padding: var(--px); }
.arena-wrap canvas { width: 100%; display: block; aspect-ratio: 1 / 1; cursor: crosshair; }
.hud { max-width: 640px; margin-left: auto; margin-right: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.teambar { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 200px; }
.teambar .bar { flex: 1; height: 12px; background: #3a2030; box-shadow: 0 0 0 2px var(--ink); }
.teambar .bar > div { height: 100%; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,18,31,.72); }
.overlay .panel { text-align: center; min-width: 300px; max-width: 90%; }
.stars { font-size: 0; margin: 10px 0; }
.stars img { margin: 0 4px; }
.stars img.off { filter: grayscale(1) brightness(.4); }

/* campaign map */
.worlds { display: flex; flex-direction: column; gap: 14px; }
.world { padding: 12px; box-shadow: 0 0 0 3px var(--ink); position: relative; }
.world h3 { color: #fff; text-shadow: 2px 2px 0 var(--ink); display: flex; align-items: center; gap: 10px; }
.nodes { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 8px; }
.node { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--panel2); cursor: pointer; font-family: 'Silkscreen', monospace; font-size: 14px; box-shadow: 0 0 0 3px var(--ink), inset 0 -3px 0 rgba(0,0,0,.3); position: relative; padding: 0; margin: 0; }
.node.done { background: #2f8f4a; }
.node.next { background: #b07a14; animation: bob 1s steps(2) infinite; }
.node.locked { background: #3a3550; color: #6f6896; cursor: not-allowed; }
.node.boss { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.2) 0 4px, transparent 4px 8px); }
.node .st { font-size: 8px; color: var(--yellow); letter-spacing: 1px; }
@keyframes bob { 50% { transform: translateY(-3px); } }

.vs { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 14px; align-items: start; }
.vs .mid { font-family: 'Silkscreen', monospace; font-size: 30px; color: var(--red); align-self: center; text-shadow: 3px 3px 0 var(--ink); }
.slot { background: var(--bg2); padding: 8px; margin: 8px 3px; box-shadow: 0 0 0 3px var(--ink); display: flex; gap: 10px; align-items: center; }
.slot img { width: 48px; height: 48px; image-rendering: pixelated; }
.slot select { flex: 1; min-width: 0; width: calc(100% - 6px); max-width: 100%; }

.bracket { display: flex; gap: 22px; overflow-x: auto; padding: 8px 4px; }
.round { display: flex; flex-direction: column; justify-content: space-around; gap: 10px; min-width: 170px; }
.match { background: var(--bg2); box-shadow: 0 0 0 3px var(--ink); }
.match div { padding: 4px 8px; display: flex; gap: 6px; align-items: center; }
.match div img { width: 22px; height: 22px; }
.match .w { background: #2f6a3e; }
.match .l { opacity: .5; text-decoration: line-through; }
.match.live { box-shadow: 0 0 0 3px var(--yellow); }

.tools { display: flex; flex-wrap: wrap; gap: 2px; }
.console { background: #0d0b18; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: #b9f5c2; padding: 8px; height: 120px; overflow-y: auto; white-space: pre-wrap; box-shadow: 0 0 0 3px var(--ink); margin: 3px; }
.console .err { color: #ff8a9a; }
.docs { font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.5; color: #cfc8f5; max-height: 380px; overflow-y: auto; white-space: pre-wrap; }
.docs b { color: var(--yellow); font-weight: normal; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: var(--panel2); padding: 8px 14px; font-family: 'Silkscreen', monospace; font-size: 12px; box-shadow: 0 0 0 3px var(--ink); animation: fadein .2s steps(3); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }

.modal-bg { position: fixed; inset: 0; background: rgba(10,8,20,.75); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.modal .btns { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.modal textarea { width: 100%; min-height: 110px; }
.modal input[type=text] { width: 100%; }
.chart { width: 100%; height: 140px; background: var(--bg2); box-shadow: 0 0 0 3px var(--ink); margin: 3px; }
.foot { text-align: center; color: var(--muted); margin-top: 30px; font-size: 18px; }

@media (max-width: 860px) {
  .split, .split.wide, .grid2, .vs { grid-template-columns: minmax(0, 1fr); }
  .vs .mid { text-align: center; }
  .nodes { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .param { grid-template-columns: 110px 1fr 48px; }
  body { font-size: 19px; }
}

/* fullscreen battles: arena fills the screen, controls float as liquid-glass pills */
.battle:fullscreen { background: radial-gradient(circle at 50% 30%, #2a2450, #0b0916 70%); display: flex; align-items: center; justify-content: center; padding: 0; }
.battle:fullscreen .arena-wrap { max-width: none; width: min(100vw, 100vh); padding: 0; background: transparent; }
.battle:fullscreen .arena-wrap canvas { cursor: default; }
.battle:fullscreen .hud {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: calc(100vw - 32px); width: max-content;
  margin: 0; padding: 10px 14px; gap: 8px; border-radius: 26px;
  background: linear-gradient(135deg, rgba(255,255,255,.18), rgba(255,255,255,.05));
  backdrop-filter: blur(18px) saturate(180%); -webkit-backdrop-filter: blur(18px) saturate(180%);
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: 0 10px 40px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.45), inset 0 -1px 0 rgba(255,255,255,.08);
}
.battle:fullscreen .teambar { min-width: 220px; }
.battle:fullscreen .teambar .bar { height: 10px; border-radius: 6px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); background: rgba(0,0,0,.35); }
.battle:fullscreen .hud button {
  margin: 0; border-radius: 999px; padding: 8px 14px; font-size: 11px; color: #fff;
  background: linear-gradient(180deg, rgba(255,255,255,.26), rgba(255,255,255,.07));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.32);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 2px 10px rgba(0,0,0,.25);
  text-shadow: 0 1px 2px rgba(0,0,0,.4); transition: background .15s, transform .1s;
}
.battle:fullscreen .hud button:hover { background: linear-gradient(180deg, rgba(255,255,255,.38), rgba(255,255,255,.12)); }
.battle:fullscreen .hud button:active { transform: scale(.95); box-shadow: inset 0 1px 0 rgba(255,255,255,.3); }
.battle:fullscreen .hud button.on { background: linear-gradient(180deg, rgba(120,200,255,.6), rgba(76,201,255,.22)); border-color: rgba(160,225,255,.7); }
.battle:fullscreen .hud .pix { color: rgba(255,255,255,.85); }
.battle:fullscreen .overlay .panel { border-radius: 24px; background: linear-gradient(135deg, rgba(255,255,255,.2), rgba(255,255,255,.06)); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,.3); box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.45); }
.battle:fullscreen .overlay .panel button { border-radius: 999px; background: linear-gradient(180deg, rgba(255,255,255,.26), rgba(255,255,255,.07)); border: 1px solid rgba(255,255,255,.32); box-shadow: inset 0 1px 0 rgba(255,255,255,.55); }
.battle:fullscreen .overlay .panel button.primary { background: linear-gradient(180deg, rgba(125,255,122,.55), rgba(47,143,74,.35)); }

.pip.locked { background: repeating-linear-gradient(45deg, #2a2540 0 3px, #1a1730 3px 6px); cursor: not-allowed; }
