:root {
  --bg: #0a0c11;
  --bg-soft: #11141c;
  --panel: rgba(20, 24, 34, 0.72);
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef1f7;
  --muted: #99a1b3;
  --accent: #6ea8fe;
  --accent2: #b48cff;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

/* 覆蓋 .lightbox/.loading/.empty 等 display 宣告，確保 hidden 屬性有效 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 600px at 82% -8%, rgba(180, 140, 255, 0.16), transparent 60%),
    radial-gradient(900px 520px at 8% 0%, rgba(110, 168, 254, 0.14), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* ---------------- 頂部列 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 3vw, 40px);
  background: linear-gradient(180deg, rgba(10, 12, 17, 0.92), rgba(10, 12, 17, 0.62));
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }

.logo {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent2));
  box-shadow: 0 8px 20px rgba(110, 168, 254, 0.35);
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(17px, 2.2vw, 21px);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--muted);
  transition: border-color .2s, background .2s;
}
.search:focus-within { border-color: rgba(110, 168, 254, 0.55); background: rgba(255, 255, 255, 0.08); }
.search input {
  border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 14px; width: 190px;
  font-family: inherit;
}
.search input::placeholder { color: var(--muted); }

.filters { display: flex; gap: 6px; padding: 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.filters button {
  border: 0; cursor: pointer;
  background: transparent; color: var(--muted);
  font-family: inherit; font-size: 13.5px; font-weight: 500;
  padding: 7px 15px; border-radius: 9px;
  transition: all .18s ease;
}
.filters button:hover { color: var(--text); }
.filters button.active {
  color: #0a0c11;
  background: linear-gradient(140deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 16px rgba(110, 168, 254, 0.3);
}

.acts { display: flex; gap: 8px; }

.toolbtn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 500;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 11px;
  transition: background .18s, border-color .18s, transform .18s;
}
.toolbtn:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }
.toolbtn.active {
  color: #0a0c11;
  background: linear-gradient(140deg, var(--accent), var(--accent2));
  border-color: transparent;
}
.toolbtn:disabled { opacity: .45; cursor: default; transform: none; }

/* ---------------- 瀑布流 ---------------- */
main { padding: clamp(14px, 2.4vw, 30px) clamp(14px, 3vw, 40px) 90px; }

.grid {
  column-count: 5;
  column-gap: 14px;
}
@media (max-width: 1500px) { .grid { column-count: 4; } }
@media (max-width: 1080px) { .grid { column-count: 3; } }
@media (max-width: 720px)  { .grid { column-count: 2; column-gap: 10px; } }
@media (max-width: 430px)  { .grid { column-count: 1; } }

.card {
  position: relative;
  break-inside: avoid;
  margin: 0 0 14px;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: zoom-in;
  background: linear-gradient(120deg, #161a24, #1d2230);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
  transform: translateZ(0);
  animation: rise .5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.card img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform .6s cubic-bezier(.2, .7, .2, 1), opacity .5s;
  opacity: 0;
}
.card img.loaded { opacity: 1; }
.card:hover img.loaded { transform: scale(1.05); }

.card .veil {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 45%, rgba(0, 0, 0, 0.72));
  opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
.card:hover .veil { opacity: 1; }

.card .cap {
  position: absolute; left: 10px; right: 10px; bottom: 9px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11.5px; color: #e7ecf6;
  opacity: 0; transform: translateY(6px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.card:hover .cap { opacity: 1; transform: none; }

.play {
  position: absolute; top: 50%; left: 50%;
  width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: rgba(12, 14, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(6px);
  transition: transform .25s, background .25s;
  pointer-events: none;
}
.card:hover .play { transform: scale(1.12); background: rgba(110, 168, 254, 0.75); }

.badge {
  position: absolute; top: 9px; right: 9px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  padding: 4px 8px; border-radius: 7px;
  color: #fff; background: rgba(12, 14, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
}

.card.no-thumb img { display: none; }
.card.no-thumb::after {
  content: "縮圖產生中…";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 12.5px;
}

/* ---------------- 批次選取 ---------------- */
.card .check {
  position: absolute; top: 10px; left: 10px; z-index: 3;
  width: 26px; height: 26px; border-radius: 8px;
  display: none; place-items: center;
  background: rgba(10, 12, 17, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  transition: background .15s, border-color .15s, transform .15s;
}
.card .check svg { display: none; }
.card .check::after {
  content: ""; width: 48%; height: 48%;
  border-radius: 3px; background: rgba(255, 255, 255, 0.9);
}

body.selecting { cursor: default; }
body.selecting .card { cursor: pointer; }
body.selecting .card .check { display: grid; }
body.selecting .card .play { display: none; }
body.selecting .foot { display: none; }

.card.selected { box-shadow: 0 0 0 3px var(--accent), 0 10px 26px rgba(0, 0, 0, 0.5); }
.card.selected img.loaded { transform: none; }
.card.selected .check { background: var(--accent); border-color: var(--accent); }
.card.selected .check::after { display: none; }
.card.selected .check svg { display: block; }

/* ---------------- 狀態 ---------------- */
.loading, .empty {
  display: grid; place-items: center; gap: 14px;
  padding: 90px 20px; color: var(--muted); text-align: center;
}
.empty-icon { font-size: 40px; opacity: .5; }

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.foot {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 9px 20px; text-align: center;
  font-size: 11.5px; color: var(--muted);
  background: linear-gradient(0deg, rgba(10,12,17,.92), transparent);
  pointer-events: none;
}

/* ---------------- 選取工具列 ---------------- */
.selbar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 60;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 12px 10px 18px;
  border-radius: 16px;
  background: rgba(18, 22, 32, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: rise .3s ease both;
  max-width: 94vw;
}
.sel-info { font-size: 13.5px; color: var(--text); white-space: nowrap; }
.sel-actions { display: flex; gap: 8px; }
.sel-btn {
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background .18s, transform .18s;
}
.sel-btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.sel-btn.primary {
  color: #0a0c11; border-color: transparent;
  background: linear-gradient(140deg, var(--accent), var(--accent2));
}
.sel-btn:disabled { opacity: .4; cursor: default; transform: none; }

@media (max-width: 720px) {
  .selbar { left: 12px; right: 12px; transform: none; max-width: none; flex-wrap: wrap; justify-content: center; }
}

/* ---------------- 燈箱 ---------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: fade .25s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lb-backdrop {
  position: absolute; inset: 0;
  background: rgba(6, 7, 10, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.lb-stage {
  position: relative;
  max-width: 94vw; max-height: 84vh;
  display: flex; align-items: center; justify-content: center;
}
.lb-stage img, .lb-stage video {
  max-width: 94vw; max-height: 84vh;
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: pop .3s cubic-bezier(.2,.8,.2,1) both;
  background: #000;
}
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

.lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 16px clamp(14px, 3vw, 30px);
  background: linear-gradient(180deg, rgba(6,7,10,.85), transparent);
}
.lb-title { font-size: 14.5px; font-weight: 600; word-break: break-all; }
.lb-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.lb-actions { display: flex; gap: 8px; flex: none; }

.lb-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px; cursor: pointer;
  color: var(--text); text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  transition: background .2s, transform .2s;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.18); transform: translateY(-1px); }

.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 52px; height: 52px; margin-top: 0;
  display: grid; place-items: center;
  border-radius: 50%; cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  transition: background .2s, transform .2s;
}
.lb-nav:hover { background: rgba(110, 168, 254, 0.7); }
.lb-nav.prev { left: clamp(8px, 2vw, 26px); }
.lb-nav.next { right: clamp(8px, 2vw, 26px); }
.lb-nav:disabled { opacity: .25; cursor: default; }

.lb-counter {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 3;
  font-size: 12.5px; color: var(--muted);
  padding: 6px 14px; border-radius: 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
}

@media (max-width: 720px) {
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .lb-nav { width: 44px; height: 44px; }
  .lb-stage img, .lb-stage video { max-height: 76vh; }
}
