:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel2: #1e242c;
  --border: #2a323d;
  --text: #e8edf2;
  --muted: #93a1b1;
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body { min-height: 100vh; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #262e38; border-color: #3a4552; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #2f74e0; }
button.danger { color: var(--danger); border-color: #5b2a2a; }
button.danger:hover { background: #2a1a1c; }
button.ghost { background: transparent; }

input, select, textarea {
  background: #10151a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

a { color: var(--accent2); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .username-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: 10px 0;
  max-height: 200px;
  overflow: auto;
}
.auth-card .username-list button {
  text-align: left;
  padding: 8px 10px;
}
.auth-card .username-list button.selected {
  border-color: var(--accent);
  color: var(--accent2);
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select { width: 100%; }
.lang-toggle { position: fixed; top: 14px; right: 14px; }

/* ---------- App shell ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(15, 18, 22, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar .brand { font-weight: 700; margin-right: 8px; }
.toolbar .spacer { flex: 1; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* ---------- Gallery ---------- */
.view-toggle button.active { border-color: var(--accent); color: var(--accent2); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--panel2);
  border: 1px solid var(--border);
}
.thumb img, .thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
}
.thumb .cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 10px 8px;
  font-size: 13px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s;
}
.thumb:hover .cap { opacity: 1; }
.thumb .deleted-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.list-view .item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--panel);
  cursor: pointer;
}
.list-view .item img, .list-view .item video {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}
.list-view .item .meta { flex: 1; min-width: 0; }
.list-view .item .cap { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-view .item .sub { color: var(--muted); font-size: 13px; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 20px 0; flex-wrap: wrap; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 96vw;
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal .modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}
.modal .modal-head .title { font-weight: 700; flex: 1; }

/* ---------- Media dialog ---------- */
.media-dialog { width: min(1100px, 96vw); }
.media-stage { display: grid; grid-template-columns: 1fr 340px; min-height: 300px; }
.media-stage .viewer { display: flex; align-items: center; justify-content: center; background: #000; }
.media-stage .viewer img, .media-stage .viewer video { max-width: 100%; max-height: 80vh; }
.media-stage .side { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.side section h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 13px;
  margin: 2px;
}
.tag-chip .x { cursor: pointer; color: var(--muted); font-weight: 700; }
.tag-chip.developer { border-color: #7c5cff; color: #b9a6ff; }

.comment { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
.comment .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.comment .body { white-space: pre-wrap; word-break: break-word; }

@media (max-width: 760px) {
  .media-stage { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: rgba(59, 130, 246, 0.06); }
.upload-progress { margin-top: 16px; }

/* ---------- Lists / tag manager ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card h3 { margin: 0 0 6px; }
.card .meta { color: var(--muted); font-size: 13px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

/* ---------- Scroll top ---------- */
#scrollTop {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 30;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  padding: 0;
  display: none;
}
#scrollTop.show { display: block; }

/* ---------- Filters panel ---------- */
.filter-panel {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 40;
  width: min(320px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  max-height: 70vh;
  overflow: auto;
}
.filter-panel .tag-opts { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.filter-panel .tag-opts label { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 6px; cursor: pointer; }
.filter-panel .tag-opts label:hover { background: var(--panel2); }
.filter-panel .tag-opts button {
  text-align: left;
  padding: 8px 10px;
}
.filter-panel .tag-opts button.active {
  border-color: var(--accent);
  color: var(--accent2);
}

.views-nav { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.views-nav button.active { border-color: var(--accent); color: var(--accent2); }
