body, html { margin: 0; padding: 0; width: 100%; height: 100%; font-family: "PingFang TC", "Microsoft JhengHei", sans-serif; background: #f8fafc; overflow: hidden; }
    
    /* 頂部導覽列 */
    #topbar { position: fixed; top: 0; left: 0; right: 0; height: 56px; background: #1e293b; color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; z-index: 1000; box-shadow: 0 2px 8px rgba(0,0,0,0.15); gap: 8px; overflow: visible; }
    #topbar h1 { font-size: 16px; margin: 0; font-weight: 600; white-space: nowrap; }
    .top-controls { display: flex; align-items: center; gap: 6px; overflow: visible; }
    .control-box { display: flex; align-items: center; background: #334155; padding: 4px 8px; border-radius: 6px; border: 1px solid #475569; font-size: 13px; white-space: nowrap; }
    .control-box label { color: #cbd5e1; margin-right: 4px; }
    .control-box select { background: transparent; color: #38bdf8; font-weight: 600; border: none; outline: none; font-size: 13px; cursor: pointer; max-width: 120px; }
    .control-box select option { background: #1e293b; color: white; }

    /* 搜尋身分下拉選單 (Combobox) */
    .me-combobox-wrapper { position: relative; }
    .combobox-inner { display: flex; align-items: center; position: relative; }
    .combobox-input {
      background: transparent;
      color: #38bdf8;
      font-weight: 600;
      border: none;
      outline: none;
      font-size: 13px;
      cursor: text;
      width: 140px;
      padding-right: 18px;
    }
    .combobox-input::placeholder { color: #94a3b8; font-weight: normal; }
    .combobox-arrow {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      background: none;
      border: none;
      color: #94a3b8;
      font-size: 10px;
      cursor: pointer;
      padding: 2px;
    }
    .combobox-arrow:hover { color: #38bdf8; }

    /* 全域簡約 Toast 回饋提示 */
    .global-toast {
      position: fixed;
      top: 70px;
      left: 50%;
      transform: translateX(-50%) translateY(-15px);
      background: #0f172a;
      color: #38bdf8;
      border: 1px solid #0284c7;
      padding: 8px 18px;
      border-radius: 30px;
      font-size: 14px;
      font-weight: 600;
      z-index: 11000;
      opacity: 0;
      pointer-events: none;
      transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
      white-space: nowrap;
    }
    .global-toast.show {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }

    .combobox-options-list {
      position: absolute;
      top: calc(100% + 8px);
      left: 0;
      min-width: 275px;
      max-width: 360px;
      max-height: 380px;
      background: #1e293b;
      border: 1px solid #475569;
      border-radius: 8px;
      box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55);
      z-index: 1002;
      display: none;
      padding: 0;
      overflow: hidden;
    }
    .combobox-options-list.show { display: flex; flex-direction: column; }
    .combobox-search-bar {
      padding: 8px 10px;
      background: #1e293b;
      border-bottom: 1px solid #334155;
      flex-shrink: 0;
    }
    .combobox-filter-input {
      width: 100%;
      box-sizing: border-box;
      background: #0f172a;
      border: 1px solid #475569;
      border-radius: 6px;
      color: #f8fafc;
      font-size: 13px;
      padding: 6px 10px;
      outline: none;
    }
    .combobox-filter-input:focus { border-color: #38bdf8; }

    /* 身分清單排序工具列 */
    .combobox-sort-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 6px 10px;
      background: #162032;
      border-bottom: 1px solid #334155;
      font-size: 12px;
      gap: 6px;
      flex-shrink: 0;
    }
    .combobox-sort-group {
      display: flex;
      align-items: center;
      gap: 4px;
    }
    .combobox-sort-label {
      color: #94a3b8;
      font-size: 11.5px;
      margin-right: 2px;
      user-select: none;
    }
    .combobox-sort-btn {
      background: #1e293b;
      color: #94a3b8;
      border: 1px solid #334155;
      border-radius: 5px;
      padding: 3px 8px;
      font-size: 12px;
      cursor: pointer;
      line-height: 1.4;
      transition: all 0.15s ease;
      user-select: none;
    }
    .combobox-sort-btn:hover {
      color: #e2e8f0;
      border-color: #475569;
    }
    .combobox-sort-btn.active {
      background: rgba(2, 132, 199, 0.22);
      color: #38bdf8;
      border-color: #0284c7;
      font-weight: 600;
    }
    .combobox-order-btn {
      display: inline-flex;
      align-items: center;
      gap: 3px;
      background: #1e293b;
      color: #e2e8f0;
      border: 1px solid #334155;
      border-radius: 5px;
      padding: 3px 8px;
      font-size: 12px;
      cursor: pointer;
      line-height: 1.4;
      transition: all 0.15s ease;
      user-select: none;
    }
    .combobox-order-btn:hover {
      color: #38bdf8;
      border-color: #38bdf8;
      background: rgba(56, 189, 248, 0.1);
    }
    .combobox-order-btn #sort-order-icon {
      font-size: 10px;
    }
    .combobox-items-container {
      overflow-y: auto;
      max-height: 300px;
      padding: 4px 0;
      -webkit-overflow-scrolling: touch;
    }
    .combobox-option {
      padding: 9px 13px;
      font-size: 13.5px;
      color: #f1f5f9;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      align-items: center;
      transition: background 0.12s ease;
      white-space: nowrap;
      user-select: none;
      -webkit-user-select: none;
    }
    .combobox-option:hover {
      background: #334155;
      color: #38bdf8;
    }
    .combobox-option.selected {
      background: #0284c7;
      color: #ffffff;
      font-weight: 600;
    }
    .combobox-option-meta {
      font-size: 11.5px;
      color: #94a3b8;
      margin-left: 10px;
    }
    .combobox-option.selected .combobox-option-meta { color: #e0f2fe; }
    .reset-option { color: #94a3b8; font-style: italic; border-bottom: 1px solid #334155; margin-bottom: 3px; }
    .reset-option:hover { color: #f87171; background: #334155; }
    .combobox-empty {
      padding: 12px;
      font-size: 12px;
      color: #94a3b8;
      text-align: center;
    }
    
    .top-btn { background: #334155; color: #f8fafc; border: 1px solid #475569; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; transition: all 0.2s; }
    .top-btn:hover { background: #475569; }
    .top-btn.active { background: #0284c7; border-color: #38bdf8; color: white; font-weight: 600; }
    
    /* 鍵盤無障礙焦點外框 (WCAG 2.4.7 Focus Visible) */
    button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
      outline: 2px solid #0284c7;
      outline-offset: 2px;
    }

    #tree { width: 100%; height: calc(100% - 56px); margin-top: 56px; }

    /* 載入中遮罩（覆蓋全螢幕與導覽列，防阻重複點擊與競態崩潰） */
    #loading { position: fixed; inset: 0; background: rgba(248, 250, 252, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 2000; font-size: 15px; color: #334155; font-weight: 600; }
    .spinner { width: 36px; height: 36px; border: 4px solid #cbd5e1; border-top-color: #2563eb; border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 12px; }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* 右側滑出式個人 Wiki 面板 */
    #drawer { position: fixed; top: 56px; right: -390px; width: 350px; max-width: 92vw; height: calc(100% - 56px); background: white; box-shadow: -4px 0 16px rgba(0,0,0,0.12); transition: right 0.3s ease; z-index: 200; padding: 22px; box-sizing: border-box; overflow-y: auto; }
    #drawer.open { right: 0; }
    .close-btn { float: right; cursor: pointer; font-size: 22px; color: #64748b; border: none; background: none; }
    .avatar-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
    .avatar-wrapper { position: relative; width: 106px; height: 106px; margin: 0 auto 8px; cursor: zoom-in; border-radius: 50%; }
    .avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #e2e8f0; display: block; border: 3.5px solid #f8fafc; box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12); box-sizing: border-box; transition: transform 0.2s, box-shadow 0.2s; }
    .avatar-wrapper:hover .avatar { transform: scale(1.02); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16); }
    .avatar-actions-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
    .btn-change-avatar { background: #f1f5f9; border: 1px solid #cbd5e1; color: #334155; font-size: 12px; font-weight: 500; padding: 4px 12px; border-radius: 999px; cursor: pointer; transition: all 0.2s; }
    .btn-change-avatar:hover { background: #e2e8f0; color: #0284c7; border-color: #38bdf8; }
    .btn-remove-avatar { background: none; border: 1px solid #e2e8f0; color: #94a3b8; font-size: 12px; padding: 4px 12px; border-radius: 999px; cursor: pointer; transition: all 0.2s; }
    .btn-remove-avatar:hover { background: #fee2e2; border-color: #fca5a5; color: #ef4444; }
    .avatar-hover-overlay { position: absolute; inset: 0; border-radius: 50%; background: rgba(15, 23, 42, 0.65); display: flex; align-items: center; justify-content: center; color: white; font-size: 12px; font-weight: 600; opacity: 0; transition: opacity 0.2s ease; backdrop-filter: blur(2px); pointer-events: none; }
    .avatar-wrapper:hover .avatar-hover-overlay { opacity: 1; }
    .name-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 6px; flex-wrap: wrap; }
    .member-name { text-align: center; font-size: 21px; font-weight: bold; margin: 0; color: #0f172a; word-break: break-word; overflow-wrap: anywhere; max-width: 100%; }
    .btn-edit-name { background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 6px; cursor: pointer; font-size: 12px; padding: 3px 8px; color: #475569; transition: all 0.2s; display: inline-flex; align-items: center; gap: 3px; font-weight: 500; flex-shrink: 0; }
    .btn-edit-name:hover { background: #e2e8f0; color: #0284c7; border-color: #38bdf8; transform: scale(1.04); }
    
    .kinship-badge { display: table; margin: 0 auto 6px; background: #e0f2fe; color: #0369a1; font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; border: 1px solid #bae6fd; }
    .kinship-chain { text-align: center; font-size: 12px; color: #64748b; margin-bottom: 10px; }
    
    .quick-btn-group { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
    .mini-btn { background: #f8fafc; color: #334155; border: 1px solid #cbd5e1; padding: 5px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
    .mini-btn:hover { background: #e2e8f0; }

    .meta-row { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 14px; }
    .member-meta { text-align: center; font-size: 13px; color: #64748b; margin-bottom: 0; }
    .mini-edit-btn { background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 4px; cursor: pointer; font-size: 11px; padding: 2px 7px; color: #64748b; transition: all 0.2s; display: inline-flex; align-items: center; gap: 2px; }
    .mini-edit-btn:hover { background: #e2e8f0; color: #0284c7; border-color: #38bdf8; transform: scale(1.05); }
    .section-title-row { display: flex; align-items: center; justify-content: flex-start; gap: 8px; margin-bottom: 8px; }
    .action-title { font-size: 13px; font-weight: 600; color: #475569; margin-bottom: 8px; }
    .bio-box { background: #f1f5f9; padding: 14px; border-radius: 8px; font-size: 14px; line-height: 1.6; color: #334155; margin-bottom: 20px; white-space: pre-wrap; max-height: 170px; overflow-y: auto; overflow-wrap: anywhere; word-break: break-word; }
    .bio-textarea { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 14px; line-height: 1.6; color: #1e293b; font-family: inherit; resize: vertical; min-height: 130px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
    .bio-textarea:focus { border-color: #0284c7; box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15); }
    .bio-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
    .bio-btn-cancel { background: #f1f5f9; border: 1px solid #cbd5e1; padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; color: #64748b; font-weight: 500; }
    .bio-btn-cancel:hover { background: #e2e8f0; color: #334155; }
    .bio-btn-save { background: #0284c7; border: 1px solid #0284c7; padding: 6px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; color: white; font-weight: 600; transition: background 0.2s; }
    .bio-btn-save:hover { background: #0369a1; }
    .btn { display: block; width: 100%; padding: 10px; margin-bottom: 8px; border-radius: 8px; text-align: center; text-decoration: none; font-weight: 600; font-size: 14px; box-sizing: border-box; transition: opacity 0.2s; }
    .btn:hover { opacity: 0.9; }
    .btn-edit { background: #2563eb; color: white; }
    .btn-parent { background: #d97706; color: white; }
    .btn-child { background: #059669; color: white; }
    .btn-spouse { background: #7c3aed; color: white; border: none; cursor: pointer; }
    .btn-parent { border: none; cursor: pointer; }
    .btn-child { border: none; cursor: pointer; }
    /* 新增家族成員彈窗 (Modal Dialog) */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.72);
      backdrop-filter: blur(4px);
      z-index: 10000;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      box-sizing: border-box;
      animation: modalFadeIn 0.2s ease;
    }
    @keyframes modalFadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }
    .modal-card {
      background: #ffffff;
      width: 100%;
      max-width: 440px;
      border-radius: 12px;
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      animation: modalSlideUp 0.25s ease;
    }
    @keyframes modalSlideUp {
      from { opacity: 0; transform: translateY(20px) scale(0.97); }
      to { opacity: 1; transform: translateY(0) scale(1); }
    }
    .modal-header {
      background: #1e293b;
      color: white;
      padding: 14px 18px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .modal-title {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .modal-close-btn {
      background: none;
      border: none;
      color: #94a3b8;
      font-size: 20px;
      cursor: pointer;
      line-height: 1;
      padding: 2px 6px;
      border-radius: 4px;
      transition: color 0.2s;
    }
    .modal-close-btn:hover { color: white; background: #334155; }
    .modal-body {
      padding: 18px 20px;
      display: flex;
      flex-direction: column;
      gap: 14px;
      max-height: calc(85vh - 120px);
      overflow-y: auto;
    }
    .form-group {
      display: flex;
      flex-direction: column;
      gap: 5px;
    }
    .form-label {
      font-size: 13px;
      font-weight: 600;
      color: #334155;
    }
    .required-star { color: #ef4444; }
    .form-input, .form-textarea {
      width: 100%;
      box-sizing: border-box;
      padding: 9px 12px;
      border: 1.5px solid #cbd5e1;
      border-radius: 8px;
      font-size: 14px;
      font-family: inherit;
      color: #0f172a;
      outline: none;
      transition: border-color 0.2s, box-shadow 0.2s;
    }
    .form-input:focus, .form-textarea:focus {
      border-color: #0284c7;
      box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
    }
    .gender-radio-group {
      display: flex;
      gap: 12px;
    }
    .gender-radio-label {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      padding: 8px;
      border: 1.5px solid #cbd5e1;
      border-radius: 8px;
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      color: #475569;
      transition: all 0.2s;
      user-select: none;
    }
    .gender-radio-label:has(input:checked) {
      border-color: #0284c7;
      background: #e0f2fe;
      color: #0369a1;
      font-weight: 600;
    }
    .gender-radio-label.disabled,
    .gender-radio-label:has(input:disabled) {
      opacity: 0.45;
      cursor: not-allowed;
      background: #f1f5f9;
      border-color: #cbd5e1;
      color: #94a3b8;
      pointer-events: none;
    }
    .gender-radio-label input { accent-color: #0284c7; }
    .form-hint {
      font-size: 12px;
      color: #64748b;
      background: #f8fafc;
      border-left: 3px solid #0284c7;
      padding: 6px 10px;
      border-radius: 4px;
      line-height: 1.4;
    }
    .photo-upload-preview-row {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .preview-avatar-box {
      position: relative;
      width: 60px;
      height: 60px;
      border-radius: 50%;
      overflow: hidden;
      cursor: pointer;
      border: 2px solid #e2e8f0;
      flex-shrink: 0;
    }
    .preview-avatar-box img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }
    .preview-avatar-overlay {
      position: absolute;
      inset: 0;
      background: rgba(15, 23, 42, 0.65);
      color: white;
      font-size: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.2s;
    }
    .preview-avatar-box:hover .preview-avatar-overlay { opacity: 1; }
    .photo-upload-actions {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }
    .btn-select-photo {
      background: #f1f5f9;
      border: 1px solid #cbd5e1;
      color: #334155;
      padding: 5px 12px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 500;
      cursor: pointer;
      width: fit-content;
      transition: all 0.2s;
    }
    .btn-select-photo:hover { background: #e2e8f0; color: #0284c7; border-color: #38bdf8; }
    .btn-clear-photo {
      background: none;
      border: none;
      color: #ef4444;
      font-size: 11px;
      cursor: pointer;
      padding: 0;
      text-align: left;
      text-decoration: underline;
    }
    .photo-hint { font-size: 11px; color: #64748b; }
    .modal-footer {
      padding: 12px 20px;
      background: #f8fafc;
      border-top: 1px solid #e2e8f0;
      display: flex;
      justify-content: flex-end;
      gap: 10px;
    }
    .modal-btn-cancel {
      background: #ffffff;
      border: 1px solid #cbd5e1;
      color: #64748b;
      padding: 8px 16px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
    }
    .modal-btn-cancel:hover { background: #f1f5f9; color: #334155; }
    .modal-btn-submit {
      background: #0284c7;
      border: 1px solid #0284c7;
      color: white;
      padding: 8px 18px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.2s;
    }
    .modal-btn-submit:hover { background: #0369a1; }

    .link-delete-member {
      display: inline-block;
      font-size: 11px;
      color: #64748b;
      background: none;
      border: none;
      cursor: pointer;
      font-family: inherit;
      text-decoration: none;
      cursor: pointer;
      padding: 4px 8px;
      border-radius: 4px;
      transition: all 0.2s ease;
      letter-spacing: 0.2px;
    }
    
    /* 檢視設定下拉選單 (Scheme 2) */
    .view-menu-wrapper { position: relative; }
    .view-menu-panel {
      position: absolute;
      top: calc(100% + 8px);
      right: 0;
      width: 266px;
      background: #1e293b;
      border: 1px solid #475569;
      border-radius: 8px;
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
      padding: 12px;
      z-index: 9999;
      display: none;
    }
    .view-menu-panel.show { display: block; }
    .view-menu-section { display: flex; flex-direction: column; gap: 4px; }
    .view-menu-title { font-size: 11px; font-weight: 700; color: #94a3b8; letter-spacing: 0.5px; margin-bottom: 4px; }
    .view-radio-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 7px 8px;
      border-radius: 6px;
      cursor: pointer;
      font-size: 13px;
      color: #f1f5f9;
      transition: background 0.15s;
      user-select: none;
    }
    .view-radio-item:hover { background: #334155; }
    .view-radio-item input[type="radio"] { cursor: pointer; accent-color: #0284c7; }
    .view-menu-divider { height: 1px; background: #334155; margin: 10px 0; }
    .depth-btn-group { display: flex; gap: 4px; background: #0f172a; padding: 3px; border-radius: 6px; border: 1px solid #334155; }
    .depth-btn {
      flex: 1;
      background: transparent;
      border: none;
      color: #94a3b8;
      padding: 6px 0;
      font-size: 12px;
      font-weight: 600;
      border-radius: 4px;
      cursor: pointer;
      transition: all 0.15s;
      text-align: center;
    }
    .depth-btn:hover { color: #f8fafc; }
    .depth-btn.active { background: #0284c7; color: #ffffff; }
    .view-active-dot {
      display: inline-block;
      width: 7px;
      height: 7px;
      background: #38bdf8;
      border-radius: 50%;
      margin-left: 5px;
      box-shadow: 0 0 6px #38bdf8;
      vertical-align: middle;
    }
    .branch-filter-tag {
      margin-top: 6px;
      padding: 6px 10px;
      background: rgba(2, 132, 199, 0.15);
      border: 1px solid rgba(56, 189, 248, 0.35);
      border-radius: 6px;
      font-size: 12px;
      color: #e0f2fe;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: space-between;
      transition: background 0.15s;
    }
    .branch-filter-tag:hover { background: rgba(2, 132, 199, 0.25); }

    .link-delete-member:hover {
      color: #e11d48;
      background: #fff1f2;
      text-decoration: none;
    }
    .hint { font-size: 12.5px; color: #64748b; text-align: center; margin-top: 8px; line-height: 1.55; }

    /* 懸浮提示框 (Tooltip) */
    .tree-tooltip {
      position: fixed;
      background: rgba(15, 23, 42, 0.94);
      color: #f8fafc;
      padding: 7px 12px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 500;
      line-height: 1.4;
      pointer-events: none;
      z-index: 9999;
      display: none;
      box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
      white-space: nowrap;
      border: 1px solid rgba(255, 255, 255, 0.16);
      backdrop-filter: blur(4px);
      transition: opacity 0.15s ease;
    }
    /* 卡片邊緣「＋ / －」開合圓鈕互動效果 */
    [data-ctrl-ec-id] {
      cursor: pointer;
    }
    [data-ctrl-ec-id]:hover circle {
      stroke: #0284c7 !important;
      stroke-width: 2.5px !important;
    }

    /* 卡片右上角「向上展開 / 向上收合」按鈕微互動效果 */
    [data-ctrl-up-id] {
      cursor: pointer;
      transition: transform 0.15s ease-out;
    }
    [data-ctrl-up-id]:hover {
      filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
    }
    [data-ctrl-up-id]:hover circle {
      filter: brightness(1.12);
    }

    /* 優化內建搜尋框樣式 (.bft-search) */
    .bft-search {
      top: 14px !important;
      right: 16px !important;
      z-index: 90 !important;
    }
    .bft-search .bft-form-field {
      min-width: 240px !important;
    }
    .bft-search .bft-input > label {
      display: none !important;
    }
    .bft-search .bft-input > input {
      height: 38px !important;
      padding: 0 16px !important;
      font-size: 13px !important;
      line-height: 38px !important;
      border-radius: 999px !important;
      background: rgba(255, 255, 255, 0.94) !important;
      backdrop-filter: blur(6px);
      border: 1px solid #cbd5e1 !important;
      box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08) !important;
      color: #0f172a !important;
      box-sizing: border-box !important;
      transition: border-color 0.2s, box-shadow 0.2s !important;
    }
    .bft-search .bft-input > input::placeholder {
      color: #64748b !important;
      opacity: 1 !important;
    }
    .bft-search .bft-input > input:focus {
      border-color: #0284c7 !important;
      box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15), 0 2px 10px rgba(15, 23, 42, 0.08) !important;
      outline: none !important;
    }

    /* ====== 手機與平板自適應版面 (Responsive Mobile Design) ====== */
    @media screen and (max-width: 680px) {
      /* 1. 頂部導覽列改為雙層緊湊排版，文字適度放大更清晰 */
      #topbar {
        height: 88px;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        padding: 7px 12px;
        gap: 6px;
        box-sizing: border-box;
      }
      #topbar h1 {
        font-size: 15.5px;
        font-weight: 700;
        line-height: 1.2;
        text-align: left;
        margin: 0;
        letter-spacing: 0.4px;
      }
      .top-controls {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
      }
      .control-box.me-combobox-wrapper {
        flex: 1;
        min-width: 0;
        height: 36px;
        padding: 0 8px;
        box-sizing: border-box;
      }
      .control-box label {
        font-size: 13.5px;
        margin-right: 2px;
        flex-shrink: 0;
      }
      .combobox-inner {
        flex: 1;
        min-width: 0;
      }
      .combobox-input {
        width: 100%;
        min-width: 0;
        font-size: 14px;
        font-weight: 600;
        padding-right: 18px;
        text-overflow: ellipsis;
      }
      .top-btn {
        height: 36px;
        padding: 0 10px;
        font-size: 13.5px;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 3px;
        box-sizing: border-box;
        flex-shrink: 0;
      }

      /* 手機版身分選單：置頂大面板，居中對齊螢幕兩側，保證好滑好點不卡手 */
      .combobox-options-list {
        position: fixed;
        top: 98px;
        left: 10px;
        right: 10px;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: calc(78vh - 98px);
        border-radius: 12px;
        box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
        border: 1px solid #475569;
        z-index: 1002;
      }
      .combobox-search-bar {
        padding: 9px 12px;
      }
      .combobox-filter-input {
        font-size: 14.5px;
        padding: 8px 12px;
      }
      .combobox-sort-bar {
        padding: 7px 12px;
      }
      .combobox-sort-btn, .combobox-order-btn {
        padding: 4px 10px;
        font-size: 13px;
      }
      .combobox-items-container {
        max-height: calc(78vh - 198px);
      }
      .combobox-option {
        padding: 13px 15px;
        font-size: 15.5px;
        min-height: 46px;
        box-sizing: border-box;
      }
      .combobox-option:active {
        background: #0284c7 !important;
        color: #ffffff;
      }
      .combobox-option-meta {
        font-size: 13px;
      }
      .global-toast {
        top: 100px;
        font-size: 13px;
        padding: 7px 16px;
      }
      .view-menu-panel {
        right: 0 !important;
        width: 276px;
        max-width: calc(100vw - 24px);
        padding: 14px;
      }
      .view-menu-title {
        font-size: 12.5px;
      }
      .view-radio-item {
        font-size: 14.5px;
        padding: 8px;
      }
      .depth-btn {
        font-size: 13px;
        padding: 7px 2px;
        white-space: nowrap;
      }
      .branch-filter-tag {
        font-size: 13.5px;
        padding: 7px 10px;
      }

      /* 2. 調整畫布與載入遮罩高度以配合雙層頂部列 */
      #tree {
        height: calc(100% - 88px);
        margin-top: 88px;
      }
      #loading {
        inset: 0 !important;
        font-size: 15px;
        padding: 0 20px;
        text-align: center;
      }

      /* 3. 族譜畫布上方搜尋框改為膠囊懸浮條，高度精緻且不遮擋節點 */
      .bft-search {
        top: 8px !important;
        left: 14px !important;
        right: 14px !important;
        width: auto !important;
      }
      .bft-search .bft-form-field {
        min-width: 0 !important;
        width: 100% !important;
      }
      .bft-search .bft-input > input {
        height: 36px !important;
        line-height: 36px !important;
        font-size: 14.5px !important;
        padding: 0 16px !important;
        border-radius: 999px !important;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12) !important;
      }

      /* 4. 個人資料抽屜 (#drawer) 在手機改為底部滑出面板 (Bottom Sheet) */
      #drawer {
        top: auto;
        left: 0;
        right: 0;
        bottom: -100%;
        width: 100%;
        max-width: 100%;
        height: 78vh;
        max-height: calc(100dvh - 92px);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.25);
        transition: bottom 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        padding: 14px 18px 28px;
      }
      #drawer::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 999px;
        margin: 0 auto 10px;
      }
      #drawer.open {
        bottom: 0;
        right: 0;
      }
      .close-btn {
        width: 34px;
        height: 34px;
        border-radius: 50%;
        background: #f1f5f9;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        color: #475569;
      }
      .avatar-wrapper {
        width: 104px;
        height: 104px;
        margin: 0 auto 10px;
      }
      /* 手機上取消原先壓在圓圈底部的黑條，由下方獨立按鈕取代，畫面乾淨字體清晰 */
      .avatar-hover-overlay {
        display: none !important;
      }
      .member-name {
        font-size: 22px;
      }
      .btn-edit-name {
        font-size: 13px;
        padding: 4px 9px;
      }
      .kinship-badge {
        font-size: 14.5px;
        padding: 5px 14px;
      }
      .kinship-chain {
        font-size: 13px;
      }
      .mini-btn {
        font-size: 13px;
        padding: 6px 12px;
      }
      .member-meta {
        font-size: 14px;
      }
      .mini-edit-btn {
        font-size: 12.5px;
        padding: 3px 8px;
      }
      .action-title {
        font-size: 14.5px;
      }
      .bio-box {
        max-height: 140px;
        font-size: 15px;
        line-height: 1.65;
        padding: 13px;
      }
      .btn {
        font-size: 15px;
        padding: 11px;
      }
      .btn-change-avatar, .btn-remove-avatar {
        font-size: 13px;
        padding: 5px 14px;
      }
      .bio-textarea, .form-input, .form-textarea {
        font-size: 16px;
      }

      /* 5. 新增成員彈窗在手機上的適配 */
      .modal-overlay {
        padding: 10px;
        align-items: flex-end;
      }
      .modal-card {
        max-width: 100%;
        border-radius: 16px 16px 12px 12px;
        max-height: 90dvh;
      }
      .modal-body {
        padding: 14px 16px;
        gap: 12px;
        max-height: calc(90dvh - 116px);
      }
      .preview-avatar-overlay {
        opacity: 1;
        inset: auto 0 0 0;
        height: 18px;
        font-size: 9px;
      }

      /* 6. 觸控裝置隱藏滑鼠懸浮提示框，避免點擊後殘留黑框 */
      .tree-tooltip {
        display: none !important;
      }
    }

    /* 超窄螢幕手機 (< 390px) 進一步精簡按鈕文字 */
    @media screen and (max-width: 390px) {
      .btn-text-full {
        display: none;
      }
    }

    /* 圖片大圖檢視燈箱 (Lightbox) */
    .lightbox-overlay {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.88);
      backdrop-filter: blur(8px);
      z-index: 99999;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      box-sizing: border-box;
      animation: modalFadeIn 0.2s ease;
      cursor: zoom-out;
    }
    .lightbox-content {
      position: relative;
      max-width: 90vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      cursor: default;
    }
    .lightbox-img {
      max-width: 88vw;
      max-height: 72vh;
      border-radius: 14px;
      box-shadow: 0 24px 50px rgba(0, 0, 0, 0.55);
      object-fit: contain;
      background: #0f172a;
      border: 3px solid rgba(255, 255, 255, 0.15);
      display: block;
    }
    .lightbox-caption {
      color: #f8fafc;
      font-size: 15px;
      font-weight: 600;
      margin-top: 14px;
      text-align: center;
      text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
      letter-spacing: 0.5px;
    }
    .lightbox-close {
      position: absolute;
      top: -46px;
      right: 0;
      background: rgba(255, 255, 255, 0.22);
      border: 1px solid rgba(255, 255, 255, 0.35);
      color: white;
      font-size: 20px;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 0.2s, transform 0.2s;
    }
    .lightbox-close:hover {
      background: rgba(255, 255, 255, 0.4);
      transform: scale(1.08);
    }

    /* 尚未選擇「我是誰」時的引導微光與底部輕量提示條 */
    .me-combobox-wrapper.unselected-pulse {
      border-color: rgba(56, 189, 248, 0.75);
      box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18);
    }
    .identity-onboarding-banner {
      position: fixed;
      bottom: 18px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 950;
      background: rgba(15, 23, 42, 0.92);
      color: #f8fafc;
      border: 1px solid rgba(56, 189, 248, 0.45);
      border-radius: 999px;
      padding: 8px 14px 8px 16px;
      font-size: 13px;
      display: none;
      align-items: center;
      gap: 10px;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
      backdrop-filter: blur(8px);
      max-width: calc(100vw - 24px);
      white-space: nowrap;
      cursor: pointer;
      transition: transform 0.2s, background 0.2s;
    }
    .identity-onboarding-banner:hover {
      background: rgba(15, 23, 42, 0.98);
      transform: translateX(-50%) translateY(-1px);
    }
    .identity-onboarding-banner .banner-text {
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .identity-onboarding-banner .banner-highlight {
      color: #38bdf8;
      font-weight: 700;
      text-decoration: underline;
      text-underline-offset: 3px;
    }
    .identity-onboarding-banner .banner-close {
      background: rgba(255, 255, 255, 0.12);
      border: none;
      color: #cbd5e1;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      font-size: 12px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }
    .identity-onboarding-banner .banner-close:hover {
      background: rgba(255, 255, 255, 0.25);
      color: #fff;
    }
    @media (max-width: 680px) {
      .identity-onboarding-banner {
        bottom: 12px;
        font-size: 12px;
        padding: 7px 10px 7px 13px;
        gap: 6px;
      }
    }

    /* ====== 照片裁切與圓框預覽彈窗 (Photo Cropper Modal) ====== */
    .cropper-modal-overlay {
      z-index: 10005;
    }
    .cropper-modal-card {
      max-width: 380px;
      width: 100%;
    }
    .cropper-modal-body {
      align-items: center;
      padding: 18px 18px 14px;
      gap: 14px;
    }
    .cropper-stage-wrapper {
      display: flex;
      justify-content: center;
      width: 100%;
    }
    .cropper-viewport {
      position: relative;
      width: 280px;
      height: 280px;
      background: #0f172a;
      border-radius: 14px;
      overflow: hidden;
      cursor: grab;
      touch-action: none;
      user-select: none;
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 8px 24px rgba(15, 23, 42, 0.18);
    }
    .cropper-viewport.dragging {
      cursor: grabbing;
    }
    #cropper-canvas {
      width: 100%;
      height: 100%;
      display: block;
      pointer-events: none;
    }
    .cropper-circle-mask {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 220px;
      height: 220px;
      transform: translate(-50%, -50%);
      border-radius: 50%;
      border: 3px solid #ffffff;
      box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.64), 0 0 16px rgba(0, 0, 0, 0.4);
      pointer-events: none;
      box-sizing: border-box;
      overflow: hidden;
    }
    .cropper-grid-h,
    .cropper-grid-v {
      position: absolute;
      inset: 0;
      opacity: 0;
      transition: opacity 0.2s ease;
      pointer-events: none;
    }
    .cropper-grid-h {
      border-top: 1px dashed rgba(255, 255, 255, 0.45);
      border-bottom: 1px dashed rgba(255, 255, 255, 0.45);
      top: 33.33%;
      bottom: 33.33%;
    }
    .cropper-grid-v {
      border-left: 1px dashed rgba(255, 255, 255, 0.45);
      border-right: 1px dashed rgba(255, 255, 255, 0.45);
      left: 33.33%;
      right: 33.33%;
    }
    .cropper-viewport.dragging .cropper-grid-h,
    .cropper-viewport.dragging .cropper-grid-v {
      opacity: 1;
    }
    .cropper-controls {
      width: 100%;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }
    .cropper-zoom-row {
      display: flex;
      align-items: center;
      gap: 8px;
      width: 100%;
    }
    .cropper-zoom-btn {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: #f8fafc;
      color: #334155;
      font-size: 13px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: all 0.15s;
    }
    .cropper-zoom-btn:hover {
      background: #e2e8f0;
      border-color: #94a3b8;
    }
    .cropper-zoom-slider {
      flex: 1;
      accent-color: #0284c7;
      cursor: pointer;
      height: 6px;
    }
    .cropper-reset-btn {
      padding: 6px 10px;
      height: 32px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: #f8fafc;
      color: #475569;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      flex-shrink: 0;
      transition: all 0.15s;
    }
    .cropper-reset-btn:hover {
      background: #e2e8f0;
      color: #0f172a;
    }
    .cropper-hint {
      font-size: 12px;
      color: #64748b;
      text-align: center;
      line-height: 1.45;
    }
