.map-container {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC,
    WenQuanYi Micro Hei, sans-serif;
  user-select: none;
  height: 100%;
  width: 100%;
  overflow: hidden; // prevent browser scroll container while dragging
  font-size: 15px;
  outline: none; // prevent browser default focus outline
  touch-action: none; // use pointer events instead of touch events
  * {
    box-sizing: border-box; // must have, to make getComputedStyle work right
  }
  &::-webkit-scrollbar {
    width: 0px;
    height: 0px;
  }
  .selected {
    outline: 2px solid var(--selected);
    outline-offset: 1px;
  }
  .hyper-link {
    text-decoration: none;
    margin-left: 0.3em;
  }
  me-main > me-wrapper > me-parent > me-epd {
    top: 50%;
    transform: translateY(-50%);
  }
  me-epd {
    top: 100%;
    transform: translateY(-50%);
  }
  .lhs {
    direction: rtl;
    & > me-wrapper > me-parent > me-epd {
      left: -10px;
    }
    me-epd {
      left: 5px;
    }
    me-tpc {
      direction: ltr;
    }
  }
  .rhs {
    & > me-wrapper > me-parent > me-epd {
      right: -10px;
    }
    me-epd {
      right: 5px;
    }
  }
  background-color: var(--bgcolor);
  .map-canvas {
    position: relative;
    user-select: none;
    width: fit-content; // 100% width if not set
    transform: scale(1);
    me-nodes {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      height: max-content;
      width: max-content;
      padding: var(--map-padding);
    }
  }
  me-main {
    // primary node / main node
    & > me-wrapper {
      position: relative; // make subline svg's offsetParent be the main node
      margin: var(--main-gap-y) var(--main-gap-x);
      & > me-parent {
        margin: 10px;
        padding: 0;
        & > me-tpc {
          border-radius: var(--main-radius);
          background-color: var(--main-bgcolor);
          border: 2px solid var(--main-color);
          color: var(--main-color);
          padding: 8px 25px;
        }
      }
    }
  }
  me-wrapper {
    display: block;
    pointer-events: none;
    width: fit-content;
    // position: relative;
  }
  me-children,
  me-parent {
    display: inline-block;
    vertical-align: middle;
  }
  me-root {
    position: relative;
    margin: 45px 0;
    z-index: 10;
    me-tpc {
      font-size: 25px;
      color: var(--root-color);
      padding: 10px 30px;
      border-radius: var(--root-radius);
      border: var(--root-border-color) 2px solid;
      background-color: var(--root-bgcolor);
    }
  }
  me-parent {
    position: relative; // for locating expand button
    cursor: pointer;
    padding: 6px var(--node-gap-x);
    margin-top: var(--node-gap-y);
    z-index: 10;
    me-tpc {
      position: relative;
      border-radius: 3px;
      color: var(--color);
      padding: var(--topic-padding);

      // drag preview
      .insert-preview {
        position: absolute;
        width: 100%;
        left: 0px;
        z-index: 9;
      }
      .show {
        background: #7ad5ff;
        pointer-events: none;
        opacity: 0.7;
        border-radius: 3px;
      }
      .before {
        height: 14px;
        top: -14px;
      }
      .in {
        height: 100%;
        top: 0px;
      }
      .after {
        height: 14px;
        bottom: -14px;
      }
    }
    me-epd {
      position: absolute;
      height: 18px;
      width: 18px;
      opacity: 0.8;
      background-image: url('./icons/add-circle.svg');
      background-repeat: no-repeat;
      background-size: contain;
      background-position: center;

      pointer-events: all;
      z-index: 9;
      &.minus {
        background-image: url('./icons/minus-circle.svg') !important;
        transition: opacity 0.3s;
        opacity: 0;
        @media (hover: hover) {
          &:hover {
            opacity: 0.8;
          }
        }
        @media (hover: none) {
          & {
            opacity: 0.8;
          }
        }
      }
    }
  }

  // iconfont
  .icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
  }
  .lines,
  .summary,
  .subLines,
  .topiclinks,
  .linkcontroller {
    position: absolute;
    height: 102%;
    width: 100%;
    top: 0;
    left: 0;
  }
  .topiclinks,
  .linkcontroller,
  .summary {
    pointer-events: none;
    z-index: 20;
  }

  .summary > g,
  .topiclinks > g {
    cursor: pointer;
    pointer-events: stroke;
    z-index: 20;
  }

  .lines,
  .subLines {
    pointer-events: none;
  }

  #input-box {
    position: absolute;
    top: 0;
    left: 0;
    width: max-content; // let words expand the div and keep max length at the same time
    max-width: 35em;
    direction: ltr;
    user-select: auto;
    pointer-events: auto;
    color: var(--color);
    background-color: var(--bgcolor);
    z-index: 100;
  }

  me-tpc {
    display: flex !important;
    max-width: 35em;
    white-space: pre-wrap;
    pointer-events: all;
    // 确保整个节点内容居中对齐
    text-align: center !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    // 确保节点有固定的最小高度，避免内容变化导致尺寸不稳定
    min-height: 2em !important;
    // 确保节点内容不会溢出
    overflow: hidden !important;
    // 强制节点尺寸稳定
    position: relative !important;
    // 确保节点内容不会因为动态变化而影响布局
    contain: layout style !important;
    
    & > * {
      // tags,icons,images should not response to click event
      pointer-events: none;
    }
    & > a,
    & > iframe {
      pointer-events: auto;
    }
    & > .text {
      display: block !important;
      text-align: center !important; // 确保文本居中对齐，避免与连线错位
      width: 100% !important; // 确保文本容器占满节点宽度
      margin: 0 auto !important; // 强制居中
      // 确保文本不会导致节点尺寸不稳定
      word-wrap: break-word !important;
      word-break: break-word !important;
      line-height: 1.4 !important;
      // Allow links inside markdown text to be clickable
      a {
        pointer-events: auto;
      }
    }
    & > img {
      display: block !important;
      margin: 0 auto 8px auto !important; // 图片居中
      object-fit: cover;
      max-width: 200px !important;
      max-height: 150px !important;
      width: auto !important;
      height: auto !important;
      // 确保图片加载失败时不会影响节点布局
      min-width: 0 !important;
      min-height: 0 !important;
      // 图片加载失败时的占位符样式
      background-color: #f5f5f5 !important;
      border: 1px solid #ddd !important;
    }
    
    // 更具体的选择器，确保覆盖所有图片
    img {
      max-width: 200px !important;
      max-height: 150px !important;
      width: auto !important;
      height: auto !important;
      margin: 0 auto !important; // 确保所有图片都居中
      min-width: 0 !important;
      min-height: 0 !important;
      // 处理图片加载失败的情况
      &[src=""], &[src*="undefined"], &[src*="null"] {
        display: none !important; // 隐藏无效图片
      }
    }
  }
  .circle {
    position: absolute;
    height: 10px;
    width: 10px;
    margin-top: -5px;
    margin-left: -5px;
    border-radius: 100%;
    background: #757575;
    border: 2px solid #ffffff;
    z-index: 50;

    cursor: pointer;
  }

  .tags {
    direction: ltr;
    span {
      display: inline-block;
      border-radius: 3px;
      padding: 2px 4px;
      background: #d6f0f8;
      color: #276f86;
      margin: 0px;
      font-size: 12px;
      line-height: 1.3em;
      margin-right: 4px;
      margin-top: 2px;
    }
  }
  .icons {
    display: inline-block;
    direction: ltr;
    margin-left: 5px;
    span {
      display: inline-block;
      line-height: 1.3em;
    }
  }

  .mind-elixir-ghost {
    position: fixed;
    top: -100%;
    left: -100%;
    box-sizing: content-box;
    opacity: 0.5;
    background-color: var(--main-bgcolor);
    border: 2px solid var(--main-color);
    color: var(--main-color);
    max-width: 200px;
    width: fit-content;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 8px 16px;
    border-radius: 6px;
  }

  .selection-area {
    background: #4f90f22d;
    border: 1px solid #4f90f2;
  }

  /* Markdown表格样式 */
  .markdown-table {
    border-collapse: collapse;
    width: 100%;
    margin: 4px 0;
    font-size: 11px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    background-color: #fafafa;
    overflow: hidden;
    white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
  }
  
  .markdown-table th,
  .markdown-table td {
    border: 1px solid #e0e0e0;
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
    position: relative;
    white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
  }
  
  .markdown-table th {
    background-color: #f5f5f5;
    font-weight: 600;
    color: #333;
    text-align: center;
    border-bottom: 1px solid #d0d0d0;
  }
  
  .markdown-table td {
    background-color: #fff;
  }
  
  .markdown-table tr:nth-child(even) td {
    background-color: #f8f8f8;
  }
  
  .markdown-table tr:hover td {
    background-color: #f0f8ff;
  }
  
  /* 移除多余的边框，保持简洁 */
  .markdown-table th:not(:last-child),
  .markdown-table td:not(:last-child) {
    border-right: 1px solid #e0e0e0;
  }
  
  .markdown-table tr:not(:last-child) td {
    border-bottom: 1px solid #e0e0e0;
  }
}
