/* ============================================================
   SVG 图集样式
   浅色 / 深色双主题（data-theme 切换），深森林绿强调色（OKLCH）
   ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
  --paper: oklch(0.975 0.006 85);
  --surface: oklch(0.99 0.004 85);
  --canvas: oklch(0.995 0.004 85);
  --ink: oklch(0.26 0.02 85);
  --ink-2: oklch(0.5 0.015 85);
  --line: oklch(0.88 0.008 85);
  --accent: oklch(0.45 0.07 155);
  --accent-hover: oklch(0.38 0.07 155);
  --accent-soft: oklch(0.93 0.02 155);
  --checker-a: oklch(0.955 0.005 85);
  --checker-b: oklch(0.985 0.004 85);
  --shadow: 0 1px 3px oklch(0.2 0.01 85 / 0.08);
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  --paper: oklch(0.21 0.012 85);
  --surface: oklch(0.26 0.014 85);
  --canvas: oklch(0.16 0.01 85);
  --ink: oklch(0.92 0.01 85);
  --ink-2: oklch(0.68 0.012 85);
  --line: oklch(0.36 0.015 85);
  --accent: oklch(0.72 0.09 155);
  --accent-hover: oklch(0.8 0.09 155);
  --accent-soft: oklch(0.3 0.03 155);
  --checker-a: oklch(0.24 0.012 85);
  --checker-b: oklch(0.18 0.01 85);
  --shadow: 0 1px 3px oklch(0 0 0 / 0.35);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

a { color: var(--accent); text-decoration: none; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 32px;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  flex: none;
  width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.0625rem; font-weight: 700; }

.tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 6px 16px;
}
.tree-empty { padding: 12px 14px; color: var(--ink-2); font-size: 0.875rem; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 5px 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.875rem;
  white-space: nowrap;
}
.tree-item:hover { background: var(--accent-soft); }
.tree-item.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }

.chevron {
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 0.75rem;
  cursor: pointer;
  line-height: 1;
}
.chevron.open { transform: rotate(90deg); }

.tree-name, .tree-file {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.tree-name:hover { color: var(--accent-hover); }

/* ---------- 顶栏 ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

/* ---------- 按钮 ---------- */
.btn {
  flex: none;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color 150ms var(--ease), background 150ms var(--ease), color 150ms var(--ease);
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn { padding: 4px 9px; font-size: 1rem; line-height: 1; }

/* ---------- 面包屑 ---------- */
.crumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--ink-2);
}
.crumb-item { color: var(--ink-2); }
.crumb-item:hover { color: var(--accent); }
.crumb-sep { color: var(--line); }

/* ---------- 目录卡片 ---------- */
.dir-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 150ms var(--ease), transform 150ms var(--ease);
}
.dir-card:hover { border-color: var(--accent-hover); transform: translateY(-1px); }
.dir-card-icon { color: var(--accent); display: flex; }
.dir-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dir-card-sub { font-size: 0.8125rem; color: var(--ink-2); }

/* ---------- 网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color 150ms var(--ease), transform 150ms var(--ease);
}
.card:hover, .card:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
  outline: none;
}

.folder-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px 0;
  color: var(--accent);
  background: var(--canvas);
  border-bottom: 1px solid var(--line);
}
.folder-icon svg { width: 34px; height: 34px; }

.thumb {
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
  background-color: var(--canvas);
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  border-bottom: 1px solid var(--line);
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }

.caption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px 12px;
}
.card-title { font-size: 0.9375rem; font-weight: 600; }
.card-file { font-size: 0.75rem; color: var(--ink-2); word-break: break-all; }

/* ---------- 查看器 ---------- */
.viewer-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin: -20px -24px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.viewer-bar .title-box {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
.viewer-bar .title {
  min-width: 0;
  font-weight: 600;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer-bar .pos {
  flex: none;
  font-size: 0.75rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.viewer-bar .mode {
  flex: none;
  font-size: 0.72rem;
  color: var(--ink-2);
  white-space: nowrap;
}

/* 查看器整体：flex 纵向布局，画布高度自适应剩余空间（不写死估算值，避免顶出视口） */
.viewer-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background-color: var(--canvas);
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.viewer-stage svg {
  display: block;
}
.viewer-stage img {
  display: block;
}

.viewer-hint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 5;
  padding: 4px 10px;
  font-size: 0.72rem;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  opacity: 0.75;
  pointer-events: none;
  user-select: none;
  transition: opacity 600ms var(--ease);
}
.viewer-hint.faded { opacity: 0; }
.viewer-stage svg a { cursor: pointer; }
.viewer-stage svg a text {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.notice {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: min(560px, 90vw);
  margin: 0;
  padding: 8px 14px;
  font-size: 0.8125rem;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

/* ---------- 空状态 ---------- */
.empty {
  max-width: 70ch;
  margin: 48px auto;
  padding: 28px 32px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink);
}

/* ---------- 设置弹层 ---------- */
.popover {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 50;
  width: min(300px, 90vw);
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.popover-title { font-weight: 600; margin-bottom: 10px; }
.radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.875rem;
  cursor: pointer;
}
.popover-hint { margin: 10px 0 0; font-size: 0.75rem; color: var(--ink-2); }

/* ---------- 移动端 ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 200ms var(--ease);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }

  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: oklch(0 0 0 / 0.4);
  }

  .content { padding: 14px 14px 24px; }
  .viewer-bar { margin: -14px -14px 10px; padding: 8px 10px; gap: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
}

/* 桌面端：菜单按钮和侧边栏关闭按钮没有作用，直接隐藏（只保留手机端） */
@media (min-width: 769px) {
  #menuBtn { display: none; }
  #closeSidebar { display: none; }
}

/* ---------- 侧栏收起 / 展开（桌面端） ---------- */
/* 把手骑在侧栏右边缘、垂直居中，不与顶栏/侧栏头部任何按钮重叠 */
.side-toggle {
  position: fixed;
  top: 50%;
  left: 250px; /* 264 - 14，按钮居中骑在 264px 侧栏边缘上 */
  transform: translateY(-50%);
  z-index: 25;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: left 200ms var(--ease), border-color 150ms var(--ease), background 150ms var(--ease), color 150ms var(--ease);
}
.side-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}
body.sidebar-collapsed .side-toggle { left: 12px; }

@media (min-width: 769px) {
  .sidebar { transition: width 200ms var(--ease); min-width: 0; }
  body.sidebar-collapsed .sidebar { width: 0; min-width: 0; overflow: hidden; border-right: 0; }
}

/* 手机端：侧栏本来就是抽屉，收起按钮隐藏，用 ☰ 打开 */
@media (max-width: 768px) {
  .side-toggle { display: none; }
}

/* 禁用的上一张/下一张直接隐藏，不显示"点了没反应"的按钮 */
.viewer-bar .btn:disabled { display: none; }

/* 小屏：隐藏次要按钮和模式标签，避免工具条溢出 */
@media (max-width: 480px) {
  .viewer-bar .btn-raw { display: none; }
  .viewer-bar .pos { display: none; }
  .viewer-bar .mode { display: none; }
  .viewer-bar .title { font-size: 0.8125rem; }
}

/* ============================================================
   查看器 v2：分隔符 / 缩放胶囊 / 缩略图条 / 小地图 / 全屏
   ============================================================ */
.bar-sep { flex: none; width: 1px; height: 20px; background: var(--line); }

.btn-strip.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* 内容淡入 */
.viewer-stage > svg,
.viewer-stage > img { animation: viewerIn 180ms var(--ease); }
@keyframes viewerIn { from { opacity: 0; } to { opacity: 1; } }

/* 加载动画 */
.viewer-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink-2);
  font-size: 0.8125rem;
  pointer-events: none;
}
.spin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 缩放胶囊（右下；缩略图条展开时自动上移） */
.zoom-pill {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.viewer-stage.has-strip .zoom-pill { bottom: 102px; }
.zp-btn {
  padding: 4px 10px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.3;
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
}
.zp-btn:hover { background: var(--accent-soft); color: var(--accent-hover); }
.zp-level {
  min-width: 52px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* 底部缩略图条 */
.filmstrip {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px;
  max-width: min(720px, calc(100% - 20px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filmstrip-track {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.fs-item {
  flex: none;
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
  font: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.fs-item:hover { background: var(--accent-soft); }
.fs-item.active { border-color: var(--accent); background: var(--accent-soft); }
.fs-item img {
  width: 100%;
  height: 44px;
  object-fit: contain;
  background: var(--canvas);
  border-radius: 5px;
  pointer-events: none;
}
.fs-item span {
  max-width: 100%;
  font-size: 0.68rem;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fs-item.active span { color: var(--accent-hover); font-weight: 600; }
.fs-close {
  flex: none;
  align-self: flex-start;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 0.7rem;
  border-radius: 6px;
  cursor: pointer;
}
.fs-close:hover { background: var(--accent-soft); color: var(--accent-hover); }
.viewer-stage.has-strip .viewer-hint { bottom: 102px; }
.viewer-stage.has-strip .notice { bottom: 106px; } /* 提示条避开缩略图条 */

/* 小地图（图超出画布时自动浮现） */
.minimap {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  cursor: crosshair;
}
.minimap svg, .minimap img {
  display: block;
  pointer-events: none;
  border-radius: 6px;
  background: var(--canvas);
}
.minimap-viewport {
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  pointer-events: none;
}
.minimap-close {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.minimap-close:hover { color: var(--accent-hover); border-color: var(--accent); }

/* 目录图链接：平时保持原图配色，悬停变强调色 */
.viewer-stage svg a text { transition: fill 120ms var(--ease); }
.viewer-stage svg a:hover text { fill: var(--accent); text-decoration-style: solid; }

/* 全屏（作用于 .main 持久元素，翻页不会退出全屏） */
.main:fullscreen { background: var(--paper); }
.main:fullscreen .topbar { display: none; }
.main:fullscreen .content { padding: 12px; overflow: hidden; }
.main:fullscreen .viewer-wrap { height: 100%; display: flex; flex-direction: column; }
.main:fullscreen .viewer-bar { margin: 0 0 10px; }
.main:fullscreen .viewer-stage { flex: 1; min-height: 0; height: auto; }

/* 移动端：缩略图条更矮，按钮更紧凑 */
@media (max-width: 768px) {
  .filmstrip { bottom: 8px; max-width: calc(100% - 16px); padding: 5px; }
  .fs-item { width: 80px; }
  .fs-item img { height: 36px; }
  .viewer-stage.has-strip .zoom-pill { bottom: 92px; }
  .viewer-stage.has-strip .viewer-hint { bottom: 92px; }
  .viewer-stage.has-strip .notice { bottom: 96px; }
  .viewer-bar .btn-strip, .viewer-bar .btn-full { padding: 6px 8px; }
}

/* 中等宽度：隐藏模式标签，防止查看器栏挤压换行 */
@media (max-width: 1100px) {
  .viewer-bar .mode { display: none; }
}

/* 触屏：放大缩放胶囊的触控热区 */
@media (pointer: coarse) {
  .zp-btn { padding: 8px 12px; }
}
