:root {
  --violet-deep: #12091F; --violet: #2E0F8C; --violet-mid: #5B3FE6; --violet-bright: #620DFE;
  --lime: #9BE41E; --lime2: #93E401; --fur: #FBB14E; --cream: #FEE9CA; --ink: #0F0704; --amber: #F5A33C;
  --panel: rgba(18, 9, 31, .82);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--violet-deep); color: var(--cream); font-family: Nunito, system-ui, sans-serif; font-weight: 700; overflow: hidden; touch-action: manipulation; }
button { font: inherit; font-weight: 900; color: var(--ink); background: var(--lime); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 16px; cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: var(--violet-mid); color: #fff; }
button.big { font-size: 28px; padding: 16px 48px; border-radius: 22px; }
#app { position: fixed; inset: 0; max-width: 520px; margin: 0 auto; background: var(--violet-deep); display: flex; flex-direction: column; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* title */
#title { align-items: center; justify-content: flex-end; }
#intro { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.title-inner { position: relative; text-align: center; padding: 24px 16px calc(40px + env(safe-area-inset-bottom)); width: 100%; background: linear-gradient(transparent, var(--violet-deep) 70%); }
h1 { margin: 0; font-size: 64px; font-style: italic; letter-spacing: -2px; color: #fff; text-shadow: 4px 4px 0 var(--ink), 0 0 30px var(--violet-bright); line-height: .9; }
h1 span { color: var(--lime); }
.tag { margin: 8px 0 20px; color: var(--cream); }
.note { color: var(--lime); min-height: 1.4em; font-size: 14px; }

/* home */
#hud { padding: calc(8px + env(safe-area-inset-top)) 12px 6px; background: var(--panel); z-index: 2; }
.hud-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.pill { display: flex; align-items: center; gap: 6px; background: var(--violet); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 15px; color: #fff; }
.pill img { width: 22px; height: 22px; border-radius: 50%; }
.pill small { color: var(--lime); }
.xp { height: 8px; margin: 6px 2px; background: var(--ink); border-radius: 4px; overflow: hidden; }
#xpbar { height: 100%; width: 0; background: var(--lime); transition: width .4s; }
#needs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.need { text-align: center; font-size: 11px; }
.need .bar { height: 9px; background: var(--ink); border-radius: 5px; overflow: hidden; margin-top: 2px; }
.need .bar i { display: block; height: 100%; background: var(--lime); transition: width .4s; }
.need.low .bar i { background: var(--amber); }
.need.crit .bar i { background: #ff4a4a; }
#stage { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; }
#room-ui { position: absolute; left: 0; right: 0; bottom: calc(74px + env(safe-area-inset-bottom)); padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; z-index: 2; pointer-events: none; }
#room-ui > * { pointer-events: auto; }
.tray { display: flex; gap: 8px; background: var(--panel); border: 2px solid var(--ink); border-radius: 16px; padding: 8px 8px 24px; max-width: 100%; overflow-x: auto; }
.item { position: relative; width: 62px; height: 62px; border-radius: 12px; background: var(--violet); border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; cursor: grab; }
.item img { width: 48px; height: 48px; object-fit: contain; pointer-events: none; }
.item .n { position: absolute; right: -4px; top: -6px; background: var(--lime); color: var(--ink); border-radius: 999px; font-size: 11px; padding: 1px 6px; border: 2px solid var(--ink); }
.item.empty { opacity: .35; cursor: default; }
.item.selected { outline: 3px solid var(--lime); }
.item .label { position: absolute; bottom: -18px; font-size: 10px; white-space: nowrap; color: var(--cream); }
.panel { background: var(--panel); border: 2px solid var(--ink); border-radius: 16px; padding: 10px 12px; color: #fff; font-size: 14px; max-width: 100%; }
.panel h3 { margin: 0 0 6px; color: var(--lime); font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#rooms { display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 3px solid var(--ink); z-index: 3; }
#rooms button { background: transparent; border: none; box-shadow: none; color: var(--cream); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 22px; padding: 4px 6px; }
#rooms button span { font-size: 10px; }
#rooms button.active { color: var(--lime); }
#toast { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); background: var(--lime); color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 16px; font-size: 16px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 5; text-align: center; max-width: 80%; }
#toast.show { opacity: 1; }
.dragging { position: fixed; width: 64px; height: 64px; pointer-events: none; z-index: 9; object-fit: contain; filter: drop-shadow(0 4px 4px rgba(0,0,0,.5)); }

/* shop + games list */
.shop-panel { width: 100%; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; max-height: 44vh; overflow-y: auto; }
.shop button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px; font-size: 11px; background: var(--violet); color: #fff; }
.shop button img { width: 44px; height: 44px; object-fit: contain; }
.shop button .price { color: var(--lime); }
.shop button.owned { background: #2b6b1f; }
.games { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.games button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; font-size: 12px; }
.games button small { font-weight: 700; font-size: 10px; color: #333; }

/* game screen */
#gamecanvas { width: 100%; height: 100%; display: block; touch-action: none; }
#game-hud { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
#game-hud .pill { pointer-events: auto; }
#game-over { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(18,9,31,.75); text-align: center; padding: 20px; }
#game-over h2 { margin: 0; font-size: 40px; color: var(--lime); text-shadow: 3px 3px 0 var(--ink); }
#game-over .rewards { display: flex; gap: 14px; font-size: 18px; color: #fff; }
.blur { filter: blur(0.8px) saturate(.85); }

/* account sheet */
button.small { font-size: 13px; padding: 6px 12px; box-shadow: 0 2px 0 var(--ink); }
#account-modal { position: absolute; inset: 0; z-index: 50; background: rgba(8, 4, 16, .78); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
#account-modal.hidden { display: none; }
#account-modal .sheet { width: 100%; max-width: 440px; background: var(--panel, #1c1030); border: 3px solid var(--ink); border-radius: 22px; padding: 18px 16px 20px; color: #fff; box-shadow: 0 8px 0 var(--ink); max-height: 85vh; overflow: auto; }
#account-modal h2 { margin: 0 0 6px; color: var(--lime); font-size: 22px; }
#account-modal p { margin: 0 0 14px; font-size: 14px; opacity: .9; line-height: 1.4; }
#account-modal .row { display: flex; gap: 8px; flex-wrap: wrap; }
#account-modal .row.col { flex-direction: column; }
#account-modal .row button, #account-modal .btn { width: 100%; text-align: center; }
#account-modal .row:not(.col) button { flex: 1; }
#account-modal input { width: 100%; box-sizing: border-box; font: inherit; font-weight: 700; padding: 10px 12px; margin-bottom: 8px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; color: var(--ink); }
#account-modal .err { color: #ff8a8a; font-size: 13px; min-height: 18px; margin: 4px 0; }
#account-modal .ok { color: var(--lime); font-size: 14px; }
#account-modal .links { margin-top: 10px; font-size: 13px; text-align: center; }
#account-modal .links a, #account-modal a.btn { color: var(--lime); cursor: pointer; text-decoration: underline; }
#account-modal a.btn { display: block; text-decoration: none; font-weight: 900; color: var(--ink); background: var(--lime); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 16px; box-shadow: 0 4px 0 var(--ink); box-sizing: border-box; }
