:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b1f22;
  --panel-2: #242a2e;
  --text: #f3f5f6;
  --muted: #9aa4aa;
  --line: #343c42;
  --accent: #4fb3a5;
  --danger: #e36d6d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 19, 21, 0.94);
  backdrop-filter: blur(12px);
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

input,
select,
button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

input,
select {
  padding: 0 10px;
}

input[type="search"] {
  width: min(280px, 44vw);
}

button {
  min-width: 92px;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

main {
  padding: 22px;
}

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

.item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.thumb {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0d0f10;
}

.thumb img,
.thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb audio {
  width: calc(100% - 16px);
}

.file-icon {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 800;
  font-size: 18px;
}

.meta {
  padding: 10px;
}

.name {
  overflow: hidden;
  min-height: 40px;
  display: -webkit-box;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.details {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  padding: 56px 16px;
  color: var(--muted);
  text-align: center;
}

.pager {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(17, 19, 21, 0.94);
  backdrop-filter: blur(12px);
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  color: var(--muted);
}

#pageInput {
  width: 76px;
  text-align: center;
}

dialog {
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-width: 38px;
  width: 38px;
  background: rgba(0, 0, 0, 0.72);
}

#viewerBody {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 48px 16px 16px;
}

#viewerBody img,
#viewerBody video,
#viewerBody iframe {
  max-width: 100%;
  max-height: calc(100vh - 110px);
}

#viewerBody audio {
  width: min(720px, 100%);
}

#viewerBody iframe {
  width: min(1000px, 100%);
  height: min(760px, calc(100vh - 110px));
  border: 0;
  background: white;
}

.download {
  color: var(--accent);
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    justify-content: stretch;
  }

  input,
  select {
    flex: 1 1 140px;
  }

  input[type="search"] {
    width: auto;
    flex-basis: 100%;
  }

  main {
    padding: 12px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
}
