:root {
  --ink: #1b1424; --paper: #fffbea; --paper2: #f3e9c8; --red: #d8282f; --red2: #a81c22;
  --yellow: #ffd23a; --blue: #2a5ad8; --r3: #3a7ad8; --r4: #9a4ad8; --r5: #f0b020; --green: #3a9a4a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--ink); }
body { font-family: 'DotGothic16', monospace; color: var(--ink); -webkit-font-smoothing: none; user-select: none; }
#wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#stage { position: relative; width: 960px; height: 630px; transform-origin: center; overflow: hidden; background: var(--ink); }
canvas { image-rendering: pixelated; display: block; }
img.px { image-rendering: pixelated; }

/* ---------- shared pieces ---------- */
.screen { position: absolute; inset: 0; }
.speed { background:
  radial-gradient(circle at 50% 46%, #fff6d0 0 70px, transparent 230px),
  repeating-conic-gradient(from 3deg at 50% 46%, var(--red) 0 5deg, var(--red2) 5deg 10deg); }
.tone::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(rgba(27,20,36,.18) 1px, transparent 1.4px) 0 0 / 6px 6px; }
.win { background: var(--paper); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--paper2), 4px 4px 0 var(--ink); }
.win h2 { background: var(--red); color: #fff; margin: -3px -3px 10px; padding: 6px 12px; font-size: 20px; letter-spacing: 1px;
  border: 3px solid var(--ink); text-shadow: 2px 2px 0 var(--ink); }
.btn { font: inherit; font-size: 18px; cursor: pointer; background: var(--yellow); color: var(--ink); border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink); padding: 6px 14px; position: relative; top: 0; }
.btn:hover { background: #fff; }
.btn:active { top: 3px; box-shadow: 0 1px 0 var(--ink); }
.btn.red { background: var(--red); color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.btn.red:hover { background: #ff4048; }
.btn.blue { background: var(--blue); color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.btn:disabled { background: #b8b0a0; color: #6a6070; cursor: default; }
.btn.small { font-size: 14px; padding: 3px 8px; box-shadow: 0 3px 0 var(--ink); }
.gems { display: inline-flex; align-items: center; gap: 6px; font-size: 20px; background: var(--paper); border: 3px solid var(--ink);
  padding: 2px 10px; box-shadow: 3px 3px 0 var(--ink); }
.gem { width: 14px; height: 14px; background: #5ad8f0; border: 2px solid var(--ink); transform: rotate(45deg); box-shadow: inset 3px 3px 0 #c8f4ff; }
.stars { color: var(--yellow); text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); letter-spacing: 1px; }
.stars .off { color: #6a6070; }
.r3 { --rc: var(--r3); } .r4 { --rc: var(--r4); } .r5 { --rc: var(--r5); }
.card { position: relative; background: var(--paper); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--rc, #888), 3px 3px 0 var(--ink); cursor: pointer; text-align: center; }
.card img { display: block; margin: 4px auto 0; }
.card .nm { font-size: 11px; line-height: 1.1; padding: 0 3px 4px; height: 28px; overflow: hidden; }
.card .rar { position: absolute; top: 3px; left: 5px; font-size: 11px; color: var(--rc); text-shadow: 1px 1px 0 var(--ink); }
.card .lb { position: absolute; top: 3px; right: 5px; font-size: 11px; background: var(--ink); color: var(--yellow); padding: 0 3px; }
.card.on { background: #fff3b0; transform: translateY(-3px); }
.card.locked { filter: grayscale(1); opacity: .55; }
.back { position: absolute; top: 14px; left: 14px; z-index: 5; }
.topright { position: absolute; top: 14px; right: 14px; z-index: 5; }
.title-bar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%) rotate(-2deg); background: var(--yellow); border: 3px solid var(--ink);
  padding: 4px 24px; font-size: 26px; box-shadow: 5px 5px 0 var(--ink); z-index: 4; white-space: nowrap; }

/* ---------- hub ---------- */
.logo { position: absolute; top: 60px; left: 0; right: 0; text-align: center; transform: rotate(-4deg); }
.logo .kanji { font-size: 120px; line-height: 1; color: var(--yellow); letter-spacing: 8px;
  text-shadow: 6px 0 0 var(--ink), -6px 0 0 var(--ink), 0 6px 0 var(--ink), 0 -6px 0 var(--ink), 6px 6px 0 var(--ink), -6px -6px 0 var(--ink), 6px -6px 0 var(--ink), -6px 6px 0 var(--ink), 12px 12px 0 var(--ink); }
.logo .en { display: inline-block; margin-top: 8px; font-size: 30px; background: var(--ink); color: #fff; padding: 2px 18px; letter-spacing: 10px; }
.menu { position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); display: grid; grid-template-columns: repeat(4, 180px); gap: 14px; }
.menu .btn { font-size: 20px; padding: 10px 0; }
.parade { position: absolute; left: 0; right: 0; bottom: 168px; height: 72px; overflow: hidden; }
.parade img { position: absolute; bottom: 0; image-rendering: pixelated; }

/* ---------- campaign ---------- */
.regions { position: absolute; top: 80px; left: 30px; right: 30px; bottom: 30px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.region { display: flex; flex-direction: column; padding: 0 10px 12px; }
.region h2 { font-size: 16px; }
.lvl { display: block; width: 100%; margin-top: 12px; text-align: left; font-size: 15px; padding: 8px 10px; }
.lvl small { display: block; font-size: 12px; opacity: .8; }
.lvl.boss { background: #ffb0b0; }
.lvl .bossimg { float: right; margin: -4px -4px 0 0; }

/* ---------- squad / index ---------- */
.slots { position: absolute; top: 70px; left: 24px; right: 24px; height: 128px; display: flex; gap: 10px; align-items: center; padding: 10px 14px; }
.slot { width: 82px; height: 104px; border: 3px dashed #8a8070; display: flex; align-items: center; justify-content: center; color: #8a8070; font-size: 12px; }
.slot .card { width: 82px; height: 104px; }
.grid { position: absolute; left: 24px; right: 24px; overflow-y: auto; display: grid; grid-template-columns: repeat(10, 82px); gap: 10px; padding: 10px 14px 14px; align-content: start; }
.grid .card { width: 82px; height: 104px; }
.grid::-webkit-scrollbar { width: 10px; } .grid::-webkit-scrollbar-thumb { background: var(--ink); }
.info { position: absolute; padding: 10px 14px; font-size: 14px; line-height: 1.35; }
.info b { font-size: 18px; }
.br { margin-top: 6px; padding: 4px 6px; border-left: 4px solid var(--r4); background: #fff; }
.br.b2 { border-color: var(--r3); }

/* ---------- battle ---------- */
#cv { position: absolute; left: 0; top: 0; width: 960px; height: 540px; cursor: crosshair; }
.hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 3; }
.hud > * { pointer-events: auto; }
.chip { background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 2px 10px; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.chip .ic { width: 12px; height: 12px; border: 2px solid var(--ink); }
.hud .sp { flex: 1; }
.bossbar { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); width: 420px; z-index: 3; display: none; }
.bossbar .nm { font-size: 16px; color: #fff; text-shadow: 2px 2px 0 var(--ink); text-align: center; }
.bossbar .bb { height: 14px; border: 3px solid var(--ink); background: #3a2a3a; box-shadow: 3px 3px 0 var(--ink); }
.bossbar .bb i { display: block; height: 100%; background: linear-gradient(#ff6a5a 0 40%, var(--red) 40%); }
.bar { position: absolute; left: 0; right: 0; top: 540px; height: 90px; background: var(--red); border-top: 3px solid var(--ink); display: flex; gap: 8px; padding: 8px 10px; align-items: center; }
.bar .card { width: 68px; height: 72px; flex: none; }
.bar .card img { margin-top: 2px; }
.bar .card .cost { font-size: 13px; line-height: 1; display: flex; align-items: center; justify-content: center; gap: 3px; }
.bar .card .key { position: absolute; bottom: 2px; left: 4px; font-size: 10px; opacity: .6; }
.bar .card.used { filter: grayscale(1) brightness(.8); }
.bar .card.poor .cost { color: var(--red); }
.coin { width: 10px; height: 10px; background: var(--yellow); border: 2px solid var(--ink); border-radius: 50%; display: inline-block; }
.bar .ctl { margin-left: auto; display: flex; gap: 8px; }
.panel { position: absolute; width: 300px; z-index: 6; padding: 0 12px 12px; font-size: 13px; }
.panel h2 { font-size: 16px; display: flex; justify-content: space-between; }
.panel .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.panel .stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; text-align: center; }
.panel .stat div { background: #fff; border: 2px solid var(--ink); padding: 2px; }
.panel .stat small { display: block; font-size: 10px; opacity: .7; }
.panel .up { width: 100%; text-align: left; font-size: 13px; padding: 5px 8px; }
.panel .up small { display: block; font-size: 11px; opacity: .85; margin-top: 2px; }
.cutin { position: absolute; left: 0; right: 0; top: 190px; height: 130px; z-index: 8; pointer-events: none; overflow: hidden; display: none; }
.cutin .band { position: absolute; inset: 0; background: repeating-linear-gradient(-12deg, var(--ink) 0 14px, #2e2440 14px 28px); border-top: 4px solid var(--yellow); border-bottom: 4px solid var(--yellow); animation: band .9s ease-out; }
.cutin img { position: absolute; left: 120px; top: 2px; animation: slide .9s ease-out; }
.cutin .tx { position: absolute; left: 300px; top: 30px; color: #fff; animation: slide2 .9s ease-out; }
.cutin .tx b { display: block; font-size: 34px; color: var(--yellow); text-shadow: 3px 3px 0 var(--red2); }
.cutin .tx span { font-size: 18px; }
@keyframes band { from { transform: scaleY(0); } 30% { transform: scaleY(1); } }
@keyframes slide { from { transform: translateX(-300px); } 40% { transform: translateX(0); } }
@keyframes slide2 { from { transform: translateX(400px); opacity: 0; } 40% { transform: translateX(0); opacity: 1; } }
.callout { position: absolute; top: 120px; left: 50%; transform: translateX(-50%) rotate(-3deg); z-index: 7; pointer-events: none; font-size: 40px; color: var(--yellow);
  text-shadow: 4px 0 var(--ink), -4px 0 var(--ink), 0 4px var(--ink), 0 -4px var(--ink), 6px 6px 0 var(--red2); white-space: nowrap; animation: pop 1.4s ease-out forwards; }
@keyframes pop { 0% { transform: translateX(-50%) rotate(-3deg) scale(2.4); opacity: 0; } 15% { transform: translateX(-50%) rotate(-3deg) scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translate(4px, -2px); } 50% { transform: translate(-4px, 2px); } 75% { transform: translate(2px, 3px); } }
.modal { position: absolute; inset: 0; background: rgba(27, 20, 36, .7); z-index: 9; display: flex; align-items: center; justify-content: center; }
.modal .win { width: 440px; padding: 0 18px 18px; text-align: center; }
.modal .big { font-size: 46px; margin: 4px 0; }
.modal .row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

/* ---------- summon ---------- */
.banner { position: absolute; top: 80px; left: 40px; width: 560px; height: 400px; overflow: hidden; }
.banner .art { position: absolute; inset: 0; }
.banner .lineup { position: absolute; bottom: 70px; left: 0; right: 0; display: flex; justify-content: center; align-items: flex-end; gap: 2px; }
.banner .caption { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ink); color: #fff; padding: 8px 16px; font-size: 15px; }
.banner .caption b { color: var(--yellow); font-size: 22px; display: block; }
.side { position: absolute; top: 80px; right: 40px; width: 300px; padding: 0 16px 16px; font-size: 14px; line-height: 1.5; }
.side .btn { width: 100%; margin-top: 10px; font-size: 18px; }
.reveal { position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.reveal .cards { display: grid; grid-template-columns: repeat(5, 120px); gap: 14px; }
.reveal .card { width: 120px; height: 150px; cursor: default; }
.reveal .card.hide { background: var(--ink); box-shadow: inset 0 0 0 3px var(--rc), 3px 3px 0 #000; }
.reveal .card.hide > * { visibility: hidden; }
.reveal .card.flip { animation: flip .35s; }
.reveal .card .tag { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; font-size: 11px; padding: 0 5px; border: 2px solid var(--ink); white-space: nowrap; }
.reveal .card.r5:not(.hide) { box-shadow: inset 0 0 0 3px var(--r5), 0 0 0 4px var(--yellow), 0 0 24px 8px #ffd23a; }
@keyframes flip { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.settings { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); width: 520px; padding: 0 20px 20px; font-size: 16px; }
.settings label { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.settings input[type=range] { width: 240px; accent-color: var(--red); }
.settings textarea { width: 100%; height: 70px; font: 11px monospace; margin-top: 8px; border: 2px solid var(--ink); }
.toast { position: absolute; bottom: 110px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 6px 14px; z-index: 10; font-size: 15px; border: 2px solid var(--yellow); }
