:root {
  --bg: #07080e;
  --panel: rgba(16, 18, 28, 0.86);
  --panel2: rgba(24, 27, 40, 0.94);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #e8e6df;
  --muted: #8b93a8;
  --gold: #ffcf6b;
  --hp: #d8352f;
  --mp: #2f7fd8;
  --xp: #ffcf6b;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --reserve: 120px;
}
@media (pointer: coarse) { :root { --reserve: 186px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; }

#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; display: grid; place-items: center; background:
  radial-gradient(120% 90% at 50% 0%, #0d1018, #05060b 70%); }
#game {
  aspect-ratio: 16 / 9;
  width: min(100vw, calc((100dvh - var(--reserve)) * 16 / 9));
  max-height: calc(100dvh - var(--reserve));
  image-rendering: pixelated; image-rendering: crisp-edges;
  border-top: 1px solid rgba(255,255,255,.05); border-bottom: 1px solid rgba(255,255,255,.05);
  box-shadow: 0 0 60px rgba(0,0,0,.7);
}

#ui { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#ui > * { pointer-events: auto; }

/* ------------------------------- HUD top ------------------------------- */
.hud-top { position: absolute; top: calc(var(--sat) + 6px); left: 8px; right: 8px;
  display: flex; align-items: center; gap: 10px; }
.hud-tl { flex: 1 1 auto; min-width: 0; }
.zone-label { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--gold);
  text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog { height: 4px; background: rgba(255,255,255,.1); border-radius: 3px; margin: 4px 0 3px; overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7a4bd0, var(--gold)); transition: width .3s; }
.prog-text { font-size: 10px; color: var(--muted); }
.prog-text.open { color: #7cf9a8; }
.lvl-chip { display: flex; align-items: baseline; gap: 3px; background: var(--panel); border: 1px solid var(--stroke);
  border-radius: 10px; padding: 4px 9px; }
.lvl-chip b { font-size: 16px; color: var(--gold); }
.lvl-chip span { font-size: 9px; color: var(--muted); }
.hud-btns { display: flex; gap: 5px; }
.hbtn { width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--stroke);
  background: var(--panel); color: var(--text); font-size: 14px; cursor: pointer; }
.hbtn:active { transform: scale(.92); }

/* -------------------------------- globes ------------------------------- */
.globes { position: absolute; left: 10px; bottom: calc(var(--sab) + 10px); display: flex; align-items: flex-end; gap: 8px; }
@media (pointer: coarse) { .globes { bottom: calc(var(--sab) + 118px); } }
.globe { position: relative; width: 52px; height: 52px; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle at 35% 30%, #1a1e2a, #0a0c12); border: 2px solid rgba(255,255,255,.14);
  box-shadow: inset 0 0 14px rgba(0,0,0,.8), 0 3px 10px rgba(0,0,0,.5); }
.globe i { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; transition: height .2s; }
.globe-hp i { background: linear-gradient(180deg, #ff6b5a, #8f1712); box-shadow: 0 0 16px rgba(216,53,47,.6); }
.globe-mp i { background: linear-gradient(180deg, #6bb8ff, #123f8f); box-shadow: 0 0 16px rgba(47,127,216,.6); }
.globe b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 800;
  color: #fff; text-shadow: 0 1px 3px #000, 0 0 6px #000; }
.globe-mp { width: 42px; height: 42px; }
.xpbar { width: 8px; height: 96px; background: rgba(255,255,255,.1); border-radius: 4px; overflow: hidden; margin-left: 2px; }
.xpbar i { display: block; width: 100%; height: 0; background: linear-gradient(0deg, #b98a2e, var(--xp)); transition: height .3s; }
@media (max-height: 460px) { .xpbar { display: none; } }

/* ------------------------------- controls ------------------------------ */
.controls { display: none; }
@media (pointer: coarse) {
  .controls { display: flex; position: absolute; left: 0; right: 0; bottom: 0; height: calc(112px + var(--sab));
    padding: 0 14px calc(var(--sab) + 8px); align-items: center; justify-content: space-between; gap: 12px; }
}
.joypad { width: 118px; height: 118px; border-radius: 50%; border: 1px solid var(--stroke);
  background: radial-gradient(circle at 50% 40%, rgba(255,255,255,.07), rgba(255,255,255,.02)); position: relative; touch-action: none; }
.joyknob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #3a4152, #171b26); border: 1px solid rgba(255,255,255,.2);
  box-shadow: 0 3px 8px rgba(0,0,0,.6); }
.actbtns { display: grid; grid-template-columns: repeat(3, 54px); grid-auto-rows: 54px; gap: 8px; align-items: center; }
.abtn { position: relative; border-radius: 50%; border: 1px solid var(--stroke); cursor: pointer;
  background: radial-gradient(circle at 40% 32%, rgba(255,255,255,.12), rgba(255,255,255,.03));
  color: var(--text); font-size: 20px; display: grid; place-items: center; overflow: hidden; }
.abtn span { position: relative; z-index: 2; }
.abtn u { position: absolute; right: 5px; bottom: 3px; font-size: 9px; color: var(--muted); text-decoration: none; z-index: 2; }
.abtn em { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0,0,0,.62); z-index: 1; }
.abtn:active { transform: scale(.94); }
.abtn-atk { grid-column: 2; grid-row: 1 / 3; width: 74px; height: 74px; font-size: 30px; margin: 0 auto;
  border-color: rgba(255,207,107,.4); background: radial-gradient(circle at 40% 32%, rgba(255,207,107,.28), rgba(120,60,20,.12)); }
.abtn-skill { width: 50px; height: 50px; font-size: 18px; }
.abtn-skill:nth-child(1) { grid-column: 1; grid-row: 1; }
.abtn-skill:nth-child(2) { grid-column: 1; grid-row: 2; }
.abtn-skill:nth-child(4) { grid-column: 3; grid-row: 1; }
.abtn-skill:nth-child(5) { grid-column: 3; grid-row: 2; }
.abtn.cd { filter: grayscale(.6) brightness(.7); }
.abtn.nmana span { opacity: .4; }

.kbhint { position: absolute; bottom: calc(var(--sab) + 6px); left: 0; right: 0; text-align: center;
  font-size: 10px; color: var(--muted); opacity: .7; }
@media (pointer: coarse) { .kbhint { display: none; } }

/* -------------------------------- banner ------------------------------- */
.banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; opacity: 0; pointer-events: none; }
.banner.show { animation: bannerIn 2.8s ease forwards; }
.banner h2 { margin: 0; font-size: 26px; letter-spacing: .18em; color: var(--gold);
  text-shadow: 0 0 22px rgba(255,207,107,.5), 0 2px 6px #000; }
.banner p { margin: 4px 0 0; font-size: 12px; letter-spacing: .3em; color: var(--muted); }
@keyframes bannerIn { 0% { opacity: 0; transform: translateY(14px); } 12% { opacity: 1; transform: none; } 78% { opacity: 1; } 100% { opacity: 0; } }

/* -------------------------------- overlay ------------------------------ */
.overlay { position: absolute; inset: 0; display: none; place-items: center; background: rgba(4,5,10,.78);
  backdrop-filter: blur(6px); z-index: 20; padding: 18px; overflow-y: auto; }
.overlay.show { display: grid; }
.menu { width: min(440px, 94vw); text-align: center; }
.menu h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: .3em; color: var(--gold);
  text-shadow: 0 0 30px rgba(255,207,107,.45), 0 3px 8px #000; }
.menu .tag { margin: 0; font-size: 12px; letter-spacing: .5em; color: #b46bff; }
.menu .sub { color: var(--muted); font-size: 13px; margin: 12px auto; max-width: 320px; }
.menu .cont { background: var(--panel); border: 1px solid var(--stroke); border-radius: 10px;
  padding: 8px; font-size: 12px; color: var(--muted); margin: 12px 0; }
.mbtn { display: block; width: 100%; margin: 8px 0; padding: 13px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255,207,107,.45); color: #1a1206; font-weight: 800; font-size: 15px; letter-spacing: .06em;
  background: linear-gradient(135deg, var(--gold), #d99a2e); box-shadow: 0 4px 18px rgba(255,207,107,.25); }
.mbtn.ghost { background: var(--panel2); color: var(--text); border-color: var(--stroke); box-shadow: none; }
.mbtn:active { transform: scale(.98); }
.menu ul { text-align: left; color: var(--muted); font-size: 13px; line-height: 1.7; padding-left: 18px; }
.menu ul b { color: var(--text); }
.boons { display: grid; gap: 10px; margin-top: 14px; }
.boon { background: var(--panel2); border: 1px solid var(--stroke); border-radius: 14px; padding: 14px; cursor: pointer; color: var(--text); }
.boon span { font-size: 24px; }
.boon b { display: block; margin: 6px 0 3px; color: var(--gold); letter-spacing: .06em; font-size: 14px; }
.boon i { font-style: normal; color: var(--muted); font-size: 12px; }
.boon:active { transform: scale(.98); border-color: var(--gold); }
.death h1 { color: #ff4a4a; text-shadow: 0 0 30px rgba(255,60,60,.5); }

/* inventory */
.inv .stats { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.inv h2 { font-size: 12px; letter-spacing: .2em; color: var(--muted); margin: 14px 0 8px; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { background: var(--panel2); border: 1px solid var(--stroke); border-radius: 10px; padding: 8px; min-height: 62px; cursor: pointer; }
.slot em { display: block; font-style: normal; font-size: 9px; letter-spacing: .12em; color: var(--muted); margin-bottom: 4px; }
.slot b { display: block; font-size: 11px; line-height: 1.25; }
.slot i { font-style: normal; font-size: 10px; color: var(--muted); }
.slot i.empty { color: #555b6b; }
.bag { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; max-height: 34vh; overflow-y: auto; }
.bagitem { background: var(--panel2); border: 1px solid var(--stroke); border-left-width: 3px; border-radius: 8px;
  padding: 7px 8px; text-align: left; cursor: pointer; color: var(--text); }
.bagitem b { display: block; font-size: 11px; }
.bagitem i { font-style: normal; font-size: 10px; color: var(--muted); }
.bag .empty { color: #555b6b; font-size: 12px; }

/* --------------------------------- toast ------------------------------- */
.toast { position: absolute; left: 50%; bottom: 30%; transform: translate(-50%, 10px); opacity: 0;
  background: var(--panel2); border: 1px solid var(--stroke); border-left: 3px solid #fff; border-radius: 10px;
  padding: 8px 14px; font-size: 12px; max-width: 86vw; text-align: center; transition: .25s; z-index: 30; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
