:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e2db;
  --accent: #b45309;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(28 25 23 / 0.08), 0 8px 24px rgb(28 25 23 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #211e18;
    --text: #f5f1ea;
    --muted: #a8a29e;
    --line: #322e26;
    --accent: #f59e0b;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

header {
  padding: 40px 0 28px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
}

.sub { margin: 0; color: var(--muted); font-size: 15px; }

/* ---- gallery grid ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  padding-bottom: 60px;
}

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  margin: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .18s ease;
}

.tile:hover { transform: translateY(-2px); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile .play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.tile .play span {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.55);
  display: grid; place-items: center;
  backdrop-filter: blur(4px);
}

.tile .play svg { fill: #fff; margin-left: 3px; }

.tile figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 10px 8px;
  font-size: 12px;
  color: #fff;
  text-align: left;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.75));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty, .loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 64px 16px;
}

/* ---- lightbox ---- */

dialog#lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

dialog#lightbox::backdrop { background: rgb(0 0 0 / 0.92); }

.lb-stage {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  padding: 12px;
}

.lb-stage img, .lb-stage video {
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  object-fit: contain;
  border-radius: 6px;
}

.lb-meta {
  color: #e7e5e4;
  font-size: 14px;
  text-align: center;
  padding: 12px 8px 4px;
  max-width: 60ch;
}

.lb-meta time { display: block; color: #a8a29e; font-size: 12px; margin-top: 2px; }

.lb-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 0;
  background: rgb(255 255 255 / 0.14);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.lb-btn:hover { background: rgb(255 255 255 / 0.26); }
#lb-prev { left: 10px; }
#lb-next { right: 10px; }
#lb-close { top: 12px; right: 10px; transform: none; }

/* ---- admin ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }

input[type=password], input[type=text], textarea {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button.primary {
  padding: 11px 20px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button.primary:disabled { opacity: .5; cursor: not-allowed; }

button.ghost {
  padding: 7px 13px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}

.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); }

.queue { list-style: none; margin: 16px 0 0; padding: 0; }

.queue li {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.queue img {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.queue .name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue .state { font-size: 12px; color: var(--muted); }
.queue .state.err { color: #dc2626; }
.queue .state.done { color: #16a34a; }

.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.msg { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-top: 12px; }
.msg.err { background: #fee2e2; color: #991b1b; }
.msg.ok  { background: #dcfce7; color: #166534; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

nav.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; font-size: 14px; }
nav.top a { color: var(--accent); text-decoration: none; }
nav.top a:hover { text-decoration: underline; }

.manage-item { display: grid; grid-template-columns: 60px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.manage-item img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; }
