* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111;
  --surface: #1a1a1a;
  --surface2: #252525;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #4a9eff;
  --accent-hover: #6bb3ff;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid #333;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.2rem; font-weight: 600; }
.header h1 a { color: var(--text); }
.header .search-box {
  display: flex;
  gap: 8px;
}
.header .search-box input {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  width: 250px;
}
.header .search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Main content */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}
.login-form {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius);
  text-align: center;
}
.login-form h2 { margin-bottom: 20px; }
.login-form input {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 1rem;
  width: 250px;
  margin-bottom: 12px;
  display: block;
}
.login-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 32px;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.login-form button:hover { background: var(--accent-hover); }
.login-error { color: #ff5555; margin-top: 12px; display: none; }

/* Family cards */
.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.family-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  border: 1px solid #333;
}
.family-card:hover {
  transform: translateY(-2px);
  background: var(--surface2);
}
.family-card h2 {
  font-size: 1.5rem;
  text-transform: capitalize;
  margin-bottom: 8px;
}
.family-card .count { color: var(--text-dim); }

/* Video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.video-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s;
  border: 1px solid #333;
}
.video-card:hover { transform: translateY(-2px); }
.video-card .thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.video-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-card .thumb .no-thumb {
  font-size: 2rem;
  color: var(--text-dim);
}
.video-card .info {
  padding: 10px 12px;
}
.video-card .info h3 {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-card .info .meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.filters select, .filters input {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* Video player page */
.player-page h2 {
  margin-bottom: 16px;
  font-size: 1.3rem;
}
.player-page .tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.player-page .tags .tag {
  background: var(--surface2);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.player-page video {
  width: 100%;
  max-height: 70vh;
  background: #000;
  border-radius: var(--radius);
}
.player-meta {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 12px 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.player-meta a {
  font-size: 0.85rem;
}

/* Filmstrip */
.filmstrip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}
.filmstrip .frame {
  flex-shrink: 0;
  width: 120px;
  height: 68px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.filmstrip .frame:hover { border-color: var(--accent); }
.filmstrip .frame.active { border-color: var(--accent); }
.filmstrip .frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.filmstrip .frame .time {
  position: relative;
  bottom: 22px;
  left: 4px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 2px;
  display: inline-block;
}

/* Slides/Photos grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.image-grid .img-card {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
}
.image-grid .img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}
.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
}

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}
.pagination button {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 6px 16px;
  border-radius: var(--radius);
  cursor: pointer;
}
.pagination button:hover { background: #333; }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination .page-info { padding: 6px 8px; color: var(--text-dim); font-size: 0.85rem; }

/* Browse stills grid */
.stills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
}
.still-card {
  position: relative;
  aspect-ratio: 16/9;
  overflow: hidden;
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface);
}
.still-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}
.still-card:hover img { transform: scale(1.05); }
.still-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  opacity: 0;
  transition: opacity 0.2s;
}
.still-card:hover .still-overlay { opacity: 1; }
.still-title {
  font-size: 0.75rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.still-time {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
}

/* Face grid */
.face-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.face-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  border: 1px solid #333;
  transition: transform 0.15s;
  padding-bottom: 8px;
}
.face-card:hover { transform: translateY(-2px); }
.face-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}
.face-card .no-thumb {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  font-size: 2rem;
  color: var(--text-dim);
}
.face-name {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 6px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.face-count {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 2px 6px;
}
.face-detail-header {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
}
.face-detail-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
}
.face-label-editor {
  display: flex;
  gap: 8px;
  align-items: center;
}
.face-label-editor input {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 1rem;
}
.face-label-editor button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.face-label-editor button:hover { background: var(--accent-hover); }

/* Face actions (hide, merge) */
.face-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}
.btn-secondary {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-secondary:hover { background: #333; }
.face-actions select {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  max-width: 200px;
}
.face-hidden { opacity: 0.4; }
.hide-mode .face-card { cursor: crosshair; }
.hide-mode .face-card:hover { border-color: #ff4444; transform: scale(0.95); }
.hide-mode-active { background: #ff4444 !important; border-color: #ff4444 !important; color: #fff !important; }
.face-hiding { opacity: 0; transform: scale(0.5); transition: opacity 0.3s, transform 0.3s; }

/* Face bubbles on stills */
.face-bubbles {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 2px;
  z-index: 5;
}
.face-bubbles a {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid rgba(255,255,255,0.8);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.face-bubbles a:hover {
  transform: scale(1.3);
  z-index: 10;
}
.face-bubbles img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.face-bubble-more {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.6rem;
  border: 1.5px solid rgba(255,255,255,0.8);
}
/* Ensure img-card also has position relative for face bubbles */
.img-card { position: relative; }

/* Slide detail */
.slide-detail { max-width: 900px; }
.slide-viewer {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.slide-viewer img {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  transition: transform 0.3s;
}
.slide-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.slide-faces { margin-bottom: 12px; }
.slide-face-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.slide-face-link {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 4px 10px 4px 4px;
  font-size: 0.8rem;
  transition: background 0.15s;
}
.slide-face-link:hover { background: var(--surface2); }
.slide-face-link img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

/* Browse button */
.browse-btn {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--accent);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  text-decoration: none;
  transition: background 0.15s;
}
.browse-btn:hover { background: #333; }

/* Breadcrumb */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--accent); }

/* Lazy image placeholder */
img[data-src]:not([src]) {
  background: var(--surface2);
}

/* Loading */
.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-dim);
}

/* Responsive */
@media (max-width: 900px) {
  .family-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .stills-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 600px) {
  .container { padding: 12px; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .family-grid { grid-template-columns: 1fr; }
  .stills-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .header .search-box input { width: 150px; }
  .filmstrip .frame { width: 90px; height: 51px; }
}
