/* v3.css —— v3 大版本前端新组件样式
 * 覆盖范围：toc-fab、lightbox、footnote popover、linkcard 浮窗、反向链接面板
 * 颜色 token 严格按 v3-roadmap-ux.md A.3 节定义
 * 本文件总行数应严格 < 500
 */

/* ---- A.3 新增颜色 token ---- */
:root {
  --surface-overlay: rgba(28, 25, 23, 0.72);
  --surface-elevated: #ffffff;
  --surface-elevated-border: #d6d3d1;
  --surface-shadow: 0 4px 16px rgba(28, 25, 23, 0.08), 0 1px 2px rgba(28, 25, 23, 0.06);
  --border-strong: #a8a29e;
}
html[data-theme="dark"] {
  --surface-overlay: rgba(0, 0, 0, 0.78);
  --surface-elevated: #1a1d23;
  --surface-elevated-border: #3a3633;
  --surface-shadow: 0 4px 16px rgba(0, 0, 0, 0.40), 0 1px 2px rgba(0, 0, 0, 0.32);
  --border-strong: #57534e;
}

/* ---- 1. TOC FAB & 抽屉 ---- */
.toc-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-elevated);
  border: 1px solid var(--surface-elevated-border);
  box-shadow: var(--surface-shadow);
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
  z-index: 40;
  padding: 0;
}
.toc-fab.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.toc-fab:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.toc-fab:active {
  transform: scale(0.96);
}
.toc-fab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toc-drawer {
  margin: 0;
  margin-left: auto;
  margin-right: 0;
  padding: 0;
  border: none;
  width: min(320px, 80vw);
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  background: var(--surface-elevated);
  color: var(--fg);
  box-shadow: var(--surface-shadow);
  border-left: 1px solid var(--border-strong);
  overflow: hidden;
}
.toc-drawer::backdrop {
  background: var(--surface-overlay);
}
.toc-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--surface-elevated-border);
}
.toc-drawer__title { font-weight: 600; }
.toc-drawer__close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--fg-muted);
}
.toc-drawer__close:hover { color: var(--accent); }
.toc-drawer__body {
  padding: 16px 20px;
  overflow-y: auto;
  height: calc(100vh - 57px);
}
.toc-drawer__body a {
  display: block;
  padding: 8px 0;
  color: var(--fg-muted);
  text-decoration: none;
  line-height: 1.5;
  border-left: 2px solid transparent;
  padding-left: 8px;
  transition: color 150ms ease-out, border-color 150ms ease-out;
}
.toc-drawer__body a:hover { color: var(--accent); }
.toc-drawer__body a.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.toc-drawer__body ul,
.toc-drawer__body ol { list-style: none; padding-left: 0; margin: 0; }
.toc-drawer__body .lvl-h3 a,
.toc-drawer__body ul ul a { padding-left: 20px; font-size: 0.875rem; }

/* ---- 2. Lightbox ---- */
.lightbox {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  color: rgba(255, 255, 255, 0.92);
  overflow: hidden;
}
.lightbox::backdrop {
  background: var(--surface-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
body.lightbox-open { overflow: hidden; }
.lightbox__top {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2;
}
.lightbox__zoom {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.72);
}
.lightbox__close {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.lightbox__close:hover { color: #fff; }
.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 0.85);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 2;
}
.lightbox__prev { left: 24px; }
.lightbox__next { right: 24px; }
.lightbox__nav:hover { background: rgba(0, 0, 0, 0.6); color: #fff; }
.lightbox__stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox__img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  cursor: zoom-out;
  transform-origin: center center;
  transition: transform 180ms cubic-bezier(0, 0, 0.2, 1), opacity 160ms ease-out;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox__caption {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: 80vw;
  text-align: center;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.72);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.prose img.zoomable { cursor: zoom-in; }

/* ---- 4. 脚注 hover 浮窗 ---- */
.fn-pop {
  position: absolute;
  z-index: 60;
  max-width: 360px;
  min-width: 200px;
  max-height: 240px;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--surface-elevated-border);
  border-radius: 4px;
  box-shadow: var(--surface-shadow);
  color: var(--fg-muted);
  font-size: 0.875rem;
  line-height: 1.6;
  border-top: 4px solid var(--accent);
  animation: v3FadeIn 80ms ease-out;
}
.fn-pop[hidden] { display: none; }
.fn-pop a { color: var(--accent); }
.fn-pop p:first-child { margin-top: 0; }
.fn-pop p:last-child { margin-bottom: 0; }
@media (max-width: 640px) {
  .fn-pop { max-height: 50vh; max-width: calc(100vw - 24px); }
}

/* ---- 5. 链接卡片 hover ---- */
.linkcard-pop {
  position: absolute;
  z-index: 60;
  width: 380px;
  max-width: calc(100vw - 24px);
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--surface-elevated-border);
  border-radius: 4px;
  box-shadow: var(--surface-shadow);
  color: var(--fg);
  font-size: 0.8125rem;
  line-height: 1.5;
  animation: v3FadeUp 120ms cubic-bezier(0, 0, 0.2, 1);
}
.linkcard-pop[hidden] { display: none; }
.linkcard-pop__img {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg-muted, rgba(0, 0, 0, 0.04));
}
.linkcard-pop__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.linkcard-pop__body { flex: 1; min-width: 0; }
.linkcard-pop__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-subtle, var(--fg-muted));
  margin-bottom: 4px;
}
.linkcard-pop__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.linkcard-pop__desc {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--fg-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.linkcard-pop__skel {
  height: 12px;
  margin: 6px 0;
  background: linear-gradient(90deg,
    rgba(0, 0, 0, 0.06) 0%,
    rgba(0, 0, 0, 0.10) 50%,
    rgba(0, 0, 0, 0.06) 100%);
  background-size: 200% 100%;
  animation: v3Skel 1.2s ease-in-out infinite;
  border-radius: 2px;
}
html[data-theme="dark"] .linkcard-pop__skel {
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.06) 100%);
  background-size: 200% 100%;
}
.linkcard-pop__skel--title { height: 16px; width: 80%; }
.linkcard-pop__skel--desc { width: 100%; }

/* ---- 6. 反向链接面板 ---- */
.backlinks-panel {
  margin: 48px 0 16px;
  padding: 16px 20px;
  border: 1px solid var(--surface-elevated-border);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--surface-elevated);
  box-shadow: var(--surface-shadow);
}
.backlinks-panel__title {
  margin: 0 0 12px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: none;
  letter-spacing: 0.02em;
}
.backlinks-panel__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.backlinks-panel__item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9375rem;
  line-height: 1.5;
}
.backlinks-panel__item a {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 150ms ease-out, border-color 150ms ease-out;
}
.backlinks-panel__item a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.backlinks-panel__date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-subtle, var(--fg-muted));
  white-space: nowrap;
}

/* ---- 动效 ---- */
@keyframes v3FadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes v3FadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes v3Skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__img,
  .fn-pop,
  .linkcard-pop,
  .toc-fab { transition: none; animation-duration: 80ms; }
  @keyframes v3FadeUp { from { opacity: 0; } to { opacity: 1; } }
  @keyframes v3Skel { 0%, 100% { background-position: 0 0; } }
}

/* 触摸目标可命中区不小于 44px：FAB 已 48；关闭按钮、导航按钮通过 padding 扩展 */
@media (hover: none) {
  .toc-drawer__close,
  .lightbox__close { padding: 6px; }
}
