:root {
  --bg: #07090f;
  --card: #0a0d14;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --green: #22c55e;
  --green-d: #16a34a;
  --purple: #400873;
  --violet: #7c3aed;
  --lilac: #f5d0f0;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 15px Inter, sans-serif; color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 999px; padding: 10px 18px;
  text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: rgba(34, 197, 94, 0.12); border-color: var(--green); }
.btn:active { transform: scale(.97); }
.btn:disabled { cursor: not-allowed; background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .14); color: #9ca3af; }
#enter:disabled { cursor: progress; }
.btn-primary { background: var(--green); color: #052e16; border-color: var(--green); }
.btn-primary:hover:not(:disabled) { background: var(--green-d); }
.btn.big { width: 100%; padding: 16px; font-size: 17px; }
.btn.small { padding: 8px 14px; font-size: 13px; background: rgba(10, 13, 20, .78); backdrop-filter: blur(6px); }

.kicker {
  display: flex; align-items: center; gap: 12px; margin: 0 0 14px;
  font: 700 13px Inter, sans-serif; letter-spacing: .28em; text-transform: uppercase; color: var(--muted);
}
.kicker span { width: 10px; height: 10px; background: var(--green); border-radius: 2px; }

kbd {
  display: inline-block; min-width: 26px; padding: 2px 7px; margin-right: 4px;
  font: 500 12px "JetBrains Mono", monospace; text-align: center;
  border: 1px solid rgba(34, 197, 94, .45); border-radius: 6px; background: rgba(34, 197, 94, .08); color: var(--text);
}

/* ---------- Tela inicial ---------- */
#start {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(60% 50% at 100% 0%, rgba(34, 197, 94, .22), transparent 70%),
    radial-gradient(50% 50% at 0% 100%, rgba(124, 58, 237, .25), transparent 70%),
    rgba(7, 9, 15, .86);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  transition: opacity .35s;
}
#start.is-hidden { opacity: 0; pointer-events: none; }
.start-card {
  width: min(560px, 100%);
  background: rgba(10, 13, 20, .9);
  border: 1px solid var(--line); border-radius: 22px;
  padding: clamp(22px, 5vw, 40px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.start-card h1 { font-size: clamp(38px, 8vw, 60px); font-weight: 800; letter-spacing: -.03em; line-height: 1; margin: 0 0 14px; }
.lead { color: #d1d5db; font-size: 16px; line-height: 1.55; margin: 0 0 22px; }
.controls-help h3 { font-size: 14px; margin: 0 0 10px; color: var(--green); text-transform: uppercase; letter-spacing: .12em; }
.controls-help ul { list-style: none; margin: 0 0 22px; padding: 0; display: grid; gap: 9px; font-size: 14px; color: #d1d5db; }
.controls-help li { line-height: 1.5; }
.touch-only { display: none; }
.is-touch .touch-only { display: block; }
.is-touch .desktop-only { display: none; }
.load { height: 4px; background: rgba(255, 255, 255, .08); border-radius: 4px; overflow: hidden; margin-bottom: 16px; }
#load-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--violet), var(--green)); transition: width .2s; }
#start.is-ready .load { opacity: .3; }
.foot { margin: 16px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.foot a { color: var(--green); text-decoration: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; opacity: 0; transition: opacity .3s; }
.in-world #hud { opacity: 1; }
#hud > * { pointer-events: auto; }
#hud > #crosshair, #hud > #hint { pointer-events: none; }

.brand {
  position: absolute; top: 14px; left: 14px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(10, 13, 20, .72); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px 8px 8px;
}
.brand img { border-radius: 8px; display: block; }
.brand strong { display: block; font-size: 13px; }
.brand span { display: block; font-size: 12px; color: var(--green); font-weight: 700; }
#room-name.pulse { animation: pulse .6s ease; }
@keyframes pulse { from { color: #fff; transform: translateY(3px); } }

.map-wrap {
  position: absolute; top: 14px; right: 14px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
#minimap {
  width: 150px; height: 138px; display: block; cursor: pointer;
  background: rgba(10, 13, 20, .72); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 14px;
}
.compass { display: flex; align-items: center; gap: 8px; }
.compass small { font: 500 10px "JetBrains Mono", monospace; color: var(--muted); max-width: 150px; text-align: right; }
#compass-needle {
  width: 36px; height: 36px; border-radius: 50%; position: relative; flex: none;
  border: 1px solid var(--line); background: rgba(10, 13, 20, .72);
}
#compass-needle::before {
  content: ""; position: absolute; left: 50%; top: 4px; width: 0; height: 0; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 14px solid var(--green);
}
#compass-needle span { position: absolute; inset: auto 0 3px; text-align: center; font: 700 9px Inter, sans-serif; color: var(--muted); }

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%; background: rgba(255, 255, 255, .8); box-shadow: 0 0 0 2px rgba(0, 0, 0, .35);
  transition: transform .15s, background .15s;
}
.aim #crosshair { transform: scale(2.2); background: var(--green); }
.is-touch #crosshair { opacity: .5; }

#hint {
  position: absolute; left: 50%; top: calc(50% + 26px); transform: translateX(-50%);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: rgba(10, 13, 20, .8); border: 1px solid rgba(34, 197, 94, .4); border-radius: 999px; padding: 6px 12px;
  opacity: 0; transition: opacity .15s;
}
#hint.show { opacity: 1; }

.help { position: absolute; left: 14px; bottom: calc(14px + var(--safe-b)); width: 38px; height: 38px; padding: 0; font-size: 16px; }

.touch-ui { display: none; }
.is-touch .touch-ui { display: block; }
.touch-buttons { position: absolute; right: 14px; bottom: calc(14px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
#btn-sensors[aria-pressed="true"] { border-color: var(--green); color: var(--green); }
#joystick {
  position: absolute; left: 24px; bottom: calc(70px + var(--safe-b));
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(10, 13, 20, .5); border: 1px solid rgba(34, 197, 94, .35);
  touch-action: none;
}
.sensors-on #joystick { display: none; }
#joystick .knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(34, 197, 94, .35); border: 1px solid var(--green);
}

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translate(-50%, 20px);
  z-index: 40; max-width: min(90vw, 460px); text-align: center;
  background: rgba(10, 13, 20, .92); border: 1px solid rgba(34, 197, 94, .45); border-radius: 14px;
  padding: 10px 16px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.is-touch #toast { bottom: calc(200px + var(--safe-b)); }

/* ---------- Modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 5, 10, .72); backdrop-filter: blur(6px);
}
#modal[hidden] { display: none; }
.modal-box {
  position: relative; width: min(980px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
#modal-body { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
#modal-body img { width: 100%; height: auto; display: block; border-radius: 22px 0 0 22px; }
.modal-text { padding: 32px; display: flex; flex-direction: column; }
.modal-text h2 { font-size: 36px; margin: 0 0 12px; letter-spacing: -.02em; }
.modal-text p { color: #d1d5db; line-height: 1.6; margin: 0 0 20px; }
.modal-text .kicker { color: var(--muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.modal-nav { margin-top: auto; display: flex; justify-content: space-between; gap: 10px; }
.modal-text.contact { grid-column: 1 / -1; padding: 40px; }
.close {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 38px; height: 38px;
  border-radius: 50%; border: 1px solid var(--line); background: rgba(10, 13, 20, .85); color: var(--text);
  font-size: 22px; line-height: 1; cursor: pointer;
}

@media (max-width: 720px) {
  #modal-body { grid-template-columns: 1fr; }
  #modal-body img { border-radius: 22px 22px 0 0; }
  .modal-text { padding: 22px; }
  .modal-text h2 { font-size: 28px; }
  #minimap { width: 112px; height: 104px; }
  .brand strong { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Criação do avatar ---------- */
.creator { border-top: 1px solid var(--line); padding-top: 18px; margin-bottom: 18px; }
.creator h3 { font-size: 14px; margin: 0 0 12px; color: var(--green); text-transform: uppercase; letter-spacing: .12em; }
.field { display: grid; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, #chat-input {
  font: 500 15px Inter, sans-serif; color: var(--text);
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; outline: none;
}
.field input:focus, #chat-input:focus { border-color: var(--green); }
.creator-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.creator-row > span { width: 44px; flex: none; }
.swatches, .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }
.swatch.on { border-color: #fff; transform: scale(1.12); }
.chip { font: 600 13px Inter, sans-serif; color: var(--text); background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chip.on { border-color: var(--green); background: rgba(34,197,94,.15); }
.small-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

/* ---------- Rótulos e balões ---------- */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.peer-label {
  position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transform-origin: 50% 100%; will-change: transform; pointer-events: none;
}
.peer-name {
  font: 700 12px Inter, sans-serif; color: #fff; white-space: nowrap;
  background: rgba(10, 13, 20, .75); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px;
}
.peer-label.talking .peer-name { border-color: var(--green); box-shadow: 0 0 0 2px rgba(34,197,94,.35); }
.peer-label.is-group .peer-name { border-color: #a78bfa; }
.peer-label.is-private { opacity: .7; }
.peer-icons { font-size: 12px; line-height: 1; }
.peer-icons:empty { display: none; }
.peer-bubbles { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bubble {
  max-width: 220px; font: 500 13px/1.4 Inter, sans-serif; color: #0a0d14; background: #f3f4f6;
  border-radius: 14px; padding: 7px 11px; position: relative; overflow-wrap: anywhere;
  animation: pop .18s ease-out; transition: opacity .5s;
}
.bubble:last-child::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 6px solid #f3f4f6;
}
.bubble.private { background: #ede9fe; }
.bubble.private:last-child::after { border-top-color: #ede9fe; }
.bubble.out { opacity: 0; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* ---------- Chat ---------- */
#chat-log {
  position: absolute; left: 14px; bottom: calc(64px + var(--safe-b)); width: min(360px, calc(100vw - 28px)); max-height: 30vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 4px; pointer-events: auto;
  opacity: 0; transition: opacity .4s; scrollbar-width: none;
}
#chat-log.fresh, #chat-log:hover { opacity: 1; }
.chat-line { font-size: 13px; line-height: 1.45; background: rgba(10,13,20,.72); border-radius: 10px; padding: 5px 10px; overflow-wrap: anywhere; }
.chat-line b { color: var(--green); }
.chat-line.private b { color: #c4b5fd; }
#chat-form {
  position: absolute; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px)); display: flex; gap: 8px; z-index: 5;
}
#chat-form[hidden] { display: none; }
#chat-input { flex: 1; min-width: 0; background: rgba(10,13,20,.92); }

/* ---------- Barra de ações ---------- */
#actions {
  position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 10px;
}
.act {
  position: relative; width: 52px; height: 52px; border-radius: 50%; font-size: 21px; cursor: pointer;
  background: rgba(10,13,20,.8); border: 1px solid rgba(34,197,94,.35); color: var(--text);
  backdrop-filter: blur(6px); touch-action: none; user-select: none; -webkit-user-select: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.act:hover { border-color: var(--green); }
.act.on, .talking #btn-talk, #btn-talk.locked { background: var(--green); border-color: var(--green); }
#btn-talk.locked { box-shadow: 0 0 0 4px rgba(34,197,94,.3); }
.talking #btn-talk { transform: scale(1.08); }
#people-count {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  font: 700 11px/20px Inter, sans-serif; background: var(--violet); color: #fff;
}
body:not(.online) .needs-online { opacity: .45; }
.in-group #btn-people { border-color: #a78bfa; box-shadow: 0 0 0 3px rgba(167,139,250,.3); }

#self-view {
  position: absolute; right: 14px; top: 200px; width: 120px; border-radius: 12px; border: 2px solid var(--green);
  transform: scaleX(-1); background: #000;
}

/* ---------- Pessoas ---------- */
#people-panel {
  position: absolute; right: 14px; bottom: calc(80px + var(--safe-b)); width: min(320px, calc(100vw - 28px));
  max-height: 60vh; overflow-y: auto; z-index: 6;
  background: rgba(10,13,20,.95); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
#people-panel[hidden] { display: none; }
#people-panel header { display: flex; justify-content: space-between; align-items: center; }
.close-sm { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 18px; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }
#people-list { display: flex; flex-direction: column; gap: 4px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.person:hover { background: rgba(255,255,255,.05); }
.person input { accent-color: var(--green); width: 18px; height: 18px; }
.person .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.person .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person small { color: var(--muted); font-size: 11px; }

#invite-card {
  position: absolute; left: 50%; top: 90px; transform: translateX(-50%); z-index: 7;
  width: min(380px, calc(100vw - 28px)); background: rgba(10,13,20,.96); border: 1px solid #a78bfa; border-radius: 16px; padding: 14px 16px;
}
#invite-card[hidden] { display: none; }
#invite-card p { margin: 0 0 10px; font-size: 14px; }
#invite-card .row { display: flex; gap: 8px; }

.is-touch .touch-buttons { bottom: calc(80px + var(--safe-b)); }
.is-touch #joystick { bottom: calc(150px + var(--safe-b)); }
.is-touch #chat-log { bottom: calc(280px + var(--safe-b)); }
.is-touch #self-view { top: auto; bottom: calc(180px + var(--safe-b)); width: 96px; }
@media (max-width: 720px) {
  .act { width: 48px; height: 48px; font-size: 19px; }
  #actions { gap: 8px; }
}
