/* Iron Legion v2 — pixel war theme (Fusion Pixel font + AI-generated UI kit) */
@font-face {
  font-family: 'PixelZh';
  src: url('/fonts/pixel-zh.woff2') format('woff2');
  font-display: swap;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: #0b0d14; color: #e8ecf4; font-family: PixelZh, "Segoe UI", system-ui, sans-serif; overflow: hidden; }
body { position: fixed; inset: 0; width: 100%; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

#wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #07080d; }
#stage { position: relative; width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16/9; background: #0b0d14; overflow: hidden; }
@supports (height: 100dvh) {
  #stage { width: min(100vw, calc(100dvh * 16 / 9)); max-height: 100dvh; }
}
#stage canvas { position: absolute !important; inset: 0; image-rendering: pixelated; }

/* ---------- pixel frame helpers ---------- */
.px-plaque {
  border: 12px solid transparent;
  border-image: url('../assets/ui/plaque.webp') 60 fill / 12px stretch;
  image-rendering: pixelated;
}
.px-panel {
  border: 20px solid transparent;
  border-image: url('../assets/ui/panel.webp') 78 fill / 20px stretch;
  image-rendering: pixelated;
}
.px-card {
  border: 10px solid transparent;
  border-image: url('../assets/ui/card.webp') 62 / 10px stretch;
  image-rendering: pixelated;
}

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 9%;
  display: flex; align-items: center; gap: 1%; padding: 0 1%;
  background: linear-gradient(rgba(6,8,13,.9), rgba(6,8,13,.5) 80%, transparent);
  z-index: 20; pointer-events: none; font-size: clamp(11px, 2.3vmin, 19px);
}
#topbar > * { pointer-events: auto; }
.stat {
  display: flex; align-items: center; gap: .35em;
  border: 8px solid transparent;
  border-image: url('../assets/ui/plaque.webp') 60 fill / 8px stretch;
  padding: .05em .45em; font-weight: 700; white-space: nowrap;
}
.stat .ico { font-style: normal; }
#st-hp b { color: #ff6b6b; } #st-gold b { color: #ffd166; }
#st-wave b { color: #55d7ff; } #st-kills b { color: #ff9f43; }
#st-streak b { color: #39ffa0; }
.tb-spacer { flex: 1; }
.tb-btn {
  border: 8px solid transparent;
  border-image: url('../assets/ui/plaque.webp') 60 fill / 8px stretch;
  padding: .05em .55em; font-weight: 700; color: #cfd6e4; text-decoration: none; display: inline-block;
}
.tb-btn:active { transform: scale(.95); }

/* ---------- synergy panel ---------- */
#traits {
  position: absolute; left: .8%; top: 12%; z-index: 18; display: flex; flex-direction: column; gap: .4vmin;
  font-size: clamp(10px, 2vmin, 16px); max-width: 19%;
}
.trait {
  display: flex; align-items: center; gap: .4em; padding: .14em .5em;
  background: rgba(14,17,28,.82); border: 1px solid rgba(255,255,255,.12);
  color: #8a93a8; transition: .15s; image-rendering: pixelated;
}
.trait.on { color: #ffe9b0; border-color: rgba(255,209,102,.6); background: rgba(46,36,18,.9);
  box-shadow: 0 0 10px rgba(255,209,102,.15); }
.trait.on .t-cnt { color: #39ffa0; }
.trait .t-cnt { font-weight: 800; margin-left: auto; }

/* ---------- bottom dock ---------- */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  background: linear-gradient(transparent, rgba(5,7,11,.9) 30%);
  padding: 3% 1% calc(.7% + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: .5vmin;
  transition: transform .25s;
}
#dock.hide { transform: translateY(103%); }

#army-row { display: flex; gap: .6%; justify-content: center; min-height: 8vmin; }
.chip {
  position: relative; width: 8vmin; height: 8vmin;
  border: 8px solid transparent;
  border-image: url('../assets/ui/card.webp') 62 / 8px stretch;
  background: rgba(18,20,32,.85); overflow: visible; image-rendering: pixelated;
}
.chip img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.chip .stars { position: absolute; top: -2.2vmin; left: 0; right: 0; text-align: center; font-size: 1.7vmin; color: #ffd166; text-shadow: 0 1px 2px #000; }
.chip .fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 4vmin; }
.chip.sel { filter: brightness(1.35) drop-shadow(0 0 8px rgba(255,209,102,.6)); }
.chip .sell {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: -3.6vmin;
  background: #7a2c2c; border: 1px solid #ff8f8f; color: #ffd9d9;
  font-size: 1.8vmin; padding: .2vmin 1vmin; white-space: nowrap; z-index: 5;
}

#shop-row { display: flex; gap: .8%; justify-content: center; align-items: stretch; }
.scard {
  width: 13.5%; padding: .5vmin .4vmin .4vmin; text-align: center; position: relative; transition: .12s;
  border: 10px solid transparent;
  border-image: url('../assets/ui/card.webp') 62 / 10px stretch;
  background: linear-gradient(180deg, rgba(30,35,54,.92), rgba(15,17,28,.95));
  image-rendering: pixelated;
}
.scard:not(.empty):hover { transform: translateY(-.4vmin); filter: brightness(1.15); }
.scard img { width: 100%; height: 6.8vmin; object-fit: contain; image-rendering: pixelated; }
.scard .fallback { height: 6.8vmin; display: flex; align-items: center; justify-content: center; font-size: 4.4vmin; }
.scard .nm { font-size: 1.9vmin; font-weight: 700; line-height: 1.15; }
.scard .tr { font-size: 1.5vmin; color: #9aa3b8; }
.scard .sk { font-size: 1.4vmin; color: #7d879c; line-height: 1.25; min-height: 2.5em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.scard .cost { position: absolute; top: 0; right: .2vmin; font-size: 1.9vmin; font-weight: 800; color: #ffd166; text-shadow: 0 1px 2px #000; }
.scard .own {
  position: absolute; top: 0; left: .2vmin; font-size: 1.5vmin; font-weight: 700;
  color: #9aa3b8; text-shadow: 0 1px 2px #000;
}
.scard .own.hot { color: #ffe066; animation: hotpulse 1s infinite; }
.scard.mergeable { filter: brightness(1.18) drop-shadow(0 0 8px rgba(255,209,102,.55)); }
@keyframes hotpulse { 50% { transform: scale(1.15); } }
.sbtn.lvl { color: #b9c1d2; font-weight: 700; cursor: default; }
.sbtn.lvl b { color: #55d7ff; }
.scard.empty { opacity: 0; pointer-events: none; }
.scard.c1 { box-shadow: inset 0 -4px 0 #9aa3b5; } .scard.c2 { box-shadow: inset 0 -4px 0 #4ade80; }
.scard.c3 { box-shadow: inset 0 -4px 0 #38bdf8; } .scard.c4 { box-shadow: inset 0 -4px 0 #c084fc; }
.scard.c5 { box-shadow: inset 0 -4px 0 #ffd166; }
.scard.deal { animation: deal .25s; }
@keyframes deal { from { transform: translateY(2vmin); opacity: 0; } }

#shop-btns { display: flex; gap: .8%; justify-content: center; align-items: center; font-size: clamp(11px, 2.2vmin, 18px); }
.sbtn {
  border: 10px solid transparent;
  border-image: url('../assets/ui/plaque.webp') 60 fill / 10px stretch;
  padding: .1vmin 1.2vmin; font-weight: 700; color: #cfd6e4; image-rendering: pixelated;
}
.sbtn:active { transform: scale(.96); }
.sbtn.gold { color: #ffd166; }
.sbtn.lock.on { color: #ff9f43; filter: brightness(1.3); }
#btn-fight {
  color: #b6ffce; font-size: clamp(13px, 2.7vmin, 23px); font-weight: 800;
  filter: drop-shadow(0 0 10px rgba(47,224,141,.35));
  padding: .2vmin 2.6vmin;
}
#btn-fight:disabled { filter: grayscale(1); opacity: .5; }

/* ---------- battle HUD ---------- */
#speed-ui { position: absolute; right: 1%; bottom: 1.5%; z-index: 22; display: none; gap: .5vmin; }
#speed-ui.show { display: flex; }

#feed {
  position: absolute; top: 12%; left: 0; right: 0; text-align: center; z-index: 15; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: .5vmin;
}
.feed-line {
  border: 9px solid transparent;
  border-image: url('../assets/ui/plaque.webp') 60 fill / 9px stretch;
  color: #ffd166; font-size: clamp(11px, 2.3vmin, 18px); font-weight: 700; padding: 0 1em;
  animation: feedin .3s; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
  image-rendering: pixelated;
}
.feed-line.warn { color: #ff6b6b; font-size: clamp(13px, 2.9vmin, 23px); }
@keyframes feedin { from { transform: translateY(-1em); opacity: 0; } }

/* ---------- story dialogue ---------- */
.ov.story { align-items: flex-end; background: rgba(4,5,9,.5); }
.story-box {
  width: min(96%, 900px); margin-bottom: 3%;
  display: flex; gap: 14px; align-items: flex-end;
  border: 18px solid transparent;
  border-image: url('../assets/ui/framemed.webp') 70 fill / 18px stretch;
  background: rgba(10,12,20,.55); padding: 6px 12px 10px; image-rendering: pixelated;
  cursor: pointer;
}
#story-port { width: clamp(80px, 16vmin, 130px); image-rendering: pixelated; margin-top: -34%; filter: drop-shadow(0 6px 14px rgba(0,0,0,.6)); }
#story-port.flip { transform: scaleX(-1); }
.story-right { flex: 1; min-width: 0; }
.story-name {
  display: inline-block; color: #ffe9b0; font-weight: 800; font-size: clamp(13px, 2.6vmin, 19px);
  border: 9px solid transparent;
  border-image: url('../assets/ui/banner.webp') 78 fill / 9px stretch;
  padding: 0 1.2em; margin-bottom: 6px; image-rendering: pixelated;
}
.story-text { min-height: 3.4em; white-space: pre-line; font-size: clamp(13px, 2.5vmin, 19px); line-height: 1.55; color: #e8ecf4; }
.story-hint { display: flex; justify-content: space-between; align-items: center; color: #6f7789; font-size: clamp(10px, 1.9vmin, 13px); margin-top: 6px; }
.story-skip { color: #7dd3fc; padding: 2px 10px; border: 1px solid rgba(125,211,252,.4); }

/* ---------- overlays ---------- */
.ov {
  position: absolute; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center;
  background: rgba(5,6,10,.72); backdrop-filter: blur(2px);
}
.ov.show { display: flex; }
.pnl {
  width: min(94%, 590px); max-height: 94%; overflow-y: auto;
  border: 24px solid transparent;
  border-image: url('../assets/ui/panel.webp') 78 fill / 24px stretch;
  padding: 8px 14px; text-align: center; image-rendering: pixelated;
}
.qg-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 2px; }
.qg-logo { width: clamp(30px, 6vmin, 44px); image-rendering: pixelated; }
.qg-txt { color: #58627a; letter-spacing: .4em; font-size: clamp(9px, 1.8vmin, 12px); }
.logo { font-size: clamp(26px, 6vmin, 46px); font-weight: 900; letter-spacing: .06em; color: #ffd166;
  text-shadow: 0 0 24px rgba(255,209,102,.35), 0 3px 0 #7a5a10; }
.logo span { color: #55d7ff; text-shadow: 0 0 24px rgba(85,215,255,.4), 0 3px 0 #1a5a74; }
.tagline { color: #9aa3b8; margin: 4px 0 10px; font-size: clamp(11px, 2.2vmin, 15px); }

#ch-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 4px 0 10px; }
.ch-btn {
  width: clamp(58px, 12vmin, 84px); padding: 4px 2px; line-height: 1.3;
  font-size: clamp(10px, 2vmin, 13px); color: #cfd6e4;
  border: 8px solid transparent;
  border-image: url('../assets/ui/card.webp') 62 / 8px stretch;
  background: rgba(18,20,32,.85); image-rendering: pixelated;
}
.ch-btn.on { color: #ffe9b0; filter: brightness(1.4) drop-shadow(0 0 8px rgba(255,209,102,.5)); }
.ch-btn.locked { opacity: .38; cursor: not-allowed; }

.b-pri {
  color: #06220f; font-weight: 800; background: linear-gradient(135deg, #2fe08d, #16a34a);
  font-size: clamp(15px, 3vmin, 22px); padding: 10px 40px; margin: 6px 0;
  box-shadow: 0 4px 0 #0c5c30, 0 8px 20px rgba(47,224,141,.3); image-rendering: pixelated;
}
.b-pri:active { transform: translateY(3px); box-shadow: 0 1px 0 #0c5c30; }
.b-sec { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.2); padding: 8px 18px; font-weight: 700; }
.howto { list-style: none; text-align: left; margin: 8px auto 10px; max-width: 460px; font-size: clamp(11px, 2.1vmin, 14px); color: #b9c1d2; }
.howto li { margin: 6px 0; display: flex; gap: 10px; align-items: flex-start; }
.howto i { font-style: normal; flex: 0 0 1.6em; text-align: center; }
.meta-row { margin-top: 8px; font-size: 13px; color: #6f7789; }
.text-link { color: #7dd3fc; text-decoration: none; }
.meta-dot { margin: 0 8px; }

/* relic picker */
#relic-row { display: flex; gap: 10px; justify-content: center; margin: 12px 0 8px; flex-wrap: wrap; }
.relic {
  flex: 1 1 140px; max-width: 170px; padding: 12px 8px; transition: .12s;
  border: 12px solid transparent;
  border-image: url('../assets/ui/card.webp') 62 / 12px stretch;
  background: linear-gradient(180deg, rgba(52,36,80,.85), rgba(22,16,36,.92)); image-rendering: pixelated;
}
.relic:hover { transform: translateY(-3px); filter: brightness(1.25); }
.relic .r-ico { font-size: 30px; }
.relic .r-nm { font-weight: 800; margin: 6px 0 4px; color: #e3d1ff; font-size: 14px; }
.relic .r-ds { font-size: 12px; color: #9aa3b8; line-height: 1.35; }

/* result */
.res-big { font-size: clamp(24px, 5.2vmin, 38px); font-weight: 900; color: #ff6b6b; margin-bottom: 4px; }
.res-stats { display: flex; justify-content: center; gap: 18px; margin: 8px 0 12px; flex-wrap: wrap; }
.res-stat b { display: block; font-size: clamp(18px, 4vmin, 30px); color: #ffd166; }
.res-stat span { font-size: 12px; color: #8a93a8; }
.submit-row { display: flex; gap: 8px; margin: 8px auto; max-width: 400px; }
.text-input { flex: 1; padding: 8px 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(0,0,0,.35); color: #fff; font: inherit; }
.submit-status { min-height: 1.3em; font-size: .85rem; color: #7dd3fc; margin-bottom: 6px; }
.leaderboard-card { margin: 6px 0 4px; text-align: left; }
.card-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: #7a8498; margin-bottom: 6px; }
.board-list { font-size: .88rem; }
.board-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.board-rank { color: #8a93a8; width: 2.2em; }
.board-name { font-weight: 700; }
.board-meta { font-size: .75rem; color: #6f7789; }
.board-score { margin-left: auto; font-weight: 800; color: #ffd166; }
.board-empty { color: #6f7789; padding: 8px 0; }

#rotate-hint { position: fixed; inset: 0; z-index: 90; display: none; align-items: center; justify-content: center; background: #0b0d14; color: #9aa3b8; text-align: center; font-size: 16px; padding: 30px; }
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: flex; }
}
