* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --gold: #e8c46a;
  --frame: #6e5a3c;
  --frame-dark: #2a2018;
  --panel: rgba(22, 17, 28, 0.96);
  --text: #efe6d4;
  --muted: #9a8f80;
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
}
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #060509; color: var(--text);
  font-family: 'Rubik', system-ui, sans-serif; font-weight: 500;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
img { image-rendering: pixelated; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; touch-action: none; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.frame {
  background: var(--panel);
  border: 2px solid var(--frame);
  box-shadow: 0 0 0 2px #000, inset 0 0 0 1px #000, 0 4px 12px rgba(0, 0, 0, .5);
  border-radius: 6px;
}
#hero-box {
  position: absolute; left: calc(8px + var(--sa-l)); top: calc(8px + var(--sa-t));
  display: flex; align-items: center; gap: 7px; padding: 5px 7px 5px 5px; width: min(46vw, 200px);
}
#portrait {
  width: 36px; height: 36px; flex: none; border: 2px solid var(--frame); border-radius: 4px;
  background: radial-gradient(circle at 50% 40%, #3b5a8a, #121a2a); overflow: hidden;
}
#portrait img { width: 100%; height: 100%; }
.hero-info { flex: 1; min-width: 0; }
#hero-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; text-shadow: 0 1px 0 #000; }
.bar { position: relative; height: 11px; margin-top: 2px; background: #120c10; border: 1px solid #000; border-radius: 3px; overflow: hidden; }
.bar .fill { height: 100%; width: 100%; transition: width .15s; }
.bar span { position: absolute; inset: 0; font-size: 8px; line-height: 10px; text-align: center; text-shadow: 0 1px 0 #000, 0 0 2px #000; font-family: 'Rubik', system-ui, sans-serif; font-weight: 700; }
.bar.hp .fill { background: linear-gradient(#ff7a7a, #c21d2b 60%, #8e1220); }
.bar.mp .fill { background: linear-gradient(#7ab4ff, #2458d0 60%, #173b94); }
.bar.xp { height: 3px; border: 0; }
.bar.mp { height: 8px; }
.bar.mp span { font-size: 7px; line-height: 8px; }
#hud #hero-name { display: none; }
.hero-info .bar:first-of-type { margin-top: 0; }
.bar.xp .fill { background: linear-gradient(#ffe27a, #d39b1c); }
.bar.boss { height: 14px; }
.bar.boss .fill { background: linear-gradient(#e45cff, #8a1fb0); }

#map-box { position: absolute; right: calc(8px + var(--sa-r)); top: calc(8px + var(--sa-t)); padding: 4px; width: 92px; }
#minimap { width: 84px; height: 84px; display: block; background: #0a080d; border: 1px solid #000; image-rendering: pixelated; }
.map-info { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 10px; margin-top: 3px; white-space: nowrap; }
.map-info img { width: 10px; height: 10px; }
.gold { display: inline-flex; align-items: center; gap: 2px; color: var(--gold); }
.gold img { width: 16px; height: 16px; }
.mini-btn {
  position: absolute; right: calc(132px + var(--sa-r)); top: calc(10px + var(--sa-t));
  width: 32px; height: 32px; border-radius: 6px; background: var(--panel); border: 2px solid var(--frame); font-size: 14px;
}

#boss-bar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(84px + var(--sa-t)); width: min(80vw, 360px); text-align: center; }
#boss-bar .boss-name { font-family: 'Rubik', system-ui, sans-serif; font-weight: 800; font-size: 14px; color: #ff9ae0; text-shadow: 0 2px 0 #000; margin-bottom: 2px; }

#toasts { position: absolute; left: 50%; transform: translateX(-50%); top: calc(130px + var(--sa-t)); display: flex; flex-direction: column; align-items: center; gap: 4px; width: 90vw; }
.toast {
  background: rgba(10, 8, 14, .85); border: 1px solid var(--frame); padding: 5px 12px; border-radius: 4px;
  font-size: 13px; text-shadow: 0 1px 0 #000; animation: toastIn .25s ease-out; transition: opacity .5s; text-align: center;
}
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

#joy {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .15); background: rgba(255, 255, 255, .04); opacity: .45; transition: opacity .15s;
}
#joy.active { opacity: 1; transition: none; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, .45), rgba(255, 255, 255, .12));
  border: 2px solid rgba(255, 255, 255, .4);
}
@media (hover: hover) and (pointer: fine) { #joy { display: none; } }

#actions { position: absolute; right: calc(12px + var(--sa-r)); bottom: calc(16px + var(--sa-b)); width: 190px; height: 180px; }
.act {
  position: absolute; border-radius: 50%; overflow: hidden;
  border: 2px solid #8a7444;
  background: radial-gradient(circle at 50% 35%, #463852, #1a1420);
  box-shadow: 0 0 0 2px #000, inset 0 -4px 0 rgba(0, 0, 0, .4), 0 4px 10px rgba(0, 0, 0, .5);
  display: flex; align-items: center; justify-content: center;
}
.act img { width: 58%; height: 58%; position: relative; z-index: 1; }
.act.pressed, .belt-btn.pressed { transform: scale(.93); filter: brightness(1.3); }
.act .cd, .belt-btn .cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0, 0, 0, .65); z-index: 2; }
.act small { position: absolute; bottom: 5px; font-size: 9px; color: #9cc4ff; z-index: 3; text-shadow: 0 1px 0 #000; font-weight: 700; }
.act.nomana img { filter: grayscale(1) brightness(.6); }
.act.nomana small { color: #ff6a6a; }
#btn-attack { width: 86px; height: 86px; right: 0; bottom: 0; border-color: #c9a24a; }
#btn-s1 { width: 58px; height: 58px; right: 94px; bottom: 2px; }
#btn-s2 { width: 58px; height: 58px; right: 78px; bottom: 74px; }
#btn-dash { width: 58px; height: 58px; right: 10px; bottom: 98px; }

#belt { position: absolute; right: calc(12px + var(--sa-r)); bottom: calc(206px + var(--sa-b)); display: flex; gap: 6px; }
.belt-btn {
  position: relative; width: 48px; height: 48px; border-radius: 6px; overflow: hidden;
  background: var(--panel); border: 2px solid var(--frame); box-shadow: 0 0 0 2px #000;
  display: flex; align-items: center; justify-content: center;
}
.belt-btn img { width: 34px; height: 34px; }
.belt-btn b { position: absolute; right: 3px; bottom: 1px; font-size: 11px; text-shadow: 0 1px 0 #000, 0 0 3px #000; z-index: 3; }
.belt-btn .badge {
  top: 2px; right: 2px; bottom: auto; width: 16px; height: 16px; border-radius: 50%;
  background: #e8343c; font-size: 10px; line-height: 16px; text-align: center; animation: pulse 1s infinite;
}
@keyframes pulse { 50% { transform: scale(1.2); } }

/* ---------- Panels ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 10; }
.panel {
  background: linear-gradient(#1f1826, #15101b);
  border: 2px solid var(--frame); border-radius: 8px;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 2px #0c0910, inset 0 0 0 3px #3b3022, 0 10px 30px rgba(0, 0, 0, .7);
  padding: 12px; color: var(--text);
}
.panel-title {
  font-family: 'Rubik', system-ui, sans-serif; font-weight: 800; font-size: 16px; letter-spacing: .3px; color: var(--gold); text-align: center;
  padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid #3b3022; position: relative; text-shadow: 0 2px 0 #000;
}
.x { position: absolute; right: -4px; top: -6px; width: 30px; height: 30px; font-size: 16px; color: var(--muted); }
.inv-panel { width: min(96vw, 420px); max-height: calc(100vh - 24px); overflow-y: auto; touch-action: pan-y; }
.inv-top { display: flex; gap: 12px; }
#equip-grid { display: grid; grid-template-columns: repeat(3, 52px); gap: 6px; flex: none; }
#stat-list { flex: 1; font-size: 12px; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
.st { display: flex; gap: 6px; align-items: center; }
.st b { width: 14px; text-align: center; }
.st span { flex: 1; color: var(--muted); }
.st em { font-style: normal; font-weight: 700; }
.panel-sub { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 6px; font-size: 13px; color: var(--gold); }
.panel-sub em { color: var(--muted); font-style: normal; font-size: 11px; }
#bag-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.slot {
  position: relative; aspect-ratio: 1; min-height: 46px; border-radius: 5px;
  background: radial-gradient(circle at 50% 40%, #2c2433, #17121c);
  border: 2px solid #3b3022; box-shadow: inset 0 0 0 1px #000;
  display: flex; align-items: center; justify-content: center; flex-direction: column; cursor: pointer;
}
.slot img { width: 78%; height: 78%; }
.slot img.ph { width: 50%; height: 50%; opacity: .18; }
.slot span { font-size: 8px; color: #6b5f50; margin-top: 1px; }
.slot.empty { cursor: default; }
.slot.r0 { border-color: #6b6b6b; }
.slot.r1 { border-color: #3fae5a; box-shadow: inset 0 0 10px rgba(94, 227, 122, .25); }
.slot.r2 { border-color: #3b7fd6; box-shadow: inset 0 0 10px rgba(90, 169, 255, .3); }
.slot.r3 { border-color: #9a4fd6; box-shadow: inset 0 0 12px rgba(199, 125, 255, .35); }
.slot.r4 { border-color: #e08a1f; box-shadow: inset 0 0 14px rgba(255, 166, 61, .45); }
.slot .up { position: absolute; right: 2px; top: 1px; font-size: 10px; color: #5ee37a; font-style: normal; text-shadow: 0 1px 0 #000; }
.shop { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.shop-label { font-size: 12px; color: var(--muted); flex: 1; min-width: 90px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 9px 14px; border-radius: 6px; font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(#7a5cd6, #4b2fa0); border: 2px solid #000;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2), inset 0 -3px 0 rgba(0, 0, 0, .3);
  text-shadow: 0 1px 0 #000;
}
.btn:active { transform: translateY(1px); filter: brightness(1.15); }
.btn img { width: 18px; height: 18px; }
.btn.small { padding: 6px 8px; font-size: 12px; background: linear-gradient(#4a3b2a, #2c2219); border-color: #000; }
.btn.sell { background: linear-gradient(#b8892c, #7a5612); }
.btn.ghost { background: #2a2230; }
.btn.big { font-size: 16px; padding: 14px 22px; min-width: 240px; flex-direction: column; }
.btn.big small { font-size: 11px; font-weight: 500; opacity: .8; }

/* ---------- Tooltip ---------- */
.tt { width: min(92vw, 340px); border-color: var(--rc, var(--frame)); }
.tt-head { display: flex; gap: 10px; align-items: center; }
.tt-icon { width: 60px; height: 60px; border-radius: 6px; flex: none; display: flex; align-items: center; justify-content: center; border: 2px solid var(--rc); background: radial-gradient(circle, rgba(255, 255, 255, .08), rgba(0, 0, 0, .3)); }
.tt-icon img { width: 48px; height: 48px; }
.tt-name { font-size: 16px; font-weight: 700; line-height: 1.15; text-shadow: 0 1px 0 #000; }
.tt-sub { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; margin-top: 4px; color: var(--gold); }
.tt-sub span { display: inline-flex; align-items: center; gap: 2px; }
.tt-sub span:last-child { color: var(--muted); }
.tt-sub img { width: 16px; height: 16px; }
.tt-rar { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tt-cols { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin: 10px 0 4px; padding-top: 8px; border-top: 1px solid #3b3022; }
.tt-row { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.tt-row b { width: 16px; text-align: center; }
.tt-row .n { flex: 1; }
.tt-row .v { font-weight: 700; min-width: 44px; text-align: right; }
.tt-row .d { min-width: 70px; text-align: right; font-size: 12px; color: var(--muted); }
.tt-row .d.up { color: #5ee37a; }
.tt-row .d.down { color: #ff5a5a; }
.tt-flavor { margin-top: 10px; padding: 8px; font-size: 12px; font-style: italic; color: #c8bba5; background: rgba(0, 0, 0, .25); border-radius: 4px; border-left: 2px solid var(--rc); }
.tt-btns { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.tt-btns .btn { flex: 1; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px; text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #2a1c38 0%, #0d0912 60%, #050307 100%);
}
#death-screen { background: rgba(20, 0, 4, .82); }
.logo { font-family: 'Rubik', system-ui, sans-serif; font-weight: 900; font-size: clamp(32px, 12vw, 58px); letter-spacing: 1px; color: #f2d27a; line-height: 1.25; text-shadow: 0 4px 0 #6b3a0f, 0 8px 0 #000; }
.logo span { display: block; color: #ff8a3d; font-size: .8em; }
.logo.red { color: #ff4a4a; text-shadow: 0 4px 0 #5a0a0a, 0 8px 0 #000; font-size: clamp(20px, 7vw, 34px); }
.title-hero { width: 128px; height: 128px; animation: float 2.4s ease-in-out infinite; filter: drop-shadow(0 10px 6px rgba(0, 0, 0, .6)); }
@keyframes float { 50% { transform: translateY(-8px); } }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.hint { font-size: 11px; color: var(--muted); max-width: 420px; line-height: 1.6; }
#death-info { font-size: 14px; line-height: 1.6; }
#death-info small { color: var(--muted); }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .35s; z-index: 30; }
#fade.on { opacity: 1; }

@media (max-height: 560px) {
  #actions { transform: scale(.82); transform-origin: right bottom; }
  #belt { bottom: calc(165px + var(--sa-b)); }
}

/* ---------- Juice ---------- */
.bar .ghost { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: #ffe0c0; transition: width .5s ease-in .25s; }
.bar .fill { position: relative; }
.bar .fill::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 35%; background: rgba(255, 255, 255, .25); }

#hurt { position: fixed; inset: 0; pointer-events: none; z-index: 5; opacity: 0; box-shadow: inset 0 0 90px 30px rgba(220, 0, 20, .75); }
#hurt.hit { animation: hurtHit .35s ease-out; }
#hurt.low { animation: hurtLow 1.1s ease-in-out infinite; }
#hurt.low.hit { animation: hurtHit .35s ease-out, hurtLow 1.1s ease-in-out .35s infinite; }
@keyframes hurtHit { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes hurtLow { 0%, 100% { opacity: .15; } 50% { opacity: .55; } }

.act.ready::before { content: ''; position: absolute; inset: -2px; border-radius: 50%; z-index: 4; box-shadow: 0 0 0 3px #fff, 0 0 18px 6px rgba(255, 230, 150, .9); animation: ready .45s ease-out forwards; }
@keyframes ready { from { opacity: 1; transform: scale(.9); } to { opacity: 0; transform: scale(1.35); } }
#btn-attack { animation: idleGlow 2.4s ease-in-out infinite; }
@keyframes idleGlow { 50% { box-shadow: 0 0 0 2px #000, inset 0 -4px 0 rgba(0, 0, 0, .4), 0 0 16px rgba(255, 200, 90, .45); } }

#floor-banner {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center; opacity: 0; pointer-events: none;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
#floor-banner b { font-family: 'Rubik', system-ui, sans-serif; font-weight: 900; font-size: 36px; color: #f2d27a; text-shadow: 0 3px 0 #6b3a0f, 0 6px 0 #000; letter-spacing: 2px; }
#floor-banner span { font-size: 13px; color: #d8c8a8; text-shadow: 0 2px 0 #000; padding: 4px 16px; border-top: 1px solid rgba(232, 196, 106, .5); border-bottom: 1px solid rgba(232, 196, 106, .5); background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .55), transparent); }
#floor-banner.show { animation: banner 2.6s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.4); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

.toast { animation: toastIn .3s cubic-bezier(.2, 1.6, .4, 1); }
.overlay:not(.hidden) .panel { animation: panelIn .22s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes panelIn { from { transform: scale(.9) translateY(10px); opacity: 0; } }
.slot { transition: transform .1s; }
.slot:not(.empty):active { transform: scale(.92); }
.slot.r3 img, .slot.r4 img { animation: shine 2s ease-in-out infinite; }
@keyframes shine { 50% { filter: brightness(1.35) drop-shadow(0 0 3px rgba(255, 220, 150, .8)); } }

#title-screen { background: radial-gradient(ellipse at 50% 40%, rgba(20, 10, 30, .25) 0%, rgba(8, 5, 12, .75) 70%, rgba(5, 3, 7, .95) 100%); }
.logo { animation: logoIn .8s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes logoIn { from { transform: translateY(-30px) scale(.8); opacity: 0; } }
.title-hero { animation: float 2.4s ease-in-out infinite, fadeIn .8s; }
@keyframes fadeIn { from { opacity: 0; } }
