:root {
  --ink: #1f2a22; --forest: #24452f; --forest2: #2f5a3c; --gold: #f2c14e; --gold2: #d9a53a; --red: #c8412f; --blue: #2f6db3;
  --stone: #eceae3; --stone2: #d9d5c9; --wood: #8a5a33; --wood2: #6e4426; --cream: #fff9ea;
  font-size: clamp(11px, calc(min(2.2vh, 1.6vw) + 4px), 22px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--forest); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#hud { flex: none; height: 2.7rem; display: flex; align-items: center; gap: .35rem; padding: .25rem .45rem;
  background: linear-gradient(#2f5a3c, var(--forest)); color: #fff; border-bottom: 3px solid var(--gold); }
.sp { flex: 1; }
.ib { height: 2.05rem; min-width: 2.05rem; padding: 0 .35rem; border: 2px solid rgba(255,255,255,.4); border-radius: 50%;
  background: rgba(255,255,255,.1); display: inline-flex; align-items: center; justify-content: center; }
.ib.txt { border-radius: 1rem; font-weight: 800; min-width: 2.7rem; }
.ib svg { width: 1.2rem; height: 1.2rem; }
.ib.on { background: var(--gold); color: var(--ink); border-color: #fff3c4; }
.ib:active { transform: scale(.94); }
.snd .x { display: none; } .snd.off .x { display: inline; } .snd.off .w { display: none; }
.chip { height: 2.05rem; display: inline-flex; align-items: center; gap: .3rem; padding: 0 .65rem; border-radius: .5rem;
  background: rgba(0,0,0,.28); border: 1.5px solid rgba(242,193,78,.45); font-weight: 800; white-space: nowrap; }
.chip b { font-size: 1.08rem; }
.chip .lab { font-size: .78rem; opacity: .85; }
.chip.life b { color: #ffd0c6; } .chip.wood b { color: #ffe4a8; }
.chip.bump { animation: bump .3s; } .chip.hurt { animation: hurt .45s; }
@keyframes bump { 40% { transform: scale(1.15); } }
@keyframes hurt { 30% { transform: translateX(-3px); background: #c8412f; } 60% { transform: translateX(3px); } }
.heart { width: 1rem; height: 1rem; display: inline-block; background: no-repeat center/contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 21s-8-5.3-8-11a4.5 4.5 0 0 1 8-2.8A4.5 4.5 0 0 1 20 10c0 5.7-8 11-8 11z" fill="%23e8553f" stroke="%23fff" stroke-width="1.5"/></svg>'); }
.logs { width: 1.2rem; height: 1.2rem; display: inline-block; background: no-repeat center/contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="3" y="12" width="18" height="6" rx="3" fill="%23b5753d" stroke="%231f2a22" stroke-width="1.4"/><rect x="5" y="6" width="15" height="6" rx="3" fill="%23c98a4b" stroke="%231f2a22" stroke-width="1.4"/><circle cx="18" cy="15" r="2.2" fill="%23f0d39a" stroke="%231f2a22" stroke-width="1"/><circle cx="17" cy="9" r="2.2" fill="%23f0d39a" stroke="%231f2a22" stroke-width="1"/></svg>'); }
.star { width: 1.1rem; height: 1.1rem; display: inline-block; vertical-align: -.15rem; background: no-repeat center/contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2.5l2.9 6 6.6.8-4.9 4.5 1.3 6.5L12 17l-5.9 3.3 1.3-6.5L2.5 9.3l6.6-.8z" fill="%23f2c14e" stroke="%231f2a22" stroke-width="1.5" stroke-linejoin="round"/></svg>'); }
.star.off { filter: grayscale(1) opacity(.35); }
.star.sm { width: .9rem; height: .9rem; }

#main { flex: 1; min-height: 0; display: flex; flex-direction: row; }
#stage { flex: 1; min-width: 0; min-height: 0; position: relative; overflow: hidden; background: #3c6b43; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#tip { position: absolute; left: 50%; bottom: .35rem; transform: translateX(-50%); max-width: 94%; padding: .25rem .8rem;
  background: rgba(31,42,34,.85); color: #fff; border-radius: .5rem; font-size: .82rem; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; pointer-events: none; border: 1.5px solid rgba(242,193,78,.7); }
#banner { position: absolute; left: 50%; top: 36%; transform: translate(-50%, -50%) scale(.8); opacity: 0; pointer-events: none;
  padding: .45rem 1.6rem; background: var(--cream); border: 3px solid var(--ink); border-radius: .4rem; font-weight: 900; font-size: 1.55rem;
  box-shadow: 0 .3rem 0 var(--ink); transition: opacity .25s, transform .25s; white-space: nowrap; color: var(--ink); }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner.boss { background: var(--red); color: #fff; }

#bar { flex: none; width: 11rem; display: flex; flex-direction: column; gap: .4rem; padding: .45rem;
  background: var(--wood) repeating-linear-gradient(0deg, transparent 0 1.9rem, rgba(0,0,0,.18) 1.9rem calc(1.9rem + 2px));
  border-left: 3px solid var(--ink); }
#towers { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.tw { position: relative; border: 2.5px solid var(--ink); border-radius: .5rem; background: var(--stone); padding: .15rem .1rem .1rem;
  display: flex; flex-direction: column; align-items: center; line-height: 1.08; box-shadow: 0 .18rem 0 var(--ink); min-width: 0; }
.tw canvas { width: 2.1rem; height: 2.1rem; }
.tw .n { font-weight: 800; font-size: .7rem; white-space: nowrap; }
.tw .c { font-weight: 800; font-size: .76rem; color: #7a4a1c; display: flex; align-items: center; gap: .1rem; }
.tw .c i { width: .8rem; height: .8rem; }
.tw .kk { position: absolute; top: .05rem; left: .25rem; font-size: .6rem; font-weight: 800; opacity: .55; }
.tw .air { position: absolute; top: .1rem; right: .2rem; width: .75rem; height: .75rem; background: no-repeat center/contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 9c2-4 6-5 10-3-1 3-3 5-6 5 1 2 0 4-1 5-1-2-2-3-3-3s-2 1-3 3c-1-1-2-3-1-5-3 0-5-2-6-5 4-2 8-1 10 3z" fill="%237a4fb5" stroke="%231f2a22" stroke-width="1.2"/></svg>'); }
.tw.arm { background: #ffe39a; outline: 3px solid var(--red); }
.tw.poor { opacity: .5; }
.tw:active { transform: translateY(.12rem); box-shadow: 0 .06rem 0 var(--ink); }
#low { display: flex; flex-direction: column; gap: .4rem; flex: 1; min-height: 0; }
#info { background: var(--cream); border: 2.5px solid var(--ink); border-radius: .5rem; padding: .3rem .4rem; }
.ihead { display: flex; align-items: center; gap: .35rem; font-weight: 900; font-size: .9rem; }
.ihead #iName { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ihead #iLv { color: var(--red); font-size: .74rem; white-space: nowrap; flex: none; }
.ihead .x { margin-left: 0; width: 1.6rem; height: 1.6rem; flex: none; border: 2px solid var(--ink); border-radius: 50%; background: #fff; font-weight: 900; line-height: 1; padding: 0; }
#iStats { font-size: .72rem; line-height: 1.3; margin: .15rem 0 .25rem; color: #3b3a33; }
.ibtns { display: flex; gap: .3rem; }
.ibtns .btn { flex: 1; padding: .25rem .1rem; font-size: .8rem; }
.btn { border: 2.5px solid var(--ink); border-radius: .5rem; background: #fff; font-weight: 900; box-shadow: 0 .2rem 0 var(--ink);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.btn small { font-size: .68rem; font-weight: 800; opacity: .85; }
.btn:active { transform: translateY(.15rem); box-shadow: 0 .05rem 0 var(--ink); }
.btn:disabled { opacity: .45; }
.btn.up { background: #ffe39a; } .btn.sell { background: #f1d6cc; }
.btn.tgt { width: 100%; padding: .2rem; font-size: .74rem; margin-bottom: .3rem; background: #dbe8f7; box-shadow: 0 .12rem 0 var(--ink); }
.btn.go { background: var(--red); color: #fff; padding: .45rem .3rem; font-size: 1.05rem; margin-top: auto; }
.btn.go.call { background: var(--blue); }
.btn.go.wait { background: #c9bda4; color: var(--ink); }
#next { background: rgba(255,249,234,.85); border: 2px dashed var(--ink); border-radius: .5rem; padding: .2rem .35rem; }
.nlab { font-size: .7rem; font-weight: 800; color: #5a4630; }
#prev { display: flex; flex-wrap: wrap; gap: .1rem .4rem; align-items: center; min-height: 1.6rem; }
#prev span { display: inline-flex; align-items: center; font-weight: 900; font-size: .82rem; }
#prev img { width: 1.5rem; height: 1.5rem; }

/* portrait: bar under the map */
body.port #main { flex-direction: column; }
body.port #bar { width: auto; border-left: 0; border-top: 3px solid var(--ink); padding: .4rem; gap: .35rem; }
body.port #towers { grid-template-columns: repeat(5, 1fr); }
body.port #low { flex-direction: row; align-items: stretch; flex: none; min-height: 5.8rem; }
body.port #info, body.port #next { flex: 1; min-width: 0; }
body.port #info { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "h h" "s b" "t b"; gap: .15rem .3rem; }
body.port .ihead { grid-area: h; } body.port #iStats { grid-area: s; margin: 0; } body.port .btn.tgt { grid-area: t; margin: 0; }
body.port .ibtns { grid-area: b; flex-direction: column; }
body.port .btn.go { width: 6.2rem; margin-top: 0; flex: none; }

/* overlays */
.ov { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: .6rem; z-index: 10;
  background: rgba(20,32,24,.55); }
#start { background: rgba(20,32,24,.45) center/cover no-repeat; }
#start.art { background-image: linear-gradient(rgba(20,32,24,.35), rgba(20,32,24,.35)), url('img/keyart.webp'); }
.card { background: var(--cream); border: 3px solid var(--ink); border-radius: .8rem; box-shadow: 0 .4rem 0 var(--ink);
  max-height: 94vh; max-width: 100%; display: flex; flex-direction: column; overflow: hidden; }
.card h2 { margin: .6rem .9rem .3rem; font-size: 1.4rem; display: flex; align-items: center; gap: .5rem; }
.scroll { overflow-y: auto; min-height: 0; flex: 1; padding: 0 .9rem; touch-action: pan-y; }
.foot { display: flex; gap: .45rem; padding: .55rem .9rem .7rem; flex-wrap: wrap; justify-content: center; flex: none; }
.foot.col { flex-direction: column; align-items: stretch; }
.btn.big { background: var(--red); color: #fff; font-size: 1.25rem; padding: .5rem 1.6rem; }
.btn.sub { background: #fff; font-size: .95rem; padding: .45rem .9rem; flex-direction: row; gap: .3rem; }
.scard { flex-direction: row; width: 52rem; align-items: stretch; }
.scard .mas { width: 13rem; object-fit: contain; align-self: flex-end; margin: .5rem 0 0 .3rem; flex: none; }
.sbody { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sbody h1 { margin: .6rem 0 .1rem; font-size: 2.2rem; line-height: 1; color: var(--forest); letter-spacing: .01em; }
.sbody h1 small { display: block; font-size: 1.05rem; color: var(--red); margin-top: .2rem; }
.intro { margin: .35rem 0 .45rem; font-size: .88rem; line-height: 1.35; }
#maps { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.mapc { border: 2.5px solid var(--ink); border-radius: .5rem; background: #fff; padding: .2rem; display: flex; flex-direction: column; align-items: stretch; box-shadow: 0 .15rem 0 var(--ink); line-height: 1.1; min-width: 0; }
.mapc canvas { width: 100%; aspect-ratio: 18 / 10; border-radius: .3rem; border: 1.5px solid var(--ink); }
.mapc .mn { font-weight: 900; font-size: .82rem; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mapc .ms { font-size: .68rem; font-weight: 700; color: #6b5a45; display: flex; justify-content: space-between; align-items: center; }
.mapc.sel { outline: 3.5px solid var(--red); background: #fff3d2; }
.mapc.lock { opacity: .55; }
.keys { display: flex; flex-wrap: wrap; gap: .25rem .7rem; margin: .5rem 0 .2rem; font-size: .74rem; font-weight: 700; color: #4a4338; }
.k { display: inline-block; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: .3rem; padding: 0 .3rem; margin-right: .2rem; background: #fff; font-size: .7rem; }
.hcard { width: 40rem; }
.hcard p, .hcard li { font-size: .88rem; line-height: 1.4; }
.hcard ol { padding-left: 1.2rem; margin: .3rem 0; }
.red { color: var(--red); }
.small { font-size: .76rem !important; color: #5d5446; }
.roster { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.roster div { display: flex; align-items: center; gap: .3rem; background: #fff; border: 1.5px solid var(--ink); border-radius: .4rem; padding: .1rem .4rem .1rem .1rem; font-size: .74rem; line-height: 1.15; }
.roster img { width: 2rem; height: 2rem; }
.roster b { display: block; font-size: .8rem; }
.have { margin-left: auto; font-size: 1.1rem; display: inline-flex; align-items: center; gap: .2rem; }
.perk { display: flex; align-items: center; gap: .5rem; background: #fff; border: 2px solid var(--ink); border-radius: .5rem; padding: .35rem .5rem; margin: .35rem 0; }
.perk .pt { flex: 1; min-width: 0; } .perk .pt b { display: block; } .perk .pt span { font-size: .78rem; color: #5d5446; }
.perk .pips { display: flex; gap: .2rem; } .perk .pips i { width: .8rem; height: .8rem; border: 2px solid var(--ink); border-radius: 50%; background: #fff; }
.perk .pips i.on { background: var(--gold); }
.perk .btn { padding: .3rem .7rem; background: #ffe39a; flex-direction: row; gap: .2rem; }
.pcard { width: 17rem; } .pcard h2 { justify-content: center; }
.ecard { flex-direction: row; width: 34rem; }
.ecard .mas.sm { width: 9rem; object-fit: contain; align-self: flex-end; margin: .4rem 0 0 .4rem; }
.ebody { flex: 1; display: flex; flex-direction: column; padding-top: .2rem; min-width: 0; }
#eStars { display: flex; gap: .3rem; padding: 0 .9rem; } #eStars .star { width: 2.4rem; height: 2.4rem; }
#eStars .star.pop { animation: pop .4s backwards; }
@keyframes pop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } }
#eText { margin: .35rem .9rem; font-size: .9rem; line-height: 1.4; }
.ebody .foot { justify-content: flex-start; }

@media (max-height: 560px) {
  .scard .mas { width: 10rem; }
  .sbody h1 { font-size: 1.8rem; margin-top: .4rem; }
  .intro { font-size: .8rem; margin: .25rem 0 .35rem; }
  .keys { margin: .35rem 0 0; }
  .foot { padding: .4rem .9rem .5rem; }
  .ecard .mas.sm { width: 7rem; }
}
@media (max-height: 420px) {
  body:not(.port) .tw .n { display: none; }
  body:not(.port) .tw canvas { width: 1.9rem; height: 1.9rem; }
  body:not(.port) #bar { gap: .3rem; padding: .35rem; }
  .scard .mas { display: none; }
  .ecard .mas.sm { display: none; }
  .sbody h1 { font-size: 1.5rem; }
  .btn.big { font-size: 1.1rem; padding: .4rem 1.3rem; }
}
@media (max-width: 640px) {
  .scard .mas { display: none; }
  .ecard .mas.sm { display: none; }
}
@media (max-width: 640px) and (min-height: 500px) {
  #maps { grid-template-columns: 1fr 1fr; }
  .sbody h1 { font-size: 1.8rem; }
}
