* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1530; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: #fff; }
#game { position: fixed; inset: 0; touch-action: none; }
#game canvas { display: block; }
button { font: inherit; cursor: pointer; }

#joinscreen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #3a7bd5 0%, #1d2b64 55%, #0b1530 100%); }
#join { width: min(420px, 100%); background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px; padding: 28px; backdrop-filter: blur(6px); }
#join h1 { margin: 0 0 6px; font-size: 44px; letter-spacing: 1px; text-shadow: 0 3px 0 #1d2b64; }
#join .sub { margin: 0 0 20px; opacity: 0.9; line-height: 1.4; }
#join label, #join .lbl { display: block; font-weight: 600; margin: 14px 0 6px; }
#name { width: 100%; font-size: 22px; padding: 10px 14px; border-radius: 12px; border: 0; color: #111; }
#colors { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: #fff; transform: scale(1.12); }
#joinbtn { margin-top: 22px; width: 100%; font-size: 20px; font-weight: 700; padding: 14px; border: 0; border-radius: 14px;
  background: #ffcc33; color: #3b2a00; box-shadow: 0 4px 0 #c99a10; }
#joinbtn:disabled { opacity: 0.7; }
.note { font-size: 13px; opacity: 0.8; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud input, #help { pointer-events: auto; }
#top { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); left: 12px; display: flex; flex-direction: column; gap: 6px; }
#myname { font-weight: 800; font-size: 20px; text-shadow: 0 2px 3px rgba(0,0,0,0.6); }
#compass { background: rgba(0,0,0,0.4); padding: 6px 12px; border-radius: 999px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
#arrow { display: inline-block; font-size: 18px; transition: transform 0.1s; }
#players { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px; background: rgba(0,0,0,0.35);
  padding: 8px 12px; border-radius: 12px; font-size: 14px; max-height: 40vh; overflow: auto; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
#inv { position: absolute; top: calc(90px + env(safe-area-inset-top, 0px)); left: 12px; background: rgba(0,0,0,0.4);
  padding: 6px 12px; border-radius: 10px; font-size: 14px; max-width: 60vw; }
#log { position: absolute; left: 12px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); width: min(460px, 70vw);
  display: flex; flex-direction: column; gap: 4px; }
.line { background: rgba(0,0,0,0.45); padding: 5px 10px; border-radius: 10px; font-size: 15px; transition: opacity 2s; width: fit-content; max-width: 100%; }
.line.sys { color: #ffe58a; }
.line.me { color: #b9e3ff; }
.line.old { opacity: 0.35; }
#heard { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); background: rgba(255,255,255,0.92); color: #222;
  font-size: 22px; padding: 10px 18px; border-radius: 16px; max-width: 80vw; text-align: center; }
#magic { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); background: rgba(80,30,140,0.85); padding: 14px 22px;
  border-radius: 18px; text-align: center; font-size: 18px; box-shadow: 0 0 30px #c084fc; }
#magic .stars { font-size: 32px; animation: wobble 0.8s infinite alternate; }
#magictext { font-style: italic; opacity: 0.85; margin-top: 4px; }
@keyframes wobble { from { transform: rotate(-12deg) scale(1); } to { transform: rotate(12deg) scale(1.2); } }
#crosshair { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 26px; opacity: 0.7; }
#mic { position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: 72px; height: 72px; border-radius: 50%;
  border: 0; font-size: 32px; background: #ffcc33; box-shadow: 0 4px 0 #c99a10; }
#mic.on { background: #ff4d6d; box-shadow: 0 0 0 8px rgba(255,77,109,0.35); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 16px rgba(255,77,109,0.15); } }
#touchbtns { display: none; position: absolute; right: 100px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); gap: 8px; flex-wrap: wrap; max-width: 220px; justify-content: flex-end; }
#touchbtns button { width: 58px; height: 58px; border-radius: 50%; border: 0; font-size: 24px; background: rgba(255,255,255,0.8); }
body.touch #touchbtns { display: flex; }
body.touch #log { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
#stick { position: absolute; width: 100px; height: 100px; border-radius: 50%; background: rgba(255,255,255,0.2); border: 2px solid rgba(255,255,255,0.5); }
#knob { position: absolute; left: 30px; top: 30px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.8); }
#chatbox { position: absolute; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: min(600px, 92vw); }
#chatinput { width: 100%; font-size: 18px; padding: 12px 16px; border-radius: 14px; border: 0; color: #111; }
#help { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(640px, 94vw); max-height: 86vh; overflow: auto;
  background: rgba(15,25,60,0.94); border-radius: 18px; padding: 18px 24px; line-height: 1.5; }
#help h2 { margin-top: 0; }
#help li { margin-bottom: 6px; }
#lost { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.6); font-size: 22px; pointer-events: auto; }
#lost button { margin-left: 10px; font-size: 20px; padding: 8px 18px; border-radius: 12px; border: 0; background: #ffcc33; }
