* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1420;
  --panel: #1a2233;
  --panel2: #212b40;
  --text: #e8edf7;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --accent2: #6fa5ff;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --err: #ff6b6b;
  --radius: 12px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  line-height: 1.6;
  padding: 24px clamp(12px, 4vw, 48px) 60px;
}

header h1 { font-size: 1.7rem; letter-spacing: 1px; }
header .sub { color: var(--muted); margin: 4px 0 18px; font-size: .95rem; }
header .privacy { color: #6fcf97; font-size: .85rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid #2e3a55;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, transform .05s;
  font-family: inherit;
}
.btn:hover { background: #2a3650; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }

.progress { margin: 10px 0 14px; }
.progress .bar {
  height: 8px; background: var(--panel); border-radius: 99px; overflow: hidden;
}
#progressBar {
  height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #7cc4ff);
  border-radius: 99px; transition: width .25s;
}
#progressText { color: var(--muted); font-size: .85rem; margin-top: 6px; }

.searchWrap { margin: 6px 0 18px; }
#search {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid #2e3a55;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem;
  padding: 12px 16px;
  font-family: inherit;
  outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.2); }
#count { color: var(--muted); font-size: .85rem; margin-top: 6px; min-height: 1.2em; }

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid #26314a;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  position: relative;
  display: flex;
  flex-direction: column;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card.hidden { display: none; }

.thumbWrap {
  aspect-ratio: 4/3;
  background: #0b0f18;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumbWrap img { width: 100%; height: 100%; object-fit: cover; display: block; }

.spinner {
  width: 26px; height: 26px;
  border: 3px solid #2e3a55; border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cardName {
  font-size: .8rem; color: var(--text);
  padding: 8px 10px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  font-size: .72rem;
  padding: 1px 10px 0;
  min-height: 1.1em;
}
.b-wait { color: var(--muted); }
.b-run  { color: var(--accent2); }
.b-done { color: var(--ok); }
.b-none { color: var(--warn); }
.b-err  { color: var(--err); }

.snippet {
  font-size: .78rem; color: var(--muted);
  padding: 2px 10px 10px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}
.snippet mark { background: #f0b429; color: #111; border-radius: 3px; padding: 0 2px; }

.empty {
  color: var(--muted); text-align: center;
  padding: 70px 20px; font-size: 1rem;
  border: 2px dashed #2e3a55; border-radius: var(--radius);
}
.empty.hidden { display: none; }
.hidden { display: none; }

.dropHint {
  position: fixed; inset: 0;
  background: rgba(15,20,32,.85);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; color: var(--accent2);
  border: 4px dashed var(--accent);
  z-index: 50;
  pointer-events: none;
}
.dropHint.hidden { display: none; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modalBox {
  background: var(--panel);
  border: 1px solid #2e3a55;
  border-radius: var(--radius);
  width: min(1100px, 96vw);
  max-height: 92vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modalHead {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #2e3a55;
  font-size: .9rem;
}
#modalName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.modalBtns { display: flex; gap: 8px; flex-shrink: 0; }
.modalBody {
  display: grid; grid-template-columns: 1.4fr 1fr;
  gap: 0; overflow: hidden; min-height: 0;
}
.modalImgWrap {
  background: #0b0f18; display: flex; align-items: center; justify-content: center;
  overflow: auto; min-height: 200px;
}
#modalImg { max-width: 100%; max-height: 80vh; object-fit: contain; }
.modalTextWrap { padding: 14px 16px; overflow: auto; border-left: 1px solid #2e3a55; }
.modalTextTitle { color: var(--muted); font-size: .8rem; margin-bottom: 8px; }
#modalText {
  white-space: pre-wrap; word-break: break-all;
  font-family: inherit; font-size: .92rem; color: var(--text);
}
@media (max-width: 760px) {
  .modalBody { grid-template-columns: 1fr; }
  .modalTextWrap { border-left: none; border-top: 1px solid #2e3a55; }
}

footer {
  margin-top: 40px; color: var(--muted); font-size: .8rem; text-align: center;
}
footer a { color: var(--accent2); }
