:root {
  --bg: #5bb7f0; --panel: #fff8ec; --panel2: #ffeccf; --line: #f2d9ad; --ink: #2b2b3a; --muted: #7d7266;
  --green: #ff8a3d; --green2: #ff7a1a; --gold: #ffc93c; --red: #ff5a5f; --sheet-h: 62vh;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif; --display: 'Lilita One', 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #2d8ed1; color: var(--ink); font: 600 15px/1.35 var(--font); overflow: hidden; overscroll-behavior: none; }
#app { position: relative; width: 100%; height: 100%; max-width: 560px; margin: 0 auto; background: var(--bg); overflow: hidden; overflow: clip; touch-action: none; }
canvas#town { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; }
img.missing { visibility: hidden; }

/* title */
.screen { position: absolute; inset: 0; z-index: 50; background: #5bb7f0; display: flex; align-items: flex-end; justify-content: center; transition: opacity .4s, transform .4s; }
.screen.gone { opacity: 0; transform: scale(1.05); pointer-events: none; }
#splash { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.tcontent { position: relative; width: 100%; padding: 30px 24px calc(28px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(45,142,209,0) 0%, rgba(45,142,209,.92) 35%, #2d8ed1 100%); text-align: center; }
.tcontent h1 { font-family: var(--display); font-size: 64px; line-height: .9; margin: 0 0 8px; letter-spacing: 1px; color: #fff; text-shadow: 0 6px 0 rgba(0,0,0,.35); }
.tcontent h1 span { display: block; }
.tcontent h1 .green { color: var(--green); font-size: 84px; }
.tag { color: #eaf6ff; margin: 0 0 18px; }
.tstatus { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.mbr { margin-top: 22px; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 13px; color: #fff; letter-spacing: .5px; opacity: .9; }
.mbr img { height: 34px; width: auto; }

/* buttons */
.btn { background: var(--green2); border: 0; border-radius: 14px; padding: 10px 16px; font-weight: 800; color: #fff; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,.18); white-space: nowrap; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.btn.big { width: 100%; padding: 14px; font-size: 18px; margin-top: 12px; }
.btn.play { background: #ffd23f; color: #3a2a10; font-family: var(--display); font-size: 28px; letter-spacing: 1px; }
.btn.ghost { background: #fff3dc; color: #5a4a3a; border: 1px solid #e3c99c; box-shadow: none; }
.btn.red { background: var(--red); }
.btn.off, .btn:disabled { opacity: .45; cursor: default; }

/* HUD */
#hud { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; display: grid; grid-template-columns: 1.2fr .7fr 1fr 1fr; gap: 6px; z-index: 10; pointer-events: none; }
.pill { color: #2b2b3a; background: rgba(255,255,255,.42); -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%); border: 1px solid rgba(255,255,255,.22); box-shadow: 0 4px 14px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.25); border-radius: 999px; padding: 5px 10px 5px 6px; display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; min-height: 34px; }
.pill img { width: 24px; height: 24px; object-fit: contain; }
.pill.cash { color: #7a4a00; }
.pill.gems { color: #5a3e00; }
.pill.level { flex-wrap: wrap; row-gap: 2px; }
.pill.level .bar { flex-basis: 100%; height: 4px; margin: 0 2px; }
.pill.heatp .bar { flex: 1; height: 8px; }
.bar { height: 8px; background: rgba(0,0,0,.14); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .4s; }
.bar.energy i { background: linear-gradient(90deg, #ffd23f, #ff8a3d); }
.bar.energy.low i { background: #ff5a5f; }

@keyframes hot { to { box-shadow: 0 0 0 3px rgba(237,28,36,.5); } }

#buildhint { position: absolute; top: calc(56px + env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 10; color: #2b2b3a; background: rgba(255,255,255,.55); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border: 1px solid rgba(255,255,255,.2); border-radius: 14px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.fab { position: absolute; right: 14px; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 10; width: 58px; height: 58px; border-radius: 50%; border: 3px solid #fff; background: var(--gold); box-shadow: 0 5px 0 rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 24px; color: #0b1f12; }
.fab img { width: 36px; height: 36px; object-fit: contain; }
.fab.pulse { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); box-shadow: 0 5px 0 rgba(0,0,0,.4), 0 0 0 8px rgba(255,211,77,.3); } }

/* nav */
#nav { position: absolute; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 5px; border-radius: 30px; background: rgba(255, 255, 255, .42); -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%); border: 1px solid rgba(255,255,255,.22); box-shadow: 0 12px 32px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.28); }
#nav button { position: relative; background: none; border: 0; border-radius: 24px; padding: 6px 0 5px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; font-weight: 800; color: #2b2b3a; letter-spacing: .2px; transition: background .2s, color .2s; }
#nav button.on { background: rgba(255,255,255,.75); color: #e8600a; box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 2px 8px rgba(0,0,0,.2); }
#nav button img { width: 32px; height: 32px; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
#nav button img.face { border-radius: 50%; object-fit: cover; }
#nav button i { position: absolute; top: 3px; right: 16%; background: var(--red); color: #fff; font-style: normal; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; text-align: center; padding: 0 4px; }

/* sheet */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 15; max-height: var(--sheet-h); background: rgba(255,248,236,.9); -webkit-backdrop-filter: blur(28px) saturate(160%); backdrop-filter: blur(28px) saturate(160%); border-top: 1px solid rgba(255,255,255,.6); border-radius: 26px 26px 0 0; padding: 10px 16px calc(96px + env(safe-area-inset-bottom)); overflow-y: auto; transform: translateY(105%); transition: transform .25s ease-out; box-shadow: 0 -10px 40px rgba(0,0,0,.45); }
.sheet:not(.open) { visibility: hidden; }
.sheet.open { transform: none; }
.sheet .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet .x { position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: #efe3cc; color: #6b5f52; font-weight: 900; }
.sheet h2 { font-family: var(--display); font-size: 24px; margin: 4px 0 6px; letter-spacing: .5px; }
.sheet h3 { font-size: 14px; color: var(--muted); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 1px; }
.lv { font: 800 12px var(--font); color: #a35a00; background: rgba(255,201,60,.25); padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint.warn { color: #ff8a8a; }
.bhead { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.bhead .bimg { width: 84px; height: 84px; object-fit: contain; flex: none; }
.bhead p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; }
.row.foot { margin-top: 14px; }
.row.foot .btn:first-child { flex: 1; }
.col2 { display: flex; flex-direction: column; gap: 6px; }

.stat { display: flex; align-items: center; gap: 12px; background: var(--panel2); border-radius: 14px; padding: 10px 12px; margin-top: 8px; }
.stat > img { width: 46px; height: 46px; object-fit: contain; flex: none; }
.stat > img.face { border-radius: 50%; object-fit: cover; }
.stat > div:not(.col2) { flex: 1; }
.stat b { display: block; font-size: 16px; }
.stat small { color: var(--muted); display: block; font-size: 12px; }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.slot { background: var(--panel2); border-radius: 14px; padding: 10px 6px 8px; text-align: center; border: 2px solid transparent; }
.slot img { width: 54px; height: 54px; object-fit: contain; display: block; margin: 0 auto 4px; }
.slot b { display: block; font-size: 14px; }
.slot small { display: block; color: var(--muted); font-size: 11px; }
.slot.empty { border-style: dashed; border-color: var(--line); cursor: pointer; }
.slot.ready { border-color: var(--green); cursor: pointer; background: rgba(255,138,61,.14); }
.slot .bar { margin-top: 6px; height: 5px; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card { background: var(--panel2); border-radius: 14px; padding: 8px 6px; text-align: center; cursor: pointer; }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.card b { display: block; font-size: 13px; }
.card small { color: #e8600a; font-size: 12px; }
.card.off { opacity: .55; }
.card.locked small { color: var(--muted); }

.deal { display: flex; gap: 10px; background: var(--panel2); border-radius: 16px; padding: 10px; margin-top: 8px; align-items: center; }
.deal.coke { outline: 2px solid rgba(237,28,36,.5); }
.deal .face { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; border: 2px solid var(--line); }
.dbody { flex: 1; min-width: 0; }
.dbody b { font-size: 16px; }
.dbody q { display: block; color: var(--muted); font-size: 12px; font-style: italic; quotes: none; }
.want { margin-top: 4px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.want .bud { width: 26px; height: 26px; }
.want small { color: var(--muted); }
.pay { color: #e8600a; font-weight: 900; font-size: 17px; margin-top: 2px; }
.pay em { color: #ff8a8a; font-size: 12px; font-style: normal; }
.pay .timer { float: right; color: var(--muted); font-size: 12px; font-weight: 700; margin-top: 4px; }
.dbtns { display: flex; flex-direction: column; gap: 6px; }
.dbtns .btn { padding: 8px 12px; font-size: 13px; }

.picker, .book { display: flex; flex-wrap: wrap; gap: 6px; }
.pk { width: 58px; text-align: center; background: var(--panel2); border-radius: 12px; padding: 6px 2px; border: 2px solid transparent; cursor: pointer; }
.pk img { width: 40px; height: 40px; object-fit: contain; display: block; margin: 0 auto; }
.pk small { display: block; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pk em { display: block; font-size: 10px; color: #e8600a; font-style: normal; }
.pk.on { border-color: var(--green); }
.pk.unknown img { filter: brightness(0) opacity(.35); }
.book .pk { width: calc(25% - 5px); }
.lab { display: flex; gap: 8px; align-items: flex-start; }
.lab .col { flex: 1; }
.lab label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.lab .plus, .eq { font-family: var(--display); font-size: 28px; color: var(--green); text-align: center; padding-top: 22px; }
.eq { padding: 4px 0 0; }
.result { text-align: center; background: var(--panel2); border-radius: 14px; padding: 10px; }
.result img { width: 64px; height: 64px; object-fit: contain; }
.result small { display: block; color: var(--muted); font-size: 12px; }
.result.none b { font-family: var(--display); font-size: 40px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; text-align: center; }
.stats div { background: var(--panel2); border-radius: 12px; padding: 8px 2px; }
.stats b { display: block; font-size: 15px; color: #e8600a; }
.stats small { color: var(--muted); font-size: 11px; }

/* toasts and modal */
#toasts { position: absolute; left: 0; right: 0; bottom: calc(104px + env(safe-area-inset-bottom)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { color: #2b2b3a; background: rgba(255,255,255,.7); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,.22); border-radius: 12px; padding: 9px 14px; font-size: 14px; max-width: 86%; text-align: center; opacity: 0; transform: translateY(10px); transition: all .25s; }
.toast.show { opacity: 1; transform: none; }
#modal { position: absolute; inset: 0; z-index: 40; background: rgba(20,60,100,.55); display: none; align-items: center; justify-content: center; padding: 24px; }
#modal.open { display: flex; }
#modal .box { background: var(--panel); border-radius: 22px; padding: 22px 20px 18px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
#modal h2 { font-family: var(--display); font-size: 28px; margin: 6px 0; }
#modal p { color: var(--muted); font-size: 14px; margin: 6px 0; }
#modal .hero { width: 120px; height: 120px; object-fit: contain; }
#modal .hero.face { border-radius: 50%; object-fit: cover; }
#modal .book { justify-content: center; margin: 10px 0; }
#modal .book .pk { width: 80px; }

/* store, gems, boost */
.btn.gold { background: var(--gold); color: #3a2a10; }
.gemcost { display: inline-flex; align-items: center; gap: 4px; }
.gemcost .gi, .lv .gi { width: 16px; height: 16px; object-fit: contain; vertical-align: middle; }
.packs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pack { position: relative; background: var(--panel2); border-radius: 14px; padding: 12px 8px 10px; text-align: center; cursor: pointer; border: 2px solid transparent; }
.pack.tagged { border-color: var(--gold); }
.pack em { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #0b1f12; font-style: normal; font-size: 10px; font-weight: 900; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pack img { width: 54px; height: 54px; object-fit: contain; }
.pack b { display: block; font-size: 20px; color: #e8600a; }
.pack small { display: block; color: var(--muted); font-size: 12px; }
.pack .price { display: inline-block; margin-top: 8px; background: var(--green2); color: #fff; font-weight: 900; padding: 6px 14px; border-radius: 10px; }
#boost { position: absolute; top: calc(58px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 10; background: var(--gold); color: #3a2a10; font-weight: 900; font-size: 12px; padding: 3px 10px; border-radius: 99px; pointer-events: none; }
.row .btn.gold { flex: 1; margin-top: 8px; }
.stat .btn.gold { white-space: nowrap; }

#modal .box.guide .row.foot { margin-top: 14px; }
#modal .box.guide .row.foot .btn { flex: 1; }
#modal .dots { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
#modal .dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(0,0,0,.18); }
#modal .dots i.on { background: var(--green2); }
.btn.soft { background: #ffd9a0; color: #5a3a10; box-shadow: none; }
.btn.danger { background: transparent; color: #c0392b; box-shadow: none; font-size: 14px; padding: 8px; }
.mrow { display: flex; justify-content: space-between; align-items: center; background: var(--panel2); border-radius: 14px; padding: 13px 14px; margin-top: 8px; font-weight: 800; cursor: pointer; }
.mrow span { color: var(--muted); font-weight: 400; }
.madeby { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 13px; margin: 14px 0 4px; }
.madeby img { height: 30px; width: auto; }
#modal .box .madeby { margin-top: 10px; }
#modal .box .row.foot .btn { flex: 1; }
.mini { position: absolute; left: 14px; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 10; width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.28); -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%); box-shadow: 0 8px 20px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; color: #fff; cursor: pointer; }
.mini .slash { display: none; }
.mini.off .wave { display: none; }
.mini.off .slash { display: block; }
.mini.off { color: rgba(255,255,255,.6); }
