/*══════════════════════════════════ 
              PAGE 2 — GRAPH
══════════════════════════════════ */
/* 1. 底层：深空背景图 */
#p-graph {
  background-color: transparent;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* 暗化遮罩已迁移到共享 #space-bg 层 */



/* 3. 顶层：你的知识图谱（保持透明） */
#fg-wrap {
  position: absolute;
  inset: 0;
  z-index: 5;
  /* 确保比遮罩层高 */
  background: transparent !important;
}

.graph-tooltip {
  background: transparent !important;
  /* 强制干掉默认的黑底 */
  padding: 0 !important;
  /* 干掉默认的内边距，让你自己的 padding 生效 */
  border: none !important;
  box-shadow: none !important;
  color: inherit !important;
}

/* Topbar */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: max(env(safe-area-inset-top), 14px) 16px 0;
  background: linear-gradient(to bottom, rgba(8, 12, 20, .92) 55%, transparent);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Hidden state */
#topbar.hidden {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

/* Ghost back button: visible when topbar is hidden */
#ghost-back {
  position: absolute;
  top: max(env(safe-area-inset-top), 14px);
  left: 16px;
  z-index: 21;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .04);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  pointer-events: all;
  opacity: 0;
  transition: opacity 0.4s ease;
}

#ghost-back::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

#ghost-back.visible {
  opacity: 0.45;
}

#ghost-back:active {
  background: rgba(255, 255, 255, .1);
  color: rgba(255, 255, 255, 0.6);
}

#topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
}

#btn-back {
  pointer-events: all;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s;
  flex-shrink: 0;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#btn-back::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

#btn-back:active {
  background: rgba(255, 255, 255, .12);
}

#btn-reset {
  pointer-events: all;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s, color .15s;
  flex-shrink: 0;
  margin-left: 6px;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#btn-reset::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

#btn-reset:active {
  background: rgba(255, 255, 255, .12);
  color: var(--text-tertiary);
}

#btn-unlearned {
  pointer-events: all;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .2s, color .2s, border-color .2s;
  flex-shrink: 0;
  margin-left: 4px;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#btn-unlearned::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

#btn-unlearned.active {
  background: rgba(255, 255, 255, .15);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

#btn-unlearned:active {
  background: rgba(255, 255, 255, .12);
}

#tbar-info {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

#tbar-name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

#tbar-stat {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── 🌟 搜索框 (统一尺寸，融入 topbar flex 布局) ─── */
#g-search-wrap {
  position: relative;
  z-index: 100;
  pointer-events: auto;

  display: flex;
  align-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  gap: 0;
  justify-content: center;
  flex-shrink: 0;

  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);

  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#g-search-wrap:focus-within {
  width: 280px;
  height: 44px;
  padding: 0 14px;
  gap: 10px;
  justify-content: flex-start;
  border-radius: 22px;
  background: rgba(24, 26, 36, 0.75);
  border-color: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
}

/* ─── 2. 搜索图标 ─── */
.search-icon {
  color: var(--text-primary);
  flex-shrink: 0;
  transition: color 0.3s ease, border-color 0.3s ease;
}

#g-search-wrap:focus-within .search-icon {
  color: #fff;
}

/* ─── 3. 输入框：收起时隐藏，展开时现身 ─── */
#g-search {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  background: transparent !important;
  border: none !important;
  outline: none;
  color: rgba(255, 255, 255, 0.95);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
}

#g-search-wrap:focus-within #g-search {
  position: relative;
  flex: 1;
  min-width: 0;
  opacity: 1;
  cursor: text;
  width: auto;
  height: auto;
  z-index: auto;
}

#g-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

#g-search::placeholder {
  color: rgba(255, 255, 255, 0.3);
  font-weight: 400;
}

/* ─── 4. 下拉搜索结果面板 (完美对接你的 JS 类名) ─── */
#g-search-results {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 12px;
  width: min(320px, 88vw);
  background: rgba(18, 20, 28, 0.82);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);

  display: none;
  /* 默认隐藏 */
  max-height: 50vh;
  overflow-y: auto;
  z-index: 50;
}

/* 兼容你 JS 里的 .show 逻辑 */
#g-search-results.show,
#g-search-results:not(:empty) {
  display: block;
  animation: dropDownFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dropDownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── 5. 🍎 JS 渲染结果的内部条目排版 (全面升级 Apple 质感) ─── */
.gsr-label {
  font-family: var(--mono, monospace);
  font-size: 10px;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.4);
  padding: 12px 16px 6px;
  text-transform: uppercase;
}

.gsr-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.2s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.gsr-item:last-child {
  border-bottom: none;
}

/* 苹果级高亮反馈 */
.gsr-item:hover,
.gsr-item:active {
  background: rgba(255, 255, 255, 0.1);
}

.gsr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.gsr-word {
  font-family: var(--sans, sans-serif);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  flex: 1;
  min-width: 0;
}

.gsr-zh {
  font-family: var(--serif, serif);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
  text-align: right;
}

.gsr-badge {
  font-family: var(--mono, monospace);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.gsr-empty {
  padding: 24px 16px;
  font-family: var(--sans, sans-serif);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
}

/* ─── 📱 移动端搜索框适配 ─── */
@media (hover: none) and (pointer: coarse),
(max-width: 768px) {
  #g-search-wrap:focus-within {
    /* 核心修复：100vw 减去左右所有的边距、按钮(返回44、重置50、高亮48)与间距，算得恰好是 214px，给搜索框留下的安全扩张空间 */
    /* 用 min 限制在最大 280px（兼顾平板），完美实现宽度平滑动画且确保右侧按钮毫无保留地归位，再无变形割裂感 */
    width: min(280px, calc(100vw - 214px));
    border-radius: 22px;
    background: rgba(24, 26, 36, 0.9);
  }

  #g-search-results {
    width: calc(100vw - 40px);
    max-height: 40vh;
    /* 核心修复：抵消因为右侧排布着两个按钮（高亮 48px + 重置 50px）造成的右锚点内缩，
       利用负偏移量强制将宽大的结果框向右拉回 100 像素。
       计算得到：下拉框左边缘刚好停在距离屏幕左侧约 22px 处的完美安全区！ */
    right: -100px;
  }
}

/* hint */
#g-hint {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .13);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .4s;
  z-index: 5;
}

/* ── 通关庆祝浮层 ── */
#complete-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: coFadeIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
#complete-overlay.co-out {
  animation: coFadeOut 0.6s ease forwards;
}
.co-glow {
  position: absolute;
  width: 200px; height: 200px;
  border-radius: 50%;
  animation: coPulse 2s ease-in-out infinite;
}
.co-icon {
  font-size: 48px;
  margin-bottom: 12px;
  animation: coIconIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}
.co-title {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .35em;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  animation: coTextIn 0.6s ease 0.35s both;
}
.co-sub {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: .15em;
  color: var(--text-muted);
  margin-top: 8px;
  animation: coTextIn 0.6s ease 0.5s both;
}
.co-sparks {
  position: absolute;
  top: 50%; left: 50%;
}
.co-spark {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: coSpark 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes coFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes coFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes coIconIn {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes coTextIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes coPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.1); }
}
@keyframes coSpark {
  0%   { opacity: 1; transform: translate(-50%, -50%) translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translate(var(--sx), var(--sy)) scale(0); }
}