* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1a1a2e;
  --text: #f8f8f8;
  --accent: #4488ff;
  --accent-dark: #2255bb;
  --green: #00e676;
  --font: 'Press Start 2P', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* ── LOBBY ── */
#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 24px;
}

#lobby h1 {
  font-size: 24px;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--accent-dark);
}

#player-name {
  font-family: var(--font);
  font-size: 12px;
  padding: 12px 16px;
  background: #0d0d1a;
  border: 2px solid var(--accent-dark);
  color: var(--text);
  outline: none;
  width: 280px;
  text-align: center;
}

#player-name:focus {
  border-color: var(--accent);
}

#avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, 64px);
  gap: 12px;
}

.avatar-option {
  width: 64px;
  height: 64px;
  background-size: 200% 100%;
  background-position: 0% 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}

.avatar-option:hover {
  border-color: var(--accent);
}

.avatar-option.selected {
  border-color: var(--green);
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.4);
}

#join-btn {
  font-family: var(--font);
  font-size: 12px;
  padding: 12px 32px;
  background: var(--accent-dark);
  color: var(--text);
  border: 2px solid var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}

#join-btn:hover:not(:disabled) {
  background: var(--accent);
}

#join-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── GAME ── */
#game {
  width: 100vw;
  height: 100vh;
  position: relative;
}

#viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: #2a2a1e;
}

#map {
  width: 1200px;
  height: 896px;
  background-image: url('assets/Escritorio.png');
  background-size: 1200px 896px;
  background-repeat: no-repeat;
  position: absolute;
  image-rendering: pixelated;
}

#hover-tile {
  position: absolute;
  width: 32px;
  height: 32px;
  pointer-events: none;
  z-index: 4;
  display: none;
}

#hover-tile.walkable {
  background: rgba(0, 230, 118, 0.2);
  border: 1px solid rgba(0, 230, 118, 0.4);
  cursor: pointer;
}

#hover-tile.blocked {
  background: rgba(255, 68, 68, 0.15);
  border: 1px solid rgba(255, 68, 68, 0.3);
}

#map {
  cursor: default;
}

#players-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.player {
  position: absolute;
  width: 64px;
  height: 64px;
  background-size: 200% 100%;
  background-position: 0% 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  transition: left 0.1s linear, top 0.1s linear;
  transform: translate(-50%, -50%);
}

.player-name {
  position: absolute;
  bottom: 68px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font);
  font-size: 7px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
  white-space: nowrap;
  pointer-events: none;
}

/* ── HUD ── */
#hud {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--green);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#mute-btn, #cam-btn, #deafen-btn, #fs-btn {
  font-size: 16px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}

#mute-btn:hover, #cam-btn:hover, #deafen-btn:hover, #fs-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#fs-btn {
  font-family: var(--font);
  font-size: 8px;
  padding: 6px 12px;
}

#mute-btn.off, #cam-btn.off, #deafen-btn.off {
  background: rgba(255, 68, 68, 0.3);
  border-color: #ff4444;
}

.mute-indicator {
  position: absolute;
  bottom: 76px;
  right: -4px;
  font-size: 12px;
  background: rgba(255, 68, 68, 0.8);
  padding: 2px 4px;
  border-radius: 4px;
  z-index: 11;
  white-space: nowrap;
  line-height: 1;
}

/* ── PIP PANEL (hidden — camera now on player head) ── */
#pip-panel {
  display: none;
}

.player-cam {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 54px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--green);
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.5);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.player-cam video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-cam.speaking {
  border-color: #4cff91;
  box-shadow: 0 0 0 3px rgba(76, 255, 145, 0.5), 0 0 12px rgba(0, 230, 118, 0.6);
}

.player-cam.cam-off {
  background: rgba(0, 0, 0, 0.6);
}

.player-cam.cam-off video {
  display: none;
}

.player-cam .cam-off-icon {
  display: none;
  font-size: 20px;
}

.player-cam.cam-off .cam-off-icon {
  display: block;
}


/* ── CHAT BAR ── */
#chat-bar {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: 360px;
}

#chat-input {
  width: 100%;
  font-family: var(--font);
  font-size: 9px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

#chat-input:focus {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.9);
}

#chat-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* ── CHAT BUBBLE (Habbo style) ── */
.chat-bubble {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #1a1a2e;
  font-family: var(--font);
  font-size: 7px;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 8px 8px 8px 0;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-wrap: break-word;
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  animation: bubbleIn 0.2s ease-out;
}

/* Triangle pointer */
.chat-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 12px;
  width: 0;
  height: 0;
  border-left: 8px solid #fff;
  border-bottom: 8px solid transparent;
}

.chat-bubble.fading {
  animation: bubbleOut 0.4s ease-in forwards;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes bubbleOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(-50%) translateY(-4px); }
}

/* ── PLAYER MENU ── */
.player-menu {
  position: absolute;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 8px 0;
  z-index: 50;
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  animation: menuIn 0.15s ease-out;
}

.player-menu-title {
  font-family: var(--font);
  font-size: 8px;
  color: var(--accent);
  padding: 4px 12px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.player-menu-btn {
  display: block;
  width: 100%;
  font-family: var(--font);
  font-size: 7px;
  color: var(--text);
  background: none;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.player-menu-btn:hover {
  background: rgba(68, 136, 255, 0.25);
}

@keyframes menuIn {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── WALK INVITE ── */
.walk-invite {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid var(--green);
  border-radius: 10px;
  padding: 12px 20px;
  z-index: 300;
  text-align: center;
  font-family: var(--font);
  font-size: 9px;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 230, 118, 0.3);
  animation: menuIn 0.2s ease-out;
}

.walk-invite-btns {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  justify-content: center;
}

.walk-invite-accept,
.walk-invite-decline {
  font-family: var(--font);
  font-size: 8px;
  padding: 6px 14px;
  border: 2px solid;
  border-radius: 6px;
  cursor: pointer;
}

.walk-invite-accept {
  background: rgba(0, 230, 118, 0.2);
  border-color: var(--green);
  color: var(--green);
}

.walk-invite-accept:hover {
  background: rgba(0, 230, 118, 0.4);
}

.walk-invite-decline {
  background: rgba(255, 68, 68, 0.2);
  border-color: #ff4444;
  color: #ff4444;
}

.walk-invite-decline:hover {
  background: rgba(255, 68, 68, 0.4);
}
