:root {
  --bg: #0b1220;
  --panel: rgba(14, 21, 36, 0.72);
  --panel-solid: #0e1524;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e8eefc;
  --muted: #94a3b8;
  --accent: #6ee7b7;
  --accent-2: #60a5fa;
  --danger: #fb7185;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hidden { display: none !important; }

/* ───────────────────────── Nametags ───────────────────────── */
#tags { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }

.tag {
  position: absolute;
  transform: translate(-50%, -100%);
  text-align: center;
  white-space: nowrap;
  line-height: 1.28;
  will-change: transform, opacity;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.75));
}

.tag .name {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.1px;
  color: #fff;
}
.tag .name.self { color: var(--accent); }

.tag .place {
  font-size: 11.5px;
  font-weight: 500;
  color: #c7d3e8;
  opacity: 0.95;
}

.tag .time {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}
.tag .time.night { color: #a78bfa; }

.bubble {
  margin-bottom: 5px;
  display: inline-block;
  max-width: 220px;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(12, 18, 31, 0.92);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  white-space: normal;
  word-break: break-word;
  text-align: left;
}

/* ───────────────────────── HUD ───────────────────────── */
#hud {
  position: fixed;
  top: calc(12px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.hud-left {
  pointer-events: none;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 13px;
}

.brand {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

.stats { font-size: 11.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.hud-right { pointer-events: auto; }

.icon-btn {
  pointer-events: auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.icon-btn:hover { background: rgba(30, 41, 61, .85); }
.icon-btn:active { transform: scale(.94); }

/* ───────────────────────── Chat ───────────────────────── */
#chat {
  position: fixed;
  left: calc(12px + var(--safe-l));
  bottom: calc(12px + var(--safe-b));
  width: min(360px, calc(100vw - 24px));
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

#chatLog {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  max-height: 32vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
  pointer-events: auto;
}
#chatLog::-webkit-scrollbar { display: none; }

.msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 9px;
  border-radius: 10px;
  background: rgba(11, 18, 32, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  width: fit-content;
  max-width: 100%;
  word-break: break-word;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

.msg .who { font-weight: 650; color: var(--accent); margin-right: 5px; }
.msg.self .who { color: var(--accent-2); }
.msg.sys { color: var(--muted); font-style: italic; font-size: 12px; }

#chatForm {
  display: flex;
  gap: 6px;
  pointer-events: auto;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 5px;
  transition: border-color .2s, opacity .2s;
  opacity: .72;
}
#chatForm:focus-within { opacity: 1; border-color: rgba(110, 231, 183, .45); }

#chatInput {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
}
#chatInput::placeholder { color: #64748b; }

.send-btn {
  width: 34px; height: 34px;
  border: 0; border-radius: 10px;
  background: rgba(110, 231, 183, .16);
  color: var(--accent);
  display: grid; place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.send-btn:active { transform: scale(.92); }

/* ───────────────────── Touch controls ───────────────────── */
#touch { position: fixed; inset: 0; z-index: 11; pointer-events: none; }

#stick {
  position: absolute;
  left: calc(26px + var(--safe-l));
  bottom: calc(26px + var(--safe-b));
  width: 124px; height: 124px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .16);
  background: radial-gradient(circle, rgba(255,255,255,.07), rgba(255,255,255,.02));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
  touch-action: none;
  opacity: .82;
}
#stickKnob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(232, 238, 252, .82);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: transform .05s linear;
}

#jumpBtn {
  position: absolute;
  right: calc(26px + var(--safe-r));
  bottom: calc(34px + var(--safe-b));
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 1.5px solid rgba(110, 231, 183, .35);
  background: rgba(110, 231, 183, .14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--accent);
  font: 700 13px/1 'Inter', sans-serif;
  letter-spacing: .6px;
  pointer-events: auto;
  touch-action: none;
}
#jumpBtn:active { transform: scale(.93); background: rgba(110, 231, 183, .26); }

#chatBtn {
  position: absolute;
  right: calc(30px + var(--safe-r));
  bottom: calc(134px + var(--safe-b));
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  display: grid; place-items: center;
  pointer-events: auto;
}
#chatBtn:active { transform: scale(.93); }

/* ───────────────────── Overlays / cards ───────────────────── */
#overlay, #settings {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 20px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(37, 99, 235, .16), transparent 60%), rgba(4, 8, 16, .78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(20, 29, 48, .96), rgba(12, 18, 32, .96));
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .6);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.card.small { width: min(380px, 100%); }

.logo { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.logo h1 { margin: 0; font-size: 25px; letter-spacing: -0.7px; font-weight: 700; }
.tagline { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 7px; letter-spacing: .2px; }
.field input[type='text'] {
  width: 100%;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.field input[type='text']:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(110, 231, 183, .14); }

.where {
  background: rgba(0, 0, 0, .26);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  margin-bottom: 16px;
}
.where-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 600; }
.where-value { font-size: 14px; margin-top: 4px; font-weight: 500; white-space: pre-line; line-height: 1.45; }

.toggle { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.track {
  flex: 0 0 auto;
  width: 42px; height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
  border: 1px solid var(--line-strong);
  position: relative;
  transition: background .2s;
  margin-top: 1px;
}
.thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #cbd5e1;
  transition: transform .2s cubic-bezier(.4,.9,.3,1.2), background .2s;
}
.toggle input:checked + .track { background: rgba(110, 231, 183, .32); border-color: rgba(110, 231, 183, .5); }
.toggle input:checked + .track .thumb { transform: translateX(18px); background: var(--accent); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(110, 231, 183, .2); }

.toggle-text strong { display: block; font-size: 13.5px; font-weight: 600; }
.toggle-text small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.slider input[type='range'] { width: 100%; accent-color: var(--accent); }

.play {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231c;
  font: 700 15.5px 'Inter', sans-serif;
  letter-spacing: .2px;
  cursor: pointer;
  transition: transform .14s, filter .14s;
}
.play:hover { filter: brightness(1.08); }
.play:active { transform: scale(.985); }
.play:disabled { opacity: .55; cursor: default; }

.privacy { font-size: 11px; color: #7c8aa3; line-height: 1.55; margin: 14px 0 0; }
.error { margin-top: 12px; font-size: 12.5px; color: var(--danger); text-align: center; }

.settings-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.settings-head h2 { margin: 0; font-size: 18px; letter-spacing: -.3px; }

.you-box { background: rgba(0,0,0,.26); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; margin: 4px 0 14px; }

.keys { font-size: 11.5px; color: var(--muted); display: grid; gap: 6px; }
kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255,255,255,.06);
  font: 600 10.5px 'Inter', monospace;
  margin-right: 2px;
  color: #cbd5e1;
}

#toast {
  position: fixed;
  top: calc(70px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: slideIn .2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ───────────────────────── Mobile ───────────────────────── */
@media (max-width: 760px), (pointer: coarse) {
  #chat { width: min(320px, calc(100vw - 24px)); bottom: calc(170px + var(--safe-b)); }
  #chatLog { max-height: 22vh; }
  #chatForm { display: none; }
  #chat.open { bottom: calc(12px + var(--safe-b)); width: calc(100vw - 24px); z-index: 20; }
  #chat.open #chatForm { display: flex; opacity: 1; }
  #chat.open #chatLog { max-height: 30vh; }
  .card { padding: 20px; border-radius: 20px; }
  .logo h1 { font-size: 22px; }
  .tag .name { font-size: 13px; }
  .tag .place, .tag .time { font-size: 11px; }
  .keys { display: none; }
}

@media (max-height: 460px) {
  #stick { width: 104px; height: 104px; }
  #jumpBtn { width: 66px; height: 66px; }
  #chatBtn { bottom: calc(112px + var(--safe-b)); width: 46px; height: 46px; }
}
