:root {
  --mint: #8fe3c8;
  --peach: #ffb3a7;
  --lav: #b9a8f0;
  --cream: #fff7ec;
  --plum: #5a3d6e;
  --gold: #ffd76a;
  --font: "Arial Rounded MT Bold", "Nunito", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #d9d2f5; touch-action: none; user-select: none; -webkit-user-select: none; }
body { font-family: var(--font); color: var(--cream); }
#app { position: fixed; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.outl {
  paint-order: stroke fill;
  -webkit-text-stroke: 5px var(--plum);
}
.num, .hud-title, #banner-main, #banner-sub, #toast, #title-prompt, .game-btn, .panel-title, #boss-label, .popup {
  font-weight: 900;
  color: var(--cream);
  paint-order: stroke fill;
  -webkit-text-stroke: 5px var(--plum);
  text-shadow: 0 3px 0 rgba(90, 61, 110, 0.55);
}

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-panel {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  padding: 8px 12px 8px 10px;
  border-radius: 18px;
  background: rgba(90, 61, 110, 0.42);
  border: 2px solid rgba(255, 247, 236, 0.55);
  display: flex; flex-direction: column; gap: 4px;
}
#hearts { display: flex; gap: 2px; flex-wrap: wrap; max-width: 112px; }
#hearts svg { width: 20px; height: 20px; filter: drop-shadow(0 2px 0 rgba(90,61,110,.6)); }
#hearts svg.pop { animation: heartpop .35s ease-out; }
@keyframes heartpop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
.hud-row { display: flex; align-items: center; gap: 6px; }
#gold-icon { width: 24px; height: 24px; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(90,61,110,.5)); }
.num { font-size: 18px; letter-spacing: 0.02em; }
.num.big { font-size: 26px; }
/* level & EXP */
#lv-row { gap: 5px; }
#lv { font-size: 14px; -webkit-text-stroke: 4px var(--plum); min-width: 34px; white-space: nowrap; }
#xp-wrap { width: 64px; height: 11px; border-radius: 6px; background: rgba(90,61,110,.6); border: 2px solid var(--cream); overflow: hidden; }
#xp-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #9fffd8, #c9b8ff); transition: width .3s; }
#lv-row.up #lv { animation: lvpop .6s cubic-bezier(.34,1.56,.64,1); color: #fff2a8; }
#lv-row.up #xp-wrap { box-shadow: 0 0 10px #fff2a8; }
@keyframes lvpop { 0% { transform: scale(1.8); } 100% { transform: scale(1); } }
/* the room's name is shown by the banner when a room starts; the HUD keeps score, beds and the burst meter */
#room-name { display: none; }
#hud-center {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 100px;
}
.hud-title { font-size: 13px; line-height: 1.15; text-align: center; max-width: 100%; -webkit-text-stroke: 4px var(--plum); }
#beds { display: flex; gap: 4px; }
#beds .bed { width: 18px; height: 18px; border-radius: 50%; background: rgba(255,255,255,.35); border: 2px solid var(--plum); position: relative; overflow: hidden; }
#beds .bed i { position: absolute; left: 0; bottom: 0; width: 100%; background: var(--mint); }
#beds .bed.done { background: var(--peach); box-shadow: 0 0 8px #fff; }
#beds .bed.low { animation: bedwarn .5s ease-in-out infinite alternate; }
@keyframes bedwarn { from { box-shadow: 0 0 2px #ff4d6d; } to { box-shadow: 0 0 10px #ff4d6d; border-color: #ff4d6d; } }
#burst-wrap { width: 96px; height: 12px; border-radius: 6px; background: rgba(90,61,110,.55); border: 2px solid var(--cream); overflow: hidden; margin-top: 2px; }
#burst-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #ffb3d9, #ffe58a); transition: width .15s; }
#burst-wrap.full { box-shadow: 0 0 10px #ffe58a; animation: glow 0.8s ease-in-out infinite alternate; }
@keyframes glow { from { box-shadow: 0 0 4px #ffe58a; } to { box-shadow: 0 0 14px #ffb3d9; } }
#boss-bar {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(100px + env(safe-area-inset-top, 0px));
  width: 70%; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
#boss-label { font-size: 14px; -webkit-text-stroke: 4px var(--plum); }
#boss-track { width: 100%; height: 14px; border-radius: 8px; background: rgba(90,61,110,.6); border: 2px solid var(--cream); overflow: hidden; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #9fd8ff, #c9b8ff); transition: width .2s; }

/* floating score popups */
.popup {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 18px; -webkit-text-stroke: 4px var(--plum); white-space: nowrap;
  pointer-events: none; z-index: 3;
  animation: floatup .9s ease-out forwards;
}
.popup.xp { color: #c8ffe8; font-size: 17px; animation: floatup 1.15s ease-out .22s both; }
.popup.heal { color: #a8ffcc; font-size: 21px; }
@keyframes floatup {
  0% { transform: translate(-50%, -30%) scale(.6); opacity: 0; }
  20% { transform: translate(-50%, -70%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -180%) scale(1); opacity: 0; }
}

/* banner & toast & subtitle */
#banner {
  position: absolute; left: 0; right: 0; top: 30%;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; text-align: center; padding: 0 16px;
}
#banner-main { font-size: 34px; -webkit-text-stroke: 7px var(--plum); }
#banner-sub { font-size: 16px; -webkit-text-stroke: 4px var(--plum); max-width: 90%; }
#banner.show { animation: slam .5s cubic-bezier(.34,1.56,.64,1); }
@keyframes slam { 0% { transform: scale(2.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#toast {
  position: absolute; left: 50%; top: calc(150px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  font-size: 16px; -webkit-text-stroke: 4px var(--plum); white-space: nowrap; pointer-events: none;
  padding: 6px 14px; border-radius: 14px; background: rgba(90,61,110,.35);
  max-width: 94%; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { animation: drop .3s cubic-bezier(.34,1.56,.64,1); }
@keyframes drop { 0% { transform: translate(-50%, -20px); opacity: 0; } 100% { transform: translate(-50%, 0); opacity: 1; } }
#subtitle {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 56%; max-width: 86%; text-align: center;
  padding: 8px 14px; border-radius: 14px; background: rgba(40, 24, 60, 0.6);
  color: #fff; font-weight: 800; font-size: 16px; line-height: 1.35; pointer-events: none; z-index: 6;
}

/* title */
#title { position: absolute; inset: 0; overflow: hidden; cursor: pointer; }
#title-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; animation: kb 18s ease-in-out infinite alternate; }
@keyframes kb { from { transform: scale(1.02); } to { transform: scale(1.08) translateY(-1%); } }
#title-snow { position: absolute; inset: 0; pointer-events: none; }
#title-snow i { position: absolute; top: -10px; width: 6px; height: 6px; border-radius: 50%; background: #fff; opacity: .85; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(20px, 110vh); } }
#title-logo {
  position: absolute; left: 50%; top: 8%; width: 84%; max-height: 30%; object-fit: contain;
  transform: translateX(-50%); filter: drop-shadow(0 6px 10px rgba(90,61,110,.35));
  animation: logoIn .7s cubic-bezier(.34,1.56,.64,1) both, float 3.2s ease-in-out .7s infinite;
}
@keyframes logoIn { 0% { transform: translate(-50%, -60px) scale(.6); opacity: 0; } 100% { transform: translate(-50%, 0) scale(1); opacity: 1; } }
@keyframes float { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -8px); } }
#title-prompt {
  position: absolute; left: 0; right: 0; margin: 0 auto; bottom: 11%;
  width: fit-content; max-width: 86%; text-align: center; font-size: 22px; line-height: 1.25;
  padding: 6px 18px; border-radius: 22px; background: rgba(90, 61, 110, 0.28);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: .85; } }
.corner-btn {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); width: 48px; height: 48px;
  border-radius: 50%; border: 2px solid rgba(255,247,236,.85); background: rgba(90,61,110,.38);
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
  transition: transform .1s;
}
.corner-btn:active { transform: scale(.9); }
.corner-btn img { width: 34px; height: 34px; object-fit: contain; pointer-events: none; }
#btn-trophy { right: calc(12px + env(safe-area-inset-right, 0px)); }
#btn-shop { left: calc(12px + env(safe-area-inset-left, 0px)); }

/* intro */
#intro { position: absolute; inset: 0; background: #d9d2f5 url("../assets/cover-bg.webp") center / cover no-repeat; z-index: 5; }
#intro video { width: 100%; height: 100%; object-fit: cover; display: block; }
#intro-skip { position: absolute; top: calc(14px + env(safe-area-inset-top, 0px)); right: 14px; }

/* panels */
#modal { position: absolute; inset: 0; z-index: 8; background: rgba(60, 40, 90, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.game-panel {
  width: min(360px, 100%); max-height: 92%; overflow-y: auto;
  border-style: solid; border-width: 34px; border-color: transparent;
  border-image: url("../assets/ui-panel.webp") 120 fill / 34px stretch;
  padding: 6px 4px; color: var(--plum);
  display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  animation: popin .28s cubic-bezier(.34,1.56,.64,1);
  scrollbar-width: none;
}
.game-panel::-webkit-scrollbar { display: none; }
@keyframes popin { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.panel-title { font-size: 24px; text-align: center; margin: 0 0 4px; line-height: 1.2; }
.panel-text { font-weight: 700; font-size: 15px; line-height: 1.45; color: var(--plum); margin: 0; }

/* buttons: a chunky glossy vinyl pill (drawn in CSS so it never squashes, whatever the label's length) */
.game-btn {
  position: relative; isolation: isolate;
  min-height: 54px; padding: 10px 22px 12px;
  font-family: inherit; font-size: 17px; line-height: 1.15; text-align: center; white-space: normal;
  cursor: pointer;
  border: 3px solid var(--plum); border-radius: 999px;
  background: linear-gradient(180deg, #ffe0d8 0%, #ffb8ac 46%, #ff98ac 100%);
  box-shadow: inset 0 -5px 0 rgba(214, 92, 128, 0.35), 0 5px 0 var(--plum), 0 8px 12px rgba(90, 61, 110, 0.28);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s, filter .12s, box-shadow .1s;
  -webkit-text-stroke: 4px var(--plum);
}
/* the glossy highlight across the top */
.game-btn::before {
  content: ""; position: absolute; z-index: -1; left: 10%; right: 10%; top: 4px; height: 42%;
  border-radius: 999px; background: linear-gradient(180deg, rgba(255,255,255,.85), rgba(255,255,255,.08));
  pointer-events: none;
}
.game-btn:active { transform: translateY(4px) scale(.98); box-shadow: inset 0 -3px 0 rgba(214, 92, 128, 0.35), 0 1px 0 var(--plum), 0 2px 4px rgba(90, 61, 110, 0.25); }
.game-btn.focus {
  filter: brightness(1.07);
  transform: scale(1.04);
  box-shadow: inset 0 -5px 0 rgba(214, 92, 128, 0.35), 0 5px 0 var(--plum), 0 0 0 4px #fff7ec, 0 0 18px 4px rgba(255, 231, 140, 0.95);
}
.game-btn.focus:active { transform: translateY(4px) scale(1.0); }
.game-btn img { width: 28px; height: 28px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 0 rgba(90,61,110,.45)); }
.game-btn span { min-width: 0; }
.game-btn.alt { background: linear-gradient(180deg, #e2fff4 0%, #aef0d8 46%, #7fd9bb 100%); box-shadow: inset 0 -5px 0 rgba(52, 150, 118, 0.35), 0 5px 0 var(--plum), 0 8px 12px rgba(90, 61, 110, 0.28); }
.game-btn.alt.focus { box-shadow: inset 0 -5px 0 rgba(52, 150, 118, 0.35), 0 5px 0 var(--plum), 0 0 0 4px #fff7ec, 0 0 18px 4px rgba(255, 231, 140, 0.95); }
.game-btn.small { min-height: 44px; font-size: 15px; padding: 6px 16px 8px; }
.game-btn[disabled] { filter: grayscale(.4) brightness(.92); cursor: default; }

/* bag */
.bag-list { display: flex; flex-direction: column; gap: 8px; }
.bag-sec { font-weight: 900; font-size: 14px; color: #8a6aa0; margin: 4px 2px -2px; }
.bag-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 14px; background: rgba(255,255,255,.55); border: 2px solid rgba(90,61,110,.25); }
.bag-item img { width: 44px; height: 44px; object-fit: contain; flex: none; }
.bag-item .info { flex: 1; min-width: 0; }
.bag-item .name { font-weight: 900; font-size: 15px; color: var(--plum); }
.bag-item .stat { font-weight: 700; font-size: 12.5px; color: #7a5d8e; }
.bag-item .count { font-weight: 900; font-size: 16px; color: var(--plum); white-space: nowrap; }
.bag-item .game-btn { min-height: 44px; font-size: 14px; padding: 4px 14px 6px; flex: none; }
.bag-item.on { border-color: var(--mint); background: rgba(200,255,235,.75); }

/* level-up cards */
.up-list { display: flex; flex-direction: column; gap: 12px; padding: 2px 2px 6px; }
.up-card {
  display: flex; align-items: center; gap: 10px; text-align: left;
  width: 100%; min-height: 80px; padding: 8px 12px 8px 8px;
  border-radius: 20px; border: 3px solid var(--plum);
  background: linear-gradient(180deg, #f3fffa 0%, #cdf5e6 100%);
  box-shadow: inset 0 3px 0 #fff, inset 0 -4px 0 rgba(52, 150, 118, 0.22), 0 5px 0 var(--plum);
  font-family: inherit; color: var(--plum); cursor: pointer;
  transition: transform .1s, box-shadow .1s, filter .1s;
  animation: cardin .38s cubic-bezier(.34,1.56,.64,1) backwards;
}
.up-card.flower { background: linear-gradient(180deg, #fff6fb 0%, #ffd6e8 100%); box-shadow: inset 0 3px 0 #fff, inset 0 -4px 0 rgba(214, 92, 128, 0.22), 0 5px 0 var(--plum); }
.up-card .ic { width: 62px; height: 62px; flex: none; border-radius: 18px; background: rgba(255,255,255,.75); border: 2px solid rgba(90,61,110,.18); display: flex; align-items: center; justify-content: center; }
.up-card .ic img { width: 56px; height: 56px; object-fit: contain; }
.up-card .tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.up-card .nm { font-weight: 900; font-size: 16.5px; line-height: 1.2; }
.up-card .tag { display: inline-block; font-size: 11.5px; font-weight: 900; padding: 1px 8px; border-radius: 999px; background: var(--mint); color: var(--plum); margin-right: 6px; vertical-align: 2px; }
.up-card.flower .tag { background: #ffb3d1; }
.up-card .lvl { font-size: 12.5px; font-weight: 900; color: #b0558a; }
.up-card .ds { font-size: 14px; font-weight: 700; line-height: 1.3; color: #6d5080; }
.up-card.focus { transform: scale(1.035); box-shadow: inset 0 3px 0 #fff, 0 5px 0 var(--plum), 0 0 0 4px #fff7ec, 0 0 18px 4px rgba(255, 215, 106, 0.95); }
.up-card:active { transform: translateY(4px) scale(.99); box-shadow: inset 0 3px 0 #fff, 0 1px 0 var(--plum); }
.up-card.picked { animation: picked .2s ease-out forwards; }
@keyframes cardin { 0% { transform: translateY(28px) scale(.82); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes picked { 0% { transform: scale(1.04); } 50% { transform: scale(1.12); filter: brightness(1.2); } 100% { transform: scale(1.08); filter: brightness(1.3); } }
.lvup-title { color: #fff2a8; font-size: 30px; -webkit-text-stroke: 6px var(--plum); animation: lvpop .55s cubic-bezier(.34,1.56,.64,1); }

#fade { position: absolute; inset: 0; background: #fff7ec; opacity: 0; pointer-events: none; transition: opacity .35s; z-index: 9; }
#fade.on { opacity: 1; }
