:root {
  --ink: #2b1d3a;
  --paper: #fff8ec;
  --red: #e8443a;
  --gold: #ffc53d;
  --muted: #7a6a86;
  --card: #fffdf8;
  font-family: Fredoka, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b1d3a; touch-action: none; -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }

.screen { position: fixed; inset: 0; z-index: 5; }
.card-screen { display: grid; place-items: center; padding: 16px; overflow-y: auto; touch-action: pan-y;
  background: radial-gradient(circle at 50% 20%, #5b3b7a 0, #2b1d3a 70%); }
#results.card-screen { background: rgba(43, 29, 58, 0.72); }
.card { width: min(440px, 100%); background: var(--card); border-radius: 22px; padding: 20px 20px 18px;
  box-shadow: 0 6px 0 #1a1024, 0 18px 40px rgba(0,0,0,.35); }
#hero { display: block; margin: -4px auto 0; width: 280px; max-width: 100%; height: auto; }
.logo { font-size: 64px; line-height: .9; margin: 0 0 6px; text-align: center; letter-spacing: -1px; color: var(--red);
  text-shadow: 0 3px 0 var(--ink); }
.how { text-align: center; margin: 0 0 14px; color: var(--muted); font-size: 15px; }
h2 { margin: 0 0 8px; font-size: 24px; }
.field { display: block; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
input { font: inherit; font-size: 17px; width: 100%; padding: 10px 12px; margin-top: 4px; border: 2.5px solid var(--ink);
  border-radius: 12px; background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--ink); }
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }
.join-row input { flex: 0 0 96px; width: 96px; margin: 0; text-transform: uppercase; text-align: center; letter-spacing: 3px; }
.btn { font: inherit; font-weight: 600; font-size: 17px; padding: 11px 14px; border-radius: 14px; border: 2.5px solid var(--ink);
  background: #fff; color: var(--ink); cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { font-size: 13px; padding: 4px 10px; box-shadow: 0 2px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.error { color: #c92a2a; min-height: 1.2em; margin: 8px 0 0; font-weight: 600; }
.invite { background: #fff3bf; border: 2px dashed var(--ink); border-radius: 12px; padding: 10px; margin-bottom: 6px; display: flex;
  align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.code { font-size: 28px; letter-spacing: 3px; color: var(--red); }
.tag { font-size: 13px; background: #eee3f7; border-radius: 99px; padding: 2px 10px; vertical-align: middle; }
.share { font-size: 13px; color: var(--muted); word-break: break-all; margin: 0 0 10px; }
.members { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; }
.members li { display: flex; align-items: center; gap: 10px; background: #f6efe4; border-radius: 12px; padding: 6px 10px; font-weight: 600; }
.members .dot { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.members .badge { margin-left: auto; font-size: 12px; background: var(--ink); color: #fff; border-radius: 99px; padding: 2px 8px; }
.members .badge.bot { background: #868e96; }
.note { color: var(--muted); font-size: 14px; margin: 4px 0; }
.controls-help { margin-top: 12px; font-size: 14px; color: var(--muted); }
.controls-help summary { cursor: pointer; font-weight: 600; color: var(--ink); }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.pill { background: rgba(255, 253, 248, .92); border: 2px solid var(--ink); border-radius: 99px; padding: 3px 10px; font-weight: 600; font-size: 14px; }
.board-btn { pointer-events: auto; margin-left: auto; font: inherit; font-weight: 600; font-size: 14px; color: var(--ink); cursor: pointer; display: none; }
.board { position: absolute; top: 44px; right: 8px; margin: 0; padding: 6px 10px; list-style: none; background: rgba(255,253,248,.92);
  border: 2px solid var(--ink); border-radius: 14px; font-size: 14px; font-weight: 600; min-width: 150px; }
.board li { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.board .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.board .pts { margin-left: auto; padding-left: 10px; }
.board li.out { opacity: .5; }
.board li.me { text-decoration: underline; }
.callout { position: absolute; top: 18%; left: 0; right: 0; text-align: center; font-weight: 700; font-size: clamp(24px, 6vw, 48px); color: #fff;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); padding: 0 16px; opacity: 0; }
.callout small { display: block; font-size: .5em; -webkit-text-stroke: 1.5px var(--ink); color: var(--gold); margin-top: 6px; }
.callout.show { animation: pop 2.6s ease-out forwards; }
@keyframes pop {
  0% { opacity: 0; transform: scale(.4) rotate(-6deg); }
  10% { opacity: 1; transform: scale(1.15) rotate(2deg); }
  18% { transform: scale(1) rotate(0); }
  82% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}
.feed { position: absolute; left: 8px; top: 48px; font-size: 13px; font-weight: 600; display: grid; gap: 3px; max-width: 60vw; }
.feed div { background: rgba(255,253,248,.85); border-radius: 8px; padding: 2px 8px; justify-self: start; animation: fade 5s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.keys { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.key { background: rgba(255,253,248,.92); border: 2px solid var(--ink); border-radius: 12px; padding: 4px 10px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.key b { background: var(--ink); color: #fff; border-radius: 6px; padding: 0 6px; margin-right: 4px; font-size: 12px; }
.key i, .tbtn i { font-style: normal; background: var(--gold); border-radius: 99px; padding: 0 6px; margin-left: 4px; border: 1.5px solid var(--ink); }
.key.off, .tbtn.off { opacity: .35; }

/* phone controls: a stick on the left, three buttons on the right, low and see-through */
.touch { position: absolute; inset: 0; }
.stick-zone { position: absolute; left: 0; bottom: 0; width: 55%; height: 45%; pointer-events: auto; touch-action: none; }
.stick-base { position: absolute; left: 70px; bottom: 70px; width: 110px; height: 110px; margin: -55px; border-radius: 50%;
  background: rgba(255,255,255,.14); border: 2.5px solid rgba(255,255,255,.45); }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px; border-radius: 50%;
  background: rgba(255,253,248,.75); border: 2.5px solid var(--ink); }
.tbtn { position: absolute; pointer-events: auto; touch-action: none; font: inherit; font-weight: 700; color: var(--ink);
  border: 2.5px solid var(--ink); border-radius: 50%; background: rgba(255,253,248,.72); display: grid; place-items: center; padding: 0; line-height: 1.05; }
.tbtn.dash { right: 20px; bottom: calc(30px + env(safe-area-inset-bottom)); width: 78px; height: 78px; font-size: 16px; background: rgba(255, 197, 61, .8); }
.tbtn.hurry { right: 110px; bottom: calc(26px + env(safe-area-inset-bottom)); width: 58px; height: 58px; font-size: 12px; }
.tbtn.decoy { right: 40px; bottom: calc(118px + env(safe-area-inset-bottom)); width: 58px; height: 58px; font-size: 12px; }
.tbtn i { font-size: 11px; margin: 0; }
.tbtn:active { transform: scale(.94); }

/* results */
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ranking li { display: flex; align-items: center; gap: 10px; background: #f6efe4; border-radius: 12px; padding: 8px 12px; font-weight: 600; font-size: 17px; }
.ranking li:first-child { background: #fff3bf; font-size: 20px; }
.ranking .place { width: 28px; text-align: center; font-weight: 700; }
.ranking .dot { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.ranking .pts { margin-left: auto; color: var(--muted); font-size: 14px; }

.banner { position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); background: var(--gold); color: var(--ink); border: 2.5px solid var(--ink); border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink); padding: 8px 14px; font-weight: 600; font-size: 16px; text-align: center; pointer-events: none;
  overflow-wrap: anywhere; }

.foot { position: fixed; bottom: max(4px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-size: 12px; color: rgba(255,255,255,.6);
  z-index: 6; pointer-events: none; }

@media (max-width: 640px) {
  .board { display: none; }
  .board.open { display: block; }
  .board-btn { display: inline-block; }
  .keys { display: none; }
  .logo { font-size: 54px; }
}
