:root {
  color-scheme: dark;
  --bg: #15151b; --panel: #20202a; --line: #33333f; --fg: #e8e8ee; --muted: #9a9aab;
  --accent: #ffcc33; --danger: #ff5c6c; --ok: #5cd68a;
  font: 15px/1.4 system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
[hidden] { display: none !important; }
body[data-scope=ro] .rw, body:not([data-scope=admin]) .admin { display: none; }
a { color: var(--accent); }
button, .button, input, select, textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: .5em .8em;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.danger { color: var(--danger); }
input, select, textarea { width: 100%; }
textarea { resize: vertical; }
label { display: block; margin: .6em 0; color: var(--muted); font-size: .9em; }
label > input, label > textarea, label > select { margin-top: .25em; color: var(--fg); font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.error { color: var(--danger); }
.warn { color: var(--accent); }
.ok { color: var(--ok); }
.spacer { flex: 1; }
.row { display: flex; gap: .5em; }
.row > input { flex: 1; }
.row > select { width: auto; }

#login { min-height: 100vh; display: grid; place-items: center; padding: 1em; }
#login form { width: min(22em, 100%); display: grid; gap: .8em; }
#login h1 { margin: 0; color: var(--accent); text-align: center; }

header {
  position: sticky; top: 0; z-index: 2; background: var(--bg); padding: .5em .75em;
  padding-top: max(.5em, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); display: grid; gap: .5em;
}
.bar { display: flex; align-items: center; gap: .5em; flex-wrap: wrap; }
.logo { color: var(--accent); font-size: 1.2em; }
.badge { font-size: .75em; padding: .1em .5em; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
#q { font-size: 1.05rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3em; }
.chip { font-size: .8em; padding: .15em .6em; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); }
.chip.kind, .chip.style { border-color: #6a8cff; }
.chip.date { border-color: var(--ok); }
.chip.emoji, .chip.phrase { border-color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg input { display: none; }
.seg span { display: block; padding: .3em .7em; font-size: .85em; cursor: pointer; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: #111; }
.seg label { margin: 0; }

#grid {
  display: grid; gap: 4px; padding: 4px;
  grid-template-columns: repeat(auto-fill, minmax(min(31vw, 160px), 1fr)); grid-auto-flow: dense;
}
.card { position: relative; padding: 0; border: 0; border-radius: 6px; overflow: hidden; background: var(--panel); max-height: 320px; }
.card img, .card video { width: 100%; height: 100%; object-fit: cover; display: block; }
.card video { position: absolute; inset: 0; }
.card.busy { min-height: 120px; }
.card.busy img { filter: brightness(.45) saturate(.6); }
.card.busy::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.14) 50%, transparent 70%);
  background-size: 250% 100%; animation: sweep 1.6s linear infinite; }
.busy-veil { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .5em; color: #fff; font-size: .85em; text-shadow: 0 1px 3px #000; }
.spinner { width: 2.2em; height: 2.2em; border-radius: 50%; border: 3px solid rgba(255,255,255,.25);
  border-top-color: var(--accent, #e5a00d); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sweep { from { background-position: 125% 0; } to { background-position: -125% 0; } }
@media (prefers-reduced-motion: reduce) { .card.busy::after, .spinner { animation: none; } }
.kind { position: absolute; right: 4px; bottom: 4px; font-size: .7em; padding: .05em .4em; border-radius: 4px; background: #000a; color: #fff; }
#sentinel { height: 1px; }
#grid-status { margin: 1em; }

dialog {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 12px;
  width: min(44em, 100vw); max-height: 100dvh; padding: 0 1em 1em; overflow: auto;
}
dialog::backdrop { background: #000c; }
@media (max-width: 600px) {
  dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0; border: 0; }
}
.dlg-head {
  position: sticky; top: 0; z-index: 1; background: var(--bg); display: flex; align-items: center; justify-content: space-between;
  padding: .6em 0; font-weight: 600;
}
.close { border: 0; background: none; font-size: 1.2em; }
.media { display: grid; place-items: center; background: #000; border-radius: 8px; min-height: 6em; }
.media img, .media video { max-width: 100%; max-height: 65dvh; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: .5em; margin: .8em 0; }
.text { white-space: pre-wrap; background: var(--panel); padding: .5em .7em; border-radius: 8px; }
dl { display: grid; grid-template-columns: auto 1fr; gap: .3em 1em; margin: .8em 0; }
dt { color: var(--muted); }
dd { margin: 0; word-break: break-word; }
#item-info .chip { cursor: pointer; }
.tag-editor { align-items: center; margin: .3em 0; }
.tag-editor .chip { display: inline-flex; align-items: center; padding: 0; font-size: .9em; }
.chip-label, .chip-x { border: 0; background: none; padding: .3em .2em .3em .7em; border-radius: 99px; }
.chip-x { padding: .3em .6em .3em .35em; color: var(--muted); }
.chip-x:hover { color: var(--danger); }
.tag-input { width: auto; flex: 1 1 8em; min-width: 8em; padding: .3em .6em; border-radius: 99px; font-size: .9em; }
.drop {
  display: grid; place-items: center; min-height: 7em; border: 2px dashed var(--line); border-radius: 12px;
  color: var(--muted); cursor: pointer; text-align: center; padding: 1em;
}
.drop.over { border-color: var(--accent); color: var(--accent); }
.queue, .keys { list-style: none; padding: 0; margin: .5em 0; display: grid; gap: .4em; }
.queue li, .keys li {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5em; background: var(--panel); padding: .5em .7em; border-radius: 8px;
}
.queue .name { flex: 1; min-width: 8em; word-break: break-all; }
.state { display: flex; align-items: center; gap: .4em; flex-wrap: wrap; }
.keys li > div { flex: 1; }
.mini { display: inline-flex; align-items: center; gap: .3em; padding: .2em .4em; font-size: .85em; }
.mini img { width: 2em; height: 2em; object-fit: cover; border-radius: 4px; }
h3 { margin: 1.2em 0 .4em; }
#toast {
  position: fixed; left: 50%; bottom: max(1.5em, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  background: var(--fg); color: var(--bg); padding: .5em 1em; border-radius: 99px; font-weight: 600;
}

.media-wrap { position: relative; }
.step { position: absolute; top: 50%; transform: translateY(-50%); width: 2.4em; height: 2.4em; padding: 0;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 1.4em; line-height: 1; z-index: 2; }
.step:hover { background: rgba(0,0,0,.8); }
.step.prev { left: .4em; }
.step.next { right: .4em; }
.step[hidden] { display: none; }
.actions .icon { display: inline-flex; align-items: center; justify-content: center; padding: .45em .6em; }
