:root {
  /* Bright "candy" theme: sky background, white glossy panels, chunky rounded type. */
  --bg: #9fdcff;
  --bg-2: #eef5ff;
  --surface: #ffffff;
  --surface-2: #f3f7ff;
  --text: #2b2456;
  --muted: #6f6e95;
  --border: #dbe4f6;
  --brand: #7b5cff;
  --brand-2: #ff5c93;
  --good: #22b864;
  --bad: #ff4d5e;
  --gold: #f5a300;
  --mana: #2f8cff;
  --press: #c9d5ee;
  --radius: 20px;
  --font: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120px 46px at 12% 9%, rgba(255,255,255,.95) 60%, transparent 62%),
    radial-gradient(90px 38px at 20% 6%, rgba(255,255,255,.95) 60%, transparent 62%),
    radial-gradient(150px 52px at 86% 15%, rgba(255,255,255,.9) 60%, transparent 62%),
    radial-gradient(100px 40px at 76% 12%, rgba(255,255,255,.9) 60%, transparent 62%),
    radial-gradient(130px 44px at 60% 72%, rgba(255,255,255,.55) 60%, transparent 62%),
    linear-gradient(180deg, #5cc4ff 0%, #a6e2ff 45%, #e2f7ff 75%, #fff4d1 100%) fixed;
  background-attachment: fixed;
  color: var(--text);
  font: 500 15px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }

.app { max-width: 960px; margin: 0 auto; min-height: 100%; }
.screen { padding: 16px 16px 40px; }

/* Buttons */
.btn {
  border: 2px solid #fff; background: linear-gradient(180deg, #fff, #eef4ff); border-radius: 18px;
  padding: 11px 16px; font-weight: 700; text-align: left; transition: transform .08s, box-shadow .08s, filter .15s;
  box-shadow: 0 4px 0 var(--press), 0 8px 18px rgba(40,70,150,.14);
}
.btn:hover:not(:disabled) { filter: brightness(1.04); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--press), 0 3px 8px rgba(40,70,150,.14); }
.btn:disabled { opacity: .5; }
.btn.small { padding: 7px 12px; font-size: 13px; text-align: center; }
.btn-main {
  background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0) 52%), linear-gradient(180deg, #ffbf3a, #ff7a2f);
  border-color: #ffe08a; color: #fff; text-shadow: 0 2px 0 rgba(170,70,0,.45); box-shadow: 0 5px 0 #d4561c, 0 10px 22px rgba(255,110,40,.35);
}
.btn-main:active:not(:disabled) { box-shadow: 0 2px 0 #d4561c, 0 4px 10px rgba(255,110,40,.3); }
.btn-ghost { background: rgba(255,255,255,.55); box-shadow: 0 3px 0 rgba(150,170,210,.5); }
.btn-danger { background: linear-gradient(180deg, #fff, #ffeef1); color: #d6334a; box-shadow: 0 4px 0 #f3c2cb, 0 8px 18px rgba(214,51,74,.12); }
.btn.wide { width: 100%; text-align: center; margin-top: 22px; padding: 14px; font-size: 17px; }
.icon-btn { width: 40px; height: 40px; border-radius: 14px; border: 2px solid #fff; background: var(--surface); font-size: 18px; flex: none; box-shadow: 0 3px 0 var(--press); }
.icon-btn.small { width: 34px; height: 34px; font-size: 15px; }

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar h1 { font-size: 24px; font-weight: 800; color: #1f4f8f; text-shadow: 0 2px 0 #fff; }
.sec { font-size: 17px; margin: 20px 0 10px; color: #1f4f8f; font-weight: 800; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid #fff; background: var(--surface); border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 14px; box-shadow: 0 3px 0 var(--press); }
.chip small { color: var(--gold); }
.chip.on { background: linear-gradient(180deg, #9a83ff, var(--brand)); border-color: #d6ccff; color: #fff; box-shadow: 0 3px 0 #5639cc; }
.chip.on small { color: #fff; }

.input { flex: 1; min-width: 0; background: var(--bg-2); border: 2px solid var(--border); border-radius: 14px; padding: 9px 12px; color: var(--text); font: inherit; font-weight: 600; }

/* Home */
.home { display: flex; flex-direction: column; gap: 18px; max-width: 460px; margin: 0 auto; }
.home-head { display: flex; }
.brand-link { color: #1f4f8f; text-decoration: none; font-size: 14px; font-weight: 700; background: rgba(255,255,255,.75); padding: 4px 12px; border-radius: 99px; }
.logo { text-align: center; padding-top: 8px; }
.logo h1 {
  font-size: 58px; letter-spacing: 1px; font-weight: 800; line-height: 1; color: #fff;
  -webkit-text-stroke: 3px #ff7a2f; paint-order: stroke fill; text-shadow: 0 5px 0 #d4561c, 0 10px 24px rgba(200,80,20,.35);
}
.logo p { margin: 8px 0 0; color: #1f4f8f; font-weight: 700; }
.logo-cards { display: flex; justify-content: center; margin-bottom: 14px; height: 88px; }
.logo-cards span {
  width: 58px; height: 80px; border-radius: 12px; display: grid; place-items: center; font: 26px var(--emoji); overflow: hidden;
  background: linear-gradient(160deg, var(--c1), var(--c2)); border: 3px solid #fff; margin: 0 -6px;
  box-shadow: 0 6px 16px rgba(40,70,150,.25);
}
.logo-cards span:nth-child(1) { transform: rotate(-14deg) translateY(8px); }
.logo-cards span:nth-child(2) { transform: rotate(-5deg); }
.logo-cards span:nth-child(3) { transform: rotate(5deg); }
.logo-cards span:nth-child(4) { transform: rotate(14deg) translateY(8px); }
.rank-card { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 3px solid #fff; border-radius: var(--radius); padding: 14px; box-shadow: 0 6px 0 var(--press), 0 12px 24px rgba(40,70,150,.15); }
.rank-emoji { font: 34px var(--emoji); }
.rank-body { flex: 1; min-width: 0; }
.rank-name { font-weight: 700; color: var(--tier); }
.rank-name small { color: var(--muted); font-weight: 500; }
.bar { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--tier); border-radius: 99px; }
.menu { display: flex; flex-direction: column; gap: 10px; }
.menu .btn { padding: 14px 18px; font-size: 16px; }
.menu .btn small { color: var(--muted); font-weight: 500; }

/* Setup */
.deck-pick, .deck-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.deck-tile {
  display: flex; align-items: center; gap: 12px; text-align: left; background: var(--surface); border: 2px solid #fff;
  border-radius: 16px; padding: 10px 12px; box-shadow: 0 3px 0 var(--press);
}
.deck-tile > span:not(.leader-badge) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.deck-tile small { color: var(--muted); }
.deck-tile.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset, 0 3px 0 #5639cc; }
.leader-badge {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none; font: 22px var(--emoji);
  background: radial-gradient(circle at 30% 25%, var(--c1), var(--c2)); box-shadow: 0 0 0 3px #fff, 0 3px 8px rgba(40,70,150,.25);
}
.leader-badge.lg { width: 60px; height: 60px; font-size: 32px; }
.leader-pick { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.leader-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 14px 12px;
  border-radius: var(--radius); border: 3px solid #fff; box-shadow: 0 4px 0 var(--press);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c1) 45%, var(--surface)), var(--surface));
}
.leader-tile b { font-size: 17px; }
.leader-tile .pw { color: #b86e00; margin-top: 4px; }

/* Cards */
.card {
  position: relative; width: 104px; height: 146px; flex: none; border-radius: 10px; padding: 4px;
  background: linear-gradient(165deg, var(--c1), var(--c2)); border: 2px solid var(--rar);
  box-shadow: 0 4px 14px rgba(0,0,0,.45); display: flex; flex-direction: column; user-select: none; -webkit-user-select: none;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}
.c-cost {
  position: absolute; top: -7px; left: -7px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #8fd0ff, var(--mana) 55%, #1f4fb5); border: 2px solid #cfe9ff; font-size: 14px; color: #fff; z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.c-art {
  height: 48px; border-radius: 7px; display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 50% 40%, rgba(255,255,255,.35), rgba(0,0,0,.25)); overflow: hidden;
}
.c-art span { font: 32px/1 var(--emoji); filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.c-name {
  font-size: 11px; font-weight: 700; text-align: center; margin: 3px 0 2px; line-height: 1.15; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.7); min-height: 2.3em; display: flex; align-items: center; justify-content: center;
}
.c-text {
  flex: 1; font-size: 9.5px; line-height: 1.25; background: rgba(8,10,22,.72); border-radius: 6px; padding: 3px 4px 10px;
  color: #e7e9f7; overflow: hidden;
}
.c-text i { color: #b9bfdc; }
.c-atk, .c-hp {
  position: absolute; bottom: -7px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.7); border: 2px solid rgba(255,255,255,.7);
}
.c-atk { left: -6px; background: radial-gradient(circle at 35% 30%, #ffe08a, #e0a412 60%, #8a5a00); }
.c-hp { right: -6px; background: radial-gradient(circle at 35% 30%, #ff9a9a, #e5383b 60%, #8a0f16); }
.c-type { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); font-size: 9px; background: #2a2f55; border: 1px solid #555d9a; padding: 1px 6px; border-radius: 6px; font-weight: 700; }
.c-count { position: absolute; top: 4px; right: 4px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 99px; }
.card.r-legendary { box-shadow: 0 0 0 1px rgba(255,181,52,.4), 0 0 16px rgba(255,181,52,.35), 0 4px 14px rgba(0,0,0,.45); }
.card.dim { opacity: .72; filter: saturate(.55); }
.card-lg { width: 180px; height: 252px; padding: 7px; border-width: 3px; }
.card-lg .c-cost { width: 40px; height: 40px; font-size: 22px; top: -10px; left: -10px; }
.card-lg .c-art { height: 86px; }
.card-lg .c-art span { font-size: 58px; }
.card-lg .c-name { font-size: 16px; }
.card-lg .c-text { font-size: 13px; padding: 6px 7px 14px; }
.card-lg .c-atk, .card-lg .c-hp { width: 38px; height: 38px; font-size: 20px; bottom: -10px; }
.card-lg .c-type { font-size: 13px; bottom: -9px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 18px 10px; padding: 14px 6px; justify-items: center; }
.grid .card { cursor: pointer; }
.grid .card:hover { transform: translateY(-3px); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(30,60,120,.45); display: grid; place-items: center; padding: 16px; z-index: 50; backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border: 4px solid #fff; border-radius: 26px; padding: 20px; box-shadow: 0 8px 0 var(--press), 0 20px 50px rgba(20,40,100,.35); max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-box h2 { margin-bottom: 14px; }
.big-card { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.big-info { flex: 1; min-width: 200px; }
.big-info p { margin: 6px 0; }
.kw-list { padding-left: 18px; font-size: 14px; color: var(--muted); }
.log { padding-left: 22px; font-size: 14px; max-height: 50vh; overflow: auto; color: var(--muted); }
.log li:last-child { color: var(--text); }
.result { text-align: center; }
.result-emoji { font: 64px var(--emoji); }
.result h2 { font-size: 30px; margin: 6px 0; }
.result.win h2 { color: var(--gold); }
.result .row { justify-content: center; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%); background: #fff; border: 3px solid #ffe08a; color: var(--text);
  padding: 10px 18px; border-radius: 18px; z-index: 60; font-weight: 700; box-shadow: 0 5px 0 #f0c040, 0 10px 24px rgba(40,70,150,.25); max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }

/* Battle */
.battle {
  height: 100dvh; display: grid; grid-template-rows: auto minmax(84px, 1fr) auto minmax(84px, 1fr) auto auto auto;
  padding: max(8px, env(safe-area-inset-top)) 10px max(6px, env(safe-area-inset-bottom)); gap: 6px; overflow: hidden;
}
.b-row { display: flex; align-items: center; gap: 10px; }
.b-meta { flex: 1; min-width: 0; }
.b-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.b-name small { color: var(--muted); font-weight: 500; }
.b-stats { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; font-weight: 700; }
.mana { display: flex; align-items: center; gap: 6px; }
.mana b { color: var(--mana); }
.gems { display: flex; gap: 2px; }
.gems i { width: 9px; height: 13px; clip-path: polygon(50% 0, 100% 35%, 80% 100%, 20% 100%, 0 35%); background: #cdd8ef; }
.gems i.on { background: linear-gradient(#a9dcff, var(--mana)); }

.leader {
  position: relative; width: 58px; height: 58px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 30% 25%, var(--c1), var(--c2)); box-shadow: 0 0 0 4px #fff, 0 6px 16px rgba(40,70,150,.3);
  display: grid; place-items: center; transition: box-shadow .15s;
}
.l-face { font: 30px/1 var(--emoji); width: 100%; height: 100%; border-radius: 50%; overflow: hidden; display: grid; place-items: center; }
.l-hp, .l-armor {
  position: absolute; bottom: -6px; min-width: 26px; height: 24px; padding: 0 5px; border-radius: 12px; display: grid; place-items: center;
  font-size: 13px; color: #fff; border: 2px solid rgba(255,255,255,.8); text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.l-hp { right: -8px; background: #d22d3d; }
.l-hp.low { animation: beat 1s infinite; }
.l-armor { left: -8px; background: #6b7690; }

.board {
  display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 22px; padding: 6px;
  background: rgba(255,255,255,.45); border: 3px dashed rgba(255,255,255,.85);
}
.b-op { background: rgba(255,214,222,.5); }
.b-me { background: rgba(214,232,255,.6); }
.board .empty { color: var(--muted); font-size: 13px; font-weight: 700; text-align: center; }

.unit {
  position: relative; width: min(64px, calc((100vw - 64px) / 6)); aspect-ratio: 4 / 5; border-radius: 14px; flex: none;
  background: linear-gradient(165deg, var(--c1), var(--c2)); border: 3px solid #fff;
  display: grid; place-items: center; box-shadow: 0 4px 0 rgba(40,70,150,.25), 0 6px 12px rgba(40,70,150,.2); transition: transform .15s, box-shadow .15s;
  user-select: none; -webkit-user-select: none;
}
.u-art { font: min(30px, 7vw)/1 var(--emoji); margin-bottom: 6px; }
.u-atk, .u-hp {
  position: absolute; bottom: -6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff;
  border: 2px solid rgba(255,255,255,.75); text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.u-atk { left: -5px; background: #d99a0f; }
.u-hp { right: -5px; background: #d22d3d; }
.u-atk.up, .u-hp.up { color: #b6ffcb; }
.u-hp.hurt { background: #7a1018; color: #ffd0d0; }
.u-icons { position: absolute; top: -8px; right: -6px; font: 12px var(--emoji); background: rgba(10,12,28,.85); border-radius: 8px; padding: 0 3px; }
.unit.guard { border-radius: 14px 14px 22px 22px; border: 3px solid #cfd6e6; box-shadow: 0 0 0 2px #5c667f, 0 4px 12px rgba(0,0,0,.4); }
.unit.shield::after { content: ""; position: absolute; inset: -5px; border-radius: 18px; border: 2px solid #ffe58a; box-shadow: 0 0 12px #ffd54a, inset 0 0 10px rgba(255,220,100,.5); pointer-events: none; }
.unit.frozen::before { content: "❄"; position: absolute; inset: 0; border-radius: 12px; background: rgba(140,210,255,.45); display: grid; place-items: center; font-size: 22px; color: #fff; z-index: 1; }
.unit.ready { box-shadow: 0 0 0 3px var(--good), 0 0 16px rgba(79,224,138,.55); cursor: pointer; }
.unit.selected { transform: translateY(-6px) scale(1.06); box-shadow: 0 0 0 3px #fff, 0 0 20px rgba(255,255,255,.6); }
.targetable { cursor: pointer; animation: target 0.9s infinite alternate; }
.leader.targetable { box-shadow: 0 0 0 4px var(--bad), 0 0 22px rgba(255,90,106,.8); }
.unit.targetable { box-shadow: 0 0 0 3px var(--bad), 0 0 18px rgba(255,90,106,.75); }
.hit { animation: shake .35s; }

.b-mid { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 2px; }
.turn-label { font-weight: 800; font-size: 15px; color: #1f4f8f; background: rgba(255,255,255,.7); padding: 2px 12px; border-radius: 99px; }
.my-turn .turn-label { color: var(--good); }
.btn-end {
  padding: 8px 18px; text-align: center; color: #fff; border-color: #b8f5cf; text-shadow: 0 2px 0 rgba(0,90,40,.4);
  background: linear-gradient(180deg, rgba(255,255,255,.4), rgba(255,255,255,0) 52%), linear-gradient(180deg, #4fe08a, #1fae5d); box-shadow: 0 4px 0 #13874a;
}
.btn-end:disabled { background: #e7edf8; color: var(--muted); text-shadow: none; border-color: #fff; box-shadow: 0 3px 0 var(--press); }
.btn-end.pulse { animation: glow 1.2s infinite; }

.power {
  display: flex; align-items: center; gap: 6px; border-radius: 16px; border: 2px solid #fff; background: var(--surface);
  padding: 6px 10px 6px 6px; font-size: 13px; font-weight: 800; max-width: 150px; box-shadow: 0 3px 0 var(--press);
}
.power b { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #cdd8ef; color: #fff; flex: none; }
.power.on { border-color: #ffd34d; background: #fff8dc; box-shadow: 0 3px 0 #f0c040; }
.power.on b { background: radial-gradient(circle at 35% 30%, #8fd0ff, var(--mana) 55%, #1f4fb5); }
.power:disabled { opacity: .55; }
.power.selected { box-shadow: 0 0 0 3px var(--brand); }

.infobar {
  min-height: 46px; display: flex; align-items: center; gap: 10px; background: var(--surface); border: 2px solid #fff;
  border-radius: 16px; padding: 6px 10px; font-size: 13px; box-shadow: 0 3px 0 var(--press);
}
.info-text { flex: 1; min-width: 0; line-height: 1.3; }
.info-text em { color: var(--good); font-style: normal; }
.why { color: var(--bad); font-weight: 600; white-space: nowrap; }

.hand {
  display: flex; gap: 0; overflow-x: auto; overflow-y: visible; padding: 12px 8px 10px; min-height: 172px;
  scrollbar-width: none; justify-content: safe center;
}
.hand::-webkit-scrollbar { display: none; }
.hand .card { margin-left: 6px; cursor: pointer; }
.hand.crowded .card { margin-left: -16px; }
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { box-shadow: 0 0 0 2px var(--good), 0 0 14px rgba(79,224,138,.5); }
.hand .card.selected { transform: translateY(-10px); z-index: 3; box-shadow: 0 0 0 3px var(--brand), 0 10px 24px rgba(40,70,150,.45); }
.their-turn .hand .card.playable { box-shadow: 0 4px 14px rgba(40,70,150,.3); }

.float {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, 0); font-weight: 900; font-size: 22px; pointer-events: none; z-index: 10;
  text-shadow: 0 2px 4px #000, 0 0 2px #000; animation: rise 1s forwards;
}
.float.dmg { color: #ff5a6a; }
.float.heal { color: #5dff9b; }
.float.blk { color: #ffe58a; font-size: 16px; }

.banner {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 40; pointer-events: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 22px; font-weight: 800;
  padding: 14px 30px; border-radius: 16px; white-space: nowrap; box-shadow: 0 10px 40px rgba(0,0,0,.5); animation: pop 1.3s forwards;
}
.played { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 40; pointer-events: none; animation: pop 1s forwards; }

/* Builder */
.builder .b-head { display: flex; gap: 10px; align-items: center; }
.builder .count { font-size: 18px; color: var(--bad); }
.builder .count.ok { color: var(--good); }
.curve { display: flex; gap: 6px; align-items: flex-end; height: 56px; margin: 12px 0 6px; }
.curve div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; }
.curve i { width: 100%; background: linear-gradient(var(--brand), #5a47c9); border-radius: 4px 4px 0 0; min-height: 2px; }
.curve small { font-size: 11px; color: var(--muted); }
.deck-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.dchip { display: flex; align-items: center; gap: 6px; border: 2px solid #fff; border-left: 6px solid var(--c1); background: var(--surface); border-radius: 10px; padding: 4px 8px; font-size: 13px; box-shadow: 0 2px 0 var(--press); }
.dchip b { color: var(--mana); }
.dchip em { color: var(--gold); font-style: normal; font-weight: 700; }

.panel { background: var(--surface); border: 3px solid #fff; border-radius: var(--radius); padding: 6px 18px 14px; box-shadow: 0 5px 0 var(--press), 0 10px 22px rgba(40,70,150,.12); }
.panel h2 { font-size: 17px; margin: 16px 0 6px; }
.panel li { margin: 4px 0; }

@keyframes shake { 0%, 100% { translate: 0; } 25% { translate: -5px 0; } 50% { translate: 5px 0; } 75% { translate: -3px 0; } }
@keyframes rise { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -34px); } }
@keyframes pop { 0% { opacity: 0; scale: .7; } 15% { opacity: 1; scale: 1.05; } 25% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes target { from { filter: brightness(1); } to { filter: brightness(1.25); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(79,224,138,.6); } 50% { box-shadow: 0 0 0 6px rgba(79,224,138,0); } }
@keyframes beat { 0%, 100% { scale: 1; } 50% { scale: 1.15; } }

@media (min-width: 720px) {
  .battle { padding-left: 24px; padding-right: 24px; }
  .unit { width: 84px; border-radius: 16px; }
  .u-art { font-size: 40px; }
  .u-atk, .u-hp { width: 28px; height: 28px; font-size: 15px; }
  .leader { width: 70px; height: 70px; }
  .l-face { font-size: 38px; }
  .board { gap: 12px; }
  .hand .card, .hand.crowded .card { margin-left: 6px; }
  .hand .card:first-child { margin-left: 0; }
  .hand .card:hover { transform: translateY(-8px); }
}
@media (max-height: 700px) and (max-width: 719px) {
  .card { width: 92px; height: 130px; }
  .c-art { height: 40px; }
  .c-art span { font-size: 26px; }
  .c-text { font-size: 9px; }
  .hand { min-height: 152px; padding-top: 10px; }
  .leader { width: 48px; height: 48px; }
  .l-face { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- v2: accounts, settings, history, effects ---------- */
.grow { flex: 1; }
.right { text-align: right; }
.screen.narrow { max-width: 620px; margin: 0 auto; }
.home-head { align-items: center; gap: 8px; }
.acct {
  display: flex; align-items: center; gap: 8px; border: 2px solid #fff; background: var(--surface); border-radius: 999px; box-shadow: 0 3px 0 var(--press);
  padding: 4px 12px 4px 4px; font-weight: 600; font-size: 14px; max-width: 180px;
}
.acct span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct > :first-child:not(.leader-badge) { padding-left: 8px; }
.leader-badge.sm { width: 30px; height: 30px; font-size: 16px; }
.leader-badge.xl { width: 84px; height: 84px; font-size: 46px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-grid .btn { padding: 12px 14px; font-size: 15px; }

/* Forms */
.tabs { display: flex; gap: 4px; background: var(--bg-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px; font-weight: 700; color: var(--muted); }
.tab.on { background: #fff; color: var(--text); box-shadow: 0 2px 0 var(--press); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.form .input { flex: none; padding: 11px 12px; }
.form .btn.wide { margin-top: 4px; }
.form.panel { padding: 16px; }
.form-err { margin: 0; background: #ffeef1; border: 2px solid #ffc2cc; color: #c0283f; padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.form-err[hidden] { display: none; }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatars label { display: block; }
.avatars input { position: absolute; opacity: 0; pointer-events: none; }
.avatars span {
  display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; font: 22px var(--emoji); cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--border);
}
.avatars input:checked + span { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; background: var(--surface-2); }
.avatars input:focus-visible + span { outline: 2px solid #fff; }

/* Profile and stats */
.profile-head { display: flex; align-items: center; gap: 16px; margin: 6px 0 16px; }
.profile-head h2 { font-size: 22px; }
.profile-head p { margin: 4px 0 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat-grid > div {
  background: var(--surface); border: 2px solid #fff; border-radius: 16px; padding: 10px 12px; box-shadow: 0 3px 0 var(--press);
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
}
.stat-grid b { font-size: 18px; }
.stat-grid small { color: var(--muted); }
.panel > p { margin: 12px 0; }

/* History */
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-row {
  display: flex; align-items: center; gap: 8px; text-align: left; background: var(--surface); border: 2px solid #fff;
  border-left: 6px solid var(--muted); border-radius: 16px; padding: 8px 12px; box-shadow: 0 3px 0 var(--press);
}
.hist-row.r-win { border-left-color: var(--good); }
.hist-row.r-loss { border-left-color: var(--bad); }
.vs { color: var(--muted); font-size: 12px; }
.h-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 4px; }
.h-main small { color: var(--muted); }
.h-delta { font-weight: 800; min-width: 36px; text-align: right; }
.r-win .h-delta { color: var(--good); }
.r-loss .h-delta { color: var(--bad); }
.h-play { color: var(--brand); font-size: 13px; }

/* Leaderboard */
.lb-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.lb-list li { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 2px solid #fff; border-radius: 16px; padding: 8px 12px; box-shadow: 0 3px 0 var(--press); }
.lb-pos { width: 26px; text-align: center; font-weight: 800; color: var(--muted); }
.lb-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-weight: 700; overflow: hidden; }
.lb-name small { color: var(--muted); font-weight: 500; }
.lb-pts { font-weight: 800; white-space: nowrap; }
.lb-list li.top1 { border-color: #ffcf4a; background: linear-gradient(90deg, rgba(255,207,74,.3), var(--surface)); }
.lb-list li.top2 { border-color: #c0c8d8; }
.lb-list li.top3 { border-color: #c98a5a; }
.top1 .lb-pos { color: #ffcf4a; }
.top2 .lb-pos { color: #c0c8d8; }
.top3 .lb-pos { color: #c98a5a; }

/* Settings */
.settings { padding: 4px 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; }
.set-row > span:first-child { display: flex; flex-direction: column; font-weight: 600; }
.set-row small { color: var(--muted); font-weight: 500; font-size: 13px; }
.set-row input[type=range] { flex: 1; max-width: 220px; accent-color: var(--brand); }
.set-row input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 46px; height: 26px; border-radius: 99px; background: #cdd8ef; flex: none; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.set-row input:checked + .switch { background: var(--good); }
.set-row input:checked + .switch::after { transform: translateX(20px); }
.set-row input:focus-visible + .switch { outline: 2px solid #fff; }
.modal-box .settings { margin-bottom: 14px; padding: 0 12px; }

/* Filters */
.filters { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.filters .input { flex: none; }
.filters .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filters .chips::-webkit-scrollbar { display: none; }
.filters .chip { padding: 6px 12px; font-size: 13px; white-space: nowrap; flex: none; }

/* Card types */
.c-type.t-spell { background: #3a2a6b; border-color: #8b74ff; }
.c-type.t-equip { background: #5a4410; border-color: #e0a412; }
.c-type.t-trap { background: #5a1830; border-color: #ff5c93; }
.c-type.t-field { background: #15493a; border-color: #4fe08a; }
.card.ct-trap .c-art { background: repeating-linear-gradient(45deg, rgba(255,92,147,.25) 0 6px, rgba(0,0,0,.25) 6px 12px); }
.card.ct-field .c-art { background: radial-gradient(ellipse at 50% 100%, rgba(79,224,138,.45), rgba(0,0,0,.2)); }
.card.ct-equip .c-art { background: radial-gradient(circle at 50% 40%, rgba(255,224,138,.5), rgba(0,0,0,.25)); }
.card-back {
  background: repeating-linear-gradient(135deg, #2a1f5c 0 10px, #1c2244 10px 20px); border-color: #8b74ff;
  display: grid; place-items: center; padding: 0;
}
.card-back span { font: 40px var(--emoji); filter: drop-shadow(0 0 10px #8b74ff); }
.played { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.played-label {
  background: linear-gradient(135deg, #ff5c93, #a8231b); color: #fff; font-weight: 900; font-size: 20px; padding: 6px 18px; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); letter-spacing: 1px;
}

/* Battle extras */
.extras { display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.trap {
  width: 24px; height: 30px; border-radius: 6px; display: grid; place-items: center; font: 13px var(--emoji); padding: 0;
  background: repeating-linear-gradient(45deg, #5a1830 0 4px, #3a1024 4px 8px); border: 1px solid #ff5c93;
}
.trap.mine { background: #3a1024; }
.field-pill {
  display: inline-flex; align-items: center; gap: 4px; border: 2px solid #4fe08a; background: #e6fbef; color: #13643a; border-radius: 99px;
  padding: 2px 4px 2px 8px; font-size: 12px; font-weight: 600; max-width: 170px; white-space: nowrap; overflow: hidden;
}
.field-pill b { background: #4fe08a; color: #0b3a20; border-radius: 99px; min-width: 18px; padding: 0 4px; text-align: center; }
.replay-bar { display: flex; align-items: center; gap: 6px; }
.u-atk.down { color: #ffd0d0; background: #7a5a10; }
.unit.stealth { opacity: .55; border-style: dashed; }
.unit.silenced { filter: grayscale(.85); }
.unit.silenced .u-art::after { content: "🚫"; position: absolute; top: 2px; left: 2px; font-size: 11px; }

/* Effects layer */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.particle {
  position: fixed; width: 7px; height: 7px; border-radius: 50%; margin: -3.5px 0 0 -3.5px; box-shadow: 0 0 8px currentColor;
  animation: particle .6s ease-out forwards;
}
.orb { position: fixed; width: 26px; height: 26px; border-radius: 50%; transform: translate(-50%, -50%); filter: blur(.5px) drop-shadow(0 0 10px #fff); }
.ghost { animation: ghost .6s ease-in forwards; pointer-events: none; z-index: 46; }
.flash { position: fixed; inset: 0; animation: flash .4s ease-out forwards; }
.shake { animation: shake .35s; }
.shake-big { animation: bigshake .45s; }
@keyframes particle { from { opacity: 1; transform: translate(0, 0) scale(1); } to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.3); } }
@keyframes ghost { 0% { opacity: 1; transform: scale(1); filter: brightness(1.6); } 100% { opacity: 0; transform: scale(.6) rotate(8deg) translateY(10px); filter: brightness(2) blur(3px); } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes bigshake { 0%, 100% { translate: 0; } 20% { translate: -9px 4px; } 40% { translate: 8px -4px; } 60% { translate: -6px 2px; } 80% { translate: 4px -2px; } }

@media (max-width: 420px) {
  .avatars { grid-template-columns: repeat(6, 1fr); }
  .acct span { max-width: 80px; }
}

/* Email recovery */
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 4px; align-self: center; text-decoration: underline; text-underline-offset: 3px; }
.warn { margin: 0; background: #fff6d9; border: 2px solid #ffe08a; color: #8a5a00; padding: 8px 12px; border-radius: 12px; }
.warn-btn { background: #fff6d9; border-color: #ffe08a; color: #8a5a00; text-align: center; box-shadow: 0 4px 0 #f0c040; }

/* ---------- v3: opponents, portraits, five levels ---------- */
.chibi { width: 100%; height: 100%; display: block; object-fit: cover; }
img.chibi { object-position: 50% 15%; }
.hp-field { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.opp-pick { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.opp-tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px 8px; border-radius: 18px;
  border: 3px solid #fff; background: linear-gradient(180deg, color-mix(in srgb, var(--c1, #c9d8ff) 40%, #fff), #fff);
  box-shadow: 0 4px 0 var(--press); transition: transform .1s;
}
.opp-tile b { font-size: 15px; line-height: 1.1; }
.opp-tile small { color: var(--muted); font-size: 12px; }
.opp-tile.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand), 0 4px 0 #5639cc; transform: translateY(-2px); }
.opp-face {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; margin-bottom: 4px;
  background: radial-gradient(circle at 30% 25%, var(--c1, #fff), var(--c2, #c9d8ff)); box-shadow: 0 0 0 3px #fff, 0 4px 10px rgba(40,70,150,.25);
}
.opp-face.dice { font: 34px var(--emoji); background: radial-gradient(circle at 30% 25%, #fff, #c9b8ff); }

.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.level-chip {
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 8px 4px; border-radius: 16px; border: 3px solid #fff;
  background: #fff; box-shadow: 0 4px 0 var(--press); line-height: 1.15;
}
.level-chip b { font-size: 14px; }
.level-chip small { font-size: 11px; color: var(--muted); }
.level-chip .stars { font-size: 11px; letter-spacing: -1px; color: #ffb020; }
.level-chip.lv1 { --lv: #7ad6ff; } .level-chip.lv2 { --lv: #5fe08f; } .level-chip.lv3 { --lv: #ffc93a; }
.level-chip.lv4 { --lv: #ff8a3d; } .level-chip.lv5 { --lv: #ff4d7a; }
.level-chip.on { background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0) 55%), var(--lv); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.25); box-shadow: 0 4px 0 color-mix(in srgb, var(--lv) 70%, #000); }
.level-chip.on small, .level-chip.on .stars { color: #fff; }
@media (max-width: 420px) { .level-chip b { font-size: 12px; } }

.speech {
  position: fixed; top: max(84px, calc(env(safe-area-inset-top) + 76px)); left: 50%; transform: translateX(-50%); z-index: 42;
  max-width: min(360px, calc(100% - 40px)); background: #fff; color: var(--text); font-weight: 700; font-size: 15px; line-height: 1.3;
  padding: 10px 16px; border-radius: 20px; border: 3px solid var(--border); box-shadow: 0 4px 0 var(--press), 0 10px 24px rgba(40,70,150,.25);
  animation: speech 3.4s forwards; pointer-events: none;
}
.speech::before {
  content: ""; position: absolute; top: -12px; left: 34px; border: 9px solid transparent; border-bottom-color: inherit; border-top: 0;
}
.speech.mood-angry { border-color: #ff9aa8; }
.speech.mood-happy { border-color: #ffe08a; }
.speech.mood-sad { border-color: #9fd3ff; }
.speech.mood-smug { border-color: #c9b8ff; }
@keyframes speech { 0% { opacity: 0; translate: 0 -8px; scale: .9; } 8% { opacity: 1; translate: 0; scale: 1; } 88% { opacity: 1; } 100% { opacity: 0; } }

.result-talk { display: flex; align-items: center; gap: 12px; text-align: left; background: var(--surface-2); border-radius: 18px; padding: 10px 12px; margin: 8px 0; }
.result-talk p { margin: 0; }
.rt-face { width: 56px; height: 56px; border-radius: 50%; overflow: hidden; flex: none; background: radial-gradient(circle at 30% 25%, var(--c1), var(--c2)); box-shadow: 0 0 0 3px #fff; }
/* Moods on drawn portraits that have no own image for that mood */
img.chibi.fx-angry { animation: moodShake .4s 2; filter: saturate(1.3) drop-shadow(0 0 6px #ff3d3d); }
img.chibi.fx-sad { filter: saturate(.55) brightness(.92); transform: translateY(3px); }
img.chibi.fx-happy { animation: moodBounce .5s 2; filter: brightness(1.08); }
img.chibi.fx-smug { transform: rotate(-6deg) scale(1.04); }
@keyframes moodShake { 0%, 100% { translate: 0; } 25% { translate: -3px 0; } 75% { translate: 3px 0; } }
@keyframes moodBounce { 0%, 100% { translate: 0; } 50% { translate: 0 -5px; } }
.leader-badge { overflow: hidden; }

/* Match intro */
.vs-intro {
  position: fixed; inset: 0; z-index: 48; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.55), rgba(90,170,255,.85)); animation: vsIn 1.8s forwards; cursor: pointer;
}
.vs-side { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: center; padding: 10px; }
.vs-side img { max-height: 62vh; max-width: 44vw; object-fit: contain; filter: drop-shadow(0 10px 24px rgba(20,40,100,.4)); }
.vs-side.left { animation: vsLeft .45s ease-out; }
.vs-side.right { animation: vsRight .45s ease-out; }
.vs-side b { font-size: 26px; font-weight: 800; color: #fff; -webkit-text-stroke: 2px var(--c2); paint-order: stroke fill; margin-top: -6px; }
.vs-face { width: 140px; height: 140px; border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 30% 25%, var(--c1), var(--c2)); box-shadow: 0 0 0 5px #fff; }
.vs-word { font-size: 64px; font-weight: 800; color: #ffd34d; -webkit-text-stroke: 4px #d4561c; paint-order: stroke fill; text-shadow: 0 6px 0 #a33c10; animation: beat .6s 2; }
.vs-persona {
  position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); background: #fff; border: 3px solid #ffe08a; border-radius: 99px;
  padding: 8px 18px; font-weight: 700; white-space: nowrap; box-shadow: 0 5px 0 #f0c040;
}
@keyframes vsIn { 0% { opacity: 0; } 10% { opacity: 1; } 82% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@keyframes vsLeft { from { translate: -60vw 0; } }
@keyframes vsRight { from { translate: 60vw 0; } }
@media (max-width: 480px) { .vs-word { font-size: 44px; } .vs-side b { font-size: 20px; } }
