:root {
  --bg: #0f1419;
  --panel: #161c24;
  --panel-2: #1c242e;
  --border: #2a3340;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #20c997;
  --accent-dim: rgba(32, 201, 151, 0.12);
  --res: #2f7fe0;
  --enl: #1fb866;
  --neutral: #9aa5b1;
  --danger: #ff6b6b;
  --danger-dim: rgba(255, 107, 107, 0.12);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --panel: #ffffff;
    --panel-2: #f1f4f8;
    --border: #d8dee6;
    --text: #1f2733;
    --muted: #5b6775;
    --accent: #12b886;
    --accent-dim: rgba(18, 184, 134, 0.1);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; color: var(--accent); }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar-actions input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  width: 220px;
}

main { max-width: 1200px; margin: 0 auto; padding: 16px 20px 60px; }

.map-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}
#map { height: 380px; width: 100%; }
.leaflet-container { background: #0b0f14; }
.leaflet-popup-content { font-family: inherit; font-size: 13px; color: #1f2733; }
.leaflet-popup-content a { color: #2f7fe0; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search input {
  width: 320px;
  max-width: 70vw;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.stats { color: var(--muted); font-size: 13px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table-wrap > table { width: 100%; }

table { border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 500;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  white-space: nowrap;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: var(--panel-2); }
.num { color: var(--muted); width: 40px; }
.title { font-weight: 500; max-width: 320px; }
.team-col { white-space: nowrap; }
.team {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--neutral);
  color: #fff;
}
.team.RESISTANCE, .team.R { background: var(--res); }
.team.ENLIGHTENED, .team.E { background: var(--enl); }
.team.NEUTRAL, .team.N { background: var(--neutral); }
.level { color: var(--muted); white-space: nowrap; }
.resos { white-space: normal; }
.reso-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 40px;
  width: 104px;
}
.reso-bar {
  width: 12px;
  min-height: 4px;
  border-radius: 2px 2px 0 0;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transition: height .2s, background .2s;
}
.reso-pct {
  font-size: 8px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  margin-top: 2px;
  pointer-events: none;
}
.guid code { font-size: 11px; color: var(--muted); word-break: break-all; }
.owner-col { white-space: nowrap; }
.owner { font-size: 12px; }
.mods { white-space: normal; }
.mod-thumbs { display: flex; gap: 4px; align-items: center; }
.mod-thumb {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  font-size: 9px;
  color: var(--text);
  background: var(--panel-2);
  flex: 0 0 auto;
  cursor: default;
  position: relative;
  font-weight: 600;
}
.mod-thumb.empty { color: var(--muted); opacity: .4; font-weight: 400; }
.mod-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 3px; }
.mod-card {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 150px;
  max-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 100;
  font-size: 11px;
  font-weight: 400;
  text-align: left;
  white-space: normal;
}
.mc-name { font-weight: 700; font-size: 12px; margin-bottom: 2px; }
.mc-rarity { font-size: 10px; font-weight: 600; margin-bottom: 2px; }
.mc-owner { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.mc-stats { border-top: 1px solid var(--border); padding-top: 4px; }
.mc-stat { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; align-items: flex-start; }
.mc-stat span { color: var(--muted); display: flex; flex-direction: column; }
.mc-stat span small { color: var(--muted); opacity: .6; font-size: 9px; margin-top: 1px; font-weight: 400; }
.mc-stat b { color: var(--accent); white-space: nowrap; }
.updated { color: var(--muted); white-space: nowrap; font-size: 12px; }
.actions { white-space: nowrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.mini { padding: 3px 8px; font-size: 11px; }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-dim); border-color: var(--danger); }
.btn.copy { margin-left: 4px; }

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}
.empty.error { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  z-index: 50;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 720px) {
  .num, .updated { display: none; }
  .search input { width: 100%; }
  #map { height: 280px; }
}
