* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1d5e; font-family: "Arial Black", "Trebuchet MS", sans-serif; color: #fff; user-select: none; -webkit-user-select: none; touch-action: none; }
#game canvas { display: block; position: fixed; inset: 0; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 20; }
.card { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(20, 12, 50, .88); border: 3px solid #fff; border-radius: 18px; padding: 24px 32px; text-align: center; min-width: 280px; }
.card a { color: #9fd3ff; }
#pause, #loading, #err { background: rgba(0, 0, 0, .4); }
#end { background: rgba(0, 0, 0, .35); }
#end h1 { margin: 0 0 8px; font-size: 2.4rem; color: #ffd23f; text-shadow: 0 4px 0 #b5179e; }
#end button, #play { background: linear-gradient(#ffe14d, #ffb703); color: #222; border: 0; border-radius: 12px; padding: 12px 22px; margin: 6px; font-size: 1.1rem; box-shadow: 0 5px 0 #a86f00; }
#end button:active, #play:active { transform: translateY(3px); box-shadow: 0 2px 0 #a86f00; }

/* character select */
#menu { pointer-events: none; }
#menu > * { pointer-events: auto; }
.logo { position: absolute; top: 14px; left: 0; right: 0; margin: 0; text-align: center; font-size: clamp(2rem, 6vw, 3.6rem); letter-spacing: 2px; color: #fff; text-shadow: 0 4px 0 #6a3cff, 0 8px 18px rgba(0,0,0,.5); font-style: italic; }
.logo span { color: #ffd23f; }
.arrow { position: absolute; top: 48%; transform: translateY(-50%); width: 64px; height: 64px; border-radius: 50%; border: 3px solid #fff; background: rgba(255,255,255,.15); color: #fff; font-size: 1.6rem; }
#prev { left: calc(50% - 190px); }
#next { right: calc(50% - 190px); }
#info { position: absolute; left: 16px; bottom: 16px; width: min(330px, 44vw); background: rgba(20, 12, 50, .8); border-radius: 16px; padding: 14px 18px; border: 2px solid rgba(255,255,255,.4); }
#info h2 { margin: 0; font-size: 1.8rem; color: #ffd23f; font-style: italic; }
#info p { margin: 4px 0 10px; font-family: "Trebuchet MS", sans-serif; font-weight: bold; opacity: .9; }
.stat { display: flex; align-items: center; gap: 8px; font-size: .75rem; margin: 4px 0; font-family: "Trebuchet MS", sans-serif; font-weight: bold; }
.stat b { width: 60px; }
.stat .t { flex: 1; height: 10px; background: rgba(255,255,255,.2); border-radius: 5px; overflow: hidden; }
.stat .t i { display: block; height: 100%; background: linear-gradient(90deg, #48cae4, #b5179e); }
#side { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.opts { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.opts button { background: rgba(20, 12, 50, .8); color: #fff; border: 2px solid rgba(255,255,255,.5); border-radius: 10px; padding: 8px 14px; font-size: .85rem; }
#play { font-size: 1.8rem; padding: 14px 44px; margin: 6px 0 0; }
.back { color: #cfe3ff; font-family: "Trebuchet MS", sans-serif; font-weight: bold; font-size: .9rem; }
@media (max-width: 640px) {
  #prev { left: 8px; } #next { right: 8px; }
  #info { width: calc(100% - 32px); bottom: 150px; }
  #side { left: 16px; align-items: stretch; }
  .opts { flex-direction: row; } .opts button { flex: 1; padding: 6px; font-size: .7rem; }
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; text-shadow: 0 2px 2px rgba(0,0,0,.6); }
#compassWrap { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); text-align: center; }
#heading { font-size: .8rem; }
#compass { width: 300px; height: 30px; display: block; }
#topright { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#mm { width: 120px; height: 120px; border: 3px solid rgba(255,255,255,.85); border-radius: 8px; background: #5aa83c; }
#topright .row { display: flex; gap: 10px; font-size: .9rem; background: rgba(0,0,0,.35); padding: 2px 8px; border-radius: 6px; }
#stormTxt { font-size: .75rem; background: rgba(90, 30, 180, .6); padding: 2px 8px; border-radius: 6px; }
#stormTxt.warn { background: rgba(200, 30, 60, .8); }
#feed { position: absolute; left: 10px; top: 45%; font-family: "Trebuchet MS", sans-serif; font-weight: bold; font-size: .8rem; display: flex; flex-direction: column; gap: 3px; }
#feed div { background: rgba(0,0,0,.4); padding: 2px 8px; border-radius: 4px; }
#feed .me { color: #ffd23f; }
#toast { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); padding: 8px 16px; border-radius: 10px; font-size: 1rem; opacity: 0; transition: opacity .25s; white-space: nowrap; }
#toast.show { opacity: 1; }
#cross { position: absolute; left: 50%; top: 50%; width: 0; height: 0; --g: 7px; }
#cross i { position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
#cross i:nth-child(1), #cross i:nth-child(2) { width: 2px; height: 8px; left: -1px; }
#cross i:nth-child(3), #cross i:nth-child(4) { height: 2px; width: 8px; top: -1px; }
#cross i:nth-child(1) { top: calc(-8px - var(--g)); } #cross i:nth-child(2) { top: var(--g); }
#cross i:nth-child(3) { left: calc(-8px - var(--g)); } #cross i:nth-child(4) { left: var(--g); }
#cross.hit i { background: #ff4d4d; } #cross.head i { background: #ffd23f; }
#bottom { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); width: min(420px, 70vw); display: flex; flex-direction: column; align-items: center; gap: 4px; }
#ammo { font-size: 1.8rem; height: 2rem; }
#hotbar { display: flex; gap: 6px; pointer-events: auto; margin-bottom: 4px; }
.slot { width: 58px; height: 58px; border-radius: 8px; background: rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.5rem; position: relative; }
.slot small { position: absolute; bottom: 1px; right: 4px; font-size: .65rem; }
.slot.on { border-color: #fff; background: rgba(255,255,255,.25); transform: translateY(-4px); }
.slot.r1 { box-shadow: inset 0 -6px 0 #2a9d8f; } .slot.r2 { box-shadow: inset 0 -6px 0 #3a86ff; } .slot.r3 { box-shadow: inset 0 -6px 0 #8338ec; }
.bar { display: flex; align-items: center; gap: 6px; width: 100%; }
.bar .ic { width: 18px; text-align: center; }
.track { position: relative; flex: 1; height: 18px; background: rgba(0,0,0,.5); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; transition: width .15s; }
.fill.shield { background: linear-gradient(#5ab0ff, #2a6fdb); }
.fill.hp { background: linear-gradient(#7be05a, #3aa52a); }
.track span { position: absolute; left: 8px; top: 0; font-size: .75rem; line-height: 18px; }
#wood { position: absolute; right: 12px; bottom: 14px; font-size: 1.1rem; background: rgba(0,0,0,.4); padding: 4px 10px; border-radius: 8px; }
#keys { position: absolute; left: 10px; bottom: 10px; font-family: "Trebuchet MS", sans-serif; font-size: .7rem; opacity: .7; max-width: 240px; }
.touch #keys { display: none; }
.touch #wood { right: auto; left: 50%; transform: translateX(-50%); top: 44px; bottom: auto; font-size: .9rem; }
.touch .slot { width: 50px; height: 50px; font-size: 1.3rem; }
.touch #compass { width: 220px; height: 22px; }
.touch #mm { width: 96px; height: 96px; }

#dmg { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.dn { position: absolute; left: 0; top: 0; font-size: 1.3rem; text-shadow: 0 2px 0 #000; display: none; will-change: transform; }
.dn.shield { color: #6cc3ff; } .dn.head { color: #ffd23f; font-size: 1.6rem; } .dn.hp { color: #fff; }
#hurt { position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; background: radial-gradient(ellipse at center, transparent 50%, rgba(255, 0, 0, .65)); }
#stormTint { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: rgba(130, 50, 255, .28); display: none; }
#scope { position: fixed; inset: 0; pointer-events: none; z-index: 4; display: none; background: radial-gradient(circle at center, transparent 0, transparent 30vmin, #000 30.5vmin); }
#scope::before, #scope::after { content: ""; position: absolute; background: rgba(0,0,0,.8); }
#scope::before { left: 50%; top: 20%; bottom: 20%; width: 2px; } #scope::after { top: 50%; left: 30%; right: 30%; height: 2px; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 7; pointer-events: none; }
#touch button { pointer-events: auto; position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.75); background: rgba(0,0,0,.3); color: #fff; font-size: 1.6rem; padding: 0; }
#touch button.on { background: rgba(255,255,255,.35); }
#bFire { right: calc(26px + env(safe-area-inset-right)); bottom: 120px; width: 92px; height: 92px; font-size: 2.2rem !important; }
#bAim { right: calc(132px + env(safe-area-inset-right)); bottom: 190px; width: 62px; height: 62px; }
#bJump { right: calc(34px + env(safe-area-inset-right)); bottom: 24px; width: 76px; height: 76px; }
#bWall { right: calc(136px + env(safe-area-inset-right)); bottom: 28px; width: 62px; height: 62px; }
#bRamp { right: calc(136px + env(safe-area-inset-right)); bottom: 104px; width: 62px; height: 62px; }
#stickBase { position: absolute; left: 70px; bottom: 70px; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 3px solid rgba(255,255,255,.5); background: rgba(0,0,0,.2); }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(255,255,255,.6); }
