:root {
  --ink: #141414; --paper: #FFF6E3; --orange: #FF7A1A; --amber: #FFB21F; --star: #D7261E;
  --ki: #4FC3FF; --red: #E0302A; --k: 1;
  --disp: 'Bangers', 'Impact', sans-serif; --body: 'Nunito', 'Segoe UI', sans-serif;
  --tone: radial-gradient(circle, rgba(20,20,20,.22) 1.1px, transparent 1.4px) 0 0 / 6px 6px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7EC8F2; font-family: var(--body); color: var(--ink);
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
button { font-family: inherit; cursor: pointer; color: inherit; }
img { -webkit-user-drag: none; }
.hidden { display: none !important; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.panel { background: var(--paper); border: calc(3px * var(--k)) solid var(--ink); box-shadow: calc(4px*var(--k)) calc(4px*var(--k)) 0 var(--ink); }
.paper { background: var(--paper); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.disp { font-family: var(--disp); letter-spacing: .02em; line-height: 1.3; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; font-size: max(calc(15px*var(--k)), 11.5px); }
#hud > * { pointer-events: auto; }
#scouter { position: absolute; left: calc(10px*var(--k)); top: calc(10px*var(--k)); width: calc(330px*var(--k));
  display: grid; grid-template-columns: calc(74px*var(--k)) 1fr; gap: calc(6px*var(--k)); padding: calc(6px*var(--k)); background: var(--paper); }
.sc-pt { width: calc(74px*var(--k)); height: calc(74px*var(--k)); border: calc(3px*var(--k)) solid var(--ink); overflow: hidden; background: #fff; }
.sc-pt img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sc-read { position: relative; overflow: hidden; border: calc(3px*var(--k)) solid var(--ink); border-radius: 0 calc(38px*var(--k)) calc(38px*var(--k)) 0;
  background: linear-gradient(rgba(90,255,130,.24), rgba(40,200,90,.34)), rgba(20,60,30,.72);
  color: #9dffa6; padding: calc(4px*var(--k)) calc(10px*var(--k)); font-family: var(--disp); line-height: 1.25; }
.sc-read::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.22) 0 1px, transparent 1px 3px); animation: scan 3.2s steps(40) infinite; }
@keyframes scan { 0%{opacity:.9} 50%{opacity:.6} 52%{opacity:1} 100%{opacity:.85} }
.sc-lv { font-size: max(calc(26px*var(--k)), 11.5px); color: #d8ffd8; }
.sc-pow { font-size: max(calc(19px*var(--k)), 11.5px); white-space: nowrap; }
.sc-crack { position: absolute; inset: 0; opacity: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 46%, rgba(255,255,255,.95) 47%, transparent 48.5%),
    linear-gradient(28deg, transparent 58%, rgba(255,255,255,.9) 59%, transparent 60%),
    linear-gradient(160deg, transparent 30%, rgba(255,255,255,.8) 31%, transparent 32%); }
#scouter.crack .sc-crack { animation: crack .9s ease-out; }
#scouter.crack .sc-read { animation: shake .35s linear 2; }
@keyframes crack { 0%{opacity:1} 70%{opacity:1} 100%{opacity:0} }
@keyframes shake { 0%,100%{transform:translate(0)} 25%{transform:translate(-3px,1px)} 75%{transform:translate(3px,-1px)} }
.bars { grid-column: 1 / 3; display: flex; flex-direction: column; gap: calc(4px*var(--k)); }
.bar { display: grid; grid-template-columns: calc(30px*var(--k)) 1fr auto; align-items: center; gap: calc(6px*var(--k)); font-weight: 900; font-size: max(calc(13px*var(--k)), 11.5px); }
.bar b { font-family: var(--disp); font-weight: 400; font-size: max(calc(16px*var(--k)), 11.5px); background: var(--ink); color: #fff; text-align: center; line-height: 1.3; }
.bar .fill { height: calc(15px*var(--k)); border: calc(2.5px*var(--k)) solid var(--ink); background: #fff; position: relative; overflow: hidden; }
.bar .fill i { position: absolute; inset: 0; transform-origin: left; transition: transform .18s; }
.bar.hp i { background: linear-gradient(#ff6a5c, #E0302A 60%, #b51d18); }
.bar.ki i { background: linear-gradient(#a8e6ff, #4FC3FF 60%, #1d8fd6); }
.bar.xp { grid-template-columns: 1fr; }
.bar.xp .fill { height: calc(8px*var(--k)); }
.bar.xp i { background: var(--amber); }
.bar span { min-width: calc(74px*var(--k)); text-align: right; font-variant-numeric: tabular-nums; }

#quest { position: absolute; right: calc(10px*var(--k)); top: calc(10px*var(--k)); width: calc(330px*var(--k)); padding: calc(7px*var(--k)); }
.q-row { display: flex; gap: calc(8px*var(--k)); }
.q-row img { width: calc(62px*var(--k)); height: calc(62px*var(--k)); border: calc(3px*var(--k)) solid var(--ink); object-fit: cover; flex: none; background: #fff; }
.q-txt { min-width: 0; }
.q-ch { font-weight: 900; font-size: max(calc(14px*var(--k)), 11.5px); border-bottom: 2px solid var(--ink); padding-bottom: 2px; }
.q-obj { font-weight: 700; font-size: max(calc(14px*var(--k)), 11.5px); line-height: 1.3; margin-top: 3px; }
.q-prog { font-family: var(--disp); font-size: max(calc(20px*var(--k)), 11.5px); color: var(--orange); -webkit-text-stroke: .5px var(--ink); line-height: 1.3; }
.balls { display: flex; gap: calc(5px*var(--k)); margin-top: calc(6px*var(--k)); justify-content: flex-end; }
.balls i { width: calc(24px*var(--k)); height: calc(24px*var(--k)); border-radius: 50%; border: 2px solid var(--ink); background: var(--tone), #e9e1cf; display: block; }
.balls i.got { background: url(img/dragonball.webp) center/cover; border-color: var(--ink); }
.hunt { font-size: max(calc(12.5px*var(--k)), 11.5px); font-weight: 800; margin-top: 4px; color: var(--red); line-height: 1.3; }
.hunt:empty { display: none; }

#menubtns { position: absolute; right: calc(10px*var(--k)); display: flex; gap: calc(5px*var(--k)); }
#menubtns button { width: calc(62px*var(--k)); height: calc(54px*var(--k)); background: var(--paper); border: calc(3px*var(--k)) solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink); padding: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#menubtns img { width: calc(28px*var(--k)); height: calc(28px*var(--k)); object-fit: contain; }
#menubtns span { font-size: max(calc(11px*var(--k)), 11px); font-weight: 900; line-height: 1.2; white-space: nowrap; }
#menubtns .snd-ico { font-size: max(calc(22px*var(--k)), 11.5px); line-height: 1.1; }
#menubtns button:active { transform: translate(2px,2px); box-shadow: none; }

#bossbar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(10px*var(--k)); width: min(calc(560px*var(--k)), 40vw); }
.bb-name { display: flex; justify-content: space-between; font-family: var(--disp); font-size: max(calc(24px*var(--k)), 11.5px); color: #fff;
  -webkit-text-stroke: calc(1.2px*var(--k)) var(--ink); paint-order: stroke fill; text-shadow: 2px 2px 0 var(--ink); line-height: 1.35; }
.bb-name #bbPow { font-size: max(calc(17px*var(--k)), 11.5px); }
.bb-bar { height: calc(20px*var(--k)); background: var(--tone), #fff; border: calc(3px*var(--k)) solid var(--ink); box-shadow: 3px 3px 0 var(--ink); position: relative; overflow: hidden; }
.bb-bar i { position: absolute; inset: 0; background: linear-gradient(#ff7a6a, #E0302A 55%, #a8160f); transform-origin: left; transition: transform .15s; }

#skillbar { position: absolute; left: 50%; bottom: calc(10px*var(--k) + var(--safe-b)); transform: translateX(-50%); display: flex; gap: calc(6px*var(--k));
  padding: calc(6px*var(--k)); background: var(--paper); border: calc(3px*var(--k)) solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.sk { position: relative; width: calc(80px*var(--k)); height: calc(80px*var(--k)); border: calc(3px*var(--k)) solid var(--ink); background: #fff; padding: 0; overflow: hidden; touch-action: none; }
.sk img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sk .key { position: absolute; left: 0; top: 0; background: var(--ink); color: #fff; font-family: var(--disp); font-size: max(calc(16px*var(--k)), 11.5px); padding: 0 calc(5px*var(--k)); line-height: 1.3; }
.sk .stars { position: absolute; right: 2px; top: 1px; color: var(--amber); font-size: max(calc(11px*var(--k)), 11px); -webkit-text-stroke: .6px var(--ink); letter-spacing: -1px; line-height: 1; }
.sk .nm { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(255,246,227,.92); border-top: 2px solid var(--ink); font-size: max(calc(10.5px*var(--k)), 10.5px); font-weight: 900; line-height: 1.25; text-align: center; white-space: nowrap; overflow: hidden; }
.sk .cd { position: absolute; inset: 0; background: radial-gradient(circle, rgba(20,20,20,.75) 1.6px, transparent 2px) 0 0 / 6px 6px, rgba(255,246,227,.35);
  -webkit-mask: conic-gradient(#000 var(--p, 0turn), transparent 0); mask: conic-gradient(#000 var(--p, 0turn), transparent 0); pointer-events: none; }
.sk.lock img { filter: grayscale(1) contrast(.7) brightness(1.2); }
.sk.lock::after { content: attr(data-lock); position: absolute; left: 0; right: 0; top: 0; bottom: max(calc(14px*var(--k)), 13px); display: flex; align-items: center; justify-content: center; text-align: center;
  background: var(--tone), rgba(255,246,227,.55); font-weight: 900; font-size: max(calc(11.5px*var(--k)), 11.5px); line-height: 1.2; padding: 2px; }
.sk.noki img { filter: saturate(.3) brightness(.85); }
.sk.on { outline: calc(4px*var(--k)) solid var(--orange); outline-offset: -2px; }
.sk.ready { animation: pop .25s; }
@keyframes pop { 50% { transform: scale(1.12); } }

#controls { position: absolute; left: calc(10px*var(--k)); bottom: calc(10px*var(--k) + var(--safe-b)); display: flex; align-items: center; gap: 6px;
  padding: calc(4px*var(--k)); font-size: max(calc(12.5px*var(--k)), 11.5px); font-weight: 800; max-width: calc(50vw - 260px*var(--k)); }
.ctl-toggle { width: calc(28px*var(--k)); height: calc(28px*var(--k)); border: 2px solid var(--ink); background: var(--amber); font-family: var(--disp); font-size: max(calc(18px*var(--k)), 11.5px); flex: none; padding: 0; line-height: 1; }
.ctl-body { display: flex; flex-wrap: wrap; gap: 3px 9px; line-height: 1.4; }
.ctl-body kbd { font-family: var(--disp); font-size: 1.05em; border: 2px solid var(--ink); background: #fff; padding: 0 4px; margin-right: 2px; border-radius: 3px; }
#controls.min .ctl-body { display: none; }

#touch { display: none; position: absolute; inset: 0; pointer-events: none; }
body.touch #touch { display: block; }
#stick { position: absolute; left: calc(18px + env(safe-area-inset-left,0px)); bottom: calc(var(--tb, 110px) + var(--safe-b)); width: 136px; height: 136px; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--tone), rgba(255,246,227,.55); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px; border-radius: 50%; background: var(--orange); border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); }
#tbtns { position: absolute; right: calc(14px + env(safe-area-inset-right,0px)); bottom: calc(var(--tb, 110px) + var(--safe-b)); width: 190px; height: 160px; pointer-events: none; }
.tb { position: absolute; pointer-events: auto; touch-action: none; border: 3px solid var(--ink); border-radius: 50%; background: var(--paper); font-family: var(--disp); font-size: 17px; box-shadow: 3px 3px 0 var(--ink); line-height: 1.2; }
.tb.big { width: 86px; height: 86px; right: 0; bottom: 0; background: var(--orange); color: #fff; font-size: 24px; -webkit-text-stroke: 1px var(--ink); }
#tJump { width: 64px; height: 64px; right: 96px; bottom: 0; }
#tFly { width: 64px; height: 64px; right: 14px; bottom: 96px; }
#tHeal { width: 52px; height: 52px; right: 100px; bottom: 82px; padding: 0; }
#tHeal img { width: 30px; height: 30px; }
#tHeal span { position: absolute; right: -4px; bottom: -4px; background: var(--ink); color: #fff; font-size: 12px; padding: 0 4px; border-radius: 6px; }
.tb.on { background: var(--ki); }
.tb:active { transform: translate(2px,2px); box-shadow: none; }
body.touch .sk { width: max(calc(80px*var(--k)), 52px); height: max(calc(80px*var(--k)), 52px); }

#toasts { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 4px 12px; font-weight: 900; font-size: max(calc(16px*var(--k)), 11.5px); display: flex; align-items: center; gap: 8px;
  animation: toastIn .25s ease-out, toastOut .4s ease-in 2.2s forwards; line-height: 1.35; white-space: nowrap; }
.toast img { width: calc(28px*var(--k)); height: calc(28px*var(--k)); object-fit: contain; }
@keyframes toastIn { from { transform: translateY(-14px) rotate(-3deg); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-10px); opacity: 0; } }
#pointer { position: absolute; top: 46%; font-family: var(--disp); font-size: max(calc(22px*var(--k)), 11.5px); color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill;
  text-shadow: 2px 2px 0 var(--ink); background: var(--red); border: 3px solid var(--ink); padding: 0 10px; line-height: 1.4; pointer-events: none; animation: bob .8s ease-in-out infinite alternate; }
#pointer.r { right: 8px; } #pointer.l { left: 8px; }
@keyframes bob { to { transform: translateX(6px); } }

/* ---------- overlays ---------- */
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 30; }
#letterbox i { position: fixed; left: 0; right: 0; height: 0; background: var(--ink); z-index: 31; transition: height .3s; }
#letterbox .lb-top { top: 0; } #letterbox .lb-bot { bottom: 0; }
#letterbox.on i { height: 11vh; }

#levelup { position: fixed; inset: 0; pointer-events: none; z-index: 25; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.lu-rays { position: absolute; width: 140vmax; height: 140vmax; left: 50%; top: 44%; transform: translate(-50%,-50%);
  background: repeating-conic-gradient(from 0deg, rgba(20,20,20,.85) 0 1.2deg, transparent 1.2deg 7deg);
  -webkit-mask: radial-gradient(circle, transparent 14%, #000 26%, #000 60%, transparent 70%); mask: radial-gradient(circle, transparent 14%, #000 26%, #000 60%, transparent 70%);
  animation: rays 2s ease-out forwards; }
@keyframes rays { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(0); } 15% { opacity: .9; } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1.15) rotate(8deg); } }
.lu-word { position: relative; font-family: var(--disp); font-size: max(calc(110px*var(--k)), 11.5px); color: var(--amber); -webkit-text-stroke: calc(4px*var(--k)) var(--ink); paint-order: stroke fill;
  text-shadow: 6px 6px 0 var(--ink); transform: rotate(-6deg) skewX(-8deg); animation: lu 2s ease-out forwards; line-height: 1.3; margin-top: -18vh; }
.lu-sub { position: relative; font-family: var(--disp); font-size: max(calc(32px*var(--k)), 11.5px); color: #fff; -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink); animation: lu 2s ease-out forwards; line-height: 1.3; }
@keyframes lu { 0% { opacity: 0; scale: 2.2; } 12% { opacity: 1; scale: .95; } 20% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

#stamp { position: fixed; left: 0; right: 0; top: 30%; display: flex; justify-content: center; pointer-events: none; z-index: 26; }
.stamp-box { background: var(--paper); border: calc(5px*var(--k)) solid var(--ink); box-shadow: 7px 7px 0 var(--ink); padding: calc(10px*var(--k)) calc(26px*var(--k)); transform: rotate(-4deg); text-align: center;
  animation: slam .45s cubic-bezier(.2,1.6,.4,1), fadeOut .5s ease-in 2.6s forwards; max-width: 94vw; }
.stamp-word { font-family: var(--disp); font-size: max(calc(54px*var(--k)), 11.5px); color: var(--red); -webkit-text-stroke: calc(1.5px*var(--k)) var(--ink); line-height: 1.3; letter-spacing: .03em; }
.stamp-box.new .stamp-word { color: var(--orange); }
.stamp-sub { font-weight: 900; font-size: max(calc(17px*var(--k)), 11.5px); line-height: 1.3; }
.stamp-rw { display: flex; gap: 12px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.stamp-rw span { display: flex; align-items: center; gap: 4px; font-family: var(--disp); font-size: max(calc(22px*var(--k)), 11.5px); line-height: 1.3; }
.stamp-rw img { width: calc(30px*var(--k)); height: calc(30px*var(--k)); object-fit: contain; }
.stamp-rw .exp { color: #2f9e2f; -webkit-text-stroke: .6px var(--ink); }
@keyframes slam { from { transform: rotate(-14deg) scale(3); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: rotate(-4deg) translateY(-20px); } }

#bossintro { position: fixed; inset: 0; z-index: 32; pointer-events: none; }
.bi-strip { position: absolute; left: -5%; right: -5%; top: 18%; background: var(--red); color: #fff; font-family: var(--disp); font-size: max(calc(46px*var(--k)), 11.5px); text-align: center;
  border-top: 5px solid var(--ink); border-bottom: 5px solid var(--ink); transform: rotate(-3deg); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; letter-spacing: .08em;
  animation: stripIn .4s ease-out; line-height: 1.35; }
.bi-panel { position: absolute; left: 0; right: 0; top: 33%; height: 34%; background: var(--tone), var(--paper); border-top: 5px solid var(--ink); border-bottom: 5px solid var(--ink);
  clip-path: polygon(0 8%, 100% 0, 100% 92%, 0 100%); display: flex; align-items: center; justify-content: center; gap: 4vw; animation: panelIn .45s cubic-bezier(.2,1.4,.4,1); }
.bi-panel img { height: 92%; aspect-ratio: 1; object-fit: cover; border: 5px solid var(--ink); transform: rotate(-3deg); box-shadow: 6px 6px 0 var(--ink); }
.bi-name { font-family: var(--disp); font-size: max(calc(96px*var(--k)), 11.5px); color: var(--red); -webkit-text-stroke: calc(3px*var(--k)) var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); transform: skewX(-10deg); line-height: 1.25; }
.bi-pow { font-family: var(--disp); font-size: max(calc(30px*var(--k)), 11.5px); line-height: 1.3; }
@keyframes stripIn { from { transform: translateX(-100%) rotate(-3deg); } }
@keyframes panelIn { from { transform: translateX(100%); } }

#dialog { position: fixed; inset: 0; z-index: 34; background: rgba(20,20,20,.5); display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 3vh 3vw calc(3vh + var(--safe-b)); }
.dlg-stage { width: min(900px, 96vw); display: flex; flex-direction: column; gap: 14px; }
.dlg-panel { display: flex; gap: 14px; align-items: stretch; background: var(--paper); border: 4px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 12px; animation: dlgIn .3s cubic-bezier(.2,1.3,.4,1); }
.dlg-panel.r { flex-direction: row-reverse; }
.dlg-panel.diag { background: var(--tone), #ffe7d1; transform: rotate(-1.6deg); clip-path: polygon(0 0, 100% 6%, 100% 100%, 0 94%); padding: 22px 14px; }
.dlg-panel.old { opacity: .55; transform: scale(.97); }
.dlg-pt { width: clamp(84px, 16vmin, 150px); flex: none; }
.dlg-pt img { width: 100%; aspect-ratio: 1; object-fit: cover; border: 3px solid var(--ink); display: block; background: #fff; }
.dlg-pt div { font-family: var(--disp); font-size: clamp(16px, 2.6vmin, 22px); text-align: center; line-height: 1.3; }
.bubble { position: relative; flex: 1; background: #fff; border: 3px solid var(--ink); border-radius: 26px; padding: 14px 18px; font-size: clamp(15px, 2.6vmin, 21px); font-weight: 700; line-height: 1.45; align-self: center; }
.bubble::before { content: ''; position: absolute; left: -20px; top: 40%; border: 12px solid transparent; border-right: 20px solid var(--ink); border-left: 0; }
.bubble::after { content: ''; position: absolute; left: -14px; top: calc(40% + 3px); border: 9px solid transparent; border-right: 15px solid #fff; border-left: 0; }
.dlg-panel.r .bubble::before { left: auto; right: -20px; border-right: 0; border-left: 20px solid var(--ink); }
.dlg-panel.r .bubble::after { left: auto; right: -14px; border-right: 0; border-left: 15px solid #fff; }
.dlg-panel.diag .bubble { font-family: var(--disp); font-weight: 400; font-size: clamp(19px, 3.2vmin, 28px); letter-spacing: .02em; }
.dlg-hint { color: #fff; font-weight: 800; margin-top: 10px; font-size: 14px; text-shadow: 1px 1px 0 var(--ink); }
@keyframes dlgIn { from { transform: translateX(-60px); opacity: 0; } }

#menu, #starmap, #death, #finale { position: fixed; inset: 0; z-index: 36; background: rgba(20,20,20,.55); display: flex; align-items: center; justify-content: center; padding: 2vh 2vw; }
#menu { background: linear-gradient(90deg, rgba(20,20,20,0) 0 35%, rgba(20,20,20,.35)); justify-content: flex-end; padding: 1.5vh 1.2vw; }
#menu .book { width: min(780px, 62vw); height: 96vh; animation: bookIn .22s ease-out; }
@keyframes bookIn { from { transform: translateX(40px); } }
#menu .grid2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); height: auto; }
#menu .eqgrid { grid-template-columns: repeat(3, minmax(0, min(92px, 14vh))); }
#menu .inv { grid-template-columns: repeat(auto-fill, minmax(min(62px, 12vh), 1fr)); }
body.ovl #touch, body.ovl #skillbar, body.ovl #controls, body.ovl #menubtns, body.ovl #quest, body.ovl #pointer, body.ovl #bossbar { visibility: hidden; }
@media (max-height: 500px) { #menu .book { height: 98vh; } .tabs button { padding: 2px 4px; } .page { padding: 8px; } .cell { padding: 6px; } }
@media (max-aspect-ratio: 1/1) {
  #menu { align-items: flex-end; justify-content: center; padding: 0; background: linear-gradient(rgba(20,20,20,0) 0 30%, rgba(20,20,20,.35)); }
  #menu .book { width: 100vw; height: 68vh; animation-name: sheetIn; }
  @keyframes sheetIn { from { transform: translateY(40px); } }
}
.book { width: min(980px, 98vw); height: min(640px, 96vh); background: var(--paper); border: 4px solid var(--ink); box-shadow: 8px 8px 0 var(--ink); display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 4px solid var(--ink); }
.tabs button { flex: 1; border: 0; border-right: 3px solid var(--ink); background: var(--tone), #efe3c8; font-family: var(--disp); font-size: clamp(17px, 2.6vmin, 24px); padding: 6px 4px; line-height: 1.3; }
.tabs button.on { background: var(--orange); color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.tabs .close { flex: 0 0 54px; border-right: 0; background: var(--red); color: #fff; }
.page { flex: 1; overflow: auto; padding: 12px; touch-action: pan-y; font-size: clamp(13px, 2.1vmin, 16px); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 12px; height: 100%; }
.cell { border: 3px solid var(--ink); background: #fffdf6; padding: 8px; min-width: 0; overflow: auto; }
.cell h3 { margin: 0 0 6px; font-family: var(--disp); font-weight: 400; font-size: clamp(19px, 2.8vmin, 24px); line-height: 1.3; border-bottom: 3px solid var(--ink); }
.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.slot { position: relative; aspect-ratio: 1; border: 3px solid var(--ink); background: var(--tone), #f2ead7; padding: 4px; display: flex; align-items: center; justify-content: center; }
.slot img { width: 86%; height: 86%; object-fit: contain; }
.slot .n { position: absolute; right: 1px; bottom: 0; font-family: var(--disp); font-size: 15px; background: var(--ink); color: #fff; padding: 0 3px; line-height: 1.2; }
.slot.sel { outline: 4px solid var(--orange); outline-offset: -1px; }
.slot.r1 { background-color: #d9ecff; } .slot.r2 { background-color: #ead9ff; } .slot.r3 { background-color: #fff0bf; box-shadow: inset 0 0 0 2px #ffc21f; }
.slot .eq { position: absolute; left: 1px; top: 0; font-size: 10px; font-weight: 900; background: var(--orange); color: #fff; padding: 0 3px; border: 1px solid var(--ink); }
.eqgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 92px)); gap: 6px; margin-bottom: 10px; }
.eqgrid .slot { flex-direction: column; }
.eqgrid .slot small { position: absolute; top: 1px; left: 3px; font-size: 10px; font-weight: 900; }
.detail { border: 3px solid var(--ink); background: #fff; padding: 8px; margin-top: 8px; line-height: 1.45; }
.detail .nm { font-family: var(--disp); font-size: 22px; line-height: 1.3; }
.badge { background: var(--orange); color: #fff; border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); font-family: var(--disp); font-size: 22px; padding: 4px 18px; border-radius: 10px; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; line-height: 1.3; }
.badge:disabled { background: #c9bfae; cursor: default; }
.badge:active:not(:disabled) { transform: translate(2px,2px); box-shadow: none; }
.btn2 { background: #fff; border: 3px solid var(--ink); font-weight: 900; padding: 4px 12px; box-shadow: 2px 2px 0 var(--ink); }
.sklist { display: flex; flex-direction: column; gap: 6px; }
.skrow { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; border: 3px solid var(--ink); padding: 4px; background: #fff; text-align: left; font-weight: 800; }
.skrow img { width: 44px; height: 44px; border: 2px solid var(--ink); object-fit: cover; }
.skrow.sel { outline: 4px solid var(--orange); outline-offset: -2px; background: #fff1e0; }
.skrow.lock { opacity: .6; }
.stars { color: var(--amber); -webkit-text-stroke: .6px var(--ink); }
table.st { width: 100%; border-collapse: collapse; }
table.st td { border-bottom: 2px dotted #9a8f7a; padding: 4px 2px; font-weight: 800; }
table.st td:last-child { text-align: right; font-family: var(--disp); font-weight: 400; font-size: 1.2em; }
.lb a { color: var(--ink); }
.lb li { padding: 2px 0; font-weight: 800; }
.lb li.me { background: #ffe0c0; }
.help p { margin: 4px 0 10px; line-height: 1.5; }
.help kbd { font-family: var(--disp); border: 2px solid var(--ink); background: #fff; padding: 0 5px; border-radius: 3px; }

#starmap { flex-direction: column; background: url(img/space_bg.webp) center/cover, #0b1640; gap: 3vh; }
.sm-head { text-align: center; }
.sm-title { display: inline-block; background: var(--paper); border: 4px solid var(--ink); box-shadow: 5px 5px 0 var(--ink); font-family: var(--disp); font-size: clamp(30px, 6vmin, 54px); padding: 0 22px; transform: rotate(-2deg); line-height: 1.35; }
.sm-sub { color: #fff; font-weight: 900; margin-top: 8px; text-shadow: 1px 1px 0 #000; }
.sm-planets { display: flex; gap: 4vw; justify-content: center; align-items: flex-start; flex-wrap: wrap; }
.pl { width: clamp(120px, 24vmin, 230px); background: none; border: 0; padding: 0; text-align: center; position: relative; }
.pl img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; transition: transform .2s; }
.pl:hover img { transform: scale(1.05); }
.pl .lbl { display: block; margin-top: 6px; background: var(--ink); color: #fff; font-family: var(--disp); font-size: clamp(18px, 3vmin, 26px); border: 3px solid #fff; line-height: 1.35; }
.pl .st { display: block; margin-top: 4px; background: #5DBB4A; color: #fff; font-weight: 900; font-size: 13px; padding: 2px 4px; border: 2px solid var(--ink); line-height: 1.3; }
.pl.here .st { background: var(--orange); }
.pl.locked img { filter: grayscale(1) brightness(.75) contrast(.9); }
.pl.locked::before { content: ''; position: absolute; left: 0; right: 0; top: 0; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, rgba(0,0,0,.5) 1.4px, transparent 1.8px) 0 0 / 7px 7px; z-index: 1; }
.pl.locked .st { background: #555; }
.pl .chain { position: absolute; left: 50%; top: 32%; transform: translate(-50%,-50%); z-index: 2; width: 46%; }
.sm-close { background: var(--paper); border: 3px solid var(--ink); font-family: var(--disp); font-size: 24px; padding: 2px 26px; box-shadow: 3px 3px 0 var(--ink); line-height: 1.3; }

#travel { position: fixed; inset: 0; z-index: 40; background: url(img/space_bg.webp) center/cover, #0b1640; overflow: hidden; }
#travel.go .tr-pod { animation: pod 2.2s ease-in-out forwards; }
.tr-pod { position: absolute; top: 42%; left: -20vw; width: clamp(70px, 13vmin, 140px); z-index: 2; }
.tr-trail { position: absolute; top: calc(42% + 3.5vmin); left: 0; height: 2.2vmin; width: 0; background: linear-gradient(90deg, transparent, rgba(79,195,255,.2), #bfe9ff); border-radius: 0 50% 50% 0; }
#travel.go .tr-trail { animation: trail 2.2s ease-in-out forwards; }
@keyframes pod { to { left: 110vw; transform: translateY(-6vh); } }
@keyframes trail { 0% { width: 0; } 100% { width: 120vw; transform: translateY(-6vh); opacity: .3; } }
.tr-card { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; opacity: 0; transition: opacity .5s; }
.tr-card.on { opacity: 1; }
.tr-card .nm { font-family: var(--disp); font-size: clamp(54px, 13vmin, 140px); color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 7px 7px 0 var(--ink); transform: rotate(-4deg) skewX(-8deg); line-height: 1.3; }
.tr-card .sb { background: var(--paper); border: 3px solid var(--ink); font-weight: 900; padding: 4px 14px; font-size: clamp(15px, 2.8vmin, 22px); }

.death-box { text-align: center; padding: 20px 30px; }
.death-word { font-family: var(--disp); font-size: 64px; color: var(--red); -webkit-text-stroke: 2px var(--ink); line-height: 1.3; transform: rotate(-3deg); }
#finale { flex-direction: column; background: radial-gradient(circle at 50% 40%, #3d5a2a, #101a0c); gap: 2vh; }
.fin-dragon { max-height: 52vh; max-width: 92vw; animation: dragon 3s ease-out; filter: drop-shadow(0 0 30px rgba(255,230,120,.6)); }
@keyframes dragon { from { transform: translateY(40vh) scale(.6); opacity: 0; } }
.fin-panel { max-width: 720px; text-align: center; padding: 10px 18px; }
.fin-word { font-family: var(--disp); font-size: clamp(32px, 6vmin, 52px); color: #2f9e2f; -webkit-text-stroke: 1.5px var(--ink); line-height: 1.3; }
.fin-wishes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 50; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.t-bg { position: absolute; inset: -2%; background: url(img/title_bg.webp) center/cover, #7EC8F2; animation: drift 30s ease-in-out infinite alternate; }
@keyframes drift { to { transform: scale(1.06) translateX(-1%); } }
.t-center { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1.6vh; padding: 2vh; }
.t-ball { position: absolute; width: clamp(160px, 42vmin, 420px); top: -14vmin; left: 50%; margin-left: calc(clamp(160px, 42vmin, 420px) / -2); opacity: .95; animation: spin 14s linear infinite; z-index: -1; filter: drop-shadow(0 0 20px rgba(255,178,31,.7)); }
@keyframes spin { to { transform: rotate(360deg); } }
.t-logo { width: clamp(280px, 70vmin, 720px); filter: drop-shadow(5px 6px 0 rgba(20,20,20,.55)); }
.stamp-btn { font-family: var(--disp); font-size: clamp(30px, 6vmin, 50px); background: var(--orange); color: #fff; border: 4px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 2px 44px;
  transform: rotate(-3deg); -webkit-text-stroke: 1.6px var(--ink); paint-order: stroke fill; line-height: 1.3; min-width: 240px; }
.stamp-btn:disabled { background: #c9bfae; }
.stamp-btn:active:not(:disabled) { transform: rotate(-3deg) translate(3px,3px); box-shadow: 2px 2px 0 var(--ink); }
.paper-btn { background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); font-weight: 900; font-size: clamp(15px, 2.6vmin, 19px); padding: 5px 22px; transform: rotate(1deg); }
.t-save { font-weight: 800; font-size: 13px; background: rgba(255,246,227,.85); padding: 2px 10px; border: 2px solid var(--ink); }
.t-save:empty { display: none; }
.t-load { position: absolute; bottom: 4vh; left: 50%; transform: translateX(-50%); width: min(360px, 70vw); }
.t-loadbar { height: 14px; border: 3px solid var(--ink); background: #fff; }
.t-loadbar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width .2s; }
.t-help { position: absolute; z-index: 3; width: min(620px, 94vw); max-height: 86vh; overflow: auto; padding: 14px 18px; }

@media (max-aspect-ratio: 1/1) {
  #quest { width: calc(46vw - 16px); }
  #scouter { width: calc(54vw - 12px); grid-template-columns: calc(54px*var(--k)) 1fr; }
  .sc-pt { width: calc(54px*var(--k)); height: calc(54px*var(--k)); }
  .bar span { min-width: 0; }
  .balls i { width: calc((46vw - 70px) / 7); height: calc((46vw - 70px) / 7); }
  .q-row img { display: none; }
  .bi-name { font-size: max(calc(64px*var(--k)), 11.5px); }
  .bi-panel { flex-direction: column; gap: 1vh; padding: 3vh 0; }
  .bi-panel img { height: 55%; }
  #bossbar { width: 92vw; top: auto; }
  .grid2 { grid-template-columns: 1fr; height: auto; }
  #controls { max-width: 60vw; }
}
@media (max-aspect-ratio: 1/1) {
  .sk, body.touch .sk { width: min(calc(80px*var(--k)), calc((100vw - 64px) / 6)); height: min(calc(80px*var(--k)), calc((100vw - 64px) / 6)); }
  #skillbar { gap: 4px; padding: 4px; }
}

.sc-planet { display: flex; align-items: center; gap: 6px; border: 2px solid var(--ink); background: var(--tone), #e9f6ff; padding: 1px 6px 1px 2px; font-weight: 900; font-size: max(calc(13px*var(--k)), 11px); line-height: 1.3; text-align: left; }
.sc-planet img { width: max(calc(22px*var(--k)), 16px); height: max(calc(22px*var(--k)), 16px); object-fit: contain; }
.sc-planet em { margin-left: auto; font-style: normal; font-size: .85em; color: #1e6fd0; text-decoration: underline; }
body.ovl.menu-open #skillbar { visibility: visible; }
.stgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.stgrid div { display: flex; justify-content: space-between; border-bottom: 2px dotted #9a8f7a; padding: 2px 0; font-weight: 800; gap: 6px; }
.stgrid div b { font-family: var(--disp); font-weight: 400; font-size: 1.15em; white-space: nowrap; }

.sk.lock .nm { color: #6b6255; }
@media (max-height: 500px) {
  .skrow { grid-template-columns: 30px 1fr auto; padding: 2px 4px; gap: 6px; }
  .skrow img { width: 30px; height: 30px; }
  .sklist { gap: 3px; }
  .cell h3 { font-size: 18px; margin-bottom: 3px; }
  .page p { margin: 4px 0; }
  .detail { margin-top: 4px; padding: 5px; }
}

.skico { width: 84px; height: 84px; border: 3px solid var(--ink); flex: none; }
.uprow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; flex-wrap: wrap; line-height: 1.35; }
.uprow img { width: 20px; vertical-align: middle; }
.sk.lock::after { white-space: nowrap; font-size: max(calc(11.5px*var(--k)), 10px); }
@media (max-height: 500px) {
  .skico { width: 52px; height: 52px; }
  .uprow { margin-top: 4px; }
  .uprow .badge { font-size: 18px; padding: 2px 12px; }
  table.st td { padding: 2px; }
}
@media (max-height: 500px) and (min-aspect-ratio: 1/1) {
  #menu .grid2 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
}
@media (max-height: 420px) and (min-aspect-ratio: 1/1) {
  #menu .page { font-size: 11.5px; padding: 6px; }
  #menu .skrow { font-size: 11.5px; }
  #menu .skrow img { width: 24px; height: 24px; }
  #menu .skico { width: 40px; height: 40px; }
  #menu .cell h3 { font-size: 16px; }
  #menu .desc { display: none; }
  #menu .uprow small { display: none; }
}
