:root {
  --card-thumb-height: 160px;

  /* Theme variables (default) */
  --bg: #0b1220;
  --fg: #e8eefc;
  --muted: rgba(232, 238, 252, 0.7);
  --nav-bg: rgba(15, 23, 42, 0.8);
  --panel-bg: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-strong: rgba(255, 255, 255, 0.12);
  --thumb-bg: rgba(255, 255, 255, 0.03);
  --shadow: rgba(0, 0, 0, 0.25);
  --badge-bg: rgba(99, 102, 241, 0.18);
  --badge-border: rgba(99, 102, 241, 0.35);
  --badge-fg: #c7d2fe;

  /* FX colors */
  --fx-1: rgba(99, 102, 241, 0.55);
  --fx-2: rgba(34, 211, 238, 0.45);
  --fx-3: rgba(236, 72, 153, 0.4);
}

html[data-theme="black"] {
  --bg: #000;
  --fg: #f2f5ff;
  --muted: rgba(242, 245, 255, 0.68);
  --nav-bg: rgba(10, 10, 10, 0.85);
  --panel-bg: rgba(255, 255, 255, 0.05);
  --panel-border: rgba(255, 255, 255, 0.1);
  --panel-border-strong: rgba(255, 255, 255, 0.14);
  --thumb-bg: rgba(255, 255, 255, 0.03);
  --shadow: rgba(0, 0, 0, 0.35);
  /* Make particles colorful & obvious like the color theme */
  --fx-1: rgba(99, 102, 241, 0.6);
  --fx-2: rgba(236, 72, 153, 0.5);
  --fx-3: rgba(34, 211, 238, 0.5);
}

html[data-theme="white"] {
  --bg: #f7f8fb;
  --fg: #0b1220;
  --muted: rgba(11, 18, 32, 0.62);
  --nav-bg: rgba(255, 255, 255, 0.88);
  --panel-bg: rgba(11, 18, 32, 0.04);
  --panel-border: rgba(11, 18, 32, 0.1);
  --panel-border-strong: rgba(11, 18, 32, 0.14);
  --thumb-bg: rgba(11, 18, 32, 0.03);
  --shadow: rgba(2, 6, 23, 0.12);
  --badge-bg: rgba(59, 130, 246, 0.14);
  --badge-border: rgba(59, 130, 246, 0.28);
  --badge-fg: #1d4ed8;
  /* Make particles colorful & obvious like the color theme */
  --fx-1: rgba(99, 102, 241, 0.6);
  --fx-2: rgba(236, 72, 153, 0.5);
  --fx-3: rgba(34, 211, 238, 0.5);
}

html[data-theme="color"] {
  /* 核心基底色（介于黑白之间偏白色，导航栏直接复用此色） */
  --base-bg: #f5f5f7;

  /* 文字色（适配浅白基底） */
  --base-text: #444446;
  --base-text-light: rgba(68, 68, 70, 0.7);

  /* 组件基础色（无导航栏独立色，仅保留必要适配色） */
  --card-bg: #ffffff;
  --border-light: rgba(68, 68, 70, 0.08);
  --border-normal: rgba(68, 68, 70, 0.12);
  --shadow: rgba(100, 100, 111, 0.15);
  --scroll-thumb: rgba(150, 150, 160, 0.6);

  /* 渐变彩色（柔和通透，适配浅白基底） */
  --gradient-purple: rgba(138, 102, 229, 0.4);
  --gradient-pink: rgba(230, 102, 168, 0.35);
  --gradient-cyan: rgba(72, 202, 228, 0.35);
  --gradient-yellow: rgba(250, 204, 21, 0.25);

  /* 功能强调色（渐变配套） */
  --badge-bg: rgba(138, 102, 229, 0.15);
  --badge-text: #7952b3;
  --primary-hover: rgba(72, 202, 228, 0.2);
}

body {
  background: var(--bg);
  color: var(--fg);
  position: relative;
  min-height: 100vh;
}

.navbar {
  background: var(--nav-bg) !important;
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
}

.navbar .navbar-brand,
.navbar .nav-link {
  color: var(--fg) !important;
}

.nav-link.active {
  font-weight: 600;
  text-decoration: underline;
}

.container-main {
  padding-top: 1.25rem;
  padding-bottom: 2rem;
}

/* Subtle colorful background for 'color' theme */
html[data-theme="color"] body {
  background:
    radial-gradient(980px 680px at 12% 12%, rgba(255, 105, 180, 0.28), transparent 62%),
    radial-gradient(940px 660px at 88% 18%, rgba(0, 255, 208, 0.22), transparent 62%),
    radial-gradient(980px 700px at 74% 90%, rgba(255, 214, 0, 0.2), transparent 64%),
    radial-gradient(920px 680px at 16% 88%, rgba(124, 58, 237, 0.22), transparent 62%),
    radial-gradient(820px 620px at 56% 44%, rgba(59, 130, 246, 0.2), transparent 64%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.18)),
    var(--bg);
}

/* FX canvas (behind UI, above background) */
#fxCanvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.95;
}

/* Same visibility across themes */
html[data-theme="white"] #fxCanvas {
  opacity: 0.95;
}
html[data-theme="color"] #fxCanvas {
  opacity: 0.95;
}

/* Generic cards */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* Video page: force 4 columns (2x4 layout with 8 slots) */
.media-grid--video {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.media-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 24px var(--shadow);
}

/* Invisible fillers so the grid keeps a 2x4 shape even if < 8 videos exist */
.media-card--placeholder {
  visibility: hidden;
  min-height: calc(var(--card-thumb-height) + 104px);
  pointer-events: none;
}

/* Images page: hover animation (do not affect music/video) */
body[data-page="image"] .media-card {
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  will-change: transform;
}

body[data-page="image"] .thumb-box {
  position: relative;
}

body[data-page="image"] .thumb-box::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 200px at 20% 10%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.1), transparent 45%);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.media-thumb {
  width: 100%;
  height: var(--card-thumb-height);
  background: var(--thumb-bg);
  display: block;
  object-fit: cover;
}

.media-card .meta {
  padding: 0.75rem 0.9rem;
}

.filename {
  font-size: 0.95rem;
  word-break: break-all;
}

.section-title {
  margin-top: 1.25rem;
  margin-bottom: 0.6rem;
}

.badge-soft {
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  color: var(--badge-fg);
}

.list-row {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0.85rem;
}

.btn-soft {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--fg);
}

.btn-soft:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.muted {
  color: var(--muted);
}

.alert {
  border-radius: 12px;
}

/* Footer */
.footer {
  padding: 26px 0 40px;
}

.footer__inner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(34, 48, 88, 0.45);
  padding-top: 14px;
  color: var(--muted);
  font-size: 16px;
}

.footer code {
  color: var(--fg);
  background: rgba(16, 26, 58, 0.55);
  border: 1px solid rgba(34, 48, 88, 0.55);
  padding: 2px 6px;
  border-radius: 8px;
}

/* Images: grid columns follow selected view (not device orientation) */
.image-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.image-grid[data-view="portrait"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.image-grid[data-view="landscape"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Small screens: reduce columns for readability (does not change per-page) */
@media (max-width: 576px) {
  .image-grid[data-view="landscape"],
  .image-grid[data-view="portrait"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.thumb-box {
  aspect-ratio: var(--thumb-ratio);
  background: var(--thumb-bg);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.thumb-box .media-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover; /* fill the frame */
  object-position: center;
  cursor: zoom-in;
}

body[data-page="image"] .thumb-box .media-thumb {
  transition: transform 220ms ease;
  transform: scale(1);
}

body[data-page="image"] .media-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

body[data-page="image"] .media-card:hover .thumb-box::after {
  opacity: 1;
}

body[data-page="image"] .media-card:hover .thumb-box .media-thumb {
  transform: scale(1.06);
}

/* Custom Lightbox */
.lb {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 2000;
}

.lb.is-open {
  display: block;
}

.lb__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.lb__ui {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  pointer-events: none;
}

.lb__title {
  pointer-events: none;
  max-width: 70vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(232, 238, 252, 0.92);
}

.lb__canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}

.lb__canvas.is-grabbing {
  cursor: grabbing;
}

.lb__transform {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.lb__img {
  display: block;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
}

/* White theme: make some bootstrap defaults readable */
html[data-theme="white"] .page-link,
html[data-theme="white"] .btn-soft {
  color: var(--fg);
}

html[data-theme="white"] .navbar .navbar-toggler {
  border-color: rgba(11, 18, 32, 0.18);
}

html[data-theme="white"] .navbar .navbar-toggler-icon {
  filter: invert(1);
}

html[data-theme="color"] .navbar .navbar-toggler {
  border-color: rgba(11, 18, 32, 0.18);
}

html[data-theme="color"] .navbar .navbar-toggler-icon {
  filter: invert(1);
}

/* Download buttons: white background + black text */
.btn-download,
.btn-download:visited {
  background: #fff !important;
  color: #000 !important;
  border: 1px solid rgba(0, 0, 0, 0.18) !important;
}

.btn-download:hover {
  background: #772c64 !important;
  color: #fff !important;
  border-color: #772c64 !important;
}

.btn-download:active {
  background: #a01e2f !important;
  color: #fff !important;
  border-color: #455826 !important;
}

/* Page Jump Button */
.js-page-jump {
  cursor: pointer;
  background: transparent;
  border: none;
  transition: background 0.2s, color 0.2s;
}

.js-page-jump:hover {
  background: var(--panel-bg);
  color: var(--fg);
}

/* Page Jump Modal Overlay */
.page-jump-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Page Jump Modal */
.page-jump-modal {
  background: var(--nav-bg);
  border: 1px solid var(--panel-border-strong);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  min-width: 280px;
  max-width: 90vw;
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.page-jump-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  font-weight: 600;
  font-size: 1rem;
}

.page-jump-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

.page-jump-close:hover {
  background: var(--panel-bg);
  color: var(--fg);
}

.page-jump-body {
  padding: 1.25rem;
}

.page-jump-body label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.page-jump-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  border: 1px solid var(--panel-border-strong);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--fg);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.page-jump-input:focus {
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.page-jump-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--panel-border);
}

/* White theme overrides for modal */
html[data-theme="white"] .page-jump-modal {
  background: #fff;
}

html[data-theme="white"] .page-jump-input {
  background: #f5f6f8;
}

/* Color theme overrides for modal */
html[data-theme="color"] .page-jump-modal {
  background: var(--card-bg);
}

html[data-theme="color"] .page-jump-input {
  background: var(--base-bg);
  color: var(--base-text);
}
