:root {
  --bg: #1d1630;
  --card: #2b2246;
  --ink: #fff7e8;
  --dim: #b9aed6;
  --accent: #ffb43b;
  --accent2: #ff6b5b;
  --line: #43386a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto; background: rgba(20, 14, 36, 0.72); backdrop-filter: blur(3px); z-index: 5;
}
.card {
  width: 100%; max-width: 420px; background: var(--card); border: 2px solid var(--line); border-radius: 22px;
  padding: 22px 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); margin: auto;
}
h1 {
  margin: 0; font-size: 64px; letter-spacing: -2px; line-height: 1; color: var(--accent);
  text-shadow: 4px 4px 0 var(--accent2); transform: rotate(-3deg); display: inline-block;
}
h2 { margin: 0 0 8px; font-size: 40px; letter-spacing: 3px; }
.how { color: var(--dim); margin: 12px 0 16px; }
.label { margin: 0; color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.field { display: block; margin: 0 0 14px; font-size: 14px; color: var(--dim); }
input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: #1b1430; color: var(--ink); font: inherit; font-size: 17px; -webkit-user-select: text; user-select: text;
}
input:focus { outline: none; border-color: var(--accent); }
.colors { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 6px; }
.colors canvas { width: 100%; aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; cursor: pointer; background: #1b1430; }
.colors canvas.on { border-color: var(--accent); background: #3a2f5e; }
button {
  font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: #4a3e78; color: var(--ink); box-shadow: 0 4px 0 #2c2350; transition: transform 0.05s;
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #2c2350; }
button:disabled { opacity: 0.45; cursor: default; }
button.big { background: var(--accent); color: #2b1a00; box-shadow: 0 4px 0 #b97a15; font-size: 18px; }
button.ghost { background: transparent; box-shadow: none; color: var(--dim); }
button.small { padding: 6px 10px; font-size: 13px; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.buttons .big { flex: 1 1 100%; }
.buttons button:not(.big) { flex: 1; }
.join { display: flex; gap: 10px; margin-top: 14px; }
.join input { margin: 0; flex: 0 0 110px; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.join button { flex: 1; }
.err { color: #ff8f84; min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }
.note { color: var(--dim); font-size: 14px; }
.share { margin: 0 0 12px; color: var(--dim); font-size: 13px; word-break: break-all; }
.players, .ranking { list-style: none; padding: 0; margin: 0 0 8px; }
.players li, .ranking li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #231b3c; margin-bottom: 6px;
}
.players canvas, .ranking canvas { width: 34px; height: 34px; flex: none; }
.players .tag, .ranking .tag { margin-left: auto; color: var(--dim); font-size: 13px; }
.ranking li:first-child { background: #4a3a16; }
.ranking .n { font-weight: 800; width: 1.4em; color: var(--accent); }
.controls-help { margin-top: 14px; font-size: 13px; color: var(--dim); border-top: 1px solid var(--line); padding-top: 10px; }
.controls-help p { margin: 4px 0; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#scores {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center; font-size: 13px; font-weight: 700;
}
#scores .s { background: rgba(20, 14, 36, 0.7); border-radius: 20px; padding: 3px 10px 3px 4px; display: flex; align-items: center; gap: 6px; }
#scores .s.out { opacity: 0.45; }
#scores .s.lead { box-shadow: 0 0 0 2px #ffd84a; }
#scores .dot { width: 14px; height: 14px; border-radius: 50%; }
#scores .pips { letter-spacing: 1px; color: #ffd84a; }
#banner {
  position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: 56px; font-weight: 900;
  color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45); transform: translateY(-50%); padding: 0 16px;
}
#banner small { display: block; font-size: 18px; font-weight: 700; }
#callouts { position: absolute; top: 56px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 12px; }
.callout {
  background: rgba(255, 255, 255, 0.92); color: #2b1a40; font-weight: 800; font-size: 18px; padding: 6px 14px; border-radius: 14px;
  animation: pop 2.8s ease-out forwards; text-align: center; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}
@keyframes pop {
  0% { transform: scale(0.4) rotate(-6deg); opacity: 0; }
  8% { transform: scale(1.15) rotate(2deg); opacity: 1; }
  14% { transform: scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}
#keys { position: absolute; bottom: 30px; left: 0; right: 0; display: flex; gap: 10px; justify-content: center; }
.cd {
  position: relative; overflow: hidden; width: 110px; padding: 6px 10px; border-radius: 12px; background: rgba(20, 14, 36, 0.75);
  font-weight: 800; font-size: 14px; text-align: center;
}
.cd i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); width: 100%; }
.cd small { display: block; color: var(--dim); font-weight: 600; font-size: 11px; }
.cd.wait { color: var(--dim); }
#watching {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); background: rgba(20, 14, 36, 0.8);
  padding: 6px 14px; border-radius: 12px; font-size: 14px; white-space: nowrap;
}

#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#stickZone { position: absolute; left: 0; bottom: 0; width: 55%; height: 210px; pointer-events: auto; }
#stickBase {
  position: absolute; left: 30px; bottom: max(36px, env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.3);
}
#stickKnob {
  position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.55);
}
#tShove, #tCrack {
  position: absolute; pointer-events: auto; border-radius: 50%; overflow: hidden; padding: 0; color: #2b1a00; font-weight: 900;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); touch-action: none;
}
#tShove { right: 24px; bottom: max(40px, env(safe-area-inset-bottom)); width: 96px; height: 96px; background: var(--accent); font-size: 17px; }
#tCrack { right: 128px; bottom: max(28px, env(safe-area-inset-bottom)); width: 70px; height: 70px; background: #c9b58a; font-size: 14px; }
#tShove i, #tCrack i { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.35); height: 0; }
#tShove span, #tCrack span { position: relative; }
#tShove.held { background: #fff36b; }
body.touch #keys { display: none; }
body.touch #watching { bottom: 220px; }

#announce {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 8;
  width: max-content; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px; text-align: center;
  background: #fff36b; color: #2b1a00; font-weight: 800; font-size: 15px; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
  pointer-events: none; overflow-wrap: anywhere;
}

footer {
  position: fixed; bottom: 6px; left: 0; right: 0; text-align: center; font-size: 11px; color: rgba(255, 255, 255, 0.45);
  pointer-events: none; z-index: 6;
}
body.touch.playing footer { display: none; }

@media (max-width: 420px) {
  h1 { font-size: 52px; }
  #banner { font-size: 40px; }
  .callout { font-size: 15px; }
  #scores { font-size: 11px; gap: 4px; }
}
