:root {
  --bg: #111;
  --panel: #1c1c1c;
  --fg: #eee;
  --muted: #999;
  --accent: #4a9eff;
  --danger: #e5484d;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Yu Gothic UI", sans-serif; }

button {
  font: inherit;
  color: var(--fg);
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { background: #333; }

.toggle[hidden] { display: none; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(17, 17, 17, 0.92);
  border-bottom: 1px solid #222;
}
h1 { margin: 0; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.dot.on { background: #3ec46d; }

.icon {
  display: inline-flex;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
}
.icon:hover { color: var(--fg); background: #2a2a2a; }
#to-camera { margin-left: 4px; }
.toggle, #toolbar button { white-space: nowrap; }

#banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: #4a2a12;
}
#banner[hidden] { display: none; }

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
  padding: 4px 16px 32px;
}
#grid h2 {
  grid-column: 1 / -1;
  margin: 16px 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #222;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover img { opacity: 0.85; }
.thumb.new { animation: appear 0.6s ease-out; }
@keyframes appear { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 0 transparent; } }

#empty { text-align: center; color: var(--muted); margin-top: 80px; }

#viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
}
#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }
#image {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  user-select: none;
  max-width: none;
}

#toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 10px 16px;
  background: linear-gradient(rgba(0, 0, 0, 0.7), transparent);
}
#toolbar .info { display: flex; gap: 10px; flex: 1; white-space: nowrap; }
#toolbar .actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#counter { color: var(--muted); font-variant-numeric: tabular-nums; }
#delete:hover { background: var(--danger); border-color: var(--danger); }

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 80px;
  font-size: 36px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
#viewer:hover .nav { opacity: 1; }
.nav:disabled { visibility: hidden; }
#prev { left: 8px; }
#next { right: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(40, 40, 40, 0.95);
}
#toast.error { background: var(--danger); }

#stage { touch-action: none; }

@media (max-width: 600px) {
  header { padding: 8px 12px; }
  #grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 0 0 24px;
  }
  #grid h2 { margin: 12px 12px 4px; }
  #toolbar { padding: 8px 12px; }
  .nav { opacity: 1; width: 40px; height: 64px; font-size: 30px; }
}

#login {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 360px;
  margin: 96px auto 0;
  padding: 0 16px;
}
#login[hidden] { display: none; }
#login input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 8px 12px;
  color: var(--fg);
  background: #1c1c1c;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
}
#login p { flex-basis: 100%; margin: 0; text-align: center; color: var(--danger); }
