:root {
  --bg: #12100c;
  --panel: #1c1813;
  --panel-2: #262019;
  --line: #3a3025;
  --gold: #c9a34e;
  --gold-dim: #8f7736;
  --text: #e9e0cf;
  --text-dim: #9c9282;
  --danger: #b4543a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", Roboto, system-ui, sans-serif;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* Top bar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--gold); font-size: 18px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: .5px; color: var(--gold); }
.brand-sub { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 2px; }

#tools { display: flex; align-items: center; gap: 8px; }
.tool {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
  transition: border-color .15s, background .15s;
}
.tool:hover { border-color: var(--gold-dim); }
.tool.active { background: var(--gold); color: #1a1509; border-color: var(--gold); font-weight: 600; }
.tool-danger:hover { border-color: var(--danger); color: #e8b8ab; }
.coords {
  margin-left: 8px; font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px; color: var(--text-dim); min-width: 130px; text-align: right;
}

/* Body layout: map + right panel */
#body { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; background: #0c0a07; cursor: grab; }
#map.placing { cursor: crosshair; }

/* Toolbar */
#toolbar { display: flex; align-items: center; gap: 6px; }
#toolbar .tool { padding: 6px 10px; font-size: 15px; line-height: 1; }
#toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#scope-toggle { font-size: 12px; }
#scope-toggle.personal { border-color: var(--gold-dim); color: var(--gold); }

#status-group { display: flex; align-items: center; gap: 10px; }

/* Right panel */
#panel { width: 288px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line); }
.panel-head { padding: 10px; border-bottom: 1px solid var(--line); }
#panel-search { width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 6px; padding: 7px 9px; font-size: 13px; }
.panel-filters { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 10px;
  font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--line); }
.panel-filters label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#panel-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; flex: 1; }
#panel-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 6px; cursor: pointer; }
#panel-list li:hover { background: var(--panel-2); }
.li-badge { width: 20px; text-align: center; flex: none; }
.li-badge img { width: 18px; height: 18px; vertical-align: middle; }
.li-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.li-lock { opacity: .7; font-size: 11px; }
.li-del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px; opacity: 0; }
#panel-list li:hover .li-del { opacity: 1; }
.li-del:hover { color: var(--danger); }
.panel-foot { padding: 8px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: space-between; }
.mini { background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 9px; font-size: 12px; cursor: pointer; }
.mini:hover { border-color: var(--gold-dim); color: var(--gold); }
.presence { font-size: 12px; color: #5eae5e; cursor: default; }

/* Markers */
.sgm-pin-img { width: 26px; height: 26px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.7)); }
.sgm-pin.sgm-personal .sgm-pin-img,
.sgm-pin.sgm-personal .sgm-pin-dot { outline: 2px dashed var(--gold); outline-offset: 2px; border-radius: 50%; }

/* Text boxes */
.sgm-textbox { background: rgba(28,24,19,.86); border: 1px solid var(--line);
  border-radius: 6px; overflow: hidden; resize: both; min-width: 60px; min-height: 28px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.sgm-textbox.sgm-personal { border-style: dashed; border-color: var(--gold-dim); }
.sgm-textbox-body { width: 100%; height: 100%; padding: 6px 8px; font-size: 13px;
  line-height: 1.35; outline: none; overflow: auto; cursor: text; }

/* Arrowheads */
.sgm-arrowhead i { display: block; width: 0; height: 0;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 12px solid; }

/* Colour picker in the toolbar */
#draw-color { width: 30px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel-2); cursor: pointer; }

/* Region popup */
.region-info { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; max-height: 180px; overflow: auto; }
.region-info pre { white-space: pre-wrap; font-family: inherit; margin: 4px 0 0; color: var(--text); }

/* Notice */
#notice {
  padding: 7px 16px; font-size: 12px; color: var(--text-dim);
  background: var(--panel); border-top: 1px solid var(--line);
}
#notice strong { color: var(--text); }

/* Leaflet control theming */
.leaflet-container { background: #0c0a07; }
.leaflet-control-layers, .leaflet-bar {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line) !important; border-radius: 8px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,.5) !important;
}
.leaflet-control-layers-expanded { padding: 10px 12px; }
.leaflet-control-layers label { margin: 3px 0; }
.leaflet-bar a { background: var(--panel) !important; color: var(--gold) !important; border-bottom: 1px solid var(--line) !important; }
.leaflet-bar a:hover { background: var(--panel-2) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--text); }
.leaflet-popup-content { margin: 10px 12px; }
.marker-popup input {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: 4px; padding: 4px 6px; margin-bottom: 6px;
}
.marker-popup .row { display: flex; gap: 6px; }
.marker-popup button {
  flex: 1; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); border-radius: 4px; padding: 4px; cursor: pointer;
}
.marker-popup button.del { border-color: var(--danger); color: #e8b8ab; }
.marker-popup select {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: 4px; padding: 4px 6px; margin-bottom: 6px;
}
.marker-popup .meta { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.tool:disabled { opacity: .4; cursor: not-allowed; }

/* Connection status */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #888; }
.status[data-state="live"] .dot { background: #5eae5e; box-shadow: 0 0 6px #5eae5e; }
.status[data-state="offline"] .dot { background: var(--danger); }

/* Auth chip */
.authbox { display: inline-flex; align-items: center; gap: 8px; }
.authbox .who { color: var(--text); font-size: 13px; }
.authbox .logout { color: var(--text-dim); font-size: 12px; text-decoration: none; border-bottom: 1px dotted var(--line); }
.authbox .logout:hover { color: var(--gold); }

/* Colored category pins */
.sgm-pin-dot {
  display: block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #1a1509; box-shadow: 0 1px 3px rgba(0,0,0,.6);
}

/* Auth gate overlay */
.gate {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: #0a0806;
}
/* Full blackout: hide the map, panel, and controls behind the gate. */
body.gated #app { visibility: hidden; }
.gate.hidden { display: none; }
.gate-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 12px;
  padding: 32px 40px; text-align: center; max-width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.gate-mark { color: var(--gold); font-size: 28px; }
.gate-card h1 { color: var(--gold); font-size: 20px; margin: 8px 0 12px; letter-spacing: .5px; }
.gate-card p { color: var(--text-dim); line-height: 1.5; margin: 0 0 20px; }
.gate-card .btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); text-decoration: none; font-size: 14px;
}
.gate-card .btn:hover { border-color: var(--gold-dim); }
.gate-card .btn-discord { background: #5865F2; border-color: #5865F2; color: #fff; font-weight: 600; }
.gate-card .btn-discord:hover { background: #4752c4; border-color: #4752c4; }
