/* BFTD Valheim map. Shared kbtkraft design system, dark only (it's a game map). */
:root {
  --bg: #080808;
  --surface: #111111;
  --surface-2: #181818;
  --border: rgba(255, 255, 255, 0.07);
  --border-2: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.93);
  --text-2: rgba(255, 255, 255, 0.55);
  --text-3: rgba(255, 255, 255, 0.32);
  --accent: #6366f1;
  --accent-soft: #818cf8;
  --green: #4caf7d;
  --amber: #f59e0b;
  --danger: #ef5350;
  --panel-w: 360px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, sans-serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- map */
#map {
  position: fixed;
  inset: 0 var(--panel-w) 0 0;
  background: #173a5c;           /* matches the deep ocean at the world edge */
}
.leaflet-container { font: inherit; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
}
.leaflet-bar { border: 1px solid var(--border-2) !important; box-shadow: none !important; }
.leaflet-control-attribution { display: none; }
#map.adding { cursor: crosshair; }
#map.adding .leaflet-interactive { cursor: crosshair; }

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.45; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-2); }
.pop-title { font-weight: 600; margin: 0 0 2px; }
.pop-meta { color: var(--text-2); margin: 0; }
.pop-actions { margin-top: 10px; display: flex; gap: 8px; }

.leaflet-tooltip.tip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-2);
  box-shadow: none;
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 12px;
}
.leaflet-tooltip.tip::before { display: none; }
.leaflet-tooltip.pin-label {
  background: rgba(8, 8, 8, 0.72);
  border: 0;
  color: var(--text);
  box-shadow: none;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.leaflet-tooltip.pin-label::before { display: none; }

.pin-icon svg { display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }

.coords {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(8, 8, 8, 0.78);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  pointer-events: none;
}

/* --------------------------------------------------------------- panel */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 600;
}
.panel-grip { display: none; }
.panel-head { padding: 20px 20px 16px; border-bottom: 1px solid var(--border); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border-2);
  font-size: 12px; color: var(--text-2);
}
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status.up i { background: var(--green); box-shadow: 0 0 0 3px rgba(76, 175, 125, 0.18); }
.status.up { color: var(--text); }
.status.down i { background: var(--danger); }

.facts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
  margin: 16px 0 0;
}
.facts div { min-width: 0; }
.facts dt { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.facts dd { margin: 2px 0 0; font-size: 14px; }
.copy {
  background: none; border: 0; padding: 0; cursor: pointer;
  border-bottom: 1px dashed var(--border-2);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.copy:hover { border-bottom-color: var(--accent-soft); color: var(--accent-soft); }
.copy:disabled { cursor: default; border-bottom: 0; color: var(--text-3); }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; border: 0; cursor: pointer;
  padding: 8px 10px 10px; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.tab-body { flex: 1; overflow-y: auto; padding: 4px 20px 24px; }
.section-label {
  margin: 20px 0 8px; font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.hint { color: var(--text-3); font-size: 12px; margin: 10px 0 0; }
.empty { color: var(--text-3); font-size: 13px; padding: 6px 0; list-style: none; }

ul, ol { list-style: none; margin: 0; padding: 0; }

.online li:not(.empty) {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.online .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.online .who { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.online .since { color: var(--text-2); font-size: 12px; }

.roster li:not(.empty) {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.roster .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster .name a { color: inherit; text-decoration: none; }
.roster .name a:hover { color: var(--accent-soft); }
.roster .seen { color: var(--text-2); font-size: 12px; text-align: right; }
.roster .seen.on { color: var(--green); }
.roster .stats { grid-column: 1 / -1; display: flex; gap: 14px; color: var(--text-3); font-size: 12px; }
.roster .stats b { color: var(--text-2); font-weight: 500; }

.sessions li:not(.empty) {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; font-size: 12.5px; color: var(--text-2);
  border-bottom: 1px solid var(--border);
}
.sessions .n { color: var(--text); font-weight: 500; }
.sessions .live { color: var(--green); }

/* map tab */
.toggles { display: grid; gap: 2px; }
.toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.toggle .sw { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.toggle .count { margin-left: auto; color: var(--text-3); font-size: 12px; }

.pin-actions { display: flex; gap: 8px; }
.btn {
  background: var(--accent); border: 1px solid var(--accent); color: #fff;
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 13px;
}
.btn:hover { background: #5458e8; }
.btn.ghost { background: transparent; border-color: var(--border-2); color: var(--text); }
.btn.ghost:hover { border-color: var(--text-3); }
.btn.danger { background: transparent; border-color: rgba(239, 83, 80, 0.45); color: var(--danger); }
.btn.active { background: var(--amber); border-color: var(--amber); color: #111; }
.btn:focus-visible, .tabs button:focus-visible, .copy:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.pin-list { margin-top: 12px; }
.pin-list li:not(.empty) {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.pin-list li:not(.empty):hover .pl-name { color: var(--accent-soft); }
.pin-list .pl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-list .pl-xy { color: var(--text-3); font-size: 11.5px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13px; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--c); border: 1px solid var(--border-2); }

/* pin form in a popup */
.pin-form { display: grid; gap: 8px; width: 220px; }
.pin-form label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
input[type="text"], input[type="password"], select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border-2);
  font: inherit; font-size: 13px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 14px;
  padding: 22px; width: min(360px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog h2 { margin: 0 0 4px; font-size: 17px; }
.dialog p { margin: 0 0 14px; color: var(--text-2); font-size: 13px; }
.dialog .error { color: var(--danger); margin: 10px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(calc(-50% - var(--panel-w) / 2));
  z-index: 1000; padding: 9px 14px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border-2); font-size: 13px;
}

/* ---------------------------------------------------- phone: bottom sheet */
@media (max-width: 760px) {
  #map { inset: 0; }
  .panel {
    top: auto; left: 0; width: auto;
    height: min(78vh, 640px);
    border-left: 0; border-top: 1px solid var(--border-2);
    border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% - 132px));
    transition: transform 0.25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: none; }
  .panel-grip {
    display: block; width: 100%; height: 22px; border: 0; background: none; cursor: pointer;
    position: relative; flex: none;
  }
  .panel-grip::after {
    content: ""; position: absolute; left: 50%; top: 9px; width: 40px; height: 4px;
    margin-left: -20px; border-radius: 2px; background: var(--border-2);
  }
  .panel-head { padding: 0 16px 14px; }
  .facts { grid-template-columns: repeat(4, auto); gap: 8px 14px; margin-top: 10px; }
  .facts dd { font-size: 13px; }
  .tab-body { padding: 4px 16px 24px; }
  .coords { bottom: 144px; }
  .toast { transform: translateX(-50%); bottom: 150px; }
}
@media (prefers-reduced-motion: reduce) { .panel { transition: none; } }
