:root {
  --pixel: 'Press Start 2P', monospace;
  --panel: rgba(20, 22, 30, 0.78);
  --go: #7a5cff;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #1b1d25; color: #fff; font-family: var(--pixel);
}

#game { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ---- HUD ---- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none;
}
#hud > * { pointer-events: auto; }
#name-chip, #online {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--panel); border-radius: 8px; font-size: 10px;
}
#name-chip { border: 0; color: #fff; font-family: inherit; cursor: pointer; }
#name-chip:hover, #name-chip:focus-visible { background: rgba(40, 44, 58, 0.92); }
#name-chip .edit { opacity: 0.6; font-family: system-ui, sans-serif; font-size: 12px; }

/* ---- name picker ---- */
#name-picker {
  position: absolute; inset: 0; z-index: 28; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.55); padding: 16px;
}
#name-picker[hidden] { display: none; }
.picker-panel {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: #1e2130; border-radius: 12px; padding: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  touch-action: pan-y; overscroll-behavior: contain;
}
.picker-head {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 14px; color: #ffe066; padding: 6px 0 4px;
}
.picker-head .dot { width: 14px; height: 14px; }
.picker-panel h3 { margin: 16px 0 8px; font-size: 9px; font-weight: normal; color: rgba(255, 255, 255, 0.6); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.picker-grid button, .picker-actions button {
  font-family: inherit; font-size: 9px; color: #fff; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); border: 2px solid transparent; border-radius: 6px; padding: 9px 4px;
}
.picker-grid button:hover { background: rgba(255, 255, 255, 0.16); }
.picker-grid button.sel { border-color: #ffe066; background: rgba(255, 224, 102, 0.2); color: #ffe066; }
.picker-actions { display: flex; gap: 8px; margin-top: 18px; }
.picker-actions button { flex: 1; padding: 12px 6px; }
.picker-actions .primary { background: var(--go); border-color: #000; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #888; flex: none; }
.dot.live { background: #666; }
#online.connected .dot.live { background: #45c96b; box-shadow: 0 0 6px #45c96b; }

#feed {
  position: absolute; left: 12px; top: 56px; z-index: 10; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; font-size: 9px;
}
#feed div {
  background: var(--panel); padding: 6px 8px; border-radius: 6px; max-width: 70vw;
  animation: fade 5s forwards;
}
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#prompt {
  position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); z-index: 10;
  background: var(--panel); padding: 12px 16px; border-radius: 8px; font-size: 11px;
  white-space: nowrap; pointer-events: none; border: 2px solid var(--accent, #fff);
}
#prompt kbd {
  background: #eef0f3; color: #111; border-radius: 4px; padding: 3px 6px;
  box-shadow: 0 2px 0 #888; font: inherit; margin-right: 6px;
}
#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 10;
  font-size: 9px; color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 1px 0 #000, 0 0 4px rgba(0, 0, 0, 0.8);
}

#emote-menu {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 15;
  background: var(--panel); padding: 10px 12px 8px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#emote-menu[hidden] { display: none; }
#emote-menu .emotes { display: flex; gap: 6px; }
#emote-menu .emotes button {
  width: 46px; height: 46px; font-size: 26px; line-height: 1; padding: 0; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); border: 2px solid transparent; border-radius: 8px;
  transition: transform 0.1s; touch-action: manipulation;
}
#emote-menu .emotes button.sel { border-color: #ffe066; background: rgba(255, 224, 102, 0.2); transform: scale(1.15); }
#emote-menu .track { width: 100%; height: 4px; background: rgba(255, 255, 255, 0.15); border-radius: 2px; overflow: hidden; }
#emote-menu .bar { height: 100%; background: #ffe066; animation: drain 2s linear forwards; }
@keyframes drain { from { width: 100%; } to { width: 0%; } }
.emote-hint { font-size: 8px; color: rgba(255, 255, 255, 0.7); }
.emote-hint kbd {
  background: #eef0f3; color: #111; border-radius: 3px; padding: 2px 4px; margin: 0 4px 0 8px;
  box-shadow: 0 2px 0 #888; font: inherit;
}

#travel {
  position: absolute; inset: 0; z-index: 30; display: grid; place-items: center;
  background: #000; animation: travel-in 0.45s ease-out;
}
#travel[hidden] { display: none; }

#idle {
  position: absolute; inset: 0; z-index: 25; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.55); padding: 16px;
}
#idle[hidden] { display: none; }
.idle-box {
  background: var(--panel); border-radius: 10px; padding: 20px 24px; text-align: center;
  font-size: 11px; line-height: 1.8; max-width: 360px;
}
.idle-box p { margin: 0 0 14px; }
#rejoin {
  font: inherit; font-size: 12px; padding: 12px 20px; border-radius: 8px; cursor: pointer;
  border: 3px solid #000; background: var(--go); color: #fff;
}
#travel-text { font-size: clamp(12px, 3vw, 20px); text-align: center; line-height: 2; padding: 0 16px; }
@keyframes travel-in { from { opacity: 0; } to { opacity: 1; } }

/* ---- touch controls (phones/tablets only) ---- */
#joy, #go-btn, .small-btn { display: none; }
@media (pointer: coarse) {
  #hint, .emote-hint { display: none; }
  #prompt { bottom: auto; top: 64px; }
  #prompt kbd { display: none; }
  #emote-menu { bottom: auto; top: 120px; }
  #joy, #go-btn, .small-btn { display: block; }
  /* small buttons fan out around GO */
  .small-btn {
    position: fixed; width: 60px; height: 60px; border-radius: 50%; z-index: 20;
    border: 3px solid #000; background: #3a3f4d; color: #fff; padding: 0;
    font-family: var(--pixel); font-size: 8px; touch-action: none; opacity: 0.85;
  }
  .small-btn.on { background: #ffe066; color: #111; opacity: 1; }
  .small-btn:active { transform: scale(0.94); }
  #emote-btn { right: 30px; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 108px); font-size: 26px; font-family: inherit; }
  #sprint-btn { right: 118px; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 80px); }
  #sneak-btn { right: 128px; bottom: max(20px, env(safe-area-inset-bottom)); }
  #joy {
    position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px;
    left: 80px; top: calc(100% - 80px);   /* resting spot, bottom left */
    border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.12); opacity: 0.5; pointer-events: none; z-index: 20;
  }
  #joy-knob {
    position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
    border-radius: 50%; background: rgba(255, 255, 255, 0.7);
  }
  #go-btn {
    position: fixed; right: 20px; bottom: max(20px, env(safe-area-inset-bottom)); width: 92px; height: 92px;
    border-radius: 50%; border: 4px solid #000; background: var(--go); color: #fff; z-index: 20;
    font-family: var(--pixel); font-size: 14px; touch-action: none; opacity: 0.45;
    transition: opacity 0.15s, background 0.15s;
  }
  #go-btn.ready { opacity: 1; background: var(--accent, var(--go)); color: #111; }
  #go-btn.emoting { opacity: 1; background: #ffe066; color: #111; }
  #go-btn:active { transform: scale(0.94); }
}
