:root {
  --bg: #e7eee4;
  --card: #f8faf4;
  --ink: #231e29;
  --muted: #56605a;
  --line: #c3cfc0;
  --green: #2f6b55;
  --green-ink: #f7f2e6;
  --gold: #f4b337;
  --gold-ink: #93590a;
  --lav: #6e52c4;
  --hud-bg: rgba(248, 250, 244, .82);
  --display: "Bagel Fat One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --body: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a16; --card: #1b2722; --ink: #efeadf; --muted: #a3afa7; --line: #2c3b34;
    --gold-ink: #f4b337; --lav: #b9a5f4; --hud-bg: rgba(27, 39, 34, .82);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body);
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#back, #gl { pointer-events: none; }
#front { cursor: grab; }
#front.grabbing { cursor: grabbing; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 16px) 0 calc(env(safe-area-inset-left, 0px) + 16px);
}
/* the ladder back up the manhole to Rummi.fun: always there, top left */
.left { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.home {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 16px 6px 10px;
  border-radius: 99px; border: 3px solid #fff; background: var(--gold); color: #3a2400; text-decoration: none;
  font: 800 1rem/1.1 var(--body); box-shadow: 0 3px 0 var(--gold-ink), 0 6px 16px rgba(0,0,0,.25);
}
.home svg { width: 30px; height: 30px; flex: none; }
.home b { font-family: var(--display); font-weight: 400; letter-spacing: .01em; }
.home:hover { transform: translateY(-2px); }
.home:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-ink); }
.home:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.home.wave { animation: home-wave 1.2s ease-in-out 3; }
@keyframes home-wave { 50% { transform: scale(1.08) rotate(-2deg); } }
@media (max-width: 520px) { .home { font-size: .88rem; padding-right: 12px; } .home svg { width: 26px; height: 26px; } }
@media (prefers-reduced-motion: reduce) { .home.wave { animation: none; } }
.brand { background: var(--hud-bg); border: 2px solid var(--line); border-radius: 18px; padding: 8px 14px 9px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.brand h1 { margin: 0; font: 400 clamp(1.15rem, 3.4vw, 1.6rem)/1 var(--display); color: var(--green); letter-spacing: .01em; }
@media (prefers-color-scheme: dark) { .brand h1 { color: var(--gold); } }
.score { margin: 4px 0 0; font: 800 clamp(1.3rem, 4vw, 1.9rem)/1 var(--body); font-variant-numeric: tabular-nums; }
.score small { font-size: .55em; font-weight: 600; color: var(--muted); }
.combo[hidden] { display: none; }
.combo { display: inline-block; margin-left: 4px; padding: 2px 8px; border-radius: 99px; background: var(--gold); color: #3a2400; font-size: .5em; vertical-align: middle; animation: pop .35s ease-out; }
.best { margin: 3px 0 0; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tools { display: flex; gap: 8px; pointer-events: auto; }
.tool {
  position: relative; width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--hud-bg); display: grid; place-items: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tool svg { width: 22px; height: 22px; }
.tool:hover { border-color: var(--green); }
.tool:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.tool .mute { display: none; }
.tool[aria-pressed="false"] .wave { display: none; }
.tool[aria-pressed="false"] .mute { display: inline; }
.tool .count { position: absolute; right: -6px; top: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--gold); color: #3a2400; font-size: .72rem; font-weight: 800; line-height: 20px; text-align: center; }

.hint {
  position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 96px);
  margin: 0; max-width: min(92vw, 520px); padding: 8px 14px; border-radius: 99px; text-align: center;
  background: var(--hud-bg); border: 2px solid var(--line); font-size: .92rem; font-weight: 600; pointer-events: none;
  transition: opacity .6s;
}
.hint.gone { opacity: 0; }
@media (max-width: 699px) { .hint { top: 34%; font-size: .85rem; border-radius: 16px; } }
@media (min-width: 700px) { .hint { top: calc(env(safe-area-inset-top, 0px) + 226px); max-width: 420px; } }
@media (min-width: 1100px) { .hint { top: calc(env(safe-area-inset-top, 0px) + 18px); } }

/* ---------- roster ---------- */
.roster {
  position: fixed; z-index: 3; left: 0; right: 0; bottom: 0;
  padding: 6px calc(env(safe-area-inset-right, 0px) + 8px) calc(env(safe-area-inset-bottom, 0px) + 8px) calc(env(safe-area-inset-left, 0px) + 8px);
  background: linear-gradient(to top, var(--bg) 55%, transparent);
}
.roster ul {
  list-style: none; margin: 0 auto; padding: 4px 4px 2px; display: flex; gap: 8px; overflow-x: auto; max-width: min(100%, max-content);
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 22px), transparent 100%); mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 22px), transparent 100%);
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.roster ul::-webkit-scrollbar { display: none; }
.pick {
  position: relative; flex: 0 0 auto; width: 54px; height: 54px; padding: 0; border-radius: 50%; overflow: visible;
  border: 3px solid #fff; background: var(--card); box-shadow: 0 2px 0 var(--line), 0 0 0 2px var(--line);
  scroll-snap-align: center; transition: transform .15s;
}
.pick .face {
  position: absolute; inset: 0; border-radius: 50%;
  background-image: var(--img); background-repeat: no-repeat; background-size: var(--zoom) auto; background-position: var(--px) var(--py);
}
.pick:hover { transform: translateY(-3px); }
.pick:active { transform: scale(.92); }
.pick:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.pick .n { position: absolute; right: -5px; bottom: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--green); color: var(--green-ink); font-size: .7rem; font-weight: 800; line-height: 20px; text-align: center; }
.pick .n:empty { display: none; }
/* a snug dock (everyone fits) needs no fade; a scrolling one fades at the edge so it reads as swipeable */
@media (min-width: 900px) { .roster ul { -webkit-mask-image: none; mask-image: none; } }
@media (max-width: 520px) { .pick { width: 46px; height: 46px; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 4; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 14px); transform: translate(-50%, -140%);
  padding: 10px 16px 10px 12px; border-radius: 16px; background: var(--green); color: var(--green-ink);
  display: flex; gap: 10px; align-items: center; max-width: min(92vw, 420px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
  transition: transform .45s cubic-bezier(.2, 1.4, .4, 1); pointer-events: none;
}
.toast.on { transform: translate(-50%, 0); }
/* on phones the top is the HUD (home button + score), so the banner pops up above the roster instead */
@media (max-width: 700px) {
  .toast { top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); transform: translate(-50%, 220%); }
  .toast.on { transform: translate(-50%, 0); }
}
.toast b { display: block; font: 400 1.05rem/1.1 var(--display); color: var(--gold); }
.toast .desc { font-size: .85rem; }
.toast .star { font-size: 1.6rem; color: var(--gold); }

/* ---------- book ---------- */
.book {
  width: min(94vw, 640px); max-height: 86dvh; padding: 18px 18px 14px; border: 3px solid var(--line); border-radius: 22px;
  background: var(--card); color: var(--ink); overflow: auto; user-select: text; -webkit-user-select: text;
}
.book::backdrop { background: rgba(10, 20, 15, .5); backdrop-filter: blur(3px); }
.book-head { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.book h2 { margin: 0; font: 400 1.5rem/1.1 var(--display); color: var(--green); }
@media (prefers-color-scheme: dark) { .book h2 { color: var(--gold); } }
.book > h2 { margin-top: 18px; }
.book .close { width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--line); background: transparent; font-size: 1.5rem; line-height: 1; }
.book-sub { margin: 4px 0 12px; color: var(--muted); }
.crew { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.crew li { position: relative; border: 2px solid var(--line); border-radius: 16px; padding: 8px 8px 10px; text-align: center; background: var(--bg); }
.crew img { width: 100%; height: 110px; object-fit: contain; filter: grayscale(1) opacity(.45); transition: filter .3s; }
.crew li.got img { filter: none; }
.crew b { display: block; font-size: .86rem; line-height: 1.15; margin-top: 4px; }
.crew small { display: block; color: var(--muted); font-size: .76rem; margin-top: 2px; }
.crew li.got::after { content: "Binned"; position: absolute; top: 8px; right: -4px; transform: rotate(12deg); padding: 2px 8px; border-radius: 6px; background: var(--gold); color: #3a2400; font-size: .7rem; font-weight: 800; }
.tricks { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.tricks li { border: 2px dashed var(--line); border-radius: 14px; padding: 8px 10px; color: var(--muted); }
.tricks li b { display: block; color: var(--ink); }
.tricks li.got { border-style: solid; border-color: var(--green); }
.tricks li.got b::before { content: "★ "; color: var(--gold); }
.tricks li:not(.got) b { color: var(--muted); }
.book-foot { margin: 14px 0 0; font-size: .78rem; color: var(--muted); }
.book-foot a { color: inherit; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; padding: 16px; text-align: center; }

@keyframes pop { from { transform: scale(.4); } 60% { transform: scale(1.25); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } .combo { animation: none; } }

/* the way into Trash Raid */
.raidlink {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px 0 10px; border-radius: 14px;
  border: 2px solid #fff; background: #c0392b; color: #fff7e8; text-decoration: none; font: 800 .95rem/1 var(--body);
  box-shadow: 0 3px 0 #7d2219, 0 6px 14px rgba(0,0,0,.2); letter-spacing: .02em;
}
.raidlink svg { width: 24px; height: 24px; }
.raidlink b { font-family: var(--display); font-weight: 400; letter-spacing: .02em; }
.raidlink:hover { transform: translateY(-2px); }
.raidlink:active { transform: translateY(2px); box-shadow: 0 1px 0 #7d2219; }
.raidlink:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
