:root {
  --bg: #0e1117;
  --bg-elev: #171c26;
  --bg-card: #1c2330;
  --line: #28303f;
  --text: #e6ebf2;
  --text-dim: #93a0b4;
  --accent: #22d3c5;
  --accent-2: #2bb7e5;
  --danger: #f87171;
  --star: #fbbf24;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }
select, input { font-family: inherit; font-size: 15px; }

.hide { display: none !important; }

/* 顶部 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(14, 17, 23, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 12px;
}
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.brand-logo {
  color: var(--accent);
  font-size: 20px;
  text-shadow: 0 0 12px rgba(34, 211, 197, 0.6);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.5px; }

.search { display: flex; gap: 8px; }
.search input {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
}

/* 工具栏 */
.toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 14px 4px;
  position: sticky;
  top: 96px;
  z-index: 20;
  background: rgba(14, 17, 23, 0.92);
  backdrop-filter: blur(10px);
}
.toolbar select, .filter-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  flex: 1;
}
.toolbar select { min-width: 0; }
.filter-btn { position: relative; font-weight: 600; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  background: var(--accent);
  color: #06231f;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
}

.result-meta {
  padding: 8px 14px 2px;
  color: var(--text-dim);
  font-size: 13px;
}

/* 网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 10px 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:active { transform: scale(0.97); border-color: var(--accent); }
.thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #10151d;
  display: block;
  overflow: hidden;
}
.thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(90deg, #141b25 25%, #1f2a38 50%, #141b25 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
.thumb img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.thumb img.loaded { opacity: 1; }
.thumb img.fallback { display: none; }
.thumb.thumb-fallback {
  background:
    radial-gradient(120% 120% at 20% 0%, #1b2735 0%, #10151d 60%);
}
.thumb.thumb-fallback::before { display: none; }
.thumb.thumb-fallback::after {
  content: "◈";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.18);
  font-size: 30px;
}
.thumb .type-tag {
  position: absolute;
  z-index: 2;
  left: 6px;
  top: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
}
.card-body { padding: 8px 10px 10px; }
.card-title {
  font-size: 13.5px;
  font-weight: 600;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}
.card-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 12px;
}
.card-stats .subs { display: flex; align-items: center; gap: 3px; }
.stars { color: var(--star); font-size: 12px; letter-spacing: 1px; }

/* 状态 */
.state-box {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-dim);
}
.state-box.error { color: var(--danger); }
.state-box .retry {
  margin-top: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 22px;
}

/* 骨架屏 */
.skeleton { pointer-events: none; }
.skeleton .sk {
  background: linear-gradient(90deg, #1a212c 25%, #232c3a 50%, #1a212c 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.sk-thumb { width: 100%; aspect-ratio: 16/10; border-radius: 0; }
.sk-line { height: 12px; margin: 8px 10px 0; }
.sk-line.short { width: 55%; margin-bottom: 10px; }

/* 分页 */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 14px 14px calc(20px + var(--safe-b));
}
.pager button {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 22px;
}
.pager button:disabled { opacity: 0.4; cursor: default; }
#pageInfo { color: var(--text-dim); font-size: 14px; min-width: 70px; text-align: center; }

/* 抽屉 */
.drawer-mask, .modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 82vh;
  background: var(--bg-elev);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  padding-bottom: var(--safe-b);
}
.drawer.open { transform: translateY(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.drawer-head h2 { margin: 0; font-size: 17px; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 14px; }
.drawer-body { overflow-y: auto; padding: 4px 18px 12px; }
.drawer-loading { color: var(--text-dim); padding: 10px 0; }
.tag-group { margin-bottom: 18px; }
.tag-group h3 {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 0 0 8px;
}
.group-hint {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  margin-left: 8px;
  vertical-align: middle;
}
.tag-options { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}
.tag-chip.on {
  background: rgba(34, 211, 197, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}
.drawer-foot { padding: 10px 18px 16px; border-top: 1px solid var(--line); }
.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 16px;
}

/* 详情弹层 */
.modal {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(16px + var(--safe-b));
  transform: translateY(100%);
  transition: transform 0.25s ease;
}
.modal.open { transform: translateY(0); }
.modal-hero { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #000; }
.modal-video {
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  display: block;
}
.hero-wrap .modal-video { cursor: default; }
.wwgl-host {
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  position: relative;
  overflow: hidden;
}
.wwgl-host canvas { width: 100% !important; height: 100% !important; display: block; }
.modal-web {
  width: 100%;
  aspect-ratio: 16/9;
  border: 0;
  background: #000;
  display: block;
}
.action-msg { color: var(--accent); font-size: 13px; margin: 10px 0 0; min-height: 16px; }
.modal-actions .btn-export {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  font-size: 15px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--accent);
}
.modal-close {
  position: sticky;
  top: 8px;
  margin-left: auto;
  margin-right: 10px;
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 18px;
  z-index: 2;
}
.modal-content { padding: 12px 18px 0; }
.modal-title { margin: 4px 0 6px; font-size: 19px; }
.modal-desc { color: var(--text-dim); font-size: 14px; white-space: pre-wrap; }
.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat .v { font-weight: 700; font-size: 16px; }
.stat .k { color: var(--text-dim); font-size: 12px; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.modal-tags span {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
}
.btn-open {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
}
.btn-detail {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
}

/* 详情主图与动态预览 */
.hero-wrap { position: relative; background: #000; }
.hero-wrap .modal-hero { cursor: zoom-in; }
.hero-badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.62);
  color: var(--accent);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}
.modal-actions .btn-preview {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  font-size: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
}
.import-note {
  margin-top: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
}
.import-note b { color: var(--text); }

/* 全屏在线预览 */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lightbox-img {
  width: 100%;
  max-width: 100%;
  height: 88vh;
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  font-size: 18px;
}
.lightbox-hint {
  margin-top: 14px;
  color: #cfd6e0;
  font-size: 13px;
  text-align: center;
  max-width: 90vw;
}

/* 登出按钮：与搜索框同行，靠右 */
.logout-btn {
  position: absolute;
  right: 14px;
  top: 44px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
.search { padding-right: 62px; }

/* 登录覆盖层 */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(1200px 600px at 50% -10%, #16242f, var(--bg));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.login-logo {
  font-size: 40px;
  color: var(--accent);
  text-align: center;
  text-shadow: 0 0 18px rgba(34, 211, 197, 0.6);
}
.login-title {
  margin: 10px 0 4px;
  font-size: 22px;
  text-align: center;
}
.login-sub {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}
.login-field {
  display: block;
  margin-bottom: 14px;
}
.login-field span {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.login-field input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 13px;
  outline: none;
}
.login-field input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%;
  margin-top: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
  font-weight: 700;
  font-size: 16px;
  border: none;
  border-radius: 12px;
  padding: 13px;
}
.login-btn:disabled { opacity: 0.6; }
.guard-tip {
  color: var(--text);
  font-size: 14px;
  margin: 0 0 14px;
}
.login-msg {
  min-height: 20px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--accent);
  text-align: center;
}
.login-msg.error { color: var(--danger); }
.login-note {
  margin: 14px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: center;
}

/* 已下载导航按钮 */
.downloaded-nav {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* 进度条 */
.progress-box {
  margin-top: 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.progress-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-track {
  height: 8px;
  background: #10151d;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}
.progress-pct {
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent);
  text-align: right;
  font-weight: 700;
}

/* 已下载视图 */
.downloaded-view { padding: 12px 14px 30px; }
.dl-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.dl-summary h2 { margin: 0 0 6px; font-size: 19px; }
.dl-path {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
}
.dl-stats { margin: 0; font-size: 13px; color: var(--accent); font-weight: 600; }
.dl-refresh {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  white-space: nowrap;
}
.dl-list { display: flex; flex-direction: column; gap: 10px; }
.dl-loading { color: var(--text-dim); padding: 20px 4px; text-align: center; }
.dl-item {
  display: flex;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.dl-thumb {
  position: relative;
  width: 96px;
  flex: 0 0 96px;
  aspect-ratio: 16/10;
  border-radius: 8px;
  overflow: hidden;
  background: #10151d;
}
.dl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dl-type {
  position: absolute;
  left: 4px; top: 4px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 5px;
}
.dl-info { flex: 1; min-width: 0; }
.dl-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.dl-meta { margin: 0 0 8px; font-size: 12px; color: var(--text-dim); }
.dl-actions { display: flex; gap: 8px; }
.dl-btn {
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.dl-btn-play {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231f;
}
.dl-btn-export {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.dl-btn-delete {
  background: transparent;
  border: 1px solid #e0556b;
  color: #ff7a8d;
}
.dl-btn-delete:active { background: rgba(224, 85, 107, 0.18); }

/* 稍宽的手机/平板 */
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
  .toolbar { top: 100px; }
}

/* 场景横屏全屏按钮 */
.landscape-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 5;
  border: 1px solid rgba(255,255,255,0.55);
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

/* 横屏全屏覆盖层 */
.landscape-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.landscape-stage {
  position: relative;
  background: #000;
  display: flex;
  flex: 0 0 auto;
}
.landscape-stage .wwgl-host {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}
.landscape-stage .wwgl-host canvas {
  width: 100% !important;
  height: 100% !important;
}
/* 竖屏手机：舞台旋转 90° 形成横屏（具体像素尺寸由 JS 精确设置） */
.landscape-stage.rotated {
  transform: rotate(90deg);
}
.landscape-close {
  position: fixed;
  top: calc(12px + var(--safe-t, 0px));
  right: 14px;
  z-index: 130;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 16px;
}
