:root {
  --bg: #12151a;
  --panel: #1c2129;
  --line: #2d3542;
  --text: #e8edf4;
  --muted: #9aa6b5;
  --accent: #d4a017;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 250px 1fr;
}

.toolbar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  z-index: 1000;
}

h1 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 650;
}

.hint {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
}

.field > span {
  color: var(--muted);
}

.team-row {
  display: grid;
  grid-template-columns: 1fr 36px 36px;
  gap: 6px;
}

select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1318;
  color: var(--text);
  outline: none;
}

select:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #252b35;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.btn.compact {
  width: 36px;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
}

.btn.icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.btn.primary {
  background: var(--accent);
  border-color: #b8870f;
  color: #1a1405;
  font-weight: 650;
}

.btn.primary.active {
  box-shadow: inset 0 0 0 2px #fff3;
}

.legend {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

#map {
  height: 100%;
  background: #0a0c10;
}

.leaflet-container {
  background: #0a0c10;
  font: inherit;
}

.leaflet-div-icon.marker-icon-root {
  background: transparent;
  border: none;
  overflow: visible !important;
}

.marker-root {
  position: relative;
  width: 28px;
  height: 28px;
}

.enemy-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: grab;
  user-select: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.enemy-marker.dead {
  border-color: #8a8f98;
}

.enemy-marker.selected {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.enemy-marker.dead.selected {
  outline-color: #8a8f98;
}

.enemy-marker:active {
  cursor: grabbing;
}

.marker-card {
  display: none;
  position: absolute;
  left: 36px;
  top: -12px;
  width: 320px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 33, 41, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color: var(--text);
  z-index: 10;
  cursor: default;
}

.marker-card.open {
  display: grid;
  grid-template-columns: auto minmax(88px, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  --marker-row-h: 88px;
}

.marker-card-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.marker-card-title {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marker-status {
  flex-shrink: 0;
  min-width: 52px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1f6b3a;
  color: #e8fff0;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  line-height: 1.2;
}

.marker-status.dead {
  background: #4a4f58;
  color: #d7dbe2;
  border-color: #6b717c;
}

.asset-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--marker-row-h);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1318;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  align-self: stretch;
}

.asset-thumb.operator {
  width: 56px;
}

.asset-thumb.weapon {
  width: 140px;
}

.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.asset-thumb.operator img {
  object-fit: cover;
  object-position: center top;
}

.asset-thumb.weapon img {
  object-fit: contain;
  background: #0a0c10;
}

.asset-thumb .asset-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  transform: translateY(50%);
  padding: 2px 4px;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.asset-thumb.placeholder {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  padding: 4px;
}

.marker-stats {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  height: var(--marker-row-h);
  overflow: hidden;
}

.marker-stats label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  flex: 1;
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  min-height: 0;
}

.marker-stats select {
  box-sizing: border-box;
  width: 100%;
  padding: 5px 6px;
  font-size: 12px;
  height: 28px;
  line-height: 1.2;
}

.picker {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.picker.hidden {
  display: none;
}

.picker-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.picker-header h2 {
  margin: 0;
  font-size: 16px;
}

.picker-search {
  margin: 12px 14px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1318;
  color: var(--text);
  outline: none;
}

.picker-search:focus {
  border-color: var(--accent);
}

.picker-grid {
  display: grid;
  gap: 14px;
  padding: 14px 16px 18px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
  align-items: start;
  grid-auto-rows: max-content;
}

.picker-grid.mode-operator {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 14px;
}

.picker-grid.mode-weapon {
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px;
}

.picker-item {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1318;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  color: inherit;
  align-self: start;
}

.picker-item:hover,
.picker-item.selected {
  border-color: var(--accent);
}

.picker-item-media {
  position: relative;
  width: 100%;
  height: auto;
  background: #0a0c10;
  overflow: hidden;
  flex: 0 0 auto;
}

.picker-grid.mode-operator .picker-item-media {
  aspect-ratio: 314 / 500;
}

.picker-grid.mode-weapon .picker-item-media {
  aspect-ratio: 2 / 1;
}

.picker-item-media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.picker-grid.mode-operator .picker-item-media img {
  object-fit: cover;
  object-position: center top;
}

.picker-grid.mode-weapon .picker-item-media img {
  object-fit: contain;
}

.picker-item-media .no-pic {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  background: #12161d;
}

.picker-item-media .asset-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  transform: translateY(50%);
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  z-index: 1;
}

.picker-empty {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 800px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .toolbar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .marker-card.open {
    width: 280px;
    --marker-row-h: 80px;
  }

  .asset-thumb.operator {
    width: 50px;
  }

  .asset-thumb.weapon {
    width: 120px;
  }
}
