:root {
  --ink: #2a2320; --washi: #f6eedb; --washi2: #efe2c2; --ai: #23345e; --ai2: #33497e; --shu: #d8452f; --shu2: #b8341f;
  --kin: #e9b44c; --matsu: #3d6b4f; --hai: #8a8170;
  font-size: clamp(11px, calc(min(2.2vh, 1.6vw) + 4px), 18px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ai); color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", 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.6rem; display: flex; align-items: center; gap: .35rem; padding: .25rem .4rem;
  background: linear-gradient(#2c4072, var(--ai)); color: #fff; border-bottom: 3px solid var(--kin); }
.sp { flex: 1; }
.ib { height: 2rem; min-width: 2rem; padding: 0 .35rem; border: 2px solid rgba(255,255,255,.35); border-radius: .55rem;
  background: rgba(255,255,255,.1); display: inline-flex; align-items: center; justify-content: center; }
.ib svg { width: 1.25rem; height: 1.25rem; }
.ib.txt { font-weight: 800; min-width: 2.6rem; }
.ib.on { background: var(--kin); 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: 2rem; display: inline-flex; align-items: center; gap: .3rem; padding: 0 .6rem; border-radius: 1rem;
  background: rgba(0,0,0,.25); font-weight: 800; white-space: nowrap; }
.chip b { font-size: 1.08rem; }
.chip .lab { font-size: .78rem; opacity: .85; }
.chip.life b { color: #ffd2c9; } .chip.rice b { color: #ffe9a8; }
.chip.bump { animation: bump .3s; }
@keyframes bump { 40% { transform: scale(1.15); } }
.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>'); }
.tawara { width: 1.15rem; height: 1.15rem; 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"><ellipse cx="12" cy="12" rx="10" ry="7.5" fill="%23e8c46a" stroke="%232a2320" stroke-width="1.6"/><path d="M6 6.2v11.6M18 6.2v11.6" stroke="%238a5a2b" stroke-width="2.2"/><path d="M3 12h18" stroke="%23c99a3e" stroke-width="1.2"/></svg>'); }

#main { flex: 1; min-height: 0; display: flex; flex-direction: row; }
#stage { flex: 1; min-width: 0; min-height: 0; position: relative; overflow: hidden; }
#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(35,52,94,.86); color: #fff; border-radius: 1rem; font-size: .85rem; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; pointer-events: none; border: 1.5px solid rgba(233,180,76,.7); }
#banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(.8); opacity: 0; pointer-events: none;
  padding: .5rem 1.6rem; background: var(--washi); border: 3px solid var(--ink); border-radius: .6rem; font-weight: 900; font-size: 1.6rem;
  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(--shu); color: #fff; }

#bar { flex: none; width: 10.8rem; display: flex; flex-direction: column; gap: .4rem; padding: .45rem;
  background: var(--washi) repeating-linear-gradient(90deg, transparent 0 22px, rgba(120,90,40,.04) 22px 23px);
  border-left: 3px solid var(--ink); position: relative; }
#towers { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.tw { position: relative; border: 2.5px solid var(--ink); border-radius: .6rem; background: #fffaf0; padding: .2rem .1rem .15rem;
  display: flex; flex-direction: column; align-items: center; line-height: 1.1; box-shadow: 0 .18rem 0 var(--ink); }
.tw canvas { width: 2.5rem; height: 2.5rem; }
.tw .n { font-weight: 800; font-size: .8rem; }
.tw .c { font-weight: 800; font-size: .78rem; color: #8a5a2b; display: flex; align-items: center; gap: .1rem; }
.tw .c i { width: .8rem; height: .8rem; }
.tw .kk { position: absolute; top: .1rem; left: .25rem; font-size: .62rem; font-weight: 800; opacity: .55; }
.tw.arm { background: #ffe9a8; outline: 3px solid var(--shu); }
.tw.poor { opacity: .5; }
.tw:active { transform: translateY(.12rem); box-shadow: 0 .06rem 0 var(--ink); }
#info { background: #fffaf0; border: 2.5px solid var(--ink); border-radius: .6rem; padding: .35rem .4rem; }
.ihead { display: flex; align-items: center; gap: .35rem; font-weight: 900; }
.ihead #iLv { color: var(--shu); font-size: .85rem; }
.ihead .x { margin-left: auto; width: 1.7rem; height: 1.7rem; border: 2px solid var(--ink); border-radius: 50%; background: #fff; font-weight: 900; line-height: 1; padding: 0; }
#iStats { font-size: .76rem; line-height: 1.35; margin: .2rem 0 .3rem; color: #4a3f36; }
.ibtns { display: flex; gap: .3rem; }
.ibtns .btn { flex: 1; padding: .3rem .1rem; font-size: .85rem; }
.btn { border: 2.5px solid var(--ink); border-radius: .6rem; 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: .7rem; 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: #f3dcd2; }
.btn.go { background: var(--shu); color: #fff; padding: .45rem .3rem; font-size: 1.15rem; margin-top: auto; }
.btn.go.wait { background: #c9bda4; color: var(--ink); }
.btn.go.call { background: var(--matsu); }
#next { background: rgba(255,255,255,.55); border: 2px dashed #b8a37a; border-radius: .6rem; padding: .25rem .35rem; }
.nlab { font-size: .72rem; font-weight: 800; color: #6d5a3c; }
#prev { display: flex; flex-wrap: wrap; gap: .15rem .4rem; align-items: center; min-height: 1.6rem; }
#prev span { display: inline-flex; align-items: center; font-weight: 900; font-size: .85rem; }
#prev img { width: 1.55rem; height: 1.55rem; }
#prev .bossw { color: var(--shu); font-size: .72rem; }

/* overlays */
.ov { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: .6rem;
  background: rgba(20,24,45,.45); z-index: 10; }
#start { background: radial-gradient(circle at 70% 20%, #f0a040, #c4562a 45%, #23345e 100%); }
#start.art { background: rgba(20,24,45,.25) url('img/keyart.webp') center/cover no-repeat; }
.ov.lock { pointer-events: none; }
.card { background: var(--washi); border: 3px solid var(--ink); border-radius: 1rem; box-shadow: 0 .4rem 0 var(--ink), 0 1rem 2rem rgba(0,0,0,.35);
  max-height: 100%; max-width: 100%; position: relative; }
.scard { width: 46rem; display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; }
.mas { width: 11rem; flex: none; align-self: flex-end; filter: drop-shadow(0 .2rem 0 rgba(0,0,0,.2)); }
.mas.sm { width: 7rem; }
.sbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .45rem; }
h1 { margin: 0; font-size: 2rem; line-height: 1.1; color: var(--ai); font-weight: 900; letter-spacing: .02em; }
h1 small { display: block; font-size: .95rem; color: var(--shu); margin-top: .15rem; }
h2 { margin: 0 0 .3rem; font-size: 1.4rem; color: var(--ai); }
.intro { margin: 0; font-size: .86rem; line-height: 1.45; }
#maps { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.mp { border: 2.5px solid var(--ink); border-radius: .6rem; background: #fff; padding: .25rem; text-align: center; box-shadow: 0 .18rem 0 var(--ink); }
.mp canvas { width: 100%; aspect-ratio: 16/9; border-radius: .3rem; display: block; }
.mp .mn { font-weight: 900; font-size: .9rem; margin-top: .15rem; }
.mp .ms { font-size: .7rem; color: #6d5a3c; font-weight: 700; }
.mp .st { color: #d9a425; letter-spacing: .05em; font-size: .85rem; }
.mp .st .e { color: #c8bfae; }
.mp.sel { background: #ffe9a8; outline: 3px solid var(--shu); }
.keys { display: flex; flex-wrap: wrap; gap: .2rem .6rem; font-size: .72rem; font-weight: 700; color: #4a3f36; }
.k { display: inline-block; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: .3rem; padding: 0 .3rem; margin-right: .15rem; background: #fff; font-size: .7rem; }
.foot { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; }
.foot.col { flex-direction: column; align-items: stretch; }
.btn.big { background: var(--shu); color: #fff; font-size: 1.3rem; padding: .5rem 1.6rem; }
.btn.sub { padding: .45rem .8rem; font-size: .9rem; }
.endl { display: inline-flex; align-items: center; gap: .3rem; font-weight: 800; font-size: .85rem; }
.endl input { width: 1.1rem; height: 1.1rem; }
.endl.locked { opacity: .5; }
.hcard { width: 40rem; display: flex; flex-direction: column; padding: .8rem 1rem; max-height: 96%; }
.scroll { overflow-y: auto; min-height: 0; flex: 1; font-size: .85rem; line-height: 1.5; touch-action: pan-y; padding-right: .3rem; }
.scroll p { margin: .2rem 0 .4rem; } .scroll ol { margin: .2rem 0 .5rem; padding-left: 1.3rem; }
.scroll .red { color: var(--shu); } .small { font-size: .75rem; color: #6d5a3c; }
.hcard .foot { margin-top: .5rem; justify-content: center; }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .3rem; margin: .3rem 0; }
.ro { display: flex; align-items: center; gap: .4rem; background: #fff; border: 1.5px solid #cbb994; border-radius: .5rem; padding: .2rem .35rem; font-size: .76rem; line-height: 1.3; }
.ro canvas, .ro img { width: 2.1rem; height: 2.1rem; flex: none; }
.ro b { font-size: .82rem; }
.pcard { width: 18rem; padding: 1rem; text-align: center; }
.ecard { width: 34rem; display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; }
.ebody { flex: 1; text-align: center; }
#eStars { font-size: 2.4rem; color: #e2ab22; letter-spacing: .1em; line-height: 1; -webkit-text-stroke: 1.5px var(--ink); }
#eStars .e { color: #e6dccb; }
#eText { margin: .4rem 0 .6rem; font-weight: 700; font-size: .95rem; }
.ecard .foot { justify-content: center; }

/* portrait: map on top, bar at the bottom */
@media (max-aspect-ratio: 1/1) {
  #main { flex-direction: column; }
  #bar { width: auto; border-left: 0; border-top: 3px solid var(--ink); display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; gap: .35rem; }
  #towers { grid-column: 1 / 3; grid-template-columns: repeat(4, 1fr); }
  #info { grid-column: 1 / 3; }
  #tip { bottom: auto; top: .35rem; }
  .btn.go { margin-top: 0; }
  .chip .lab { display: none; }
  .scard { flex-direction: column; width: 100%; padding: .7rem; gap: .2rem; }
  .mas { width: 6.5rem; align-self: center; margin-bottom: -.3rem; }
  .ecard { flex-direction: column; }
  .mas.sm { width: 5rem; }
  #maps { gap: .3rem; }
  h1 { font-size: 1.7rem; text-align: center; }
}
/* short frames (store page 794x447 and smaller) */
@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  .scard { width: 44rem; padding: .55rem .8rem; }
  .mas { width: 9rem; }
  h1 { font-size: 1.6rem; }
  .intro { font-size: .8rem; }
  .btn.big { font-size: 1.15rem; padding: .4rem 1.3rem; }
}
@media (max-height: 420px) and (min-aspect-ratio: 1/1) {
  #hud { height: 2.3rem; }
  .ib, .chip { height: 1.8rem; }
  .mas { width: 7rem; }
  .keys { display: none; }
  .intro { font-size: .76rem; }
  #bar { gap: .3rem; padding: .35rem; }
  .tw canvas { width: 2.1rem; height: 2.1rem; }
}
