/* Photos gallery — dark, contact-sheet inspired. System fonts only:
   keeps the whole UI under a few KB and avoids a web-font round trip. */

:root {
  --bg: #121214;
  --bg-raised: #1a1a1d;
  --line: #2a2a2e;
  --text: #e9e7e2;
  --text-dim: #9a9a9f;
  --accent: #c1443a;   /* darkroom safelight red — used sparingly */
  --thumb-size: 320px;
  --radius: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body { -webkit-tap-highlight-color: transparent; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(18, 18, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  min-width: 0;
}

.breadcrumb a, .breadcrumb span.current {
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb a:hover { color: var(--text); }
.breadcrumb span.current { color: var(--text); font-weight: 600; }
.breadcrumb .sep { color: var(--line); }
.breadcrumb .crumb-count { color: var(--text-dim); font-weight: 400; font-size: 0.85em; }

.logout-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  flex: none;
}
.logout-btn:hover { color: var(--text); border-color: var(--text-dim); }

.top-counts {
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.count-part {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
}

.count-icon {
  width: 11px;
  height: 11px;
  flex: none;
  opacity: 0.8;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: none;
}

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--thumb-size), 45vw), 1fr));
  gap: 3px;
  padding: 3px;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--line);
  background: linear-gradient(100deg, var(--bg-raised) 30%, #2c2c32 50%, var(--bg-raised) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

/* Stop the shimmer once the real thumbnail is in place. */
.tile.loaded { animation: none; }

.tile.folder .label {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.6rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1.2;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
}

.tile.folder .label-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile.folder .label-count {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.7);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile.folder::before {
  content: "";
  position: absolute;
  top: 8px; left: 8px;
  width: 20px; height: 16px;
  border-radius: 2px 4px 4px 4px;
  background: var(--accent);
  opacity: 0.9;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.tile.folder.no-thumb {
  display: flex;
  align-items: flex-end;
  animation: none;
  background: linear-gradient(160deg, #1e1e22, #17171a);
}

.tile.load-error {
  animation: none;
  background: var(--bg-raised);
}
.tile.load-error::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  pointer-events: none;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1rem;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 20;
  display: flex;
  flex-direction: column;
  touch-action: none;
}
.lightbox[hidden] { display: none; }

.lb-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
}

.lb-spinner {
  position: absolute;
  width: 34px; height: 34px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.lb-close, .lb-nav {
  position: absolute;
  background: rgba(0,0,0,0.35);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 2;
}

.lb-close {
  top: 10px; right: 10px;
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
}

.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 48px; height: 64px;
  font-size: 2rem;
  border-radius: var(--radius);
}
.lb-prev { left: 8px; }
.lb-next { right: 8px; }

@media (hover: hover) {
  .lb-close:hover, .lb-nav:hover { background: rgba(0,0,0,0.6); }
}

.lb-caption {
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Login ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: min(320px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 2rem;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.login-box h1 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  text-align: center;
}

.login-box input {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  font-size: 1rem;
}

.login-box button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.65rem;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.login-box button:hover { filter: brightness(1.1); }

.login-error { color: var(--accent); font-size: 0.85rem; margin: 0; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .tile, .tile img, .lb-spinner { transition: none; animation: none; }
}
