:root {
  --ink: #2a1433; --cream: #fff4dc; --gold: #ffcf5a; --gold2: #ff9f2e; --red: #ff4d5a; --night: #1b0f3a;
  --font: "Arial Rounded MT Bold", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); overscroll-behavior: none; }
body { font-family: var(--font); color: #fff; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
#safe { position: fixed; top: var(--sat); bottom: var(--sab); left: var(--sal); right: var(--sar); pointer-events: none; visibility: hidden; }
.hidden { display: none !important; }

button { font-family: var(--font); border: 0; cursor: pointer; color: var(--ink); touch-action: manipulation; }
button:active { transform: translateY(2px) scale(0.98); }
.big { display: flex; flex-direction: column; align-items: center; width: 100%; padding: 14px 16px; margin: 8px 0; border-radius: 22px;
  background: linear-gradient(#fff, #ffe7c2); box-shadow: 0 5px 0 #b5763e, 0 8px 18px rgba(0,0,0,0.35); border: 3px solid var(--ink); }
.big.gold { background: linear-gradient(#ffe28a, #ffb13c); box-shadow: 0 5px 0 #b86a14, 0 8px 18px rgba(0,0,0,0.35); }
.big .b1 { font-size: 24px; font-weight: 900; letter-spacing: 1px; }
.big .b2 { font-size: 13px; opacity: 0.8; margin-top: 2px; }
.mid { flex: 1; padding: 12px 10px; margin: 6px 0; border-radius: 16px; font-size: 15px; font-weight: 900; letter-spacing: 1px;
  background: rgba(255,255,255,0.14); color: #fff; border: 2px solid rgba(255,255,255,0.3); }
.mid.wide { width: 100%; }
.row { display: flex; gap: 10px; width: 100%; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10;
  padding: calc(var(--sat) + 12px) 18px calc(var(--sab) + 12px);
  background: radial-gradient(120% 70% at 50% 20%, #5a2270 0%, #2b1247 55%, #150a2a 100%); }
#title { align-items: flex-end; padding-bottom: calc(var(--sab) + 6vh); }
.title-wrap { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; }
#logo-art { width: 300px; height: 125px; margin-bottom: -18px; }
.logo { margin: 0; display: flex; flex-direction: column; align-items: center; line-height: 0.9; }
.logo span { font-weight: 900; paint-order: stroke fill; }
.logo span:first-child { font-size: 76px; color: var(--gold); -webkit-text-stroke: 3px var(--ink); text-shadow: 0 6px 0 var(--ink), 0 10px 26px rgba(255,120,60,0.6); letter-spacing: 3px; transform: rotate(-3deg); }
.logo span:last-child { font-size: 38px; color: #fff; -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink); letter-spacing: 4px; margin-top: 4px; }
.tag { margin: 12px 0 16px; opacity: 0.85; font-size: 14px; text-align: center; }
.foot { display: flex; justify-content: space-between; width: 100%; font-size: 11px; opacity: 0.55; margin-top: 10px; }

.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(15,5,25,0.62);
  padding: calc(var(--sat) + 10px) 14px calc(var(--sab) + 10px); animation: fade 0.18s ease-out; }
.card { width: 100%; max-width: 370px; max-height: 100%; overflow-y: auto; background: linear-gradient(#3b1a55, #25113a); border: 3px solid var(--ink);
  border-radius: 28px; padding: 18px 18px 14px; box-shadow: 0 0 0 3px rgba(255,207,90,0.6), 0 20px 50px rgba(0,0,0,0.6); text-align: center;
  animation: pop-in 0.28s cubic-bezier(.2,1.5,.4,1); }
h2 { font-weight: 900; paint-order: stroke fill; margin: 2px 0 4px; font-size: 30px; color: var(--gold); -webkit-text-stroke: 1.5px var(--ink); text-shadow: 0 3px 0 var(--ink); letter-spacing: 2px; }
.sub { margin: 0 0 12px; opacity: 0.8; font-size: 14px; }
.kicker { font-size: 13px; letter-spacing: 2px; opacity: 0.8; font-weight: 900; }
.hint { font-size: 12px; opacity: 0.7; line-height: 1.4; margin: 10px 4px 0; }
.err { color: #ff8a93; min-height: 18px; font-size: 13px; margin: 6px 0; }
input { width: 100%; font: 900 20px var(--font); padding: 12px 14px; border-radius: 14px; border: 3px solid var(--ink); margin: 6px 0; background: var(--cream); color: var(--ink); text-align: center; }

#perks { display: flex; flex-direction: column; gap: 10px; }
.perk { pointer-events: none; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; border-radius: 18px; background: linear-gradient(#fff, #ffe7c2);
  border: 3px solid var(--ink); box-shadow: 0 4px 0 #b5763e; opacity: 0; animation: deal 0.35s cubic-bezier(.2,1.4,.4,1) forwards; }
.perk:nth-child(2) { animation-delay: 0.12s; } .perk:nth-child(3) { animation-delay: 0.24s; }
.perks-ready .perk { pointer-events: auto; }
.perk.picked { transform: scale(1.06); box-shadow: 0 0 0 4px #50ffa0, 0 4px 0 #b5763e; }
#perks.chosen .perk:not(.picked) { opacity: 0.35 !important; }
.perk canvas { width: 52px; height: 52px; flex: none; }
.perk .pn { font-size: 18px; font-weight: 900; }
.perk .pt { font-size: 13px; opacity: 0.85; margin-top: 2px; }
.perk-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0 8px; font-size: 12px; }
.perk-list span { background: rgba(255,207,90,0.2); border: 1px solid rgba(255,207,90,0.5); padding: 3px 8px; border-radius: 10px; }

.wave-big { display: flex; flex-direction: column; align-items: center; margin: 4px 0; }
.wave-big span { font-size: 16px; letter-spacing: 4px; opacity: 0.8; font-weight: 900; }
.wave-big b { font-weight: 900; paint-order: stroke fill; font-size: 88px; line-height: 0.95; color: var(--gold); -webkit-text-stroke: 3px var(--ink); text-shadow: 0 6px 0 var(--ink); }
.badge { display: inline-block; background: var(--red); color: #fff; padding: 6px 16px; border-radius: 14px; font-weight: 900; letter-spacing: 2px; border: 3px solid var(--ink);
  transform: rotate(-4deg); animation: wobble 0.6s ease-in-out infinite alternate; }
.near { font-size: 16px; font-weight: 900; margin: 8px 0 6px; color: #ffe2a0; min-height: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.stats div { background: rgba(255,255,255,0.08); border-radius: 12px; padding: 6px 2px; }
.stats b { display: block; font-size: 20px; }
.stats small { font-size: 10px; opacity: 0.7; letter-spacing: 1px; }
.rank:empty, .near:empty { display: none; }
.cause { font-size: 13px; opacity: 0.9; margin: 2px 0 6px; }
.rank { font-size: 14px; min-height: 18px; margin: 4px 0 6px; }

.tabs { display: flex; gap: 8px; margin: 6px 0 10px; }
.tab { flex: 1; padding: 9px; border-radius: 12px; font-weight: 900; background: rgba(255,255,255,0.1); color: #fff; border: 2px solid rgba(255,255,255,0.25); }
.tab.on { background: var(--gold); color: var(--ink); border-color: var(--ink); }
#board { list-style: none; margin: 0; padding: 0; text-align: left; max-height: 50vh; overflow-y: auto; }
#board li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; font-size: 15px; }
#board li:nth-child(odd) { background: rgba(255,255,255,0.06); }
#board li.me { background: rgba(255,207,90,0.28); outline: 2px solid var(--gold); }
#board .n { width: 28px; font-weight: 900; opacity: 0.7; }
#board .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .w { font-weight: 900; color: var(--gold); }
#board .p { width: 64px; text-align: right; font-size: 12px; opacity: 0.7; }

#toasts { position: fixed; left: 0; right: 0; top: calc(var(--sat) + 9vh); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { max-width: min(340px, 88vw); text-align: center; pointer-events: auto; background: rgba(42,20,51,0.95); border: 2px solid var(--gold); color: #fff; padding: 8px 14px; border-radius: 16px; font-size: 14px; font-weight: 900;
  display: flex; align-items: center; gap: 12px; animation: toast-in 0.2s ease-out; }
.toast.bad { border-color: var(--red); }
.toast button { background: var(--gold); padding: 5px 12px; border-radius: 10px; font-weight: 900; font-size: 14px; }
.toast.out { opacity: 0; transform: translateY(8px); transition: 0.3s; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(0.8); opacity: 0; } }
@keyframes deal { from { transform: translateY(24px) rotate(-3deg) scale(0.9); opacity: 0; } to { opacity: 1; } }
@keyframes wobble { from { transform: rotate(-4deg) scale(1); } to { transform: rotate(3deg) scale(1.08); } }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }
