:root {
  --deep: #061a12; --deep2: #0b2a1f; --ink: #0b3b26;
  --mint: #2ee88a; --mint2: #18c06c; --emerald: #0f8f55; --aqua: #3fd0ff; --water: #2a8cff;
  --gold: #ffd34d; --rare: #5aa2ff; --red: #ff6b6b; --text: #eafff4; --muted: #8fb8a6;
  --glass: rgba(6, 30, 22, 0.62); --glass-line: rgba(110, 255, 190, 0.22);
  --display: "Lilita One", "Trebuchet MS", sans-serif; --px: "Press Start 2P", monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--deep); color: var(--text); font-family: var(--display); }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; image-rendering: pixelated; touch-action: none; transition: filter 1s ease; }
body:not(.playing) #game { filter: blur(1.5px) saturate(1.25) brightness(0.72); }

/* ================= TITLE ================= */
#title {
  position: fixed; inset: 0; z-index: 20; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; overflow-y: auto; overflow-x: hidden;
  padding: max(56px, env(safe-area-inset-top)) 16px 24px; transition: opacity .8s ease, transform .9s ease;
}
#title.leaving { opacity: 0; transform: scale(1.08); pointer-events: none; }
.vignette { position: fixed; inset: 0; pointer-events: none; background:
  radial-gradient(ellipse at 50% 38%, transparent 0%, rgba(3, 14, 10, .35) 45%, rgba(3, 14, 10, .88) 100%),
  linear-gradient(180deg, rgba(42, 140, 255, .18), transparent 40%, rgba(6, 26, 18, .7)); }
.title-inner { position: relative; width: min(520px, 100%); min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; }

.logo-wrap { position: relative; width: min(44vh, 340px, 66vw); aspect-ratio: 1; margin-bottom: 6px;
  animation: float 5s ease-in-out infinite, pop .9s cubic-bezier(.2, 1.4, .4, 1) both; }
.logo { position: relative; width: 100%; height: 100%; border-radius: 28px; display: block; object-fit: cover;
  border: 3px solid rgba(160, 255, 210, .55);
  box-shadow: 0 0 0 6px rgba(6, 26, 18, .65), 0 24px 60px rgba(0, 0, 0, .55), 0 0 80px rgba(46, 232, 138, .35); }
.logo-glow { position: absolute; inset: -18%; border-radius: 50%; filter: blur(30px);
  background: conic-gradient(from 0deg, #2ee88a66, #3fd0ff55, #2ee88a22, #3fd0ff66, #2ee88a66); animation: spin 12s linear infinite; }
.logo-shine { position: absolute; inset: 0; border-radius: 28px; overflow: hidden; pointer-events: none; }
.logo-shine::after { content: ""; position: absolute; top: -50%; left: -60%; width: 40%; height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent); transform: rotate(20deg); animation: shine 5.5s ease-in-out infinite 1.2s; }

.wordmark { margin: 10px 0 2px; font-size: clamp(30px, 6.5vw, 50px); font-weight: 400; letter-spacing: 1px; line-height: 1; color: #eafff4;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink), 0 0 30px rgba(46, 232, 138, .55); animation: rise .8s .15s both; }
.wordmark span { color: var(--mint); }
.tagline { margin: 6px 0 14px; color: #bfeedd; font-size: clamp(14px, 2.6vw, 17px); letter-spacing: .3px; animation: rise .8s .25s both; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; animation: rise .8s .35s both; }
.chip { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-size: 13px;
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.chip i { width: 9px; height: 9px; border-radius: 50%; }
.chip b { color: var(--gold); font-weight: 400; }
.chip.common i { background: #c9e8da; } .chip.rare i { background: var(--rare); box-shadow: 0 0 8px var(--rare); }
.chip.legendary i { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

.start-card { width: 100%; padding: 16px; border-radius: 22px; text-align: left; animation: rise .8s .45s both;
  background: linear-gradient(180deg, rgba(14, 58, 43, .78), rgba(6, 30, 22, .82)); border: 1px solid var(--glass-line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .08); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.start-card label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 8px 4px; letter-spacing: .5px; text-transform: uppercase; }
.start-row { display: flex; gap: 8px; }
.start-row input { flex: 1; min-width: 0; font: 20px var(--display); padding: 12px 16px; border-radius: 14px; outline: none; color: var(--ink);
  background: #effff7; border: 3px solid var(--ink); box-shadow: inset 0 -3px 0 #c6ecd9; }
.start-row input:focus { box-shadow: 0 0 0 4px rgba(46, 232, 138, .45), inset 0 -3px 0 #c6ecd9; }
#login-btn { font: 11px var(--px); padding: 0 18px; border-radius: 14px; color: #04281a; border: 3px solid var(--ink);
  background: linear-gradient(180deg, #7dffbe, var(--mint) 50%, var(--mint2)); box-shadow: 0 5px 0 var(--ink), 0 0 26px rgba(46, 232, 138, .55);
  animation: pulse 1.6s ease-in-out infinite; white-space: nowrap; }
#login-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#login-btn.loading { opacity: .7; animation: none; }
.err { color: #ffb3b3; font-size: 14px; min-height: 18px; margin: 8px 4px 0; }
.sim { margin: 14px 0 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; animation: rise .8s .55s both; }
.sim .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 10px var(--mint); animation: blink 1.4s infinite; }
#sound-hint { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 21;
  font: 14px var(--display); color: #cffbe6; padding: 8px 16px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); transition: opacity .5s; }
#sound-hint.gone { opacity: 0; pointer-events: none; }

@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -10px; } }
@keyframes pop { from { opacity: 0; transform: scale(.6) rotate(-6deg); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shine { 0%, 70% { left: -60%; } 100% { left: 130%; } }
@keyframes pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.18); } }
@keyframes blink { 50% { opacity: .3; } }

/* ================= HUD ================= */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none; opacity: 0; transform: translateY(-20px); transition: .6s .3s; }
body.playing #hud { opacity: 1; transform: none; }
#hud > * { pointer-events: auto; }
.glass { background: var(--glass); border: 1px solid var(--glass-line); border-radius: 16px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
.player { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; color: #04281a;
  background: linear-gradient(180deg, #7dffbe, var(--mint2)); border: 2px solid var(--ink); }
.who { display: flex; flex-direction: column; line-height: 1.15; }
.who b { font-weight: 400; font-size: 17px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { font-size: 12px; color: var(--muted); }
.bag { flex: 1; min-width: 170px; max-width: 360px; padding: 8px 14px; }
.bag-top { display: flex; align-items: baseline; gap: 6px; }
.bag-top b { font-weight: 400; font-size: 20px; color: var(--gold); text-shadow: 0 0 12px rgba(255, 211, 77, .35); }
.bag-top span:last-child { font-size: 13px; color: var(--muted); }
.pill-ico { width: 16px; height: 9px; border-radius: 9px; align-self: center; background: linear-gradient(90deg, var(--mint) 50%, #fff 50%); border: 2px solid var(--ink); transform: rotate(-30deg); }
.bar { height: 8px; border-radius: 8px; background: rgba(0, 0, 0, .45); overflow: hidden; margin: 5px 0 3px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); }
.bar i { display: block; height: 100%; width: 0; border-radius: 8px; background: linear-gradient(90deg, var(--emerald), var(--mint), var(--aqua)); transition: width .6s cubic-bezier(.2, 1, .3, 1); }
#hud.full .bar i, .bar.big i[style*="100%"] { background: linear-gradient(90deg, #ffb800, var(--gold), #fff3b0); animation: pulse .9s infinite; }
.bag small { font-size: 11px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 4px; padding: 5px; margin-left: auto; }
.actions button { display: flex; align-items: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 10px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); font-size: 15px; transition: background .2s; }
.actions button:hover { background: rgba(46, 232, 138, .14); }
.actions svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btn-bag { background: rgba(46, 232, 138, .14); }
#hud.full #btn-bag { background: var(--gold); color: #3a2a00; animation: pulse .9s infinite; }
#btn-sound .off-i, #btn-sound.off .on-i { display: none; }
#btn-sound.off .off-i { display: block; color: var(--muted); }

#toasts { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 12; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { font-size: 18px; padding: 8px 18px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(8px);
  animation: toast 3.2s ease forwards; color: var(--gold); }
.toast b { font-weight: 400; color: #fff; }
.toast.rare { border-color: var(--rare); box-shadow: 0 0 22px rgba(90, 162, 255, .5); }
.toast.legendary { border-color: var(--gold); box-shadow: 0 0 30px rgba(255, 211, 77, .65); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px) scale(.8); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-14px); } }

/* ================= TOUCH PAD ================= */
#pad { display: none; position: fixed; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 9; padding: 0 18px;
  justify-content: space-between; align-items: flex-end; pointer-events: none; user-select: none; -webkit-user-select: none; }
body.playing #pad { display: flex; }
@media (pointer: fine) { #pad { display: none !important; } }
#pad button { pointer-events: auto; touch-action: none; border: 2px solid rgba(160, 255, 210, .35); background: rgba(6, 30, 22, .5);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); color: #eafff4; }
#pad button.on { background: rgba(46, 232, 138, .5); }
.dpad { position: relative; width: 138px; height: 138px; }
.dpad button { position: absolute; width: 46px; height: 46px; border-radius: 12px; }
.dpad button::after { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border: 7px solid transparent; }
.dpad .u { left: 46px; top: 0; } .dpad .u::after { border-bottom-color: #eafff4; transform: translateY(-3px); }
.dpad .d { left: 46px; bottom: 0; } .dpad .d::after { border-top-color: #eafff4; transform: translateY(3px); }
.dpad .l { left: 0; top: 46px; } .dpad .l::after { border-right-color: #eafff4; transform: translateX(-3px); }
.dpad .r { right: 0; top: 46px; } .dpad .r::after { border-left-color: #eafff4; transform: translateX(3px); }
.dpad .hub { position: absolute; left: 46px; top: 46px; width: 46px; height: 46px; background: rgba(6, 30, 22, .4); }
.ab { position: relative; width: 140px; height: 104px; }
.ab button { position: absolute; width: 62px; height: 62px; border-radius: 50%; font: 18px var(--display); }
.ab .a { right: 0; top: 0; background: rgba(46, 232, 138, .55); }
.ab .b { left: 0; bottom: 0; background: rgba(255, 107, 107, .4); }

/* ================= MODALS ================= */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(2, 10, 7, .6); backdrop-filter: blur(4px); animation: fade .25s; }
.panel { width: min(560px, 100%); max-height: 86vh; overflow: auto; padding: 18px; border-radius: 22px; color: var(--text);
  background: linear-gradient(180deg, #0f3b2c, #082419); border: 1px solid var(--glass-line); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: pop2 .3s cubic-bezier(.2, 1.3, .4, 1); }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-weight: 400; font-size: 26px; flex: 1; color: var(--mint); text-shadow: 0 2px 0 var(--ink); }
.count { font-size: 14px; color: var(--muted); }
.panel-head button { width: 36px; height: 36px; border-radius: 12px; border: 1px solid var(--glass-line); background: rgba(255, 255, 255, .05); color: var(--text); font-size: 14px; }
.panel h3 { font-weight: 400; font-size: 16px; color: var(--muted); margin: 18px 0 8px; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.dex-card { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .06); }
.dex-card canvas { width: 52px; height: 52px; image-rendering: pixelated; flex: none; background: radial-gradient(circle, rgba(46, 232, 138, .2), transparent 70%); border-radius: 10px; }
.dex-card div { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.dex-card b { font-weight: 400; font-size: 16px; }
.dex-card span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-card em { font-style: normal; font-size: 12px; color: var(--gold); }
.dex-card.unseen canvas { filter: brightness(0) drop-shadow(0 0 1px rgba(160, 255, 210, .5)); opacity: .55; }
.dex-card.unseen em { color: var(--muted); }
.wbal { display: flex; align-items: baseline; gap: 10px; }
.wbal b { font-weight: 400; font-size: 42px; color: var(--gold); text-shadow: 0 0 20px rgba(255, 211, 77, .35); }
.wbal span { color: var(--muted); }
.bar.big { height: 12px; margin: 6px 0 14px; }
.holdings { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.hold { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); font-size: 15px; }
.hold b { font-weight: 400; color: var(--gold); }
.muted { color: var(--muted); font-size: 14px; }
#w-form { display: grid; gap: 8px; margin-top: 8px; }
#w-form label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#w-form input { font: 14px ui-monospace, monospace; padding: 12px; border-radius: 12px; border: 2px solid var(--glass-line); background: rgba(0, 0, 0, .3); color: var(--text); outline: none; }
#w-form input:focus { border-color: var(--mint); }
.big-btn { font: 12px var(--px); padding: 14px; border-radius: 14px; border: 3px solid var(--ink); color: #3a2a00;
  background: linear-gradient(180deg, #fff3b0, var(--gold)); box-shadow: 0 5px 0 var(--ink); }
.big-btn:disabled { filter: grayscale(1); opacity: .6; }
.ok { color: var(--mint); font-size: 14px; min-height: 18px; }
.hist { display: flex; gap: 10px; font-size: 14px; padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); align-items: center; }
.hist span:first-child { flex: 1; color: var(--muted); }
.hist .st { text-transform: capitalize; } .hist.pending .st { color: var(--gold); } .hist.paid .st { color: var(--mint); } .hist.rejected .st { color: var(--red); }
.hist a { color: var(--aqua); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop2 { from { opacity: 0; transform: scale(.92) translateY(10px); } }

@media (max-width: 640px) {
  .actions button span { display: none; }
  .actions { margin-left: 0; }
  #hud { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .bag { order: 3; max-width: none; flex-basis: 100%; }
  .player { flex: 1; }
  #toasts { top: 140px; }
}
@media (max-width: 440px) {
  .start-row { flex-direction: column; }
  #login-btn { padding: 15px; }
  .chip { font-size: 12px; padding: 6px 10px; }
}
@media (max-height: 560px) {
  .logo-wrap { width: min(38vh, 260px); }
  .wordmark { margin-top: 4px; }
}

/* ================= CHAT ================= */
#chat { position: fixed; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 11; width: min(380px, calc(100vw - 24px));
  display: none; flex-direction: column; gap: 6px; pointer-events: none; }
body.playing #chat { display: flex; }
#chat-log { max-height: 30vh; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; border-radius: 14px;
  background: linear-gradient(180deg, transparent, rgba(6, 30, 22, .55) 30%); scrollbar-width: none;
  mask-image: linear-gradient(180deg, transparent 0, #000 22px); -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px);
  opacity: .55; transition: opacity .4s; }
#chat-log::-webkit-scrollbar { display: none; }
#chat.fresh #chat-log, #chat.open #chat-log, #chat:hover #chat-log { opacity: 1; }
#chat.open #chat-log, #chat:hover #chat-log { pointer-events: auto; }
.msg { font: 15px/1.3 var(--display); color: #eafff4; text-shadow: 0 1px 2px #000a; word-wrap: break-word; animation: fade .3s; }
.msg b { font-weight: 400; margin-right: 6px; }
.msg b::after { content: ":"; color: #eafff499; }
.msg.mine span { color: #d8fff0; }
.msg.sys { color: var(--gold); font-size: 14px; }
#chat-form { display: flex; gap: 6px; pointer-events: auto; padding: 5px; border-radius: 14px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#chat-input { flex: 1; min-width: 0; font: 15px var(--display); color: var(--text); background: transparent; border: 0; outline: none; padding: 6px 8px; }
#chat-input::placeholder { color: var(--muted); }
#chat-form button { width: 36px; border-radius: 10px; border: 0; background: rgba(46, 232, 138, .25); color: var(--text); display: grid; place-items: center; }
#chat-form button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
#chat:focus-within #chat-form { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(46, 232, 138, .25); }

/* phones: chat sits above the touch pad, input only when opened */
@media (pointer: coarse) {
  #chat { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 150px); width: min(300px, calc(100vw - 24px)); }
  #chat-log { max-height: 18vh; }
  #chat:not(.open) #chat-form { display: none; }
  #chat.open { bottom: max(12px, env(safe-area-inset-bottom)); left: 8px; width: calc(100vw - 16px); z-index: 25; }
  #chat.open #chat-log { max-height: 36vh; }
}

/* ================= SOCIAL LINKS ================= */
.socials { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; animation: rise .8s .65s both; }
.social { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 999px; font: 15px var(--display); color: var(--text);
  text-decoration: none; background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform .15s, background .2s, border-color .2s; }
.social svg, .icon-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.social svg.fill, .icon-link svg.fill { fill: currentColor; stroke: none; }
.social.x:hover { transform: translateY(-2px); background: #000; border-color: #fff6; }
.social.soon, .icon-link.soon { opacity: .6; cursor: not-allowed; }
.social em, .icon-link em { font-style: normal; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(255, 211, 77, .2); color: var(--gold); }
.icon-link { position: relative; display: grid; place-items: center; height: 40px; min-width: 40px; border-radius: 12px; color: var(--text); text-decoration: none; }
.icon-link:not(.soon):hover { background: rgba(255, 255, 255, .1); }
.icon-link em { position: absolute; top: -4px; right: -6px; font-size: 9px; padding: 1px 5px; }

.social.pump { border-color: rgba(46, 232, 138, .55); color: var(--mint); }
.social.pump:hover { transform: translateY(-2px); background: rgba(46, 232, 138, .18); }
@media (max-width: 400px) { #btn-pump, #btn-full { display: none; } }
