:root {
  --bg: #06080e;
  --surface: rgba(11, 16, 28, 0.84);
  --surface-solid: #0d1324;
  --line: rgba(255, 255, 255, 0.12);
  --line-warm: rgba(255, 122, 46, 0.45);
  --text: #f4f6fb;
  --text2: #a6b1c6;
  --accent: #ff7a2e;
  --accent2: #ffb37a;
  --ok: #4ade80;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

/* Pixel rendering crispness */
.px { image-rendering: pixelated; image-rendering: crisp-edges; }

/* Loading screen */
#loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: radial-gradient(circle at 50% 42%, #131c36 0%, #06080e 72%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}
#loader.hide { opacity: 0; visibility: hidden; pointer-events: none; }
#loader img { width: 96px; height: 96px; animation: floaty 1.6s ease-in-out infinite; }
#loader p { margin: 0; color: var(--accent2); font-weight: 600; letter-spacing: 0.02em; }
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

/* 3D floating zone labels */
#labels-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}
.label3d {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  background: rgba(6, 8, 14, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font: 600 11px/1.15 inherit;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, background 0.2s;
}
.label3d:hover, .label3d.near {
  border-color: var(--accent);
  background: rgba(255, 122, 46, 0.22);
  color: #fff;
}

/* Top HUD */
.hud-top {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.hud-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 12px;
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  text-decoration: none;
  color: inherit;
}
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand strong { display: block; font-size: 14px; letter-spacing: 0.03em; }
.brand span { display: block; font-size: 11.5px; color: var(--accent2); }
.stamp-badge {
  font: 700 12px/1 ui-monospace, monospace;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 122, 46, 0.14);
  border: 1px solid var(--line-warm);
  color: var(--accent2);
}
.hbtn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font: 600 12.5px/1.2 inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.hbtn:hover { background: rgba(255, 255, 255, 0.12); border-color: var(--accent2); }
.hbtn.on { background: rgba(255, 122, 46, 0.22); border-color: var(--accent); color: var(--accent2); }

.zone-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  pointer-events: auto;
  padding-bottom: 2px;
}
.zone-pills::-webkit-scrollbar { display: none; }
.zpill {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text2);
  border-radius: 999px;
  padding: 5px 12px;
  font: 600 12px/1.2 inherit;
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.zpill:hover { color: var(--text); border-color: var(--accent); }
.zpill.done { border-color: rgba(74, 222, 128, 0.45); color: #bbf7d0; }

/* Bottom HUD */
#near-pill {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translate(-50%, 10px);
  z-index: 25;
  background: var(--accent);
  color: #1b0b00;
  font: 700 12.5px/1.2 inherit;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid #ffe4cc;
  box-shadow: 0 10px 30px rgba(255, 122, 46, 0.45);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#near-pill.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }

#controls-hint {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(6, 8, 14, 0.72);
  border: 1px solid var(--line);
  color: var(--text2);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

#toast {
  position: fixed;
  top: 118px;
  left: 50%;
  transform: translate(-50%, -10px);
  z-index: 45;
  background: var(--surface-solid);
  border: 1px solid var(--accent);
  color: var(--accent2);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* RPG Pixel Dialog Box */
#dlg-box {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 24px);
  width: min(740px, calc(100vw - 24px));
  z-index: 35;
  background: rgba(10, 15, 30, 0.94);
  border: 2px solid var(--accent);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), 0 0 0 2px #1b2544;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
}
#dlg-box.open { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.dlg-avatar {
  width: 84px;
  height: 84px;
  flex: none;
  border-radius: 12px;
  background: radial-gradient(circle, rgba(255, 122, 46, 0.22), #070b15);
  border: 1px solid var(--line-warm);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.dlg-avatar img { width: 76px; height: 76px; object-fit: contain; }
.dlg-avatar img.talking { animation: talkbob 0.22s steps(2) infinite; }
@keyframes talkbob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}
.dlg-content { flex: 1; min-width: 0; }
.dlg-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
#dlg-speaker { font-weight: 700; font-size: 13px; color: var(--accent2); text-transform: uppercase; letter-spacing: 0.04em; }
#dlg-text { margin: 0 0 12px; font-size: 15px; line-height: 1.55; color: var(--text); min-height: 46px; cursor: pointer; user-select: text; }
.dlg-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
#dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Modal */
#modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(3, 5, 11, 0.78);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#modal.open { opacity: 1; pointer-events: auto; }
.modal-card {
  width: min(860px, 100%);
  max-height: 86vh;
  background: #0b1121;
  border: 1px solid var(--line-warm);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.85);
}
.modal-hdr {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.modal-hdr h2 { margin: 0; font-size: 20px; }
.modal-hdr p { margin: 4px 0 0; font-size: 13.5px; color: var(--text2); }
#modal-body { padding: 18px 20px; overflow-y: auto; user-select: text; }

.pgrid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.pcard {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.phead { display: flex; gap: 12px; align-items: center; }
.phead img { width: 46px; height: 46px; border-radius: 11px; flex: none; }
.phead h3 { margin: 0; font-size: 16px; }
.plat { font-size: 12px; color: var(--text2); }
.pcard p { margin: 0; font-size: 13.5px; color: var(--text2); line-height: 1.5; }
.prow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.slist { display: flex; flex-direction: column; gap: 10px; }
.srow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.scode { font: 700 11.5px/1 ui-monospace, monospace; color: var(--accent2); margin-bottom: 4px; }
.sname { font-weight: 700; font-size: 15px; }
.sright { display: flex; align-items: center; gap: 12px; }
.sprice { font-weight: 700; color: var(--accent); font-size: 14px; }
.zeus-banner {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}
.badge-ok {
  font: 700 11px/1 ui-monospace, monospace;
  color: var(--ok);
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.35);
  padding: 5px 9px;
  border-radius: 999px;
}
.qactions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.postcard-img { width: 100%; border-radius: 12px; border: 1px solid var(--line-warm); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font: 600 13px/1 inherit;
  padding: 9px 15px;
}
.btn.sm { padding: 7px 13px; font-size: 12.5px; }
.btn.pri { background: var(--accent); border-color: transparent; color: #1b0b00; font-weight: 700; }
.btn:hover { opacity: 0.9; }

/* Touch joystick (shown on touch devices) */
#joy-zone {
  position: fixed;
  bottom: 52px;
  left: 18px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(11, 16, 28, 0.65);
  border: 1px solid var(--line-warm);
  z-index: 22;
  display: none;
  place-items: center;
  touch-action: none;
}
#joy-knob {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 122, 46, 0.85);
  border: 2px solid #ffe4cc;
  pointer-events: none;
}
@media (pointer: coarse) {
  #joy-zone { display: grid; }
}
@media (max-width: 640px) {
  #toast { top: 158px; font-size: 12px; }
  #dlg-box { flex-direction: column; gap: 10px; }
  .dlg-avatar { width: 64px; height: 64px; }
  .dlg-avatar img { width: 58px; height: 58px; }
  .hud-bar { padding: 7px 10px; gap: 6px; }
  .hbtn { padding: 6px 9px; font-size: 11.5px; }
}
