:root {
  --bg: #fff1dc; --ink: #4a3426; --soft: #8a6a55; --accent: #ff8a3d; --ok: #5cc46b; --bad: #ef5a5a; --gold: #f2b833; --card: #fffaf2;
  --fire: #ff9a5e; --water: #6cc4ff; --leaf: #93df6a; --light: #ffe27a; --dark: #a487e6;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: #2b2320; color: var(--ink); font-family: 'Mali', system-ui, sans-serif; touch-action: manipulation; }
#app { max-width: 480px; height: 100dvh; margin: 0 auto; position: relative; overflow: hidden; background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; }
svg { overflow: visible; }

.btn { background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; padding: 10px 16px; border-radius: 14px;
  box-shadow: 0 4px 0 #d4651f; transition: transform .06s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d4651f; }
.btn.alt { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #e0cdb5; }
.btn.big { display: block; width: 100%; font-size: 18px; padding: 13px; margin: 8px 0; }
.btn.round { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 18px; flex: none; }
.btn:disabled { opacity: .45; transform: none; }
.pill { background: #fff; border-radius: 99px; padding: 6px 12px; font-weight: 700; box-shadow: 0 2px 0 #e0cdb5; font-size: 14px; }

/* ---------- menu ---------- */
#menu { height: 100%; overflow-y: auto; padding: 14px 16px 24px; }
#menu .top { display: flex; justify-content: space-between; gap: 8px; }
.title { text-align: center; margin: 6px 0 8px; }
.logo { width: 150px; margin: 0 auto; }
.logo svg, .tc-art svg, .c-art svg, .cut-art svg, .res-art svg, .spr svg { width: 100%; height: auto; display: block; }
.title h1 { margin: -6px 0 0; font-size: 38px; color: #e2621b; text-shadow: 0 3px 0 #fff; }
.title p { margin: 2px 0 0; color: var(--soft); font-size: 14px; }
.btn.go { font-size: 22px; }
.btn.go small { display: block; font-size: 13px; font-weight: 600; opacity: .9; }
#menu h3 { margin: 16px 0 8px; }
.team { display: flex; flex-direction: column; gap: 8px; }
.tc { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 16px; padding: 8px; box-shadow: 0 3px 0 #ead8c0;
  border-left: 6px solid var(--c, #ccc); }
.tc-art { width: 72px; flex: none; }
.tc-info { flex: 1; min-width: 0; font-size: 13px; }
.tc-info b { font-size: 16px; }
.tc .lv { background: var(--ink); color: #fff; border-radius: 8px; padding: 0 6px; font-size: 12px; }
.tc .role { color: var(--soft); }
.tc .ult { margin-top: 2px; font-size: 12px; color: #8a5a1f; }
.btn.up { font-size: 13px; padding: 8px 10px; flex: none; }
.el-fire { --c: var(--fire); } .el-water { --c: var(--water); } .el-leaf { --c: var(--leaf); } .el-light { --c: var(--light); } .el-dark { --c: var(--dark); }
.stages { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.st { background: #fff; border-radius: 12px; padding: 10px 0; font-weight: 700; box-shadow: 0 3px 0 #e0cdb5; font-size: 15px; }
.st.bossst { background: #ffe0d6; }
.st.new { background: var(--accent); color: #fff; box-shadow: 0 3px 0 #d4651f; }
.help { margin-top: 16px; width: 100%; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(40, 25, 15, .55); display: none; align-items: center; justify-content: center; z-index: 500; padding: 16px; }
#modal.on { display: flex; }
#modal .box { background: var(--card); border-radius: 22px; padding: 18px; width: 100%; max-width: 380px; text-align: center; animation: pop .25s; }
#modal h2 { margin: 4px 0 8px; }
.help-list { text-align: left; padding-left: 4px; list-style: none; line-height: 1.5; font-size: 15px; }
.help-list li { margin-bottom: 6px; }
.res-art { width: 120px; margin: -4px auto 0; }
.stars { font-size: 40px; color: #ddd; letter-spacing: 4px; }
.stars .on { color: var(--gold); text-shadow: 0 2px 0 #c98d10; }
.reward { font-size: 22px; font-weight: 700; margin: 6px 0; }
.reward small { font-size: 13px; color: var(--soft); }
.tip { color: var(--soft); font-size: 14px; }

/* ---------- battle ---------- */
#battle { height: 100%; display: flex; flex-direction: column; background: #3a2c26; }
.hud { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #3a2c26; color: #fff; }
.hud .stg { flex: 1; min-width: 0; line-height: 1.15; }
.hud .stg span { font-size: 12px; opacity: .75; margin-left: 6px; }
.pips { display: flex; gap: 4px; margin-top: 4px; }
.pips i { width: 26px; height: 6px; border-radius: 3px; background: #6b5850; }
.pips i.done { background: var(--ok); } .pips i.cur { background: var(--gold); }
.btn.tog { white-space: nowrap; padding: 8px 10px; font-size: 14px; background: #6b5850; box-shadow: 0 3px 0 #2a1f1a; }
.btn.tog.on { background: var(--accent); box-shadow: 0 3px 0 #b8541a; }

#field { flex: 1; position: relative; overflow: hidden; min-height: 260px;
  --sky1: #9fdcff; --sky2: #e6f7ff; --hill: #8fcf7a; --hill2: #6fb85d; --gr1: #a9dc78; --gr2: #93c964; --dirt: #c89a63; }
#field.th1 { --sky1: #88c9a8; --sky2: #def5df; --hill: #4f9a5c; --hill2: #3c7f48; --gr1: #7cbf6a; --gr2: #6aae58; --dirt: #9d7a4f; }
#field.th2 { --sky1: #ff9e7a; --sky2: #ffe0b8; --hill: #8a5a4a; --hill2: #6e4438; --gr1: #b98a6a; --gr2: #a5775a; --dirt: #6e4a3a; }
#field.th3 { --sky1: #8ab6ff; --sky2: #e3f0ff; --hill: #a8c8f0; --hill2: #7fa8de; --gr1: #c8e2f4; --gr2: #b2d2ea; --dirt: #8fa6c2; }
#field.th4 { --sky1: #4a3a78; --sky2: #9f86c9; --hill: #3a2d5e; --hill2: #2c2148; --gr1: #6a5a92; --gr2: #5b4c80; --dirt: #3a2f55; }
.bg { position: absolute; left: 0; right: 0; background-repeat: repeat-x; }
.bg.sky { inset: 0; background: linear-gradient(var(--sky1), var(--sky2)); }
.bg.far { bottom: calc(44% - 6px); height: 140px; background-image: radial-gradient(ellipse 90px 80px at 50% 100%, var(--hill2) 98%, transparent 100%),
  radial-gradient(ellipse 70px 55px at 0% 100%, var(--hill2) 98%, transparent 100%); background-size: 210px 140px, 150px 140px; opacity: .7; }
.bg.mid { bottom: calc(44% - 10px); height: 90px; background-image: radial-gradient(ellipse 46px 40px at 50% 100%, var(--hill) 98%, transparent 100%),
  radial-gradient(circle 14px at 30% 70%, var(--hill2) 98%, transparent 100%); background-size: 120px 90px, 190px 90px; }
.bg.ground { bottom: 0; height: 44%; background-color: var(--gr1);
  background-image: linear-gradient(var(--gr2) 0 8px, transparent 8px), repeating-linear-gradient(90deg, transparent 0 46px, var(--dirt) 46px 52px, transparent 52px 98px);
  background-size: 100% 100%, 98px 100%; border-top: 4px solid var(--gr2); }
.bg.ground::after { content: ''; position: absolute; inset: 22px 0 0; background: rgba(0, 0, 0, .06); }
#field.shake { animation: shake .35s; }

#units, #fx { position: absolute; inset: 0; }
#fx { pointer-events: none; z-index: 200; }
.unit { position: absolute; width: calc(150px * var(--sc)); transform: translateX(-50%) translateX(var(--lx, 0)); transition: transform .08s; }
.unit .spr { position: relative; transform-origin: 50% 100%; }
.unit.f .spr { transform: scaleX(-1); }
.unit .shadow { position: absolute; left: 15%; right: 15%; bottom: -3px; height: 10px; border-radius: 50%; background: rgba(0, 0, 0, .18); }
.unit.moving .spr { animation: hop .32s ease-in-out infinite alternate; }
.unit.f.moving .spr { animation-name: hopf; }
.unit.flash .spr { filter: brightness(1.8) saturate(.4); }
.unit.stun .spr { filter: grayscale(.6); }
.unit.stun::before { content: '💫'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%); animation: spin 1s linear infinite; font-size: 20px; z-index: 2; }
.unit.warn .spr { animation: charge .2s ease-in-out infinite alternate; filter: drop-shadow(0 0 10px #ff3b3b); }
.unit.dead { opacity: 0; transform: translateX(-50%) translateY(10px); transition: opacity .6s, transform .6s; pointer-events: none; }
.unit.h.dead { opacity: .3; filter: grayscale(1); transform: translateX(-50%) rotate(-8deg); }
.ubar { position: absolute; left: 18%; right: 18%; top: -8px; height: 7px; background: rgba(0, 0, 0, .45); border-radius: 4px; overflow: hidden; }
.ubar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ok); border-radius: 4px; }
.unit.f .ubar i { background: var(--bad); }
.ubar s { position: absolute; left: 0; top: 0; height: 3px; background: #dff4ff; }
.unit.boss .ubar { height: 10px; left: 10%; right: 10%; }
.crownname { position: absolute; top: -28px; left: 0; right: 0; text-align: center; color: #fff; font-weight: 700; font-size: 13px; text-shadow: 0 1px 2px #000; }

.proj { position: absolute; font-size: 22px; transform: translate(-50%, 50%) rotate(90deg); }
.proj.rev { transform: translate(-50%, 50%) rotate(-90deg); }
.fxt { position: absolute; transform: translateX(-50%); white-space: nowrap; font-weight: 700; }
.fxt.num { font-size: 18px; color: #fff; text-shadow: 0 2px 0 #000, 0 0 3px #000; animation: rise .9s ease-out forwards; }
.fxt.num.hurt { color: #ff8080; } .fxt.num.heal { color: #8dff9a; } .fxt.num.crit { font-size: 24px; color: #ffd84a; }
.fxt.num.stun { color: #ffe27a; font-size: 14px; } .fxt.num.block { color: #bfe6ff; font-size: 14px; } .fxt.num.warn { color: #ff5252; font-size: 16px; }
.fxt.boom { font-size: 46px; animation: boom .6s ease-out forwards; }
.fxt.meteor { font-size: 52px; animation: meteor .45s ease-in forwards; }
.fxt.spark { font-size: 30px; animation: rise 1s ease-out forwards; }

#banner { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: 32px; font-weight: 700; color: #fff;
  text-shadow: 0 3px 0 #b3261e, 0 0 10px #000; opacity: 0; pointer-events: none; z-index: 250; }
#banner.on { animation: bannerIn 1.6s ease-out forwards; }
#cut { position: absolute; inset: 0; display: flex; align-items: center; z-index: 300; pointer-events: none; opacity: 0;
  background: linear-gradient(100deg, transparent 0 8%, color-mix(in srgb, var(--c, #fff) 85%, #000) 8% 92%, transparent 92%); background-size: 100% 46%; background-repeat: no-repeat; background-position: center; }
#cut.on { animation: cut .8s ease-out forwards; }
.cut-art { width: 130px; margin-left: 8%; flex: none; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .25)); }
.cut-txt { color: #fff; font-size: 28px; font-weight: 700; text-shadow: 0 3px 0 rgba(0, 0, 0, .35); line-height: 1.1; }
.cut-txt small { display: block; font-size: 15px; opacity: .9; }

#cards { display: flex; gap: 8px; padding: 10px; background: #3a2c26; }
.card { flex: 1; min-width: 0; position: relative; background: var(--card); border-radius: 16px; padding: 6px 6px 8px; box-shadow: 0 4px 0 #1f1714;
  border: 3px solid var(--c); transition: transform .1s; }
.card .c-art { width: 76%; margin: 0 auto -4px; }
.card .c-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .bar { height: 8px; border-radius: 4px; background: #e6d8c6; overflow: hidden; margin-top: 4px; }
.card .bar i { display: block; height: 100%; width: 0; border-radius: 4px; }
.card .bar.hp i { background: var(--ok); }
.card .bar.en i { background: linear-gradient(90deg, #ffcf3d, #ff9d2e); }
.card .c-ready { position: absolute; top: 4px; right: 4px; background: #ff4d3d; color: #fff; font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 8px; opacity: 0; }
.card.ready { animation: ready .6s ease-in-out infinite alternate; }
.card.ready .c-ready { opacity: 1; }
.card.ready .bar.en i { background: linear-gradient(90deg, #fff27a, #ffb52e, #fff27a); }
.card.dead { filter: grayscale(1); opacity: .55; }
.card:active { transform: translateY(3px); }

@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes hop { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-6px) rotate(2deg); } }
@keyframes hopf { from { transform: scaleX(-1) translateY(0) rotate(-2deg); } to { transform: scaleX(-1) translateY(-6px) rotate(2deg); } }
@keyframes charge { from { transform: scaleX(-1) scale(1); } to { transform: scaleX(-1) scale(1.08); } }
@keyframes spin { to { transform: translateX(-50%) rotate(360deg); } }
@keyframes rise { from { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 20% { transform: translate(-50%, -6px) scale(1); } to { opacity: 0; transform: translate(-50%, -44px); } }
@keyframes boom { from { opacity: 1; transform: translateX(-50%) scale(.4); } to { opacity: 0; transform: translateX(-50%) scale(1.5); } }
@keyframes meteor { from { opacity: 0; transform: translate(60px, -220px) scale(.7); } 80% { opacity: 1; } to { opacity: 0; transform: translate(-50%, 0) scale(1.3); } }
@keyframes shake { 20% { transform: translate(-6px, 3px); } 40% { transform: translate(6px, -3px); } 60% { transform: translate(-4px, 2px); } 80% { transform: translate(3px, -1px); } }
@keyframes bannerIn { 0% { opacity: 0; transform: scale(2); } 15% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes cut { 0% { opacity: 0; transform: translateX(-40%); } 20% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateX(20%); } }
@keyframes ready { from { transform: translateY(0); box-shadow: 0 4px 0 #1f1714, 0 0 0 rgba(255, 210, 60, 0); }
  to { transform: translateY(-4px); box-shadow: 0 6px 0 #1f1714, 0 0 18px rgba(255, 210, 60, .95); } }

.sun { position: absolute; right: 14%; top: 10%; width: 64px; height: 64px; border-radius: 50%; background: #fff6b8; box-shadow: 0 0 40px 14px rgba(255, 240, 160, .7); }
#field.th4 .sun { background: #f2ecff; box-shadow: 0 0 30px 8px rgba(220, 200, 255, .5); width: 48px; height: 48px; }
.cl { position: absolute; font-style: normal; font-size: 54px; opacity: .85; animation: drift 40s linear infinite; }
.cl.c1 { top: 8%; left: 10%; } .cl.c2 { top: 22%; left: 55%; font-size: 40px; animation-duration: 55s; } .cl.c3 { top: 34%; left: 25%; font-size: 30px; animation-duration: 70s; }
@keyframes drift { from { transform: translateX(0); } 50% { transform: translateX(-60px); } to { transform: translateX(0); } }

/* v0.4 — team picker (3 of 6) */
#menu h3 small { font-weight: 600; font-size: 12px; color: var(--soft); }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { position: relative; background: var(--card); border-radius: 14px; padding: 6px 4px 8px; text-align: center; box-shadow: 0 3px 0 #ead8c0;
  border-top: 5px solid var(--c, #ccc); font: inherit; color: inherit; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.slot .sl-art { width: 64px; } .slot .sl-art svg { width: 100%; height: auto; display: block; }
.slot b { font-size: 13px; } .slot small { font-size: 11px; color: var(--soft); }
.slot .x { position: absolute; top: 4px; right: 6px; font-style: normal; font-size: 11px; opacity: .45; }
.slot.empty { border: 2px dashed #e0cdb5; box-shadow: none; justify-content: center; min-height: 104px; color: var(--soft); }
.slot.empty span { font-size: 24px; }
.tc { cursor: pointer; transition: transform .1s; } .tc:active { transform: scale(.98); }
.tc-art { position: relative; }
.tc .tag { position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%); white-space: nowrap; font-size: 10px; font-weight: 700;
  background: #fff; border-radius: 8px; padding: 0 6px; box-shadow: 0 1px 3px rgba(0,0,0,.15); color: var(--soft); }
.tc.on { background: #fff6dc; box-shadow: 0 3px 0 #f1c96a, 0 0 0 2px #f6c445 inset; }
.tc.on .tag { background: #f6c445; color: #5a3b00; }
#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: rgba(60,40,30,.92); color: #fff; padding: 8px 14px;
  border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 999; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.unit.slow .spr { filter: hue-rotate(60deg) saturate(.8); }
