:root{
  --bg:#1c0734; --panel:#3c175e; --panel2:#562681; --gold:#ffd86b; --pink:#ff8fcb; --enemy:#ff5b8d; --good:#6df0a8; --text:#fff8ff;
}
*{box-sizing:border-box}
body{margin:0;background:radial-gradient(circle at top,#4a1973 0,#1e0738 58%,#140227 100%);font-family:Inter,Segoe UI,Arial,sans-serif;color:var(--text);overflow:hidden}
.game-shell{position:relative;width:100vw;height:100vh;display:grid;place-items:center}
canvas{width:min(100vw,177.78vh);height:min(56.25vw,100vh);max-width:100vw;max-height:100vh;background:#d9b1c9;border:4px solid rgba(255,255,255,.18);border-radius:18px;box-shadow:0 24px 70px rgba(0,0,0,.45)}
.hidden{display:none!important}
.hud,.inventory-bar,.roster-bar,.boss-bar-wrap,.dialogue,.toast,.overlay{position:absolute;z-index:3}
.card,.inventory-bar,.roster-bar,.dialogue,.toast,.panel,.boss-bar-wrap{backdrop-filter:blur(10px);background:linear-gradient(180deg,rgba(67,24,107,.92),rgba(52,15,86,.88));border:1px solid rgba(255,255,255,.16);box-shadow:0 14px 30px rgba(0,0,0,.28)}
.hud{top:16px;left:18px;right:18px;display:flex;gap:12px;align-items:stretch}
.hud-left{flex:1;padding:14px 18px;border-radius:20px}
.eyebrow{color:var(--gold);font-size:13px;font-weight:900;letter-spacing:.12em;text-transform:uppercase}
.headline{font-size:17px;font-weight:900;margin-top:3px}
.subline{font-size:13px;opacity:.92;margin-top:5px}
.hud-stat{width:116px;min-width:116px;border-radius:18px;padding:12px 10px;text-align:center;display:flex;flex-direction:column;justify-content:center}
.hud-stat span{font-weight:900;font-size:28px;color:var(--gold);line-height:1}
.hud-stat small{font-size:11px;letter-spacing:.14em;margin-top:8px;opacity:.9}
.boss-bar-wrap{top:102px;left:50%;transform:translateX(-50%);padding:10px 14px;border-radius:18px;min-width:420px;text-align:center}
.boss-name{font-weight:900;color:#ffd6ea;margin-bottom:6px}
.boss-bar{height:18px;background:rgba(255,255,255,.14);border-radius:999px;overflow:hidden}
#bossBar{height:100%;width:100%;background:linear-gradient(90deg,#ff6594,#ffa15f);border-radius:999px}
.inventory-bar{top:140px;left:20px;display:flex;gap:8px;padding:10px 12px;border-radius:18px;flex-wrap:wrap;max-width:720px}
.inventory-slot{width:48px;height:48px;border-radius:14px;background:rgba(255,255,255,.09);border:1px solid rgba(255,255,255,.15);display:grid;place-items:center;overflow:hidden}
.inventory-slot img{max-width:88%;max-height:88%;filter:drop-shadow(0 0 8px rgba(255,216,107,.55))}
.inventory-slot.missing{opacity:.38}
.roster-bar{left:50%;bottom:16px;transform:translateX(-50%);display:flex;gap:8px;padding:10px 12px;border-radius:22px}
.roster-card{width:86px;padding:6px;border-radius:16px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);text-align:center;cursor:pointer;transition:.15s}
.roster-card.active{outline:3px solid var(--gold);transform:translateY(-3px)}
.roster-card.ko{opacity:.3;filter:grayscale(1)}
.roster-card img{width:58px;height:58px;object-fit:contain}
.roster-card .name{font-size:11px;font-weight:800;line-height:1.1}
.roster-card .hp{font-size:11px;color:#ffd7e4;margin-top:2px}
.dialogue{left:50%;bottom:120px;transform:translateX(-50%);width:min(700px,90vw);border-radius:24px;padding:14px;display:flex;gap:16px;align-items:center}
.dialogue img{width:110px;height:110px;object-fit:contain;border-radius:18px;background:rgba(255,255,255,.08)}
.dialogue-name{font-size:21px;font-weight:900;color:var(--gold)}
.dialogue p{margin:8px 0 6px;font-size:17px;line-height:1.4}
.toast{left:50%;top:110px;transform:translateX(-50%);padding:12px 18px;border-radius:999px;font-weight:900;color:#fff3b0}
.overlay{inset:0;display:grid;place-items:center;background:rgba(12,2,23,.58)}
.panel{width:min(900px,92vw);padding:32px;border-radius:30px;text-align:center}
.start-panel h1{margin:.15em 0 0;font-size:60px;line-height:.9}
.start-panel h2{margin:.15em 0 .3em;font-size:34px;color:#ffd7eb}
.panel p{font-size:18px;line-height:1.55;opacity:.97}
.controls-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin:22px 0}
.controls-grid span{background:rgba(255,255,255,.08);padding:10px 12px;border-radius:14px;font-weight:800}
kbd{background:#fff1;border:1px solid #fff2;padding:2px 6px;border-radius:7px}
.legend-row{display:flex;justify-content:center;gap:10px;flex-wrap:wrap;margin:8px 0 20px}
.pill{padding:8px 12px;border-radius:999px;font-weight:900}
.treasure-pill{background:rgba(255,216,107,.18);color:#ffe48d;border:1px solid rgba(255,216,107,.38)}
.enemy-pill{background:rgba(255,91,141,.16);color:#ffb3ca;border:1px solid rgba(255,91,141,.35)}
.boss-pill{background:rgba(255,145,95,.16);color:#ffd0b3;border:1px solid rgba(255,145,95,.35)}
.primary-btn,.secondary-btn{border:none;border-radius:16px;padding:14px 22px;font-size:17px;font-weight:900;cursor:pointer}
.primary-btn{background:linear-gradient(180deg,#ffd86b,#ffb74a);color:#49250b;box-shadow:0 10px 22px rgba(255,183,74,.3)}
.secondary-btn{background:rgba(255,255,255,.11);color:white;border:1px solid rgba(255,255,255,.16)}
.button-row{display:flex;gap:12px;justify-content:center;flex-wrap:wrap;margin-top:12px}
.end-stats{display:flex;justify-content:center;gap:14px;flex-wrap:wrap;margin:14px 0 18px}
.end-stats span{padding:10px 14px;border-radius:14px;background:rgba(255,255,255,.08);font-weight:800}
@media (max-width: 900px){
  .controls-grid{grid-template-columns:repeat(2,1fr)}
  .hud{gap:8px}.hud-stat{width:94px;min-width:94px}.headline{font-size:15px}.subline{font-size:12px}
  .inventory-bar{max-width:calc(100vw - 40px)}
  .boss-bar-wrap{min-width:320px}
}

/* v4: music + cast instructions + victory dance */
.music-btn{min-width:82px;border:none;border-radius:18px;color:#ffe28a;font-weight:1000;font-size:15px;cursor:pointer;padding:0 12px}
.instruction-cast{display:grid;grid-template-columns:repeat(6,1fr);gap:9px;margin:18px 0 12px}
.instruction-cast>div{min-width:0;padding:8px 5px;border-radius:16px;background:rgba(255,255,255,.075);border:1px solid rgba(255,255,255,.13);display:flex;flex-direction:column;align-items:center}
.instruction-cast img{width:72px;height:82px;object-fit:contain;filter:drop-shadow(0 6px 7px rgba(0,0,0,.25))}
.instruction-cast b{font-size:12px;line-height:1.05;margin-top:4px}
.instruction-cast small{font-size:9px;opacity:.8;margin-top:3px}
.start-panel{max-height:94vh;overflow:auto}
.victory-chant{margin:14px auto 8px;padding:12px 18px;border-radius:999px;width:max-content;max-width:100%;font-size:20px;font-weight:1000;letter-spacing:.06em;color:#502307;background:linear-gradient(90deg,#ffd75d,#ff9ccf,#bca1ff,#ffd75d);box-shadow:0 0 28px rgba(255,208,91,.35);animation:chantPulse .7s ease-in-out infinite alternate}
.victory-cast{height:180px;display:flex;align-items:flex-end;justify-content:center;gap:8px;margin:8px 0 14px;overflow:visible}
.victory-cast img{width:105px;height:150px;object-fit:contain;filter:drop-shadow(0 8px 8px rgba(0,0,0,.25));transform-origin:center bottom;animation:victoryJump .8s ease-in-out infinite}
.victory-cast img:nth-child(2){animation-delay:.10s}.victory-cast img:nth-child(3){animation-delay:.20s}.victory-cast img:nth-child(4){animation-delay:.30s}.victory-cast img:nth-child(5){animation-delay:.40s}.victory-cast img:nth-child(6){animation-delay:.50s}
@keyframes victoryJump{0%,100%{transform:translateY(0) rotate(-2deg)}45%{transform:translateY(-34px) rotate(3deg)}60%{transform:translateY(-24px) rotate(-1deg)}}
@keyframes chantPulse{from{transform:scale(1)}to{transform:scale(1.035)}}
@media(max-width:900px){.instruction-cast{grid-template-columns:repeat(3,1fr)}.instruction-cast img{width:58px;height:64px}.victory-cast img{width:70px;height:110px}.victory-cast{height:135px}.music-btn{min-width:66px;font-size:12px}}

/* v5: mobile controls, level select, boss-label cleanup */
.level-select{margin:0 auto 18px;padding:12px 14px;border-radius:18px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.12);max-width:760px}
.level-select>b{display:block;margin-bottom:9px;color:#ffe38a;font-size:13px;letter-spacing:.04em}
.level-select-buttons{display:grid;grid-template-columns:repeat(5,1fr);gap:7px}
.level-select-buttons button{border:1px solid rgba(255,255,255,.15);background:rgba(255,255,255,.09);color:white;border-radius:12px;padding:9px 6px;font-weight:900;cursor:pointer;font-size:11px}
.level-select-buttons button:hover{background:rgba(255,216,107,.18);border-color:rgba(255,216,107,.45);color:#ffe798}
.mobile-controls{display:none;position:absolute;z-index:7;inset:0;pointer-events:none}
.touch-dpad,.touch-actions{pointer-events:auto;position:absolute;bottom:max(12px,env(safe-area-inset-bottom))}
.touch-dpad{left:max(12px,env(safe-area-inset-left));width:154px;height:154px}
.touch-btn{position:absolute;width:52px;height:52px;border-radius:18px;border:1px solid rgba(255,255,255,.22);background:rgba(54,18,89,.82);color:#fff4c2;font-size:21px;font-weight:1000;box-shadow:0 8px 18px rgba(0,0,0,.28);touch-action:none;-webkit-user-select:none;user-select:none}
.touch-btn.up{left:51px;top:0}.touch-btn.left{left:0;top:51px}.touch-btn.down{left:51px;top:102px}.touch-btn.right{left:102px;top:51px}
.touch-actions{right:max(12px,env(safe-area-inset-right));display:grid;grid-template-columns:76px 92px;grid-template-rows:54px 62px;gap:8px;align-items:end}
.touch-action{border:none;border-radius:20px;color:white;font-size:11px;font-weight:1000;line-height:1.05;box-shadow:0 8px 18px rgba(0,0,0,.3);touch-action:none;-webkit-user-select:none;user-select:none;padding:8px}
.touch-action.switch{grid-column:1;grid-row:1;background:rgba(84,39,121,.88)}
.touch-action.power{grid-column:1;grid-row:2;background:linear-gradient(180deg,#9a65dc,#6d3aa9)}
.touch-action.shoot{grid-column:2;grid-row:1 / span 2;background:linear-gradient(180deg,#ff759f,#d94077);font-size:15px}
.touch-btn:active,.touch-action:active{transform:scale(.94);filter:brightness(1.16)}
.rotate-hint{display:none;position:absolute;z-index:20;inset:0;background:rgba(20,3,37,.94);color:white;align-items:center;justify-content:center;flex-direction:column;text-align:center;padding:24px}
.rotate-hint>div{font-size:56px;color:#ffe06d;line-height:1}.rotate-hint b{font-size:24px;margin-top:8px}.rotate-hint span{font-size:14px;opacity:.82;margin-top:6px}

@media (pointer:coarse){
  html,body{width:100%;height:100%;overscroll-behavior:none;touch-action:none}
  body{position:fixed;inset:0}
  .game-shell{width:100vw;height:100dvh;overflow:hidden}
  canvas{width:100vw;height:100dvh;max-width:none;max-height:none;border:0;border-radius:0;box-shadow:none}
  .mobile-controls:not(.hidden){display:block}
  .hud{top:max(4px,env(safe-area-inset-top));left:max(5px,env(safe-area-inset-left));right:max(5px,env(safe-area-inset-right));gap:4px}
  .hud-left{padding:7px 9px;border-radius:13px;min-width:0}
  .eyebrow{font-size:9px}.headline{font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.subline{font-size:9px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .hud-stat{width:63px;min-width:63px;padding:7px 4px;border-radius:13px}.hud-stat span{font-size:19px}.hud-stat small{font-size:7px;margin-top:4px;letter-spacing:.08em}
  .music-btn{min-width:52px;width:52px;padding:0 5px;border-radius:13px;font-size:9px}
  .boss-bar-wrap{top:67px;min-width:230px;width:36vw;max-width:320px;padding:5px 9px;border-radius:13px}.boss-name{font-size:10px;margin-bottom:3px}.boss-bar{height:10px}
  .inventory-bar{top:67px;left:max(5px,env(safe-area-inset-left));max-width:48vw;gap:3px;padding:5px 6px;border-radius:12px;flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none}.inventory-bar::-webkit-scrollbar{display:none}.inventory-slot{width:30px;height:30px;min-width:30px;border-radius:8px}
  .roster-bar{bottom:max(5px,env(safe-area-inset-bottom));gap:3px;padding:5px 6px;border-radius:14px;max-width:44vw;overflow-x:auto;scrollbar-width:none}.roster-bar::-webkit-scrollbar{display:none}
  .roster-card{width:49px;min-width:49px;padding:3px;border-radius:10px}.roster-card img{width:34px;height:34px}.roster-card .name{font-size:7px}.roster-card .hp{font-size:7px}.roster-card.active{outline-width:2px;transform:translateY(-1px)}
  .toast{top:86px;padding:7px 11px;font-size:10px;max-width:48vw;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .dialogue{bottom:84px;width:min(580px,70vw);padding:8px 10px;border-radius:16px;gap:9px}.dialogue img{width:64px;height:64px}.dialogue-name{font-size:15px}.dialogue p{font-size:12px;line-height:1.25;margin:3px 0}.dialogue small{font-size:9px}
  .panel{width:min(860px,94vw);padding:18px;border-radius:22px;max-height:92dvh;overflow:auto}.start-panel h1{font-size:42px}.start-panel h2{font-size:24px}.panel p{font-size:13px;line-height:1.35}.instruction-cast{margin:10px 0 8px;gap:5px}.instruction-cast img{width:46px;height:50px}.instruction-cast b{font-size:9px}.instruction-cast small{font-size:7px}.controls-grid{gap:5px;margin:10px 0}.controls-grid span{padding:6px;font-size:10px}.legend-row{margin:5px 0 10px}.pill{padding:5px 8px;font-size:10px}.level-select{margin-bottom:10px;padding:8px}.level-select>b{font-size:10px;margin-bottom:6px}.level-select-buttons{gap:4px}.level-select-buttons button{padding:7px 3px;font-size:8px}.primary-btn,.secondary-btn{padding:9px 15px;font-size:12px}
  .victory-cast{height:116px}.victory-cast img{width:62px;height:96px}.victory-chant{font-size:14px;padding:8px 12px}
}

@media (pointer:coarse) and (max-height:520px){
  .touch-dpad{transform:scale(.82);transform-origin:left bottom}
  .touch-actions{transform:scale(.86);transform-origin:right bottom}
  .roster-bar{transform:translateX(-50%) scale(.9);transform-origin:center bottom}
}

@media (pointer:coarse) and (orientation:portrait){.rotate-hint{display:flex}}
@media (max-width:700px){.level-select-buttons{grid-template-columns:repeat(3,1fr)}}
