* { box-sizing: border-box; user-select: none; -webkit-user-select: none; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #0d0a08; color: #f2e6cf;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  touch-action: none;
}

#game-wrap { position: relative; width: 100%; height: 100%; overflow: hidden; }
#gl-canvas, #ui-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui-canvas { pointer-events: none; }

/* Boot preload bar */
.boot-wrap { margin-bottom: 12px; }
.boot-wrap.done { display: none; }
.boot-bar { height: 6px; background: #140e09; border: 1px solid #6b4e27; border-radius: 4px; overflow: hidden; }
.boot-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #b87a24, #ffd166); transition: width 0.15s; }
.boot-txt { font-size: 11px; color: #c7b08b; text-align: center; margin-top: 3px; }

/* Auth / Role Select Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, rgba(32,20,10,0.9), rgba(8,6,4,0.97));
}
.overlay.hidden { display: none; }
.panel {
  width: min(420px, 92vw); max-height: 92vh; overflow-y: auto;
  background: linear-gradient(180deg, #251a10 0%, #150e09 100%);
  border: 2px solid #9c743c;
  box-shadow: 0 12px 48px rgba(0,0,0,0.85), inset 0 0 24px rgba(180,120,40,0.12);
  border-radius: 10px; padding: 18px 20px;
}
.panel h1 { margin: 0 0 4px; text-align: center; font-size: 20px; color: #f6cf78; text-shadow: 0 2px 8px #000; }
.panel .sub { text-align: center; font-size: 11px; color: #bda582; margin-bottom: 14px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: #d6bc93; margin-bottom: 3px; }
.field input, .field select {
  width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid #6e522b; background: #0e0906; color: #fff4de; font-size: 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: #e4b45c; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 6px; border: 1px solid #c99748;
  background: linear-gradient(180deg, #8b5a1e 0%, #5c360e 100%);
  color: #fff5dc; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
.btn.full { width: 100%; }
.btn.secondary { background: linear-gradient(180deg, #35281e, #201710); border-color: #775a35; color: #e2cfa9; }
.status-msg { margin-top: 8px; font-size: 12px; min-height: 16px; text-align: center; color: #f0b86e; }
.status-msg.err { color: #ff7b7b; }

.role-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 180px; overflow-y: auto; }
.role-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 7px;
  background: rgba(255,220,160,0.06); border: 1px solid #694c26; cursor: pointer;
}
.role-card:hover { border-color: #ebb95d; background: rgba(255,210,120,0.13); }
.role-name { font-weight: 700; color: #ffe09a; font-size: 14px; }
.role-meta { font-size: 11px; color: #bca583; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud.hidden { display: none; }

/* Compact Top-Left Character Badge */
.hud-top-left {
  position: absolute; top: 8px; left: 8px; pointer-events: auto;
  background: rgba(18, 12, 8, 0.78); border: 1px solid #8c6632; border-radius: 7px;
  padding: 5px 10px; min-width: 155px; backdrop-filter: blur(3px);
}
.char-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.char-head .name { font-weight: 700; color: #ffd97d; font-size: 13px; }
.char-head .lvl { font-size: 11px; color: #9be89b; font-weight: 600; }
.money-row { font-size: 10px; color: #f6d365; margin-top: 2px; display: flex; justify-content: space-between; gap: 8px; }

/* Top-Center Toolbar */
.hud-toolbar {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; pointer-events: auto; flex-wrap: nowrap;
  background: rgba(18, 12, 8, 0.78); border: 1px solid #8c6632; border-radius: 7px;
  padding: 4px 6px; backdrop-filter: blur(3px);
}
.tb-btn {
  background: linear-gradient(180deg, #352416, #1d130b); border: 1px solid #775529;
  color: #f5deb3; border-radius: 4px; padding: 4px 7px; font-size: 11px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.tb-btn:hover { border-color: #f3c463; filter: brightness(1.12); }
.tb-btn small { color: #b59d78; font-weight: 400; margin-left: 2px; }

/* Compact Top-Right Minimap */
.hud-top-right {
  position: absolute; top: 8px; right: 8px; pointer-events: auto;
  background: rgba(18, 12, 8, 0.82); border: 1px solid #8c6632; border-radius: 7px;
  padding: 4px 6px; width: 158px;
}
.hud-top-right.collapsed #minimap-box { display: none; }
.map-head { display: flex; align-items: center; gap: 4px; margin-bottom: 3px; }
.map-title {
  flex: 1; font-size: 11px; font-weight: 700; color: #f7d58b;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: #2b1d12; border: 1px solid #6e5028; color: #e8cfa0; border-radius: 3px;
  font-size: 10px; padding: 1px 5px; cursor: pointer; line-height: 1.3;
}
#minimap-box {
  position: relative; width: 144px; height: 92px; background: #140f0a;
  border: 1px solid #594122; overflow: hidden; cursor: crosshair; border-radius: 4px;
}
#minimap-canvas { width: 100%; height: 100%; display: block; }
.map-coords { display: flex; justify-content: space-between; font-size: 10px; color: #c7b18e; margin-top: 2px; }

/* Bottom-Left Collapsible Chat */
.hud-chat-wrap {
  position: absolute; bottom: 8px; left: 8px; width: min(290px, 38vw);
  display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
#chat-log {
  overflow-y: auto; padding: 4px 7px; font-size: 11px; line-height: 1.35;
  border-radius: 6px; transition: max-height 0.15s;
}
#chat-log.chat-collapsed {
  max-height: 54px; background: rgba(10, 8, 6, 0.35); pointer-events: none;
  overflow: hidden;
}
#chat-log.chat-open {
  max-height: 140px; background: rgba(14, 10, 7, 0.86); border: 1px solid #6e5028;
  pointer-events: auto; user-select: text; -webkit-user-select: text;
}
.chat-line { margin-bottom: 1px; word-break: break-word; text-shadow: 0 1px 2px #000; }
.chat-line.sys { color: #ffd166; }
.chat-line.near { color: #f2ece0; }
.chat-line.world { color: #7ae582; }
.chat-bar-row { display: flex; gap: 4px; align-items: center; pointer-events: auto; }
.chat-toggle-btn {
  background: rgba(24, 16, 10, 0.86); border: 1px solid #8c6632; color: #ffd97d;
  border-radius: 5px; padding: 5px 9px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.chat-input-row {
  flex: 1; display: flex; border: 1px solid #6e5028; border-radius: 5px; overflow: hidden;
  background: rgba(14, 10, 7, 0.9);
}
.chat-input-row.hidden { display: none; }
#chat-input { flex: 1; background: transparent; border: none; color: #fff; padding: 5px 7px; font-size: 11px; outline: none; }
#chat-send { background: #754b18; color: #ffe7b3; border: none; padding: 5px 9px; font-size: 11px; font-weight: 600; cursor: pointer; }

/* Bottom-Center Classic Vo Lam Dock (HP Orb + Skills + MP Orb) */
.vl-dock {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 8px; pointer-events: auto;
}
.orb {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid #c99748; background: #140d08; overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.85), inset 0 0 12px rgba(0,0,0,0.9);
  flex-shrink: 0;
}
.orb-fill {
  position: absolute; left: 0; right: 0; bottom: 0; transition: height 0.18s ease;
}
.hp-orb .orb-fill { background: radial-gradient(circle at 35% 30%, #ff5c5c, #a81010 75%); }
.mp-orb .orb-fill { background: radial-gradient(circle at 35% 30%, #52a8ff, #114099 75%); }
.orb-txt {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000;
}
.dock-center {
  display: flex; flex-direction: column; gap: 3px;
  background: rgba(18, 12, 8, 0.86); border: 1px solid #8c6632; border-radius: 7px;
  padding: 4px 6px;
}
.dock-stamina { height: 4px; background: #1a120c; border-radius: 2px; overflow: hidden; }
.sp-fill { height: 100%; background: linear-gradient(90deg, #b58900, #ffd166); transition: width 0.18s; }
.dock-skills { display: flex; gap: 4px; align-items: center; }
.skill-btn {
  min-width: 42px; height: 38px; border-radius: 5px; border: 1px solid #7d5b2d;
  background: linear-gradient(180deg, #322215, #1b120b); color: #ffe5a8;
  font-size: 10px; font-weight: 700; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; justify-content: center; padding: 2px 5px;
}
.skill-btn.active { border-color: #ffd166; box-shadow: 0 0 8px rgba(255,209,102,0.55); }
.skill-btn small { font-size: 9px; color: #bba37d; font-weight: 400; }

/* NPC Dialog & Floating Windows */
#npc-dialog, .jx-win {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, 92vw); max-height: 76vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #241910, #140d08); border: 2px solid #b3843c;
  border-radius: 9px; box-shadow: 0 14px 48px rgba(0,0,0,0.88); pointer-events: auto; z-index: 40;
}
#npc-dialog { padding: 14px 16px; overflow-y: auto; }
#npc-dialog.hidden, .jx-win.hidden { display: none; }
#npc-dialog-text { font-size: 13px; line-height: 1.5; color: #f7e9cf; margin-bottom: 10px; white-space: pre-wrap; }
.dlg-opts { display: flex; flex-direction: column; gap: 5px; }
.dlg-opt {
  text-align: left; padding: 7px 11px; border-radius: 6px;
  border: 1px solid #7a5829; background: rgba(255,215,130,0.08);
  color: #ffe08a; font-size: 12px; cursor: pointer;
}
.dlg-opt:hover { background: rgba(255,215,130,0.2); border-color: #f3c463; }

.jx-win-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid #5c4221;
  font-weight: 700; color: #ffd97d; font-size: 13px;
}
.jx-win-close { background: none; border: none; color: #d6bc93; font-size: 16px; cursor: pointer; }
.jx-win-body { padding: 10px 12px; overflow-y: auto; font-size: 12px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; margin-bottom: 8px; }
.stat-grid div { display: flex; justify-content: space-between; background: rgba(255,220,160,0.05); padding: 4px 7px; border-radius: 4px; }
.attr-list { display: flex; flex-direction: column; gap: 5px; }
.attr-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px; background: rgba(255,220,160,0.06); border-radius: 5px; }
.sec-hdr { font-size: 11px; font-weight: 700; color: #f0c975; margin: 7px 0 4px; }
.item-list { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.item-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 5px 8px; background: rgba(255,220,160,0.06); border: 1px solid #4d371c; border-radius: 5px;
}
.item-name { font-weight: 600; color: #f6e7c8; font-size: 12px; }
.item-name.gold { color: #ffd700; }
.item-sub { font-size: 10px; color: #a89272; }
.item-acts { display: flex; gap: 4px; flex-shrink: 0; }
.tag { font-size: 9px; background: #4a3518; color: #ffd97d; padding: 1px 4px; border-radius: 3px; margin-left: 4px; }
.empty-txt { text-align: center; color: #9c8666; padding: 10px 0; font-size: 12px; }

.mini-btn {
  padding: 4px 8px; border-radius: 4px; border: 1px solid #8a642e;
  background: linear-gradient(180deg, #5e3d16, #3d250b); color: #fff0cc;
  font-size: 11px; font-weight: 600; cursor: pointer;
}
.mini-btn:hover { filter: brightness(1.15); }
.mini-btn.danger { background: linear-gradient(180deg, #6e2020, #421111); border-color: #a83c3c; }

.ctx-menu {
  position: fixed; z-index: 45; min-width: 150px; pointer-events: auto;
  background: #1c130c; border: 1px solid #b3843c; border-radius: 7px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.85); overflow: hidden;
}
.ctx-menu.hidden { display: none; }
.ctx-title { padding: 5px 10px; font-size: 12px; font-weight: 700; color: #ffd97d; border-bottom: 1px solid #4c371c; background: #291c11; }
.ctx-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: #f0e2c8; padding: 7px 10px; font-size: 12px; cursor: pointer;
}
.ctx-item:hover { background: rgba(255,210,120,0.16); color: #ffe08a; }

.invite-bar {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 42;
  display: flex; align-items: center; gap: 8px; pointer-events: auto;
  background: rgba(34, 23, 12, 0.95); border: 1px solid #e0ad52; border-radius: 7px;
  padding: 7px 12px; font-size: 12px; color: #ffe5a8; box-shadow: 0 6px 20px rgba(0,0,0,0.8);
}
.invite-bar.hidden { display: none; }

@media (max-width: 900px), (max-height: 500px) {
  .tb-btn small { display: none; }
  .tb-btn { padding: 3px 6px; font-size: 10px; }
  .hud-top-left { padding: 4px 7px; min-width: 130px; }
  .hud-top-right { width: 128px; }
  #minimap-box { width: 114px; height: 70px; }
  .orb { width: 42px; height: 42px; }
  .skill-btn { min-width: 36px; height: 32px; font-size: 9px; padding: 1px 4px; }
  .hud-chat-wrap { width: min(210px, 32vw); bottom: 118px; }
  .joystick-zone { display: flex; }
}

/* Mobile Virtual Joystick */
.joystick-zone {
  position: absolute; bottom: 16px; left: 16px; width: 96px; height: 96px;
  display: none; align-items: center; justify-content: center;
  pointer-events: auto; touch-action: none; z-index: 25;
}
.joystick-base {
  width: 84px; height: 84px; border-radius: 50%;
  background: rgba(24, 16, 10, 0.45); border: 2px solid rgba(201, 151, 72, 0.65);
  position: relative; display: flex; align-items: center; justify-content: center;
}
.joystick-knob {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f5cf7a, #8b5a1e);
  border: 1px solid #ffe4a3; box-shadow: 0 2px 8px rgba(0,0,0,0.7);
  transform: translate(0px, 0px); pointer-events: none;
}
@media (pointer: coarse) {
  .joystick-zone { display: flex; }
  .hud-chat-wrap { bottom: 118px; }
}
