/* ====== Reset & Base ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #080b10;
  --bg-panel:   #0e1218;
  --bg-card:    #131921;
  --bg-hover:   #1a2332;
  --border:     rgba(0, 200, 255, 0.12);
  --border-hi:  rgba(0, 200, 255, 0.45);
  --accent:     #00c8ff;
  --accent-dim: rgba(0, 200, 255, 0.15);
  --accent2:    #ff7b00;
  --text:       #e8edf5;
  --text-dim:   #7a8899;
  --success:    #00e676;
  --nav-h:      48px;
  --sidebar-w:  280px;
  --toolbar-w:  44px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Inter", "Roboto", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-deep);
  color: var(--text);
}

/* ====== Navigation ====== */
.nav {
  height: var(--nav-h);
  background: rgba(8, 11, 16, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 2000;
  gap: 4px;
}
.nav-brand {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 16px;
  text-decoration: none;
  white-space: nowrap;
}
.nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  white-space: nowrap;
}
.nav a:hover, .nav a.active { color: var(--accent); background: var(--accent-dim); }

/* ====== Map Layout ====== */
.map-layout {
  position: fixed;
  top: var(--nav-h);
  left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ====== Sidebar ====== */
.sidebar {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.3s ease;
}
.sidebar.collapsed { width: 0; }

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Map selector */
.map-selector {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.map-selector:hover, .map-selector:focus { border-color: var(--accent); }

/* Layer switcher */
.layer-switcher {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.layer-btn {
  flex: 1;
  padding: 7px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.layer-btn:hover { border-color: var(--accent); color: var(--text); }
.layer-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Search box */
.search-box {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px 7px 32px;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237a8899' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.category-actions {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.category-action-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(232, 237, 245, 0.72);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
  white-space: nowrap;
}

.category-action-btn-hide {
  border-color: rgba(255, 138, 46, 0.2);
  background: rgba(255, 138, 46, 0.05);
}

.category-action-btn-show {
  border-color: rgba(0, 200, 255, 0.18);
  background: rgba(0, 200, 255, 0.045);
}

.category-action-btn:hover:not(:disabled) {
  color: rgba(232, 237, 245, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

.category-action-btn-hide:hover:not(:disabled) {
  background: rgba(255, 138, 46, 0.09);
  border-color: rgba(255, 138, 46, 0.3);
}

.category-action-btn-show:hover:not(:disabled) {
  background: rgba(0, 200, 255, 0.085);
  border-color: rgba(0, 200, 255, 0.28);
}

.category-action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.category-action-icon {
  opacity: 0.65;
  font-size: 13px;
  line-height: 1.1;
}

/* Category list */
.category-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
}
.category-list::-webkit-scrollbar { width: 4px; }
.category-list::-webkit-scrollbar-track { background: transparent; }
.category-list::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

.cat-group { margin-bottom: 4px; }

.cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.cat-header:hover { background: var(--bg-hover); }
.cat-header.active { background: var(--accent-dim); }
.cat-header.partial { background: rgba(0, 200, 255, 0.08); }

.cat-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.cat-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}
.cat-toggle {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 10px;
  padding: 0;
  cursor: pointer;
  transition: transform 0.2s;
}
.cat-group.open .cat-toggle { transform: rotate(90deg); }

.cat-checkbox-btn {
  border: 0;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.cat-children {
  display: none;
  padding-left: 12px;
}
.cat-group.open .cat-children { display: block; }

.cat-child {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  transition: all 0.15s;
}
.cat-child:hover { background: var(--bg-hover); color: var(--text); }
.cat-child.active { color: var(--text); background: var(--accent-dim); }

.cat-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 6px;
  line-height: 18px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.cat-checkbox {
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-hi);
  border-radius: 3px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cat-child.active .cat-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}
.cat-header.active .cat-checkbox,
.cat-header.partial .cat-checkbox,
.cat-child.active .cat-checkbox {
  border-color: var(--accent);
}
.cat-header.active .cat-checkbox,
.cat-child.active .cat-checkbox {
  background: var(--accent);
}
.cat-header.active .cat-checkbox::after,
.cat-child.active .cat-checkbox::after {
  content: "✓";
  font-size: 9px;
  color: #000;
  font-weight: 700;
}
.cat-header.partial .cat-checkbox::after {
  content: "—";
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}

/* Progress bar */
.progress-bar-wrap {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.progress-track {
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0070ff);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ====== Map Container ====== */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#map {
  width: 100%;
  height: 100%;
  background: #06090e;
}

/* ====== Floating Toolbar ====== */
.toolbar {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tool-btn {
  width: 38px;
  height: 38px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-dim);
  font-size: 16px;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.tool-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.tool-divider { height: 1px; background: var(--border); margin: 2px 0; }

/* Sidebar toggle (in toolbar area) */
.sidebar-toggle {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 1000;
  width: 34px;
  height: 34px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-dim);
  font-size: 14px;
}
.sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ====== Popup ====== */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border-hi) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
  padding: 0 !important;
  overflow: hidden;
}
.leaflet-popup-tip { background: var(--bg-panel) !important; }
.leaflet-popup-content { margin: 0 !important; width: 280px !important; }
.leaflet-popup-close-button {
  color: var(--text-dim) !important;
  top: 10px !important;
  right: 10px !important;
  font-size: 18px !important;
}
.leaflet-popup-close-button:hover { color: var(--text) !important; }

.popup-inner { padding: 16px; }
.popup-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--border);
}
.popup-category {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.popup-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.3;
}
.popup-hash {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #00c8ff;
  padding: 0 5px;
  border-radius: 4px;
  line-height: 1.5;
  vertical-align: middle;
  margin-left: 6px;
  user-select: all;
}
.popup-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 12px;
}
.popup-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}
.popup-collect-btn {
  flex: 1;
  padding: 8px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.popup-collect-btn:hover { border-color: var(--success); color: var(--success); }
.popup-collect-btn.collected {
  background: rgba(0, 230, 118, 0.1);
  border-color: var(--success);
  color: var(--success);
}
.popup-wiki-btn {
  padding: 8px 12px;
  background: var(--accent-dim);
  border: 1px solid var(--border-hi);
  color: var(--accent);
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  white-space: nowrap;
}
.popup-wiki-btn:hover { background: rgba(0, 200, 255, 0.25); }

/* ====== Loading overlay ====== */
.map-loading {
  position: absolute;
  inset: 0;
  background: rgba(8, 11, 16, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.map-loading.visible { opacity: 1; pointer-events: auto; }
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== Leaflet overrides ====== */
.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  overflow: hidden;
  margin-top: 56px !important;
}
.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-dim) !important;
  border-color: var(--border) !important;
  transition: all 0.2s !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
  color: var(--accent) !important;
}

/* ====== Custom marker ====== */
.arc-marker {
  --marker-border: #fff;
  --marker-bg: var(--bg-panel);
  position: relative;
  width: 32px;
  height: 42px;
  transition: transform 0.15s, opacity 0.3s;
  cursor: pointer;
  transform-origin: center bottom;
}
.arc-marker-shape {
 width: 100%;
 height: 100%;
 display: block;
 overflow: visible;
 filter: drop-shadow(0 0 8px rgba(0,200,255,0.3));
}
.arc-marker-shape path {
 fill: var(--marker-bg);
 stroke: var(--marker-border);
 stroke-width: 2;
 stroke-linejoin: round;
 vector-effect: non-scaling-stroke;
}
.arc-marker-inner {
 position: absolute;
 top: 4px;
 left: 4px;
 width: 24px;
 height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.arc-marker:hover { transform: scale(1.2); }
.arc-marker.collected {
 opacity: 0.55;
}
.arc-marker.collected .arc-marker-shape {
 filter: drop-shadow(0 0 8px rgba(0,230,118,0.3));
}
.arc-marker img {
 width: 16px;
 height: 16px;
 object-fit: contain;
}
.arc-marker .iconfont {
  font-size: 16px;
  line-height: 1;
}

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .sidebar { position: absolute; z-index: 1500; top: 0; bottom: 0; left: 0; }
  .sidebar.collapsed { width: 0; overflow: hidden; }
  :root { --sidebar-w: 260px; }
}
