:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #6b7280;
  --border: #e3e6ec;
  --accent: #4f5bd5;
  --accent-ink: #ffffff;
  --accent-soft: #eceefc;
  --danger: #c93a3a;
  --danger-soft: #fbeaea;
  --ok: #1f9d63;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #181b21;
    --surface-2: #21252d;
    --text: #e8eaee;
    --muted: #8d95a3;
    --border: #2a2e37;
    --accent: #7c88f5;
    --accent-ink: #0e1020;
    --accent-soft: #232844;
    --danger: #f07878;
    --danger-soft: #3a2020;
    --ok: #4cc58a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in {
  max-width: 960px; margin: 0 auto; padding: 0 16px; min-height: 60px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 17px; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { flex: none; width: 24px; height: 24px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #9b7cf0); }
.nav { display: flex; align-items: center; gap: 4px; flex: none; }
.nav a, .link-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px;
  color: var(--muted); font: inherit; background: none; border: 0; cursor: pointer; border-radius: 8px;
}
.nav a:hover, .link-btn:hover { color: var(--text); text-decoration: none; }
.nav .nav-user { color: var(--text); max-width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-form { margin: 0; }

.notice { background: var(--accent-soft); color: var(--text); border-bottom: 1px solid var(--border); font-size: 14px; }
.notice-in { max-width: 960px; margin: 0 auto; padding: 10px 16px; overflow-wrap: anywhere; }

main { padding: 24px 16px 48px; margin: 0 auto; }
main.wide { max-width: 960px; }
main.narrow { max-width: 440px; }

/* upload page */
.drop {
  display: block; text-align: center; padding: 22px 16px; min-height: 76px;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.disabled { cursor: default; }
.drop.disabled:hover { border-color: var(--border); background: var(--surface); }
.drop-main { font-size: 17px; font-weight: 600; }
.drop-plus { color: var(--accent); font-weight: 700; margin-right: 2px; }
.drop-sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); font-size: 13px; margin: 28px 0; }
.empty[hidden] { display: none; }

.grid { list-style: none; margin: 20px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow); }
.tile-btn { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute; right: 8px; bottom: 8px; padding: 2px 10px; border-radius: 999px;
  background: rgba(15, 17, 24, .72); color: #fff; font-size: 12px; line-height: 20px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); pointer-events: none;
}
.tile.copied .badge { background: var(--ok); }
.tile.done:hover img { transform: scale(1.03); }
.tile img { transition: transform .2s; }
.progress {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: rgba(15, 17, 24, .55); color: #fff; font-weight: 650; font-size: 18px; pointer-events: none;
}
.progress .meter { width: 56%; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .3); overflow: hidden; }
.progress .meter i { display: block; height: 100%; width: 0; background: #fff; transition: width .1s linear; }
.tile.error img { filter: grayscale(1) opacity(.35); }
.tile.error .errmsg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 10px; text-align: center; background: var(--danger-soft); color: var(--danger); font-size: 13px; line-height: 1.4; pointer-events: none;
}
.errmsg b { font-size: 12px; font-weight: 600; opacity: .8; }
.errmsg span { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile.error img { display: none; }
.rm {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.rm span {
  width: 24px; height: 24px; border-radius: 50%; background: rgba(15, 17, 24, .6); color: #fff;
  font-size: 16px; line-height: 24px; text-align: center;
}
.tile.error .rm span { background: var(--danger); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.bar[hidden] { display: none; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.pill {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: none; color: var(--muted);
  font: inherit; font-size: 14px; cursor: pointer;
}
.pill[aria-checked="true"] { background: var(--surface); color: var(--accent); font-weight: 650; box-shadow: var(--shadow); }
.btn, button[type="submit"] {
  min-height: 44px; padding: 0 20px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):hover, button[type="submit"]:hover { filter: brightness(1.07); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); max-width: calc(100vw - 32px);
  padding: 10px 18px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.ad-slot { max-width: 960px; margin: 0 auto; padding: 0 16px 32px; text-align: center; overflow: hidden; }
.ad-slot:empty { display: none; }

/* forms / account pages */
main.narrow { background: var(--surface); margin-top: 32px; border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow); width: calc(100% - 32px); }
main.narrow h1 { font-size: 22px; margin: 0 0 16px; }
main.narrow h2 { font-size: 17px; margin: 28px 0 8px; }
main.narrow p { margin: 0 0 14px; }
main.narrow label { display: block; font-size: 14px; color: var(--muted); }
main.narrow input:not([type="hidden"]) {
  display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
main.narrow input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
main.narrow [role="alert"] { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }
main.narrow [role="status"] { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
main.narrow dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 16px; }
main.narrow dt { color: var(--muted); }
main.narrow dd { margin: 0; overflow-wrap: anywhere; }
main.narrow code { font-size: 13px; }

@media (max-width: 720px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; } }
@media (max-width: 480px) {
  main { padding: 16px 12px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .bar { flex-direction: column; align-items: stretch; }
  .bar .btn { width: 100%; }
  .pills { justify-content: space-between; }
  .pill { flex: 1 1 auto; padding: 0 8px; min-height: 44px; }
  main.narrow { padding: 22px 16px; margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 400px) { .drop-sub { font-size: 12px; } .drop { padding: 18px 10px; } }

/* my images / grid.js */
.my-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.my-head h1 { font-size: 22px; margin: 0; }
.quota { min-width: 220px; flex: 0 1 320px; }
.quota-text { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.quota-bar { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.quota-bar i { display: block; height: 100%; background: var(--accent); }
.tile a.tile-btn { text-decoration: none; }
.tile .sel {
  position: absolute; top: 0; left: 0; width: 44px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s;
}
.tile .sel span {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(15, 17, 24, .45); color: transparent;
  font-size: 14px; line-height: 20px; text-align: center;
}
.tile:hover .sel, .tile .sel:focus-visible, .grid.selecting .sel { opacity: 1; }
@media (hover: none) { .tile .sel { opacity: 1; } }
.tile.selected .sel span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected img { opacity: .8; }
.more { text-align: center; margin-top: 24px; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; }
.btn.ghost:hover { text-decoration: none; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.loading { opacity: .6; pointer-events: none; }
a.btn { text-decoration: none; }
.selbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 8; width: calc(100% - 24px); max-width: 560px;
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.selbar[hidden] { display: none; }
.sel-gap { flex: 1; }
.sel-count { font-weight: 600; font-size: 14px; white-space: nowrap; }
body.modal-open { overflow: hidden; }
.detail {
  position: fixed; inset: 0; z-index: 20; background: rgba(8, 10, 16, .66); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.detail-card {
  position: relative; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); width: 100%; max-width: 1040px; max-height: 100%;
  background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.detail-close {
  position: absolute; top: 6px; right: 6px; z-index: 1; width: 44px; height: 44px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(15, 17, 24, .55); color: #fff; font-size: 24px; line-height: 1;
}
.detail-view { background: var(--surface-2); display: flex; align-items: center; justify-content: center; min-height: 240px; max-height: calc(100vh - 32px); overflow: hidden; }
.detail-view img { max-width: 100%; max-height: calc(100vh - 32px); object-fit: contain; display: block; }
.detail-side { padding: 22px 20px; overflow: auto; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.detail-name { font-weight: 650; overflow-wrap: anywhere; padding-right: 36px; }
.detail-meta { color: var(--muted); font-size: 13px; }
.detail-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.detail-row { display: grid; grid-template-columns: 4.6em minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.detail-label { font-size: 13px; color: var(--muted); }
.detail-row input {
  min-width: 0; min-height: 36px; padding: 0 10px; font: 13px ui-monospace, monospace; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
@media (max-width: 720px) {
  .detail { padding: 0; align-items: flex-end; }
  .detail-card { grid-template-columns: minmax(0, 1fr); max-height: 100%; overflow: auto; border-radius: var(--radius) var(--radius) 0 0; }
  .detail-view { max-height: 45vh; min-height: 160px; }
  .detail-view img { max-height: 45vh; }
  .detail-row { grid-template-columns: minmax(0, 1fr) auto; }
  .detail-label { grid-column: 1 / -1; margin-bottom: -4px; }
}
.nav-form button[type="submit"] { min-height: 44px; padding: 0 10px; background: none; color: var(--muted); font-weight: inherit; border-radius: 8px; }
.nav-form button[type="submit"]:hover { color: var(--text); filter: none; }

/* admin */
main.admin { max-width: 1400px; }
.admin-shell { display: grid; grid-template-columns: 148px minmax(0, 1fr); gap: 24px; align-items: start; }
.admin-nav { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 2px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.admin-nav a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--muted); }
.admin-nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.admin-nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.admin-body { min-width: 0; }
.admin-h { font-size: 22px; margin: 0 0 12px; }
.admin-h small { color: var(--muted); font-weight: 400; font-size: 14px; }
.admin-sub { color: var(--muted); font-size: 13px; margin: 6px 0; }
.admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin-bar .admin-h { margin: 0; }
.admin-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.admin-search { flex: 1 1 240px; min-width: 0; max-width: 380px; min-height: 36px; padding: 0 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.admin-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.admin-grid .tile { border-radius: 10px; }
.tile .dist { position: absolute; left: 6px; bottom: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: rgba(15, 17, 24, .7); color: #fff; pointer-events: none; }
.selbar.admin { background: var(--danger); border-color: var(--danger); color: #fff; max-width: 520px; }
.selbar.admin .btn.ghost { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .35); }
.selbar.admin .btn.danger { background: #fff; color: var(--danger); font-weight: 650; }
.drawer-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(8, 10, 16, .5); display: flex; justify-content: flex-end; }
.drawer { position: relative; width: min(420px, 100%); height: 100%; overflow: auto; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.drawer-view { background: var(--surface-2); display: flex; align-items: center; justify-content: center; min-height: 200px; max-height: 38vh; overflow: hidden; }
.drawer-view img { max-width: 100%; max-height: 38vh; object-fit: contain; display: block; }
.drawer-body { padding: 16px 18px 24px; display: flex; flex-direction: column; gap: 6px; }
.dr-row { display: grid; grid-template-columns: 6.2em minmax(0, 1fr); gap: 8px; font-size: 14px; }
.dr-label { color: var(--muted); }
.dr-val { overflow-wrap: anywhere; }
.dr-meta { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.dr-sub { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.drawer .detail-actions { margin-top: 12px; }
.drawer .purge { margin-top: 12px; width: 100%; }
.muted { color: var(--muted); font-size: 13px; }
.inline-form { display: inline; margin: 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 12px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table td.err { white-space: normal; max-width: 260px; color: var(--danger); overflow-wrap: anywhere; }
.prog { width: 120px; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-bottom: 3px; }
.prog i { display: block; height: 100%; background: var(--accent); }
.st { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-2); }
.st-running, .st-pending { background: var(--accent-soft); color: var(--accent); }
.st-done { color: var(--ok); }
.st-failed { background: var(--danger-soft); color: var(--danger); }
.bad { color: var(--danger); }
@media (max-width: 960px) { .admin-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .admin-nav { position: static; flex-direction: row; overflow-x: auto; }
  .admin-nav a { white-space: nowrap; }
  .admin-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .drawer-wrap { align-items: flex-end; }
  .drawer { height: auto; max-height: 90%; width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
}
@media (max-width: 480px) { .admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.tile .dist.src { background: var(--accent); color: var(--accent-ink); }

/* admin: users / bans / settings */
.admin-sub.ok { color: var(--ok); }
.pager { display: flex; gap: 10px; margin-top: 12px; }
.admin-table tr.expired td:not(.acts) { opacity: .5; }
.admin-table td.wrap { white-space: normal; max-width: 320px; overflow-wrap: anywhere; }
.quota-form { display: inline-flex; gap: 6px; align-items: center; }
.quota-form .btn { padding: 0 10px; }
.admin-table td.acts { white-space: nowrap; }
.admin-table td.acts .inline-form { margin-left: 6px; }
.btn.ghost.bad { color: var(--danger); }
input.num { width: 84px; min-height: 36px; padding: 0 8px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.ban-form .admin-search.num { flex: 0 1 200px; max-width: 200px; }
.ban-form { margin: 10px 0; }
.settings-form { max-width: 760px; display: flex; flex-direction: column; gap: 16px; }
.settings-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.settings-form legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.settings-form label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.settings-form input[type="text"], .settings-form input[type="number"], .settings-form textarea {
  width: 100%; min-height: 38px; padding: 6px 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.settings-form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; resize: vertical; }
.settings-form .hint { font-size: 12px; color: var(--muted); }
.settings-form .hint.warn, p.hint.warn { color: var(--danger); font-size: 12px; margin: 0; }
.settings-form .row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .settings-form .row3 { grid-template-columns: minmax(0, 1fr); } }
