:root {
  --bg: #0b0e17;
  --panel: rgba(18, 22, 34, 0.92);
  --accent: #5b8cff;
  --accent2: #9b5bff;
  --text: #e8ecf5;
  --muted: #8a93a8;
  --ok: #46d39a;
  --err: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Login overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  z-index: 10;
  isolation: isolate;
}

/* Concept art on its own layer so we can brighten/saturate it back to full
   quality without touching the card. Splash lives at public/img/bitsoul3d.png. */
.overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('/img/bitsoul-login-bg.png?v=4') center/cover no-repeat;
  filter: brightness(1.12) saturate(1.14) contrast(1.04);
  z-index: 0;
}

/* Very soft vignette + a gentle glow pooled behind the card only, so the art
   stays bright everywhere except a subtle halo that keeps the form readable. */
.overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(46% 42% at 50% 47%, rgba(8, 12, 24, 0.45), rgba(8, 12, 24, 0) 70%),
    radial-gradient(130% 110% at 50% 50%, rgba(4, 6, 14, 0) 60%, rgba(4, 6, 14, 0.32));
  z-index: 1;
  pointer-events: none;
}

.overlay > * { position: relative; z-index: 2; }

.panel {
  width: min(92vw, 380px);
  background:
    linear-gradient(180deg, rgba(20, 27, 48, 0.42), rgba(10, 14, 26, 0.52));
  border: 1px solid rgba(140, 185, 255, 0.34);
  border-radius: 18px;
  padding: 28px 26px;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(140, 185, 255, 0.1) inset,
    0 0 46px rgba(80, 130, 255, 0.26);
  backdrop-filter: blur(9px) saturate(1.15);
  -webkit-backdrop-filter: blur(9px) saturate(1.15);
}

.panel h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 5px;
  font-weight: 800;
  background: linear-gradient(90deg, #8fc0ff, #c39bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(140, 170, 255, 0.5);
  filter: drop-shadow(0 0 16px rgba(150, 130, 255, 0.4));
}

.panel h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline { margin: 4px 0 20px; color: var(--muted); font-size: 13px; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  background: rgba(8, 12, 22, 0.72);
  border: 1px solid rgba(140, 175, 255, 0.18);
  border-radius: 9px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18); }

.account { margin: 6px 0 16px; }
.account summary { cursor: pointer; color: var(--muted); font-size: 12px; user-select: none; }
.account summary:hover { color: var(--text); }

button {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}
button:active { transform: translateY(1px); }

.primary {
  color: white;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.primary:hover { filter: brightness(1.08); }

.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(91, 140, 255, 0.4);
  margin-top: 8px;
}
.ghost.small { margin-top: 0; padding: 9px; font-size: 12px; }

.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 12px; color: var(--muted); font-size: 11px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.1);
}
.guest { gap: 8px; }

.status { min-height: 18px; margin: 12px 0 0; font-size: 12px; text-align: center; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.hint { color: rgba(220, 228, 245, 0.82); font-size: 11px; text-shadow: 0 1px 6px rgba(0,0,0,0.7); }

/* ---------- In-world HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

#topbar {
  position: absolute;
  top: 12px; left: 12px;
  display: flex; gap: 14px; align-items: center;
  background: rgba(11, 14, 23, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
}
#gridName { font-weight: 700; color: var(--accent); }
#onlineCount { color: var(--muted); }
#balance { color: #ffd24a; font-weight: 700; }
#logoutBtn {
  margin-left: 4px;
  color: #ffd0d0; font-weight: 700; font-size: 12px;
  background: rgba(255, 80, 80, 0.12);
  border: 1px solid rgba(255, 90, 90, 0.45);
  border-radius: 999px; padding: 3px 11px;
  cursor: pointer; pointer-events: auto;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#logoutBtn:hover { background: rgba(255, 80, 80, 0.28); border-color: rgba(255, 120, 120, 0.8); }
#multBadge {
  display: none;
  color: #d9c6ff; font-weight: 800; font-size: 12px;
  background: linear-gradient(180deg, rgba(155,107,255,0.35), rgba(106,60,255,0.25));
  border: 1px solid rgba(155,107,255,0.7);
  border-radius: 999px; padding: 2px 9px;
  box-shadow: 0 0 12px rgba(155,107,255,0.5);
  animation: multPulse 1.1s ease-in-out infinite;
}
#multBadge.show { display: inline-block; }
@keyframes multPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* Coin pickup toast (fades up near top-centre) */
#bscToast {
  position: absolute;
  top: 64px; left: 50%; transform: translate(-50%, 6px);
  background: rgba(11, 14, 23, 0.78);
  border: 1px solid rgba(255, 210, 74, 0.7);
  color: #ffd24a; font-weight: 800; font-size: 16px;
  border-radius: 999px; padding: 6px 16px;
  pointer-events: none; opacity: 0;
  text-shadow: 0 0 10px rgba(255,174,0,0.6);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
#bscToast.show { opacity: 1; transform: translate(-50%, 0); }
#bscToast.big { color: #d9c6ff; border-color: rgba(155,107,255,0.8); font-size: 18px; text-shadow: 0 0 12px rgba(155,107,255,0.7); }

/* Always-on wealth leaderboard (top-right, small) */
#leaderboard {
  position: absolute;
  top: 12px; right: 12px;
  width: 178px;
  background: rgba(11, 14, 23, 0.62);
  border: 1px solid rgba(255, 210, 74, 0.28);
  border-radius: 10px;
  padding: 8px 10px 9px;
  font-size: 11px;
  pointer-events: auto;
  backdrop-filter: blur(3px);
}
#lbHead { color: #ffd24a; font-weight: 800; font-size: 11px; letter-spacing: 0.3px; margin-bottom: 5px; }
#lbList { list-style: none; margin: 0; padding: 0; }
#lbList li { display: flex; align-items: baseline; gap: 5px; padding: 1.5px 0; color: #dfe3ec; }
#lbList li .lb-rank { color: var(--muted); width: 14px; font-weight: 700; flex: none; }
#lbList li .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lbList li .lb-amt { color: #ffd24a; font-weight: 700; flex: none; }
#lbList li.me { color: #7fe7ff; }
#lbList li.me .lb-amt { color: #7fe7ff; }
#lbList li:nth-child(1) .lb-rank { color: #ffd24a; }
#lbMoreBtn {
  margin-top: 7px; width: 100%;
  background: rgba(255, 210, 74, 0.14);
  border: 1px solid rgba(255, 210, 74, 0.4);
  color: #ffe9a8; font-weight: 700; font-size: 11px;
  border-radius: 7px; padding: 4px 0; cursor: pointer;
  pointer-events: auto;
}
#lbMoreBtn:hover { background: rgba(255, 210, 74, 0.26); }

/* Top 100 leaderboard window list */
.lb-full { list-style: none; margin: 0; padding: 0; max-height: 52vh; overflow-y: auto; }
.lb-full li { display: flex; align-items: baseline; gap: 8px; padding: 4px 6px; border-radius: 6px; font-size: 13px; }
.lb-full li:nth-child(odd) { background: rgba(255,255,255,0.03); }
.lb-full li .lb-rank { color: var(--muted); width: 30px; font-weight: 700; flex: none; text-align: right; }
.lb-full li .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-full li .lb-amt { color: #ffd24a; font-weight: 700; flex: none; }
.lb-full li.top1 .lb-rank { color: #ffd24a; }
.lb-full li.top2 .lb-rank { color: #cfd3da; }
.lb-full li.top3 .lb-rank { color: #cd7f32; }
.lb-full li.me { background: rgba(127,231,255,0.16); outline: 1px solid rgba(127,231,255,0.5); }
.lb-full li.me .lb-name, .lb-full li.me .lb-amt { color: #7fe7ff; }
.lb-self {
  margin-top: 8px; padding: 7px 8px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex; align-items: baseline; gap: 8px;
  color: #7fe7ff; font-weight: 700; font-size: 13px;
}
.lb-self .lb-rank { width: 30px; text-align: right; flex: none; }
.lb-self .lb-name { flex: 1; }

/* Emote / gesture bar + fly toggle (right side, vertical) */
#emotebar {
  position: absolute;
  right: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(11, 14, 23, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 8px;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}
#emotebar button {
  width: 56px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 10px;
  padding: 6px 4px; font-size: 18px; line-height: 1; cursor: pointer;
}
#emotebar button span { font-size: 10px; color: var(--muted); font-weight: 600; }
#emotebar button:hover { background: rgba(91, 140, 255, 0.14); }
#emotebar button.active { background: rgba(91, 140, 255, 0.24); border-color: rgba(91,140,255,0.5); }
#emotebar button.active span { color: var(--text); }
#flyBtn { margin-top: 4px; border-top: 1px solid rgba(255,255,255,0.12) !important; padding-top: 8px !important; }
#flyBtn.active { background: rgba(143, 255, 208, 0.22); border-color: rgba(143,255,208,0.6); }
#flyBtn.active span { color: #8fffd0; }
#musicBtn.active { background: rgba(155, 107, 255, 0.22); border-color: rgba(155,107,255,0.6); }
#musicBtn.active span { color: #c6a8ff; }

#driveHint {
  position: fixed; left: 50%; bottom: 140px; transform: translateX(-50%);
  display: none; z-index: 60; pointer-events: none;
  padding: 7px 16px; border-radius: 999px;
  background: rgba(12, 16, 30, 0.82); border: 1px solid rgba(143,255,208,0.55);
  color: #d8ffe9; font-size: 14px; font-weight: 600; letter-spacing: 0.3px;
  text-shadow: 0 0 10px rgba(143,255,208,0.6); box-shadow: 0 4px 18px rgba(0,0,0,0.4);
}


#chat {
  position: absolute;
  bottom: 14px; left: 12px;
  width: min(46vw, 420px);
  pointer-events: auto;
}
#chatlog {
  max-height: 28vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 8px;
  padding-right: 4px;
  font-size: 13px;
  mask-image: linear-gradient(to top, black 70%, transparent);
}
#chatlog .line { background: rgba(11, 14, 23, 0.55); border-radius: 8px; padding: 4px 9px; width: fit-content; max-width: 100%; }
#chatlog .line .who { color: var(--accent); font-weight: 600; margin-right: 6px; }
#chatlog .line.sys .who { color: var(--accent2); }

#chatform { display: flex; }
#chatinput {
  width: 100%;
  background: rgba(11, 14, 23, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}
#chatinput:focus { opacity: 1; border-color: var(--accent); }

#controls-help {
  position: absolute;
  bottom: 14px; right: 14px;
  background: rgba(11, 14, 23, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
}
#controls-help strong { color: var(--text); }

/* ---------- Bottom tool dock ---------- */
#toolbar {
  position: absolute;
  bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px;
  background: rgba(11, 14, 23, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 8px;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}
.tool {
  width: auto;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 18px;
  line-height: 1;
}
.tool span { font-size: 10px; color: var(--muted); font-weight: 600; }
.tool:hover { background: rgba(91, 140, 255, 0.14); }
.tool.active { background: rgba(91, 140, 255, 0.22); border-color: rgba(91,140,255,0.5); }
.tool.active span { color: var(--text); }

/* ---------- Floating windows ---------- */
.window {
  position: absolute;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  overflow: hidden;
  z-index: 6;
}
.win-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  cursor: grab;
  font-size: 13px; font-weight: 700;
  user-select: none;
}
.win-head:active { cursor: grabbing; }
.win-close { width: auto; background: transparent; color: var(--muted); padding: 2px 6px; font-size: 14px; }
.win-close:hover { color: var(--err); }
.win-body { padding: 12px; max-height: 60vh; overflow-y: auto; }

.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 12px; color: var(--text); }
.row.label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin: 10px 0 4px; }
.row input[type="range"] { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
.muted.small { font-size: 11px; }
.window hr { border: none; border-top: 1px solid rgba(255,255,255,0.08); margin: 12px 0; }

.grid2, .grid3, .grid4, .grid5 { display: grid; gap: 6px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }
.grid4 { grid-template-columns: 1fr 1fr; }
.grid5 { grid-template-columns: 1fr 1fr 1fr; }

.chip, .move button, .grid3 button {
  width: auto; background: #0e1320; color: var(--text);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 8px;
  padding: 9px 6px; font-size: 12px; font-weight: 600;
}
.chip:hover, .move button:hover, .grid3 button:hover { border-color: var(--accent); }
.chip.active { background: rgba(91,140,255,0.22); border-color: var(--accent); }
.danger { background: rgba(255,107,107,0.14); color: var(--err); border: 1px solid rgba(255,107,107,0.4); margin-top: 10px; }
input[type="color"] { width: 40px; height: 26px; padding: 0; border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; background: none; }
.mapcanvas { width: 100%; border-radius: 8px; background: #0e1320; border: 1px solid rgba(255,255,255,0.1); }

/* Travel · Places directory */
.travel-search {
  width: 100%; box-sizing: border-box; margin-bottom: 8px;
  background: #0e1320; color: var(--text);
  border: 1px solid rgba(140,175,255,0.22); border-radius: 8px;
  padding: 9px 10px; font-size: 13px;
}
.travel-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,0.18); }
.travel-cats { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.travel-cats .cat { padding: 5px 9px; font-size: 11px; }
.travel-list { display: flex; flex-direction: column; gap: 7px; }
.travel-item {
  display: flex; align-items: center; gap: 8px;
  background: rgba(14,19,32,0.72); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 9px 10px;
}
.travel-item.here { border-color: rgba(57,255,122,0.5); box-shadow: 0 0 0 1px rgba(57,255,122,0.25) inset; }
.travel-item .ti-main { flex: 1; min-width: 0; }
.travel-item .ti-name { font-size: 13px; font-weight: 700; color: var(--text); }
.travel-item .ti-blurb { font-size: 11px; color: var(--muted); margin: 2px 0 3px; line-height: 1.3; }
.travel-item .ti-meta { font-size: 10.5px; color: rgba(160,180,220,0.85); }
.travel-item .ti-cat {
  display: inline-block; padding: 1px 6px; border-radius: 6px;
  background: rgba(91,140,255,0.18); color: #bcd2ff; font-weight: 600;
}
.travel-item .ti-actions { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.travel-item .ti-actions .chip { padding: 7px 10px; white-space: nowrap; }
.travel-item .ti-actions .chip:disabled { opacity: 0.55; cursor: default; border-color: rgba(255,255,255,0.12); }

/* ---------- Inventory tree ---------- */
.tree { font-size: 13px; }
.tree .folder > .label { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.tree .folder > .label:hover { background: rgba(255,255,255,0.05); }
.tree .children { margin-left: 16px; border-left: 1px solid rgba(255,255,255,0.08); padding-left: 4px; }
.tree .item { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; color: var(--muted); cursor: default; }
.tree .item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.tree .caret { width: 12px; display: inline-block; transition: transform 0.1s; }
.tree .folder.collapsed > .children { display: none; }
.tree .folder.collapsed > .label .caret { transform: rotate(-90deg); }

/* =====================================================================
   Mobile / touch controls
   Hidden by default; app.js adds `touch` to <body> on phones & tablets.
   Desktop never renders any of this, so mouse/keyboard play is untouched.
   ===================================================================== */
#mobileControls { display: none; }

body.touch #mobileControls {
  display: block;
  position: absolute; inset: 0;
  pointer-events: none;          /* children opt back in */
  z-index: 40;
}

/* Hide the keyboard-only hint text on touch, show a tiny touch tip instead */
body.touch #controls-help { font-size: 0; color: var(--muted); }
body.touch #controls-help strong { display: none; }
body.touch #controls-help::before {
  content: "Stick: move · Drag: look";
  font-size: 10px;
}

/* ---- left analog stick ---- */
#mJoy {
  position: absolute;
  left: calc(20px + env(safe-area-inset-left, 0px));
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  width: 132px; height: 132px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(91,140,255,0.10), rgba(11,14,23,0.40));
  border: 1.5px solid rgba(255,255,255,0.18);
  box-shadow: 0 6px 22px rgba(0,0,0,0.4), inset 0 0 18px rgba(0,0,0,0.35);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}
#mJoyKnob {
  position: absolute; left: 50%; top: 50%;
  width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #aac4ff, #5b8cff 70%);
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 0 3px 10px rgba(0,0,0,0.5);
  transition: transform 0.04s linear;
}

/* ---- right action buttons ---- */
#mActions {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  width: 168px; height: 168px;
  pointer-events: none;
}
.mbtn {
  position: absolute;
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1;
  color: var(--text);
  background: rgba(11,14,23,0.62);
  border: 1.5px solid rgba(255,255,255,0.18);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  cursor: pointer;
}
.mbtn:active { transform: scale(0.92); background: rgba(91,140,255,0.30); }
.mbtn.jump  { right: 0;   bottom: 52px; }
.mbtn.act   { right: 64px; bottom: 8px; background: rgba(143,255,208,0.18); border-color: rgba(143,255,208,0.5); }
.mbtn.alt   { right: 90px; bottom: 78px; width: 52px; height: 52px; font-size: 22px; }
#mFly       { right: 30px; bottom: 116px; }
#mFly.active { background: rgba(143,255,208,0.28); border-color: rgba(143,255,208,0.7); }

/* ---- shrink & reflow the HUD on small / touch screens ---- */
@media (max-width: 820px), (pointer: coarse) {
  #topbar { top: 8px; left: 8px; gap: 9px; padding: 6px 10px; font-size: 11px; }

  /* Emote bar: a compact horizontal strip across the top so it never collides
     with the right-side action pad. Labels hidden to save room. */
  #emotebar {
    top: 56px; right: 8px; transform: none;
    flex-direction: row; flex-wrap: wrap; justify-content: flex-end;
    max-width: 60vw; gap: 4px; padding: 5px; border-radius: 12px;
  }
  #emotebar button { width: 42px; padding: 6px 2px; font-size: 17px; }
  #emotebar button span { display: none; }
  #flyBtn { margin-top: 0 !important; border-top: none !important; padding-top: 6px !important; }

  /* Tool dock: smaller, scrollable, lifted above the joystick/buttons. */
  #toolbar {
    bottom: 8px; gap: 4px; padding: 5px; max-width: 96vw;
    overflow-x: auto; justify-content: flex-start;
  }
  .tool { padding: 6px 8px; font-size: 16px; }
  .tool span { font-size: 9px; }

  /* Chat tucked to the left, narrower and shorter so it stays out of the way. */
  #chat { width: min(58vw, 300px); bottom: 64px; left: 8px; }
  #chatlog { max-height: 18vh; font-size: 12px; }
  #chatinput { padding: 7px 10px; font-size: 12px; }

  #controls-help { bottom: 64px; right: 8px; padding: 5px 8px; }

  /* Floating windows go (nearly) full-screen so they're usable on a phone. */
  .window {
    left: 50% !important; top: 50% !important;
    transform: translate(-50%, -50%);
    width: min(94vw, 420px) !important;
    max-height: 80vh; overflow-y: auto;
  }
}

/* Same compact reflow for any device we've flagged as touch (covers touch
   laptops/tablets whose pixel width is wide but still want thumb-friendly UI). */
body.touch #topbar { top: 8px; left: 8px; gap: 9px; padding: 6px 10px; font-size: 11px; }
body.touch #emotebar {
  top: 56px; right: 8px; transform: none;
  flex-direction: row; flex-wrap: wrap; justify-content: flex-end;
  max-width: 60vw; gap: 4px; padding: 5px; border-radius: 12px;
}
body.touch #emotebar button { width: 46px; padding: 6px 2px; font-size: 18px; }
body.touch #emotebar button span { display: none; }
body.touch #flyBtn { margin-top: 0 !important; border-top: none !important; padding-top: 6px !important; }
body.touch #toolbar { bottom: 8px; gap: 4px; padding: 5px; max-width: 96vw; overflow-x: auto; justify-content: flex-start; }
body.touch .tool { padding: 6px 8px; font-size: 16px; }
body.touch .tool span { font-size: 9px; }
body.touch #chat { width: min(56vw, 260px); bottom: 240px; left: 8px; }
body.touch #chatlog { max-height: 20vh; font-size: 12px; }
body.touch #controls-help { bottom: 64px; right: 8px; padding: 5px 8px; }

/* Short / letterboxed viewports (e.g. an embedded preview pane): drop the
   keyboard hint and shrink the chat so the bottom HUD never stacks up. */
@media (max-height: 560px) {
  #controls-help { display: none; }
  #chatlog { max-height: 20vh; }
  #chat { bottom: 10px; }
}
