:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --primary: #2d6cdf;
  --primary-dark: #1d4fae;
  --secondary: #edf2ff;
  --text: #1f2937;
  --muted: #667085;
  --success: #1d8f5f;
  --danger: #d25d5d;
  --border: #dfe7f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 100%);
  color: var(--text);
}

.library-shell {
  width: min(1360px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 64px;
}

.library-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 46px;
}

.eyebrow,
.back-link {
  color: #a5422d;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.library-header h1 {
  margin: 8px 0 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2.5rem, 5vw, 4.6rem);
  font-weight: 500;
  line-height: 0.98;
}

.sorter-link {
  background: #1f2937;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  padding: 12px 17px;
  text-decoration: none;
  white-space: nowrap;
}

.section-heading {
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
}

.section-heading h2,
.album-label h2 {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 500;
}

.section-heading p,
.album-subtitle {
  color: var(--muted);
  margin: 0;
}

.album-grid {
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.album-card {
  color: var(--text);
  display: block;
  min-width: 0;
  text-decoration: none;
}

.album-cover {
  aspect-ratio: 4 / 5;
  background: #d9e0e8;
  overflow: hidden;
}

.album-cover img,
.media-item img,
.media-item video {
  display: block;
  height: 100%;
  object-fit: cover;
  transition: transform 280ms ease;
  width: 100%;
}

.album-card:hover img {
  transform: scale(1.04);
}

.empty-cover {
  align-items: center;
  background: #c9d3cf;
  color: #40504b;
  display: flex;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 4.8rem;
  justify-content: center;
}

.album-label {
  display: flex;
  justify-content: space-between;
  padding: 12px 2px 0;
}

.album-label span {
  color: var(--muted);
  font-size: 0.86rem;
  padding-top: 4px;
}

.album-header {
  align-items: center;
}

.album-subtitle {
  margin-top: 12px;
}

.group-toggle {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.95rem;
  font-weight: 700;
  gap: 9px;
  margin-top: 20px;
}

.group-toggle[hidden],
.advanced-filters[hidden] {
  display: none;
}

.group-toggle input {
  accent-color: var(--primary);
  height: 18px;
  margin: 0;
  width: 18px;
}

.advanced-filters {
  border: 0;
  margin: 16px 0 0;
  padding: 0;
}

.advanced-filters legend {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.85rem;
  font-weight: 700;
  gap: 12px;
  margin-bottom: 9px;
}

.only-toggle {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.85rem;
  gap: 5px;
}

.only-toggle input {
  accent-color: var(--primary);
  height: 15px;
  margin: 0;
  width: 15px;
}

.family-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  max-width: 690px;
}

.family-filter {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  font-size: 0.9rem;
  gap: 6px;
}

.family-filter input {
  accent-color: var(--primary);
  height: 16px;
  margin: 0;
  width: 16px;
}

.media-grid {
  columns: 280px;
  column-gap: 16px;
}

.media-item {
  background: #d9e0e8;
  border: 0;
  break-inside: avoid;
  display: block;
  margin: 0 0 16px;
  padding: 0;
  width: 100%;
}

.media-item img,
.media-item video {
  height: auto;
}

.empty-album {
  color: var(--muted);
  margin: 44px 0;
  text-align: center;
}

.album-lightbox {
  align-items: center;
  background: rgba(10, 14, 17, 0.9);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 44px;
  position: fixed;
  z-index: 10;
}

.album-lightbox[hidden] {
  display: none;
}

.album-lightbox img,
.album-lightbox video {
  max-height: 88vh;
  max-width: min(100%, 1280px);
  object-fit: contain;
}

.album-lightbox .lightbox-close {
  position: fixed;
  right: 20px;
  top: 20px;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  letter-spacing: 0.04em;
  font-size: clamp(2rem, 4vw, 2.8rem);
}

.reset-btn {
  background: #111827;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.photo-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
  padding: 18px;
}

.photo-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 520px;
  background: #e9eefb;
  border-radius: 12px;
  overflow: hidden;
}

#photo {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.photo-meta {
  margin-top: 12px;
}

#photo-name {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  word-break: break-word;
}

.people-section {
  margin-top: 24px;
}

.people-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.person-btn {
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.person-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.person-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 8px 18px rgba(45, 108, 223, 0.2);
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.2s ease;
}

button:hover {
  filter: brightness(0.98);
}

.submit-btn {
  background: var(--primary);
  color: white;
}

.submit-btn:hover {
  background: var(--primary-dark);
}

.danger-btn {
  background: var(--danger);
  color: white;
}

.danger-btn:hover {
  filter: brightness(0.96);
}

.secondary-btn {
  background: #eef2f7;
  color: var(--text);
}

.status {
  min-height: 24px;
  margin-top: 16px;
  font-weight: 600;
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.lightbox-content {
  position: relative;
  width: min(92vw, 1200px);
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img,
.lightbox-content video {
  width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: #111827;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 700px) {
  .library-shell {
    width: min(100% - 28px, 1360px);
    padding-top: 26px;
  }

  .library-header {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 30px;
  }

  .sorter-link {
    width: 100%;
    text-align: center;
  }

  .album-grid {
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .album-label {
    display: block;
  }

  .photo-frame {
    min-height: 320px;
  }

  .person-btn {
    flex: 1 1 140px;
  }
}
