:root{
  --cream:#FFF7E4;
  --brown:#6B4A34;
  --brown-soft:#9C7A5C;
  --orange:#FFB347;
  --orange-deep:#FF9838;
  --pink:#FF8FA8;
  --sky:#7FD4E8;
  --green:#8ED17E;
  --white:#FFFFFF;
  --shadow:rgba(107,74,52,0.25);
  --maxw:480px;
}

*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%;}
body{
  margin:0;
  font-family:'Zen Maru Gothic', sans-serif;
  background:#3a2a1e;
  color:var(--brown);
  overflow:hidden;
  overscroll-behavior:none;
  user-select:none;
}
img{-webkit-user-drag:none; user-drag:none; pointer-events:none;}

#app{
  position:relative;
  width:100%;
  max-width:var(--maxw);
  height:100dvh;
  margin:0 auto;
  background:var(--cream);
  overflow:hidden;
  box-shadow:0 0 40px rgba(0,0,0,0.5);
}

.screen{
  position:absolute; inset:0;
  display:none;
  flex-direction:column;
  overflow:hidden;
}
.screen.active{display:flex;}

/* ---------- buttons ---------- */
.btn{
  font-family:'Zen Maru Gothic', sans-serif;
  font-weight:700;
  font-size:17px;
  border:none;
  border-radius:999px;
  padding:14px 28px;
  cursor:pointer;
  box-shadow:0 5px 0 rgba(0,0,0,0.15);
  transition:transform .08s ease;
}
.btn:active{transform:translateY(3px); box-shadow:0 2px 0 rgba(0,0,0,0.15);}
.btn-primary{background:linear-gradient(180deg,var(--orange),var(--orange-deep)); color:#fff;}
.btn-secondary{background:#fff; color:var(--brown); border:2px solid #EADFC8;}

.btn-back{
  width:38px; height:38px; border-radius:50%;
  border:none; background:#fff; color:var(--brown);
  font-size:18px; font-weight:800; box-shadow:0 3px 0 rgba(0,0,0,0.12);
}
.btn-back.small{width:34px;height:34px; font-size:16px;}

/* ---------- title screen ---------- */
#screen-title{
  align-items:center; justify-content:space-between; position:relative;
  background:radial-gradient(circle at 50% 20%, #fff2cf 0%, var(--cream) 60%);
  padding-top:calc(56px + env(safe-area-inset-top));
  padding-bottom:calc(18px + env(safe-area-inset-bottom));
}
.title-bg-glow{
  position:absolute; top:-20%; left:50%; transform:translateX(-50%);
  width:340px; height:340px; border-radius:50%;
  background:radial-gradient(circle, rgba(255,179,71,0.35), transparent 70%);
}
.title-wrap{position:relative; text-align:center; padding:0 24px;}
.title-emblem{
  width:150px; height:150px; margin:0 auto 6px;
  background:#fff; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 10px 0 var(--shadow), 0 0 0 6px #fff, 0 0 0 9px var(--orange);
  animation:float 2.6s ease-in-out infinite;
}
.title-emblem img{width:78%; height:78%; object-fit:contain;}
@keyframes float{0%,100%{transform:translateY(0);}50%{transform:translateY(-10px);}}

.game-title{
  font-family:'Baloo 2', 'Zen Maru Gothic', sans-serif;
  font-size:40px; font-weight:800; color:var(--brown);
  margin:18px 0 8px; line-height:1.15;
  text-shadow:3px 3px 0 #fff, 3px 3px 0 #fff;
}
.game-title .jp-num{color:var(--pink); font-size:46px;}
.game-title small{
  display:block; font-family:'Zen Maru Gothic';
  font-size:15px; font-weight:700; color:var(--brown-soft); margin-top:4px;
}
.title-buttons{display:flex; flex-direction:column; gap:12px; margin-top:26px; align-items:center;}
.title-buttons .btn{width:220px;}
.title-footnote{margin-top:0; font-size:11px; color:var(--brown-soft); opacity:0.6;}
.title-credit{
  text-align:center; font-size:10px; color:var(--brown-soft); opacity:0.55;
  line-height:1.6;
}

/* ---------- subheader (stage/skin select) ---------- */
.subheader{
  display:flex; align-items:center; gap:10px;
  padding:14px 16px; background:#fff;
  box-shadow:0 2px 8px rgba(0,0,0,0.06);
  position:relative; z-index:5;
}
.subheader h2{flex:1; text-align:center; font-size:17px; margin:0; font-weight:700;}
.subheader .spacer{width:38px;}

/* ---------- stage select ---------- */
.stage-grid{
  flex:1; overflow-y:auto;
  display:grid; grid-template-columns:1fr 1fr;
  gap:14px; padding:18px;
  align-content:start;
}
.stage-card{
  position:relative; border-radius:18px; overflow:hidden;
  aspect-ratio:3/4; background:#ddd;
  box-shadow:0 4px 0 rgba(0,0,0,0.12);
  border:3px solid #fff;
}
.stage-card img{width:100%; height:100%; object-fit:cover; display:block;}
.stage-card .stage-num{
  position:absolute; top:6px; left:8px;
  background:rgba(255,255,255,0.85); color:var(--brown);
  font-weight:800; font-size:13px; padding:2px 9px; border-radius:999px;
}
.stage-card .stage-clear-check{
  position:absolute; top:6px; right:8px;
  background:var(--green); color:#fff; font-size:13px; font-weight:800;
  width:22px; height:22px; border-radius:50%; display:flex; align-items:center; justify-content:center;
}
.stage-card.locked{filter:grayscale(1) brightness(0.55);}
.stage-card.locked::after{
  content:"🔒"; position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-size:26px;
}
.stage-card:not(.locked){cursor:pointer;}
.complete-banner{
  margin:14px 18px 0; padding:14px; text-align:center; border-radius:16px;
  background:linear-gradient(180deg,#FFE29A,#FFC157); font-weight:800; font-size:18px; color:var(--brown);
  box-shadow:0 4px 0 rgba(0,0,0,0.1);
}
.complete-banner span{font-size:12px; font-weight:600; display:block; margin-top:4px;}

/* ---------- skin select ---------- */
.skin-grid{flex:1; overflow-y:auto; padding:18px; display:flex; flex-direction:column; gap:14px;}
.skin-card{
  display:flex; align-items:center; gap:14px;
  background:#fff; border-radius:18px; padding:14px;
  box-shadow:0 3px 0 rgba(0,0,0,0.08); border:3px solid transparent;
}
.skin-card.selected{border-color:var(--orange);}
.skin-card.locked{opacity:0.5;}
.skin-card .skin-thumbs{display:flex; gap:4px;}
.skin-card .skin-thumbs img{width:40px; height:40px; object-fit:contain;}
.skin-card .skin-name{flex:1; font-weight:700; font-size:14px;}
.skin-card .skin-select-btn{
  font-size:12px; font-weight:700; padding:8px 14px; border-radius:999px;
  border:none; background:var(--orange); color:#fff;
}
.skin-card.selected .skin-select-btn{background:var(--green);}
.skin-card.locked .skin-select-btn{background:#ccc;}

/* ---------- unlock screen ---------- */
#screen-newunlock{align-items:center; justify-content:center; background:radial-gradient(circle at 50% 30%, #FFF0C2, var(--cream) 65%);}
.unlock-wrap{text-align:center; padding:24px;}
.unlock-badge{font-size:26px; font-weight:800; color:var(--pink); animation:pop 1s ease infinite;}
@keyframes pop{0%,100%{transform:scale(1);}50%{transform:scale(1.08);}}
.unlock-title{font-size:18px; font-weight:700; margin:10px 0 20px;}
.unlock-preview{display:flex; justify-content:center; gap:8px; margin-bottom:26px;}
.unlock-preview img{width:56px; height:56px; object-fit:contain; background:#fff; border-radius:14px; padding:6px; box-shadow:0 3px 0 rgba(0,0,0,0.1);}
#screen-newunlock .btn{display:block; width:220px; margin:8px auto;}

/* ---------- battle screen ---------- */
#screen-battle{background:#222;}
#battle-bg{
  position:absolute; inset:0; background-size:cover; background-position:center;
  transition:background-image .3s;
}
#battle-bg::after{
  content:""; position:absolute; inset:0;
  background:linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.0) 30%, rgba(0,0,0,0.0) 65%, rgba(0,0,0,0.35) 100%);
}
.battle-header{
  position:relative; z-index:6;
  display:flex; align-items:center; justify-content:space-between;
  padding:10px 12px;
}
.stage-label, .kill-label{
  background:rgba(255,255,255,0.88); color:var(--brown);
  font-weight:800; font-size:12px; padding:6px 12px; border-radius:999px;
}
#enemy-zone{
  position:relative; z-index:4;
  height:34%;
}
.enemy-wrap{position:absolute; bottom:8%; text-align:center; transition:opacity .3s;}
.enemy-wrap.floating{animation:enemyFloat 3.2s ease-in-out infinite;}
@keyframes enemyFloat{
  0%,100%{transform:translate(calc(-50% - 34px), 0px);}
  25%{transform:translate(calc(-50% - 14px), -10px);}
  50%{transform:translate(calc(-50% + 34px), 0px);}
  75%{transform:translate(calc(-50% - 14px), -10px);}
}
.enemy-sprite{width:118px; height:118px; object-fit:contain; filter:drop-shadow(0 6px 6px rgba(0,0,0,0.3));}
.enemy-hp-bar-wrap{width:96px; height:10px; background:rgba(0,0,0,0.35); border-radius:999px; margin:0 auto 4px; overflow:hidden; border:1px solid rgba(255,255,255,0.6);}
.enemy-hp-bar-fill{height:100%; width:100%; background:var(--green); transition:width .2s;}
.enemy-hp-bar-fill.low{background:#FF5C5C;}
.bomb-text{
  position:absolute; top:20%; left:50%; transform:translate(-50%,-50%) scale(0.4);
  font-family:'Baloo 2'; font-weight:800; font-size:22px; color:#fff;
  -webkit-text-stroke:3px #E4432A; text-stroke:3px #E4432A;
  opacity:0; pointer-events:none;
}
.bomb-text.show{animation:bombpop .6s ease forwards;}
@keyframes bombpop{
  0%{opacity:0; transform:translate(-50%,-50%) scale(0.3) rotate(-8deg);}
  35%{opacity:1; transform:translate(-50%,-50%) scale(1.15) rotate(4deg);}
  70%{opacity:1; transform:translate(-50%,-50%) scale(1) rotate(0deg);}
  100%{opacity:0; transform:translate(-50%,-60%) scale(1) rotate(0deg);}
}

#progress-center{
  position:relative; z-index:4;
  display:flex; flex-direction:column; align-items:center; gap:4px;
  padding:4px 0;
}
.progress-line{
  background:rgba(255,255,255,0.9); color:var(--brown); font-weight:800; font-size:13px;
  padding:4px 14px; border-radius:999px; min-height:14px; display:none;
}
.progress-line.show{display:block;}

#boost-bar{
  position:relative; z-index:6;
  display:flex; align-items:center; justify-content:center; gap:6px;
  padding:4px 14px 8px;
  flex-wrap:wrap;
  width:100%;
  box-sizing:border-box;
}
.boost-btn, .spboost-btn{
  font-family:'Zen Maru Gothic'; font-weight:800; font-size:11px; color:#fff;
  border:none; padding:7px 11px; border-radius:999px;
  box-shadow:0 3px 0 rgba(0,0,0,0.15);
  white-space:nowrap;
}
.boost-btn{background:linear-gradient(180deg,#7FD4E8,#4FB6D6);}
.boost-btn:disabled{background:#9c9c9c; opacity:0.7;}
.boost-btn:not(:disabled){animation:evolvePulse 1.1s ease-in-out infinite;}
.spboost-btn{background:linear-gradient(180deg,#FFD166,#FF9F1C);}
.spboost-btn:disabled{background:#9c9c9c; opacity:0.6;}
.spboost-btn:not(:disabled){animation:evolvePulse 0.8s ease-in-out infinite;}
.boost-stars{
  background:rgba(255,255,255,0.9); border-radius:999px; padding:6px 9px;
  font-size:12px; letter-spacing:1px; box-shadow:0 2px 0 rgba(0,0,0,0.1);
  white-space:nowrap;
}
#deploy-bar.sp-boost-active{
  background:rgba(255,244,214,0.98);
  box-shadow:0 0 0 3px #FFD166 inset;
}
#field-evolve-bar{
  position:relative; z-index:5;
  display:flex; justify-content:center; gap:8px;
  padding:0 10px; min-height:0;
}
.field-evolve-btn{
  display:none; align-items:center; gap:6px;
  font-family:'Zen Maru Gothic'; font-weight:800; font-size:14px; color:#fff;
  border:none; padding:10px 16px; border-radius:999px;
  background:linear-gradient(180deg,#FF8FA8,#FF5C8A);
  box-shadow:0 4px 0 rgba(0,0,0,0.15);
  animation:evolvePulse 1s ease-in-out infinite;
}
.field-evolve-btn.show{display:inline-flex;}
.field-evolve-btn img{width:32px; height:32px; object-fit:contain;}
.field-evolve-btn:active{transform:translateY(2px);}

#battlefield{
  position:relative; z-index:3; flex:1;
  overflow:hidden;
}
.unit.merging{transition:transform .45s ease, opacity .45s ease; transform:scale(1.3); opacity:0;}
.unit{
  position:absolute; bottom:6%;
  width:56px; text-align:center;
  transition:left 1.6s linear;
}
.unit img{width:56px; height:56px; object-fit:contain; filter:drop-shadow(0 4px 4px rgba(0,0,0,0.3));}
.unit .unit-hp-wrap{width:44px; height:6px; background:rgba(0,0,0,0.3); border-radius:999px; margin:0 auto 3px; overflow:hidden;}
.unit .unit-hp-fill{height:100%; background:var(--sky); width:100%;}
.unit.jump img{animation:jump .5s ease;}
@keyframes jump{0%{transform:translateY(0);}40%{transform:translateY(-22px);}100%{transform:translateY(0);}}
.unit.walk img{animation:walkbob .5s ease-in-out infinite;}
@keyframes walkbob{0%,100%{transform:translateY(0) rotate(0deg);}50%{transform:translateY(-3px) rotate(-3deg);}}
.unit.fight img{animation:fightbob .4s ease-in-out infinite;}
@keyframes fightbob{0%,100%{transform:scale(1);}50%{transform:scale(1.08);}}
.unit.dead{transition:opacity .5s; opacity:0;}
.unit .speech{
  position:absolute; top:-30px; left:50%; transform:translateX(-50%);
  background:#fff; border-radius:10px; padding:3px 8px; font-size:11px; font-weight:700;
  white-space:nowrap; box-shadow:0 2px 0 rgba(0,0,0,0.1);
  opacity:0; transition:opacity .2s;
}
.unit .speech.show{opacity:1;}
.unit .ghost{
  position:absolute; top:0; left:0; right:0; text-align:center; font-size:30px;
  opacity:0;
}
.unit.dead .ghost{opacity:1; animation:ghostfloat 1s ease forwards;}
@keyframes ghostfloat{0%{opacity:1; transform:translateY(0);}100%{opacity:0; transform:translateY(-40px);}}

#deploy-bar{
  position:relative; z-index:6;
  display:flex; justify-content:space-around; align-items:flex-end;
  background:rgba(255,247,228,0.96);
  border-top:3px solid #fff;
  padding:10px 6px calc(10px + env(safe-area-inset-bottom));
}
.deploy-slot{display:flex; flex-direction:column; align-items:center; gap:3px; width:23%;}
.deploy-count{font-weight:800; font-size:13px; color:var(--brown);}
.deploy-btn{
  width:100%; aspect-ratio:1; border-radius:16px; border:none;
  background:#8a7660; padding:8px;
  filter:brightness(0.55) saturate(0.6);
  transition:filter .25s, transform .1s;
}
.deploy-btn img{width:100%; height:100%; object-fit:contain;}
.deploy-btn:not(:disabled){
  background:linear-gradient(180deg,#fff,#FFEFD0);
  filter:brightness(1) saturate(1);
  box-shadow:0 4px 0 rgba(0,0,0,0.12);
}
.deploy-btn:not(:disabled):active{transform:translateY(3px); box-shadow:0 1px 0 rgba(0,0,0,0.12);}
.deploy-label{font-size:10px; font-weight:700; color:var(--brown-soft);}
.deploy-slot{position:relative;}
.evolve-btn{
  display:none;
  position:absolute; top:-34px; left:50%; transform:translateX(-50%);
  font-family:'Zen Maru Gothic'; font-weight:800; font-size:12px;
  color:#fff; border:none; padding:6px 14px; border-radius:999px;
  background:linear-gradient(180deg,#FF8FA8,#FF5C8A);
  box-shadow:0 3px 0 rgba(0,0,0,0.15);
  white-space:nowrap; z-index:2;
  animation:evolvePulse 1s ease-in-out infinite;
}
.evolve-btn.show{display:block;}
.evolve-btn:active{transform:translateX(-50%) translateY(2px);}
@keyframes evolvePulse{0%,100%{transform:translateX(-50%) scale(1);}50%{transform:translateX(-50%) scale(1.1);}}

/* ---------- clear screen ---------- */
#screen-clear{align-items:center; justify-content:center; background:radial-gradient(circle at 50% 25%, #FFF3CE, var(--cream) 60%); overflow-y:auto;}
.clear-wrap{padding:26px 22px; text-align:center; width:100%;}
.clear-title{
  font-family:'Baloo 2'; font-size:26px; font-weight:800; color:var(--orange-deep);
  margin-bottom:16px;
}
.clear-stats{background:#fff; border-radius:16px; padding:12px 18px; margin-bottom:16px; box-shadow:0 3px 0 rgba(0,0,0,0.08);}
.clear-stat-row{display:flex; justify-content:space-between; font-size:14px; padding:5px 0;}
.clear-used-title, .clear-record-title{font-weight:700; font-size:13px; margin:10px 0 6px; color:var(--brown-soft);}
.clear-used-list, .clear-record-list{background:#fff; border-radius:14px; padding:10px 16px; font-size:13px; text-align:left; box-shadow:0 3px 0 rgba(0,0,0,0.06);}
.clear-used-list div, .clear-record-list div{display:flex; justify-content:space-between; align-items:center; padding:5px 0;}
.clear-icon-row{border-bottom:1px solid #F3EAD4;}
.clear-icon-row:last-child{border-bottom:none;}
.clear-icon-label{display:flex; align-items:center; gap:6px; font-weight:700;}
.clear-thumb{width:28px; height:28px; object-fit:contain; background:#FFF7E4; border-radius:8px; padding:2px;}
.clear-arrow{font-size:12px; color:var(--brown-soft);}
.clear-buttons{display:flex; flex-direction:column; gap:10px; margin-top:22px;}
.clear-buttons .btn{width:100%;}

/* particles */
.fx-layer{position:absolute; inset:0; pointer-events:none; z-index:8; overflow:hidden;}
.fx-piece{position:absolute; font-size:20px; animation:fxfall linear forwards;}
@keyframes fxfall{
  0%{transform:translateY(-20px) rotate(0deg); opacity:1;}
  100%{transform:translateY(320px) rotate(360deg); opacity:0;}
}
.fx-sparkle{position:absolute; font-size:16px; animation:fxsparkle .9s ease forwards;}
@keyframes fxsparkle{
  0%{transform:scale(0) translateY(0); opacity:1;}
  60%{transform:scale(1.3) translateY(-14px); opacity:1;}
  100%{transform:scale(0.6) translateY(-30px); opacity:0;}
}

@media (min-width:481px){
  body{background:#3a2a1e;}
}
