:root {
  --bg: #101418;
  --panel: #171c21;
  --panel-2: #1f262d;
  --line: #2b333b;
  --text: #e9edf0;
  --dim: #94a1ad;
  --accent: #e08a3e;
  --me: #3dd68c;
  --mate: #4fb3ff;
  --veh: #ffb648;
  --veh-squad: #b48cff;
  --base: #ff6b8b;
  --death: #f4f1e8;
  --err: #ff6b6b;
  --trader: #39ff14;
  --zone: #ffd23f;
  --hot: #ff4d4d;
  --jail: #8b95a7;
  --cargo: #36c5ff;
  --stash: #ffcc00;
  --top-h: 54px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; overflow: hidden; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.dim { color: var(--dim); }

#top { position: fixed; inset: 0 0 auto 0; height: var(--top-h); display: flex; align-items: center; gap: 10px;
  padding: 0 12px; padding-top: env(safe-area-inset-top); background: var(--panel); border-bottom: 1px solid var(--line); z-index: 20; }
#top .brand { width: 28px; height: 28px; border-radius: 6px; }
#top .titles { flex: 1; min-width: 0; line-height: 1.2; }
#communityName { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#whoami { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; align-items: center; }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 36px; }
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1004; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #6b2a2a; }

#main { position: fixed; inset: var(--top-h) 0 0 0; display: flex; }
#viewport { position: relative; flex: 1; overflow: hidden; background: #0b2233; touch-action: none; cursor: grab; }
#viewport.dragging { cursor: grabbing; }
#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; --s: 1; }
#preview { position: absolute; top: 0; left: 0; user-select: none; pointer-events: none; max-width: none; }
#tiles { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; }  /* keeps tiles UNDER the markers */
#markers { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2; }

.mk { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; border-radius: 50%;
  width: 16px; height: 16px; border: 2px solid #0b0f12; box-shadow: 0 0 0 1px rgba(255,255,255,.35); }
.mk.me { width: 20px; height: 20px; background: var(--me); box-shadow: 0 0 0 3px rgba(61,214,140,.35), 0 0 12px rgba(61,214,140,.8); z-index: 5; }
.mk.mate { background: var(--mate); z-index: 4; }
.mk.veh, .mk.veh-squad { border-radius: 5px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; z-index: 3; }
.mk.veh { background: var(--veh); }
.mk.veh-squad { background: var(--veh-squad); }
.mk.veh img, .mk.veh-squad img { width: 18px; height: 18px; object-fit: contain; filter: drop-shadow(0 0 1px #000); }
.mk.base { background: var(--base); border-radius: 3px; transform: translate(-50%, -50%) rotate(45deg); width: 15px; height: 15px; }
.mk.death { background: #2a0d0d; border: 2px solid var(--death); width: 18px; height: 18px; }
.mk.death::before, .mk.death::after { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 2px;
  background: var(--death); transform: translate(-50%, -50%) rotate(45deg); }
.mk.death::after { transform: translate(-50%, -50%) rotate(-45deg); }
.mk.pin { border-radius: 50% 50% 50% 0; transform: translate(-50%, -100%) rotate(-45deg); width: 18px; height: 18px; z-index: 4; }
.label { position: absolute; transform: translate(14px, -50%); white-space: nowrap; font-size: 12px; font-weight: 700;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000; pointer-events: none; }
.area { position: absolute; transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none; }
.area.base { background: rgba(255,107,139,.12); border: 2px solid rgba(255,107,139,.75); }
.area.death { background: rgba(244,241,232,.1); border: 2px dashed rgba(244,241,232,.85); }
@media (pointer: coarse) { .mk { width: 22px; height: 22px; } .mk.veh, .mk.veh-squad { width: 28px; height: 28px; } .mk.me { width: 24px; height: 24px; } }

.pin-yellow { background: #ffd23f; } .pin-red { background: #ff5a5a; } .pin-green { background: #4ddc7a; }
.pin-blue { background: #4fa3ff; } .pin-purple { background: #c07bff; } .pin-white { background: #f2f2f2; }

#status { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(16,20,24,.92);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 13px; z-index: 6; max-width: 92%; text-align: center; }
#status.err { border-color: #6b2a2a; color: var(--err); }
#hint { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(16,20,24,.85);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; color: var(--dim); z-index: 6; pointer-events: none;
  transition: opacity .6s; white-space: nowrap; }

#panel { width: 300px; flex-shrink: 0; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 12px 16px; }
#panel h2, #panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 14px 0 6px; font-weight: 600; }
body.panel-closed #panel { display: none; }
.toggles { display: flex; flex-direction: column; gap: 2px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 2px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.key { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.row { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.row:hover { background: var(--panel-2); }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tag { font-size: 11px; color: var(--dim); white-space: nowrap; }
.row img { width: 20px; height: 20px; object-fit: contain; }
.empty { color: var(--dim); font-size: 13px; padding: 4px 6px; }
.foot { font-size: 12px; margin-top: 16px; line-height: 1.5; }

.pop { position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px 12px; width: min(320px, calc(100vw - 24px)); box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.pop-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 6px; gap: 8px; }
.pop .x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--dim); padding: 0 4px; }
#cardBody div { padding: 2px 0; }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; justify-content: flex-end; }
#pinForm input[type=text] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.swatches { display: flex; gap: 8px; margin: 10px 0 4px; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.err { color: var(--err); font-size: 13px; margin-top: 6px; }

#gate { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 20%, #1c2630, #0c1014 70%); }
.gate-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; text-align: center; }
.gate-icon { width: 56px; height: 56px; border-radius: 12px; }
.gate-card h1 { font-size: 22px; margin: 12px 0 8px; }
.gate-card p { color: var(--dim); line-height: 1.55; margin: 0 0 18px; }
.gate-card code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; color: var(--text); }
.discord { background: #5865f2; border-color: #5865f2; color: #fff; font-weight: 700; padding: 10px 18px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 10px; z-index: 60; max-width: 90vw; }
#toast.bad { border-color: #6b2a2a; color: var(--err); }

@media (max-width: 760px) {
  #main { flex-direction: column; }
  #panel { width: auto; max-height: 42vh; border-left: 0; border-top: 1px solid var(--line); }
  #logoutLink { display: none !important; }
  body.panel-closed #panel { display: none; }
}

/* Town names & other places (v0.234) -- never take clicks. */
.place-dot { position: absolute; transform: translate(-50%, -50%); width: 7px; height: 7px; border-radius: 50%;
  background: #fff; border: 2px solid #000; pointer-events: none; z-index: 1; }
.place-dot.poi { background: #ffcf6e; border-radius: 2px; }
.place-dot.minor { background: #b9c3cc; width: 5px; height: 5px; }
.label.place { transform: translate(9px, -50%); z-index: 1; font-weight: 700; }
.label.place.town { color: #fff; font-size: 13px; letter-spacing: .02em; }
.label.place.poi { color: #ffe2a8; font-size: 12px; }
.label.place.minor { color: #d5dde4; font-size: 11px; font-weight: 600; }

/* Public map (v0.242): traders, zones, hot zones, cargo drop, Stash 'N Dash. */
.area.square { border-radius: 3px; }
.area.trader { border: 2px solid var(--trader); background: rgba(57,255,20,.12); }
.area.zone { border: 2px solid var(--zone); background: rgba(255,210,63,.12); }
.area.hot { border: 2px dashed var(--hot); background: rgba(255,77,77,.16); }
.mk.trader { background: var(--trader); border-radius: 4px; width: 16px; height: 16px; z-index: 3; }
.mk.zone { background: var(--zone); border-radius: 4px; width: 14px; height: 14px; z-index: 3; }
.mk.hot { background: var(--hot); width: 16px; height: 16px; z-index: 3; }
.mk.hot::after { content: "!"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 900; color: #fff; }
.mk.cargo { background: var(--cargo); border-radius: 3px; width: 18px; height: 18px; z-index: 4;
  box-shadow: 0 0 0 3px rgba(54,197,255,.35), 0 0 10px rgba(54,197,255,.8); }
.mk.stash { background: var(--stash); border-radius: 2px; width: 14px; height: 18px; z-index: 4; }
@media (pointer: coarse) { .mk.trader, .mk.hot, .mk.zone, .mk.stash { width: 22px; height: 22px; } .mk.cargo { width: 24px; height: 24px; } }
.gate-alt { margin: 16px 0 0 !important; font-size: 13px; }
.gate-alt a { color: var(--text); }
#personalLink { white-space: nowrap; }

/* Map Locations (v0.263): the server's own categories (fuel stations, garages...). */
.mk.loc { width: 18px; height: 18px; border: 1.5px solid rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1; z-index: 2; box-shadow: 0 0 0 1px rgba(255,255,255,.35); }
.key.loc-key { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 9px; line-height: 1; }
.loc-head { margin: 8px 0 2px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .75; }
@media (pointer: coarse) { .mk.loc { width: 24px; height: 24px; font-size: 14px; } }

/* Jail (v0.266): the Jail tool's jail area. */
.area.jail { border: 2px solid var(--jail); background: repeating-linear-gradient(90deg, rgba(139,149,167,.22) 0 3px, rgba(139,149,167,.06) 3px 9px); }
.mk.jail { width: 20px; height: 20px; border-radius: 4px; background: #3d4553; border: 1.5px solid var(--jail);
  display: flex; align-items: center; justify-content: center; z-index: 2; }
@media (pointer: coarse) { .mk.jail { width: 26px; height: 26px; } }

/* v0.278: foldable side-panel sections */
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fold-all { font-size: 11px; color: var(--dim); white-space: nowrap; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--dim); font: inherit; cursor: pointer; text-decoration: underline; }
.linkbtn:hover { color: #fff; }
.fold { border-top: 1px solid var(--line); }
.fold:first-child { border-top: 0; }
.fold-head { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; color: var(--dim);
  padding: 10px 2px 8px; font-family: inherit; font-size: 12px; font-weight: 600; line-height: 1.2; text-transform: uppercase; letter-spacing: .06em;
  cursor: pointer; text-align: left; min-height: 36px; }
.fold-head:hover { color: #fff; }
.fold-head .chev { display: inline-block; width: 10px; font-size: 10px; transition: transform .15s; }
.fold.folded .chev { transform: rotate(-90deg); }
.fold-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-count { font-size: 11px; font-weight: 600; letter-spacing: 0; background: var(--panel-2); border-radius: 9px; padding: 1px 7px; color: var(--dim); }
.fold-body { padding-bottom: 6px; }
.fold.folded .fold-body { display: none; }
