:root {
  --bg: #171310;
  --panel: #241d18;
  --panel2: #2e251e;
  --ink: #e8dcc8;
  --dim: #a89880;
  --gold: #d9a441;
  --red: #c0453a;
  --green: #7fae4c;
  --line: #453729;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Rajdhani", system-ui, sans-serif;
  font-size: 18px;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.px { font-family: "Press Start 2P", monospace; }
.px.small { font-size: 11px; letter-spacing: 1px; }
.hidden { display: none !important; }
.view { max-width: 520px; margin: 0 auto; padding: 14px 16px 32px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 12px; color: var(--gold); }
.icon-btn { background: none; border: none; color: var(--ink); font-size: 22px; cursor: pointer; padding: 6px; }
h1.px { font-size: 22px; color: var(--gold); text-align: center; margin: 8px 0; }
.tagline { text-align: center; color: var(--dim); margin: 4px 0 18px; }
.logo { font-size: 46px; text-align: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 0 0 14px; }
.panel h3 { margin: 0 0 8px; color: var(--gold); font-size: 19px; }
.key-panel { margin-top: 10vh; }
.field-label { display: block; color: var(--dim); margin: 10px 0 6px; font-weight: 600; }
input[type="password"], input[type="text"] {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font-size: 17px; margin-bottom: 10px;
}
.btn {
  display: block; width: 100%; padding: 13px; margin: 10px 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  font-family: inherit; font-size: 18px; font-weight: 700; cursor: pointer;
}
.btn.primary { background: linear-gradient(180deg, #8a6420, #6e4f16); border-color: var(--gold); color: #ffe9b0; }
.btn.big { font-size: 20px; padding: 16px; }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }
.error { color: var(--red); }
.note { color: var(--dim); line-height: 1.45; }
.warning { background: #3a2418; border: 1px solid #7a4a21; color: #f0c98a; border-radius: 10px; padding: 10px 12px; margin: 10px 0; }

/* Main scene */
.scene { position: relative; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; height: 300px; background: #0e0b09; }
.scene .backdrop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; opacity: .9; }
.hero-wrap { position: absolute; left: 50%; bottom: 54px; transform: translateX(-50%); height: 190px; }
.hero { height: 100%; image-rendering: pixelated; filter: drop-shadow(0 6px 6px rgba(0,0,0,.55)); }
.hero.idle { animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.scene-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 12px 10px; background: linear-gradient(0deg, rgba(10,8,6,.88), rgba(10,8,6,0)); text-align: center; }
.stage-name { font-size: 13px; color: var(--gold); }
.level-line { font-size: 21px; font-weight: 700; margin-top: 5px; }

.progress-wrap { margin: 12px 2px 4px; }
.progress-label { color: var(--dim); font-size: 15px; margin-bottom: 5px; display: flex; justify-content: space-between; }
.progress-bar { height: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#progress-fill { height: 100%; background: linear-gradient(90deg, #8a6420, var(--gold)); width: 0%; transition: width .6s ease; }

.stats { display: flex; gap: 10px; margin: 14px 0 4px; }
.stat { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 6px; text-align: center; }
.stat-num { display: block; font-size: 24px; font-weight: 700; color: var(--ink); }
.stat-label { display: block; color: var(--dim); font-size: 13.5px; margin-top: 2px; }

/* Check-in */
.question { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.question p { margin: 0 0 10px; font-size: 19px; font-weight: 600; }
.yn { display: flex; gap: 10px; }
.yn button { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--dim); font-family: inherit; font-size: 17px; font-weight: 700; cursor: pointer; }
.yn button.sel-yes { background: #5a2320; border-color: var(--red); color: #ffb3ab; }
.yn button.sel-no { background: #2c4423; border-color: var(--green); color: #cdeeb2; }

/* History */
.hist { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.hist .h-head { display: flex; justify-content: space-between; font-weight: 700; }
.hist .delta-up { color: var(--green); } .hist .delta-down { color: var(--red); } .hist .delta-flat { color: var(--dim); }
.hist .h-detail { color: var(--dim); font-size: 15.5px; margin-top: 4px; line-height: 1.5; }

/* Battle */
.battle { position: fixed; inset: 0; background: rgba(8,6,5,.97); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; }
.battle-scene { position: relative; width: 100%; max-width: 520px; height: 320px; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: #0e0b09; }
.battle-scene .backdrop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.b-hero-wrap { position: absolute; left: 6%; bottom: 30px; height: 180px; transition: transform .45s ease; z-index: 3; }
.b-monster-wrap { position: absolute; right: 6%; bottom: 30px; height: 180px; transition: transform .45s ease, opacity .6s ease; z-index: 3; }
.b-sprite { height: 100%; image-rendering: pixelated; filter: drop-shadow(0 6px 6px rgba(0,0,0,.55)); }
.b-hero-wrap.lunge { transform: translateX(120px); }
.b-monster-wrap.lunge { transform: translateX(-120px); }
.b-sprite.hit { animation: hitflash .5s steps(2) 2; }
@keyframes hitflash { 0% { filter: brightness(2.4) sepia(1) hue-rotate(-45deg); } 100% { filter: none; } }
.b-sprite.shake { animation: shake .45s ease; }
@keyframes shake { 0%,100% { transform: translateX(0);} 20% { transform: translateX(-9px);} 40% { transform: translateX(8px);} 60% { transform: translateX(-6px);} 80% { transform: translateX(4px);} }
.b-monster-wrap.die { transform: translateY(26px) rotate(7deg); opacity: 0; }
.b-hero-wrap.kneel .b-sprite { transform: translateY(16px); filter: grayscale(.7) brightness(.75); }
.b-hero-wrap.weary .b-sprite { transform: translateY(22px); filter: grayscale(.4) brightness(.85); }
.slash { position: absolute; right: 16%; top: 34%; font-size: 58px; z-index: 5; animation: slashpop .5s ease; }
@keyframes slashpop { 0% { transform: scale(.3) rotate(-18deg); opacity: 0;} 40% { opacity: 1;} 100% { transform: scale(1.25) rotate(10deg); opacity: 0;} }
.battle-banner { position: absolute; left: 0; right: 0; top: 16px; text-align: center; font-size: 19px; color: var(--gold); text-shadow: 2px 2px 0 #000; z-index: 6; animation: bannerin .5s ease; }
.battle-banner.down { color: var(--red); }
.battle-banner.flat { color: var(--dim); }
@keyframes bannerin { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.battle-text { max-width: 520px; text-align: center; color: var(--ink); font-size: 19px; line-height: 1.5; min-height: 56px; margin: 16px 4px 6px; }
#battle .btn { max-width: 520px; }

/* Gold + shop */
.gold-pill { background: #3a2c14; border: 1px solid var(--gold); color: #ffe9b0; border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 16px; }
.dwelling-img { position: absolute; right: 4px; bottom: 46px; height: 118px; image-rendering: pixelated; opacity: .95; }
.pet-img { position: absolute; left: calc(50% + 62px); bottom: 50px; height: 84px; image-rendering: pixelated; animation: bob 2.6s ease-in-out infinite; }
.shop-item { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.shop-item img { width: 56px; height: 56px; object-fit: contain; image-rendering: pixelated; }
.shop-item .si-body { flex: 1; }
.shop-item .si-name { font-weight: 700; font-size: 18px; }
.shop-item .si-desc { color: var(--dim); font-size: 15px; line-height: 1.35; }
.shop-item .si-action { min-width: 92px; text-align: right; }
.shop-item .si-btn { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--gold); background: #6e4f16; color: #ffe9b0; font-family: inherit; font-weight: 700; font-size: 15px; cursor: pointer; width: 100%; }
.shop-item .si-btn:disabled { opacity: .45; cursor: default; }
.shop-item .si-btn.equipped { background: #2c4423; border-color: var(--green); color: #cdeeb2; }
.shop-item .si-btn.plain { background: var(--panel2); border-color: var(--line); color: var(--ink); }
.shop-cat { color: var(--gold); font-size: 18px; margin: 18px 0 8px; }
.reward-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.reward-row .r-name { flex: 1; }
.reward-row .r-count { color: var(--dim); font-size: 14px; }
.reward-row button { padding: 7px 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--ink); font-family: inherit; font-weight: 700; cursor: pointer; }
.reward-row button.redeem { border-color: var(--gold); color: #ffe9b0; }
input[type="number"], input[type="text"] { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--ink); font-size: 17px; margin-bottom: 10px; }
.battle-banner.crimson { color: #ff7a6b; }
.battle-banner.royal { color: #cfa9ff; }
.slash.big { font-size: 92px; right: 10%; }

/* The Room */
.room-scene { height: 320px; }
.room-layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; pointer-events: none; }
.room-base { object-fit: fill; }
.room-hero { left: 57%; bottom: 58px; height: 158px; transform: translateX(-50%); z-index: 56; }
#room-hotspots { position: absolute; inset: 0; z-index: 60; }
.hotspot { position: absolute; background: transparent; border: none; cursor: pointer; padding: 0; }
.hotspot:active { background: rgba(217,164,65,.12); }
.room-pop { background: var(--panel); border: 1px solid var(--gold); border-radius: 10px; padding: 14px; margin-top: 12px; }
.rp-title { color: var(--gold); font-size: 12px; margin-bottom: 8px; }
.rp-line { margin: 4px 0; color: var(--ink); }
.rp-line.dim { color: var(--dim); }
#rp-buy:disabled { opacity: .45; }

/* Play entry */
.play-btn { background: linear-gradient(180deg, #5a2320, #42201c); border-color: #a04a3a; color: #ffd9d0; }
.play-btn.locked { background: var(--panel2); border-color: var(--line); color: var(--dim); }

/* Battle juice extras */
.battle-banner.verdant { color: #9fe870; }
.battle-scene.shake { animation: sceneshake .4s ease; }
@keyframes sceneshake { 0%,100% { transform: translate(0,0); } 20% { transform: translate(-6px,3px); } 40% { transform: translate(5px,-3px); } 60% { transform: translate(-4px,-2px); } 80% { transform: translate(3px,2px); } }
.particle { position: absolute; font-size: 17px; z-index: 6; pointer-events: none; animation: particlefly .6s ease-out forwards; }
@keyframes particlefly { from { transform: translate(0,0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.4); opacity: 0; } }

/* Arena */
.arena-wrap { position: relative; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: #0e0b09; }
#arena { display: block; width: 100%; height: auto; touch-action: none; }
.arena-hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; background: linear-gradient(180deg, rgba(8,6,5,.85), rgba(8,6,5,0)); font-weight: 700; font-size: 17px; pointer-events: none; }
.touch-controls { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 12px 16px; pointer-events: none; }
.joy { pointer-events: auto; width: 108px; height: 108px; border-radius: 50%; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.25); position: relative; touch-action: none; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.28); transform: translate(-50%, -50%); }
.attack-btn { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; font-size: 30px; background: rgba(160,74,58,.5); border: 1px solid #c06a55; color: #fff; touch-action: none; }
.attack-btn:active { background: rgba(192,69,58,.75); }
.arena-over { position: absolute; inset: 0; background: rgba(8,6,5,.9); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 22px; text-align: center; z-index: 5; }
.arena-over .px { color: var(--gold); font-size: 15px; margin-bottom: 10px; }
.arena-over .btn { max-width: 300px; }
.confetti { position: absolute; top: -8px; z-index: 6; pointer-events: none; animation: confettifall 2.4s ease-in forwards; }
@keyframes confettifall { to { transform: translateY(430px) rotate(300deg); opacity: 0; } }
