* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1d1a17; overflow: hidden; font-family: Fredoka, system-ui, -apple-system, sans-serif; color: #fff; user-select: none; -webkit-user-select: none; }
#game { position: relative; height: 100vh; height: 100dvh; width: min(100vw, 62vh); width: min(100vw, 62dvh); margin: 0 auto; overflow: hidden; touch-action: none; background: #87b9e0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hudLeft { position: absolute; left: 0; top: max(10px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.pill { display: flex; align-items: center; gap: 8px; background: rgba(40, 44, 52, 0.72); padding: 6px 18px 6px 12px; border-radius: 0 14px 14px 0; font-weight: 700; font-size: 22px; text-shadow: 0 2px 0 rgba(0,0,0,0.35); backdrop-filter: blur(2px); }
.pill.big { font-size: 30px; padding: 6px 22px 6px 14px; flex-direction: column; align-items: flex-start; gap: 0; pointer-events: auto; cursor: default; }
.pill.big small { font-size: 12px; font-weight: 600; opacity: 0.8; letter-spacing: 0.02em; }
.pill .ico { font-size: 22px; }
.pill svg.crowd { width: 30px; height: 20px; }
.mult { font-size: 13px; background: #f4b63f; color: #3b2a07; border-radius: 8px; padding: 1px 6px; text-shadow: none; }
#powers { display: flex; flex-direction: column; gap: 5px; padding-left: 10px; }
.pw { display: flex; align-items: center; gap: 6px; background: rgba(40,44,52,0.65); border-radius: 10px; padding: 3px 8px; width: 92px; position: relative; overflow: hidden; }
.pw span { font-size: 18px; z-index: 1; }
.pw i { position: absolute; left: 0; bottom: 0; height: 4px; background: #ffd84d; }

#pauseBtn { position: absolute; right: 12px; top: max(12px, env(safe-area-inset-top)); width: 50px; height: 50px; border-radius: 12px; border: 3px solid #f5e8d4; background: linear-gradient(#d8c3a5, #b99e7b); box-shadow: 0 3px 0 #7d6547; display: flex; gap: 6px; align-items: center; justify-content: center; pointer-events: auto; cursor: pointer; }
#pauseBtn span { width: 7px; height: 20px; background: #fff; border-radius: 2px; box-shadow: 0 1px 0 rgba(0,0,0,0.25); }

#energy { position: absolute; right: 12px; top: 42%; width: 30px; height: 26%; border-radius: 10px; border: 3px solid #3c4a5c; background: rgba(30,40,55,0.75); overflow: hidden; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
#energyFill { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: linear-gradient(to top, #ff7a1a, #ffd23f); transition: height 0.15s; }
#energy b { position: absolute; left: 50%; top: -26px; transform: translateX(-50%); font-size: 13px; color: #fff; opacity: 0; text-shadow: 0 1px 3px #000; }
#energy.full { animation: pulse 0.6s infinite alternate; overflow: visible; }
#energy.full b { opacity: 1; top: auto; bottom: 50%; transform: translate(-50%, 50%) rotate(-90deg); color: #3b2a07; text-shadow: none; }
#energy.sprinting #energyFill { background: linear-gradient(to top, #2f80ed, #9fe0ff); }
@keyframes pulse { from { box-shadow: 0 0 0 2px rgba(255,255,255,0.4), 0 0 8px #ffd23f; } to { box-shadow: 0 0 0 3px #fff, 0 0 22px #ffd23f; } }

#toast { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -10px); max-width: 86%; background: rgba(30,34,42,0.82); padding: 6px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; text-align: center; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#callout { position: absolute; left: 0; right: 0; top: 18%; text-align: center; font-size: 38px; font-weight: 700; color: #fff; text-shadow: 0 3px 0 #c0392b, 0 6px 14px rgba(0,0,0,0.4); opacity: 0; pointer-events: none; padding: 0 16px; }
#callout.on { animation: pop 1.6s ease-out forwards; }
@keyframes pop { 0% { opacity: 0; transform: scale(0.6); } 15% { opacity: 1; transform: scale(1.08); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

#hint { position: absolute; left: 50%; bottom: 36%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; pointer-events: none; transition: opacity 0.5s; }
#hint.gone { opacity: 0; }
.hintRow { background: rgba(30,34,42,0.7); border-radius: 12px; padding: 6px 14px; font-size: 16px; font-weight: 600; white-space: nowrap; }
.hintRow .arrows { display: inline-block; min-width: 46px; color: #ffd84d; animation: nudge 0.9s infinite alternate; }
@keyframes nudge { to { transform: translateX(4px); } }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20, 18, 15, 0.35); }
#menu { background: linear-gradient(rgba(255, 190, 110, 0.15), rgba(20,18,15,0.45)); }
.card { width: 100%; max-width: 340px; background: rgba(255, 250, 240, 0.95); color: #3a2c1c; border-radius: 22px; padding: 22px 20px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.card.title { background: transparent; box-shadow: none; color: #fff; }
h1 { margin: 0 0 6px; font-size: 54px; line-height: 0.95; letter-spacing: 0.01em; text-shadow: 0 4px 0 #c0392b, 0 8px 18px rgba(0,0,0,0.35); }
h2 { margin: 0 0 14px; font-size: 30px; }
.sub { margin: 0 0 22px; font-size: 18px; font-weight: 600; text-shadow: 0 2px 6px rgba(0,0,0,0.5); }
.btn { display: block; width: 100%; margin: 10px 0; padding: 14px 16px; border: 0; border-radius: 16px; font: inherit; font-size: 21px; font-weight: 700; cursor: pointer; }
.btn small { display: block; font-size: 13px; font-weight: 600; opacity: 0.85; margin-top: 2px; }
.btn.primary { background: linear-gradient(#ff8c42, #e8562a); color: #fff; box-shadow: 0 4px 0 #a63a1a; text-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.btn.secondary { background: #efe3cf; color: #5a4329; box-shadow: 0 4px 0 #c7b393; }
.card.title .btn.secondary { background: rgba(255,250,240,0.92); }
.btn.link { background: none; box-shadow: none; color: #8a6d4a; font-size: 15px; font-weight: 600; text-decoration: underline; padding: 6px; margin: 4px 0 0; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.best { margin: 14px 0 6px; font-size: 17px; font-weight: 600; text-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.how { margin: 0; font-size: 13px; opacity: 0.95; text-shadow: 0 1px 4px rgba(0,0,0,0.8); line-height: 1.5; }
.corner { position: absolute; right: 14px; top: max(14px, env(safe-area-inset-top)); width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(30,34,42,0.6); font-size: 20px; cursor: pointer; }
.quote { font-size: 30px; font-weight: 700; margin: 4px 0 6px; }
.small { font-size: 14px; margin: 0 0 12px; opacity: 0.8; }
.tag { display: inline-block; background: #f4b63f; color: #3b2a07; border-radius: 10px; padding: 3px 10px; margin: -6px 0 10px; font-weight: 700; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.stats div { background: #f3e8d6; border-radius: 14px; padding: 10px 6px; }
.stats small { display: block; font-size: 12px; opacity: 0.75; }
.stats b { font-size: 22px; }

/* ---------- Developer menu ---------- */
#dev { position: absolute; inset: 0; background: rgba(18, 20, 26, 0.96); color: #eee; display: flex; flex-direction: column; font-family: system-ui, sans-serif; font-size: 14px; z-index: 10; }
.devHead { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid #333; padding-top: max(12px, env(safe-area-inset-top)); }
#dev button { background: #2d3440; color: #fff; border: 1px solid #47505e; border-radius: 8px; padding: 8px 10px; font: inherit; cursor: pointer; }
#dev button.primary { background: #e8562a; border-color: #e8562a; }
#dev button.warn { background: #6b2a2a; border-color: #8b3a3a; }
#devBody { overflow-y: auto; padding: 4px 14px 30px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#devBody h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: #f4b63f; }
#devBody .row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid #262b33; }
#devBody .row span { flex: 1; }
#devBody input, #devBody select { width: 90px; background: #0f1115; color: #fff; border: 1px solid #47505e; border-radius: 6px; padding: 6px; font: inherit; }
#devBody select { width: auto; max-width: 160px; }
#devBody .btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#devExport { width: 100%; height: 160px; background: #0f1115; color: #9fe0ff; border: 1px solid #47505e; border-radius: 6px; font: 12px monospace; }

#crowdPill.up { animation: crowdUp 0.6s; }
#crowdPill.down { animation: crowdDown 0.7s; }
@keyframes crowdUp { 30% { background: rgba(46, 160, 90, 0.9); transform: scale(1.06); } }
@keyframes crowdDown { 30% { background: rgba(200, 50, 40, 0.9); transform: translateX(4px); } 60% { transform: translateX(-3px); } }

/* ---------- Menu extras ---------- */
.row2 { display: flex; gap: 10px; }
.row2 .btn { font-size: 17px; padding: 12px 8px; margin: 4px 0; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: #e8562a; color: #fff; font-size: 13px; line-height: 20px; }
#walletPill { position: absolute; left: 0; top: max(14px, env(safe-area-inset-top)); }

/* ---------- Bully chase bar ---------- */
#chase { position: absolute; right: 12px; top: calc(max(12px, env(safe-area-inset-top)) + 60px); width: 132px; background: rgba(40,44,52,0.75); border-radius: 12px; padding: 6px 8px; display: grid; grid-template-columns: 22px 1fr; gap: 3px 6px; align-items: center; }
#chase span { grid-row: span 2; font-size: 20px; }
.cbar, .ctime { height: 8px; background: rgba(255,255,255,0.18); border-radius: 4px; overflow: hidden; }
.ctime { height: 4px; }
#chaseGap { display: block; height: 100%; background: #6fd36f; transition: width 0.2s; }
#chaseTime { display: block; height: 100%; background: #fff; }
#chase.close #chaseGap { background: #ff5a3c; }
#chase.close { animation: pulse 0.5s infinite alternate; }

/* ---------- Missions / shop ---------- */
.card.wide { max-width: 380px; max-height: calc(100% - 20px); overflow-y: auto; touch-action: pan-y; }
.mrow { text-align: left; background: #f3e8d6; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.mrow.done { background: #dff0d6; }
.mtext { font-weight: 600; font-size: 15px; }
.daily { display: inline-block; background: #e8562a; color: #fff; border-radius: 8px; font-size: 11px; padding: 1px 7px; margin-right: 6px; vertical-align: 2px; }
.mbar { height: 8px; background: rgba(0,0,0,0.1); border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.mbar i { display: block; height: 100%; background: linear-gradient(90deg, #ff8c42, #e8562a); }
.mrow.done .mbar i { background: #4caf50; }
.mmeta { display: flex; justify-content: space-between; font-size: 13px; opacity: 0.8; }
.walletLine { margin: -6px 0 10px; font-size: 20px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; border: 0; border-radius: 12px; padding: 9px; font: inherit; font-weight: 700; background: #efe3cf; color: #5a4329; cursor: pointer; }
.tab.on { background: #5a4329; color: #fff; }
.item { display: flex; align-items: center; gap: 10px; background: #f3e8d6; border-radius: 14px; padding: 8px 10px; margin-bottom: 8px; text-align: left; }
.iico { font-size: 28px; width: 40px; text-align: center; }
.swatch { width: 40px; height: 54px; }
.itext { flex: 1; min-width: 0; }
.itext small { display: block; font-size: 12px; opacity: 0.75; }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 14px; height: 5px; border-radius: 3px; background: rgba(0,0,0,0.15); }
.pips i.on { background: #e8562a; }
.buy { border: 0; border-radius: 12px; padding: 9px 10px; font: inherit; font-weight: 700; background: linear-gradient(#ff8c42, #e8562a); color: #fff; cursor: pointer; white-space: nowrap; }
.buy:disabled { background: #d9ccb6; color: #8a7a62; cursor: default; }
.bank { font-weight: 700; margin: 4px 0 6px; }
.mdone { font-size: 13px; background: #dff0d6; border-radius: 10px; padding: 5px 8px; margin-bottom: 5px; text-align: left; }
.mdone b { float: right; }
