:root {
  --blue: #1c54b8;
  --blue-d: #0f2d66;
  --red: #b0262e;
  --gold: #ffd23c;
  --ink: #0e1424;
  --panel: rgba(12, 18, 36, 0.72);
  --panel-solid: #121a30;
  --text: #ffffff;
  --muted: #b8c4dc;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1020; color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #missions, #touch * { pointer-events: auto; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--panel); color: #fff; font-size: 20px; display: inline-grid; place-items: center; backdrop-filter: blur(4px); }
.icon-btn:hover { background: rgba(28, 84, 184, 0.85); }
#topleft { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; gap: 8px; }
.chip { background: var(--panel); border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 15px; white-space: nowrap; backdrop-filter: blur(4px); }
#weather { position: absolute; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); }
#weather.bonus { color: var(--gold); }

#stats { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 176px; display: flex; flex-direction: column; gap: 4px; }
.stat { background: var(--panel); border-radius: 10px; padding: 5px 10px; display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; font-size: 16px; backdrop-filter: blur(4px); }
.stat .lbl { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.stat.big { font-size: 26px; }
.stat.streak { background: linear-gradient(90deg, rgba(255, 120, 30, 0.9), rgba(214, 40, 64, 0.9)); }
.stat.streak .lbl { color: #fff; }
.stat.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
#missions { background: var(--panel); border-radius: 10px; margin-top: 4px; overflow: hidden; backdrop-filter: blur(4px); }
#missions-toggle { width: 100%; text-align: left; background: none; border: 0; color: #fff; font-weight: 800; font-size: 13px; padding: 7px 10px; display: flex; gap: 6px; align-items: center; }
#missions-toggle .caret { margin-left: auto; transition: transform 0.2s; }
#missions.closed .caret { transform: rotate(-90deg); }
#missions.closed #missions-list { display: none; }
#missions-list { list-style: none; margin: 0; padding: 0 10px 8px; display: flex; flex-direction: column; gap: 6px; }
#missions-list li { font-size: 12px; color: #e6ecf8; }
#missions-list li.done { color: #8fe39a; }
#missions-list .mbar { height: 5px; background: rgba(255, 255, 255, 0.15); border-radius: 3px; margin-top: 3px; overflow: hidden; }
#missions-list .mbar i { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
#missions-list li.done .mbar i { background: #57d26a; }

#hint { position: absolute; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); background: var(--panel); padding: 10px 18px; border-radius: 12px; font-weight: 700; font-size: 16px; text-align: center; max-width: min(560px, 86vw); transition: opacity 0.4s; }
#hint:empty { display: none; }
#banner { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%) scale(0.8); font-size: clamp(30px, 7vw, 64px); font-weight: 900; text-align: center; letter-spacing: 0.02em; color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(0, 0, 0, 0.35); opacity: 0; transition: opacity 0.2s, transform 0.25s; white-space: nowrap; max-width: 96vw; }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner.try { color: var(--gold); }
#banner.tackle { color: #ff6a6a; }
#banner.best, #banner.daily, #banner.mission { color: #9ff0a8; font-size: clamp(22px, 4.6vw, 40px); }
#banner.pickup { font-size: clamp(20px, 3.8vw, 32px); }
#banner.announce { font-size: clamp(20px, 3.8vw, 32px); color: #cfe3ff; }
#toasts { position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 6px; max-width: 46vw; }
.toast { background: var(--panel); padding: 7px 12px; border-radius: 10px; font-size: 14px; font-weight: 700; animation: toastIn 0.25s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
#luke-bubble { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); background: #fff; color: #1e1e28; border-radius: 12px; padding: 6px 12px 8px; font-size: 14px; font-weight: 700; max-width: 240px; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); opacity: 0; transition: opacity 0.2s; }
#luke-bubble b { display: block; color: #c96026; font-size: 13px; }
#luke-bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%); border: 8px solid transparent; border-bottom: 0; border-top-color: #fff; }
#luke-bubble.show { opacity: 1; }

#prompt { position: absolute; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 8px 16px 8px 8px; border-radius: 999px; font-weight: 800; }
#prompt .ring { position: relative; width: 42px; height: 42px; }
#prompt svg { width: 42px; height: 42px; transform: rotate(-90deg); }
#prompt circle { fill: none; stroke-width: 4; }
#prompt circle.bg { stroke: rgba(255, 255, 255, 0.2); }
#prompt circle.fg { stroke: var(--gold); stroke-dasharray: 94.25; stroke-dashoffset: 94.25; }
#prompt-key { position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; }
#prompt.locked { color: #ffd98a; }

#kick, #rep { position: absolute; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); width: min(460px, 90vw); background: var(--panel); border-radius: 16px; padding: 12px 14px 12px; text-align: center; backdrop-filter: blur(4px); }
.kick-title { font-weight: 900; font-size: 18px; letter-spacing: 0.06em; margin-bottom: 8px; }
.kick-title span { color: var(--gold); }
.bar { position: relative; height: 26px; border-radius: 13px; background: linear-gradient(90deg, #2a3350, #3c4a70); overflow: hidden; }
.bar .gold { position: absolute; top: 0; bottom: 0; right: 0; background: linear-gradient(90deg, #ffb400, #ffe27a); }
.bar .needle { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: #fff; border-radius: 3px; box-shadow: 0 0 8px rgba(0, 0, 0, 0.6); }
#kick-btn, #rep-btn { margin-top: 10px; width: 100%; height: 54px; border: 0; border-radius: 14px; background: var(--gold); color: #2a1c00; font-size: 22px; font-weight: 900; letter-spacing: 0.08em; }
#kick-btn:active, #rep-btn:active { transform: scale(0.98); }
.kick-help { margin-top: 6px; color: var(--muted); font-size: 12px; }

/* ---------- Touch controls ---------- */
#touch { position: absolute; inset: 0; pointer-events: none; }
#stick { position: absolute; left: calc(26px + var(--safe-l)); bottom: calc(30px + var(--safe-b)); width: 140px; height: 140px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.28); }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); }
.tbtn { position: absolute; right: calc(24px + var(--safe-r)); bottom: calc(40px + var(--safe-b)); width: 86px; height: 86px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); background: rgba(12, 18, 36, 0.55); color: #fff; font-weight: 900; font-size: 14px; letter-spacing: 0.04em; }
.tbtn.action { bottom: calc(140px + var(--safe-b)); right: calc(40px + var(--safe-r)); background: rgba(255, 210, 60, 0.85); color: #2a1c00; }
.touch-ui #hint { bottom: auto; top: calc(62px + var(--safe-t)); font-size: 14px; padding: 7px 14px; max-width: min(460px, 56vw); }
.touch-ui #banner { top: 40%; }
.touch-ui #prompt { bottom: calc(24px + var(--safe-b)); }
.touch-ui #kick, .touch-ui #rep { bottom: auto; top: calc(10px + var(--safe-t)); width: min(400px, 52vw); }
.touch-ui #toasts { bottom: auto; top: calc(112px + var(--safe-t)); max-width: 36vw; }
.touch-ui .toast { font-size: 12px; padding: 5px 10px; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(12, 30, 70, 0.55), rgba(5, 8, 18, 0.85)); z-index: 10; overflow-y: auto; }
.card { background: var(--panel-solid); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 20px; padding: 24px 26px; width: min(460px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.card.wide { width: min(640px, 100%); text-align: left; max-height: 90vh; display: flex; flex-direction: column; }
.logo { font-size: 56px; line-height: 1; }
.logo.spin { animation: spin 1.2s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
h1 { font-size: 40px; margin: 8px 0 6px; line-height: 1.05; }
h1 span { display: block; font-size: 22px; color: var(--gold); }
h2 { margin: 0 0 12px; }
.lead { color: #dbe4f5; font-size: 16px; line-height: 1.45; margin: 8px 0 18px; }
.big-btn { width: 100%; height: 58px; border: 0; border-radius: 16px; background: var(--gold); color: #2a1c00; font-size: 22px; font-weight: 900; letter-spacing: 0.04em; box-shadow: 0 5px 0 #b88a00; margin: 6px 0 14px; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b88a00; }
.how { text-align: left; background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 10px 14px; font-size: 14px; color: #dbe4f5; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.small { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.link-btn { background: none; border: 0; color: #ff9a9a; font-size: 13px; text-decoration: underline; }
#records { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
#records div { background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 8px; font-size: 12px; color: var(--muted); }
#records b { display: block; color: #fff; font-size: 20px; }

.shop-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.shop-head h2 { margin: 0; flex: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; height: 40px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, 0.08); color: #fff; font-weight: 800; font-size: 15px; }
.tab.on { background: var(--blue); }
#shop-list { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; padding-bottom: 4px; }
.item { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.item .swatch { height: 18px; border-radius: 9px; }
.item .name { font-weight: 800; font-size: 14px; }
.item .note { font-size: 11px; color: var(--muted); }
.item button { height: 36px; border: 0; border-radius: 9px; font-weight: 800; font-size: 14px; }
.item button.buy { background: var(--gold); color: #2a1c00; }
.item button.equip { background: var(--blue); color: #fff; }
.item button.on { background: #2f9e52; color: #fff; }
.item button:disabled { background: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.5); cursor: default; }

@media (max-width: 700px), (max-height: 500px) {
  #stats { width: 138px; gap: 3px; }
  .stat { padding: 3px 8px; font-size: 14px; }
  .stat.big { font-size: 20px; }
  .stat .lbl { font-size: 10px; }
  #weather { font-size: 13px; padding: 4px 10px; top: calc(62px + var(--safe-t)); left: calc(10px + var(--safe-l)); transform: none; }
  .icon-btn { width: 40px; height: 40px; font-size: 18px; }
  #hint { font-size: 14px; }
  #luke-bubble { font-size: 12px; max-width: 180px; }
  #missions-toggle .long { display: none; }
}
@media (max-height: 500px) {
  #stick { width: 118px; height: 118px; bottom: calc(16px + var(--safe-b)); }
  .tbtn { width: 72px; height: 72px; bottom: calc(20px + var(--safe-b)); }
  .tbtn.action { bottom: calc(104px + var(--safe-b)); }
  #kick, #rep { padding: 8px 12px; }
  .kick-title { font-size: 15px; margin-bottom: 6px; }
  .bar { height: 20px; }
  #kick-btn, #rep-btn { height: 42px; font-size: 18px; margin-top: 7px; }
  .kick-help { display: none; }
  .screen { place-items: start center; }
  .card { padding: 14px 18px; margin: auto 0; }
  .card h2 { margin-bottom: 8px; }
  #records { grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 8px; }
  #records div { padding: 5px; font-size: 11px; }
  #records b { font-size: 16px; }
  .how { font-size: 12px; padding: 8px 10px; gap: 3px; }
  .big-btn { height: 46px; font-size: 19px; margin: 4px 0 8px; }
  h1 { font-size: 30px; margin: 4px 0; }
  h1 span { font-size: 18px; }
  .logo { font-size: 38px; }
  .lead { font-size: 14px; margin: 4px 0 10px; }
  #banner { top: 30%; }
}

/* ---------- Portrait phones ---------- */
@media (orientation: portrait) and (max-width: 700px) {
  #stats { width: auto; left: calc(160px + var(--safe-l)); flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
  #stats .stat { flex: 0 0 auto; gap: 6px; font-size: 15px; }
  #stats .stat.big { font-size: 17px; }
  #stats .stat:nth-child(2), #stats .stat:nth-child(3) { display: none; }
  #missions { flex: 0 0 150px; }
  .touch-ui #hint { top: auto; bottom: calc(190px + var(--safe-b)); max-width: 88vw; }
  .touch-ui #kick, .touch-ui #rep { top: auto; bottom: calc(28px + var(--safe-b)); width: 92vw; }
  #banner { white-space: normal; width: 92vw; font-size: 34px; }
  .touch-ui #banner { top: 34%; }
  #banner.best, #banner.daily, #banner.mission, #banner.pickup, #banner.announce { font-size: 24px; }
}
