:root {
  color-scheme: dark;
  --bg: #080909;
  --surface: #111313;
  --surface-2: #181a19;
  --line: #303431;
  --line-soft: #222623;
  --text: #ece7dc;
  --muted: #a9b2ad;
  --accent: #e85d4f;
  --teal: #4bb3a8;
  --amber: #e5b84c;
  --green: #66c56f;
  --focus: #f1c35c;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100%;
  min-width: 320px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #0c0d0d;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 210px;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px #25312f inset;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: var(--accent);
}

.brand-mark::before {
  width: 17px;
  height: 2px;
  left: 7px;
  top: 15px;
  transform: rotate(-22deg);
}

.brand-mark::after {
  width: 6px;
  height: 6px;
  right: 5px;
  top: 6px;
  border-radius: 50%;
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-copy strong {
  font-size: 17px;
  line-height: 1.1;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.search-field,
.select-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: var(--muted);
  font-size: 12px;
}

.search-field input,
.select-field select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
}

.search-field input {
  width: min(30vw, 280px);
  min-width: 180px;
  padding: 0 12px;
}

.select-field select {
  max-width: 160px;
  padding: 0 30px 0 10px;
}

button {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover {
  border-color: var(--focus);
  background: #20231f;
}

button:active {
  transform: translateY(1px);
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(241, 195, 92, 0.18);
}

.workspace {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr) 308px;
  min-height: 0;
}

.sidebar,
.intel-sidebar {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
  height: 100%;
  padding: 14px;
  overflow: auto;
  background: var(--surface);
}

.sidebar {
  border-right: 1px solid var(--line);
}

.intel-sidebar {
  border-left: 1px solid var(--line);
}

.panel {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #0f1110;
  padding: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.stats-grid div {
  min-width: 0;
  border-left: 2px solid var(--teal);
  padding-left: 10px;
}

.stats-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.stats-grid dd {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 700;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.filter-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--text);
  font-size: 13px;
}

.filter-grid .wide {
  grid-column: 1 / -1;
}

.filter-grid input {
  accent-color: var(--accent);
}

.time-filter {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.time-filter div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.time-filter input {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 10px;
  outline: none;
}

.time-filter span {
  color: var(--text);
  font-size: 13px;
}

.selection-panel {
  min-height: 134px;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.system-title {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.2;
}

.system-meta {
  display: grid;
  gap: 8px;
  margin: 0;
}

.system-meta div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 6px;
}

.system-meta dt {
  color: var(--muted);
}

.system-meta dd {
  margin: 0;
  text-align: right;
}

.intel-list {
  display: grid;
  gap: 8px;
}

.intel-panel {
  min-height: calc(100vh - 102px);
}

.intel-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  height: auto;
  min-height: 54px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.intel-item.is-selected {
  border-color: var(--player-color);
  background: #141818;
  box-shadow: inset 3px 0 0 var(--player-color);
}

.intel-open {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  width: 100%;
  height: auto;
  min-height: 38px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.intel-open:hover {
  border-color: transparent;
  background: transparent;
}

.intel-delete {
  width: 30px;
  height: auto;
  min-height: 38px;
  padding: 0;
  color: var(--muted);
}

.intel-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.intel-system {
  color: var(--focus);
  font-size: 12px;
}

.intel-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.intel-meta i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.pin-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.pin-form input {
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 10px;
  outline: none;
}

.pin-form button {
  height: 36px;
  padding: 0 12px;
}

.pinned-list {
  display: grid;
  gap: 8px;
}

.pinned-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #111313;
}

.pinned-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.pinned-item button {
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
}

.player-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.player-card {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px 10px;
  background: #111313;
}

.player-card strong,
.player-card span,
.player-card small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-card small {
  color: var(--muted);
}

.player-card .player-detail {
  white-space: normal;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #080909;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#mapCanvas.dragging {
  cursor: grabbing;
}

.mini-map {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 220px;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 9, 9, 0.88);
}

.tooltip {
  position: absolute;
  z-index: 3;
  max-width: min(260px, calc(100vw - 32px));
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 19, 19, 0.95);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

.map-hud {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.map-hud span {
  min-height: 28px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 19, 19, 0.9);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
    width: 100%;
  }

  .search-field {
    width: 100%;
  }

  .search-field input {
    width: 100%;
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(520px, 68vh) auto auto;
  }

  .sidebar,
  .intel-sidebar {
    order: 2;
    height: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .intel-sidebar {
    order: 3;
    border-left: 0;
  }

  .intel-panel {
    min-height: 0;
  }

  .map-stage {
    order: 1;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 12px;
  }

  .toolbar,
  .select-field {
    width: 100%;
  }

  .select-field select,
  button {
    width: 100%;
  }

  .mini-map {
    width: 154px;
    height: 112px;
    right: 10px;
    bottom: 54px;
  }

  .map-hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
}
