/* ============================================================================
   ZY视觉工作台 · 大图浏览 / 历史列表 / 作品库性能优化
   本文件必须在 styles.css、slice.css 之后加载（index.html 里已放在最后），
   用来覆盖旧布局里「flex:1 + overflow:auto」造成的小滚动框和 0 高度问题。
   ============================================================================ */

/* ---------- 布局：整页滚动，不再套小滚动框 ---------- */
.layout {
  align-items: start;
  /* 结果图懒加载完成后高度会变大；不禁用滚动锚定，浏览器会把页面往下推，
     刚跳过去的结果页会被顶出屏幕。 */
  overflow-anchor: none;
}
.stage-bottom {
  align-self: start;
  min-height: 0;
  overflow: visible;
  align-items: start;
}
.col-left,
.col-right {
  overflow: visible;
}
.task-list {
  flex: none;
  max-height: none;
  overflow: visible;
}
.gallery {
  min-height: 0;
  overflow: visible;
}
.gallery-grid {
  flex: none;
  min-height: 0;
  overflow: visible;
}

/* ---------- 历史任务：更大的缩略图，少点“点开才看清” ---------- */
.task-card {
  padding: 12px;
  gap: 14px;
}
.task-thumb {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 14px;
  background: #070b14;
}
.task-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.task-zoom {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(6, 10, 20, 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: zoom-in;
  opacity: 0;
  transition: opacity 0.16s, background 0.16s;
}
.task-card:hover .task-zoom,
.task-zoom:focus-visible {
  opacity: 1;
}
.task-zoom:hover {
  background: rgba(91, 140, 255, 0.9);
}
/* 触屏没有 hover，放大按钮必须常显，否则手机上永远点不到 */
@media (hover: none) {
  .task-zoom {
    opacity: 1;
  }
}
.task-prompt {
  font-size: 13.5px;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

/* ---------- 结果预览：不再强制 1:1 裁切，单张直接铺大 ---------- */
.result-figure img {
  aspect-ratio: auto;
  width: 100%;
  height: auto;
  max-height: 62vh;
  object-fit: contain;
  background: #070b14;
}
.result-grid.single {
  grid-template-columns: 1fr;
}
.result-grid.single .result-figure img {
  width: auto;
  max-width: 100%;
  min-height: 220px;
  max-height: calc(100vh - 300px);
  margin: 0 auto;
}
.fig-zoom {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  color: #fff;
  background: rgba(6, 10, 20, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.2);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.result-figure:hover .fig-zoom {
  opacity: 1;
  transform: none;
}

/* ---------- 作品库：瀑布流（保留原始比例），缩略图懒加载 ---------- */
.gallery-grid {
  display: block;
  columns: 190px;
  column-gap: 11px;
  padding-right: 0;
}
.gallery-item {
  break-inside: avoid;
  margin: 0 0 11px;
}
.gallery-item img {
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  object-fit: contain;
  background: #070b14;
}
.gallery-item .gi-cap {
  padding: 8px 10px 10px;
  line-height: 1.45;
  white-space: normal;
}
/* 裁剪必须放在无 padding 的内层：否则第 4 行会从 padding 区域露出半截 */
.gallery-item .gi-cap-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 滚动续载提示 ---------- */
.load-more {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 4px;
  color: var(--text-dim);
  font-size: 12px;
}
.load-more.loading::before {
  content: '';
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.load-more.done {
  opacity: 0.5;
}

/* ============================================================================
   全屏画布（替代原来的小弹窗大图）
   ============================================================================ */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(40, 62, 120, 0.28), transparent 60%),
    #02040a;
  color: #eaf0ff;
}
.viewer-top {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 18px;
  background: linear-gradient(rgba(2, 4, 10, 0.86), rgba(2, 4, 10, 0));
}
.viewer-info {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.viewer-counter {
  flex: none;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.viewer-prompt {
  min-width: 0;
  max-width: 46vw;
  color: #c3cfe8;
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.viewer-prompt.expanded {
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  max-height: 30vh;
  overflow-y: auto;
}
.viewer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.viewer-actions .btn {
  color: #eaf0ff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}
.viewer-actions .btn:hover {
  background: rgba(255, 255, 255, 0.18);
}
.viewer-stage {
  position: relative;
  min-height: 0;
  display: grid;
  /* 必须给行列一个「确定高度」的轨道：
     只用 place-items:center 时行是 auto，图片的 max-height:100% 会按原图高度计算，
     结果 1677px 高的图只露出上半截。显式 1fr 轨道后才能完整装进可视区。 */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  overflow: hidden;
  /* 只留很小的呼吸位，图片仍然接近占满整屏 */
  padding: 8px 66px;
  touch-action: none;
  cursor: zoom-in;
  overscroll-behavior: contain;
}
.viewer-stage.dragging {
  cursor: grabbing;
}
#viewer-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transform-origin: center center;
  transition: opacity 0.16s;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
#viewer-img.ready {
  opacity: 1;
}
#viewer-img.zoomed {
  cursor: grab;
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  width: 48px;
  height: 84px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(8, 13, 26, 0.5);
  color: #fff;
  font-size: 38px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.16s, background 0.16s;
}
.viewer-nav:hover {
  opacity: 1;
  background: rgba(14, 22, 42, 0.86);
}
.viewer-nav:disabled {
  opacity: 0.1;
  cursor: default;
}
.viewer-nav.prev {
  left: 12px;
}
.viewer-nav.next {
  right: 12px;
}
.viewer-hud {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 3;
  padding: 4px 13px;
  border-radius: 999px;
  font-size: 11.5px;
  color: rgba(220, 230, 255, 0.55);
  background: rgba(0, 0, 0, 0.34);
  pointer-events: none;
  white-space: nowrap;
}
.viewer-strip {
  position: relative;
  z-index: 3;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px 13px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
.viewer-thumb {
  flex: none;
  width: 78px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9px;
  overflow: hidden;
  background: #0a0f1c;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.16s, border-color 0.16s, transform 0.16s;
}
.viewer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.viewer-thumb:hover {
  opacity: 0.92;
}
.viewer-thumb.on {
  opacity: 1;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.35);
}
body.viewer-open {
  overflow: hidden;
}
/* 全屏时锁住背后的整页滚动，避免滚轮在标题栏/胶片条上时页面偷偷滚走 */
body.viewer-open .layout {
  overflow: hidden;
}
/* 全屏里也保留右下角署名 */
.viewer-credit {
  position: absolute;
  right: 16px;
  bottom: 88px;
  z-index: 5;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: rgba(220, 230, 255, 0.42);
  pointer-events: none;
  user-select: none;
}
.toasts {
  z-index: 90;
}

/* 历史列表不再把整页拉成几万像素；卡片变大后内部滚动反而更省力 */
@media (min-width: 1181px) {
  /* 选择器必须带上 .stage-bottom：slice.css 里同名规则优先级更高 */
  .stage-bottom .task-list {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
    padding-right: 4px;
  }
}
@media (max-width: 1180px) {
  /* 手机上先看结果/作品，再往下才是历史 */
  .col-right {
    order: -1;
  }
  .stage-bottom .task-list {
    max-height: 65vh;
    overflow-y: auto;
    padding-right: 4px;
  }
  .model-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 1000px) {
  .gallery-grid {
    columns: 160px;
  }
}
/* 小屏顶栏：品牌独占一行，按钮整齐排在第二行，避免主题按钮被挤到第三行 */
.brand-text strong {
  white-space: nowrap;
}
@media (max-width: 380px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .brand {
    flex: 1 1 100%;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 700px) {
  .task-thumb {
    width: 74px;
    height: 74px;
  }
  /* 手机一律常显放大按钮，不依赖 hover 媒体查询 */
  .task-zoom {
    opacity: 1;
  }
  .viewer-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 6px 9px;
  }
  .viewer-info {
    width: 100%;
  }
  .viewer-prompt {
    max-width: none;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 12px;
  }
  .viewer-actions .btn {
    padding: 5px 10px;
    font-size: 12px;
  }
  .viewer-counter {
    padding: 2px 8px;
    font-size: 11px;
  }
  .viewer-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .viewer-actions #viewer-meta {
    display: none;
  }
  .viewer-stage {
    padding: 6px 42px;
  }
  .viewer-nav {
    width: 36px;
    height: 62px;
    font-size: 28px;
    border-radius: 11px;
  }
  .viewer-nav.prev {
    left: 5px;
  }
  .viewer-nav.next {
    right: 5px;
  }
  .viewer-hud {
    display: none;
  }
  .viewer-thumb {
    width: 62px;
    height: 46px;
  }
  .viewer-credit {
    right: 10px;
    bottom: 78px;
    font-size: 10px;
  }
  .result-grid.single .result-figure img {
    max-height: calc(100vh - 260px);
  }
}
