:root {
  color-scheme: dark;
  --bg: #14131a;
  --surface: #1e1c27;
  --surface-2: #2a2736;
  --border: #393547;
  --text: #ece9f5;
  --muted: #a09bb3;
  --accent: #8b7cf6;
  --accent-text: #14131a;
  --danger: #f2727f;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button, .button {
  display: inline-block;
  padding: 8px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--danger); }

input[type=search], input[type=text], input[type=url], input[type=password] {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

label { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 13px; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(340px, 100%); padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.login-card h1 { margin: 0 0 12px; }
.login-card button { width: 100%; margin-top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.search { position: relative; flex: 1; min-width: 0; }

.suggestions {
  position: absolute;
  inset: 100% 0 auto 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.suggestions li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.suggestions li:hover, .suggestions li.selected { background: var(--border); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px 0; }
.kinds { display: flex; flex-wrap: wrap; gap: 4px; }
.kinds button { padding: 4px 10px; font-size: 13px; }
.kinds button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 2px 8px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; color: var(--text); cursor: pointer; }
.chips .chip { border-color: var(--accent); }
.chips .chip::after { content: " ✕"; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 12px 16px 24px;
}
.empty { padding: 48px 16px; text-align: center; }
#scroll-sentinel { height: 1px; }

.card { display: flex; flex-direction: column; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-thumb { position: relative; display: block; width: 100%; aspect-ratio: 16 / 10; padding: 0; background: #0d0c12; border: 0; border-radius: 0; overflow: hidden; }
.card-thumb img, .card-thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.card-thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.kind-badge { position: absolute; top: 6px; left: 6px; padding: 1px 6px; background: rgb(0 0 0 / 70%); color: #fff; border-radius: 6px; font-size: 12px; }
.opens-badge { position: absolute; top: 6px; right: 6px; padding: 1px 6px; background: rgb(0 0 0 / 70%); color: #fff; border-radius: 6px; font-size: 12px; }
.card-body { display: flex; flex: 1; flex-direction: column; gap: 6px; padding: 8px 10px 10px; }
.card-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card-actions { display: flex; gap: 6px; margin-top: auto; }
.card-actions button { flex: 1; padding: 5px 6px; font-size: 13px; }
.card-actions button.audio-toggle { flex: 0 0 auto; }

dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / 70%); }
.viewer { width: min(860px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.upload-dialog { width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.viewer-head h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.viewer-media { display: grid; place-items: center; background: #0d0c12; border-radius: 8px; overflow: hidden; }
.viewer-media img, .viewer-media video { display: block; max-width: 100%; max-height: 60dvh; }
.viewer-media audio { width: 100%; margin: 16px; max-width: calc(100% - 32px); }
.viewer-media:fullscreen img, .viewer-media:fullscreen video { max-height: 100dvh; }
.viewer-actions, .viewer-danger { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.viewer-danger { justify-content: space-between; }
.viewer-form button { margin-top: 10px; }
.share-line { margin: 12px 0 0; font-size: 13px; overflow-wrap: anywhere; }
a { color: var(--accent); }

.confirm-dialog { width: min(420px, calc(100vw - 24px)); }
.confirm-dialog p { margin: 0 0 14px; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.pick-files { position: relative; padding: 16px; text-align: center; border: 1px dashed var(--border); border-radius: 8px; cursor: pointer; }
.pick-files-hint { display: block; margin-bottom: 8px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-input:focus-visible + .button { outline: 2px solid var(--accent); outline-offset: 2px; }
.pick-files:hover .button { border-color: var(--accent); }
.upload-rows { margin: 10px 0; padding: 0; list-style: none; }
.upload-rows li { padding: 8px; margin-bottom: 6px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; }
.upload-rows progress { display: block; width: 100%; margin-top: 6px; accent-color: var(--accent); }
.row-status { margin-top: 4px; font-size: 13px; color: var(--muted); }
.row-status.failed { color: var(--danger); }
.row-status button { margin-left: 6px; padding: 1px 8px; font-size: 12px; }
.url-form { margin-top: 12px; }
.url-line { display: flex; gap: 6px; }

.drop-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgb(139 124 246 / 25%); border: 3px dashed var(--accent); font-size: 24px; font-weight: 700; pointer-events: none; }
.toast { position: fixed; bottom: 16px; left: 50%; z-index: 30; max-width: calc(100vw - 32px); padding: 8px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; transform: translateX(-50%); }

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; }
  .logo { flex: 1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .card-actions button { padding: 6px 4px; }
}
