:root {
  --bg: #f6f7f9;
  --fg: #1b1f24;
  --muted: #6a737d;
  --card: #ffffff;
  --line: #e1e4e8;
  --accent: #1f6feb;
  --ok: #1a7f37;
  --err: #cf222e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #8b949e;
    --card: #161b22;
    --line: #30363d;
    --accent: #4493f8;
    --ok: #3fb950;
    --err: #f85149;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 22px; margin: 16px 0 12px; }
button, .pick {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 10px; padding: 10px 14px; cursor: pointer;
}
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.link { border: 0; background: none; color: var(--muted); padding: 8px 0; }
.err { color: var(--err); }

#login { max-width: 420px; margin: 15vh auto 0; }
#login input {
  width: 100%; font: inherit; padding: 12px; margin: 8px 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg);
}
#login button { width: 100%; }

header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
nav { display: flex; gap: 4px; }
nav button { padding: 6px 12px; }
nav button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.pick { display: block; text-align: center; padding: 16px; margin: 8px 0 12px; font-weight: 600; }
.pick input { display: none; }
#summary { color: var(--muted); margin-bottom: 8px; min-height: 1.4em; }

#queue { list-style: none; margin: 0; padding: 0; }
#queue li {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 14px;
}
#queue .row { display: flex; justify-content: space-between; gap: 8px; }
#queue .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#queue .st { color: var(--muted); white-space: nowrap; }
#queue .st.ok { color: var(--ok); }
#queue .st.err { color: var(--err); }
#queue progress { width: 100%; height: 4px; margin-top: 6px; display: block; }

#gal-total { color: var(--muted); margin: 8px 0; }
#grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
@media (min-width: 700px) { #grid { grid-template-columns: repeat(6, 1fr); } }
#grid h2 { grid-column: 1 / -1; font-size: 15px; margin: 12px 0 4px; color: var(--muted); }
#grid .t {
  position: relative; aspect-ratio: 1; background: var(--line); overflow: hidden; cursor: pointer; border-radius: 4px;
}
#grid .t img, #grid .t video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
#grid .t.v::after {
  content: "▶"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 28px; text-shadow: 0 0 6px #000;
}
#more { width: 100%; margin: 12px 0; }
footer { text-align: center; margin: 24px 0; }

#viewer {
  position: fixed; inset: 0; background: #000; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#viewer[hidden] { display: none; }
body.noscroll { overflow: hidden; }
#v-body {
  flex: 1; width: 100%; min-height: 0; display: flex;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  scrollbar-width: none; touch-action: pan-x pinch-zoom;
}
#v-body::-webkit-scrollbar { display: none; }
#v-body .slide {
  flex: 0 0 100%; height: 100%; scroll-snap-align: center; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
}
#v-body img, #v-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
#v-top {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; color: #fff; font-size: 14px;
}
#v-count { font-weight: 600; }
#v-date { color: rgba(255,255,255,.7); }
#v-close { background: rgba(255,255,255,.15); color: #fff; border: 0; }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 11;
  background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 50%;
  width: 44px; height: 44px; padding: 0; font-size: 28px; line-height: 44px;
}
.v-nav[hidden] { display: none; }
#v-prev { left: 8px; }
#v-next { right: 8px; }
@media (hover: none) { .v-nav { display: none; } }
#v-dl { color: #fff; padding: 12px; }
