:root {
  --fb-blue: #1877f2;
  --fb-blue-dark: #145dbf;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #050505;
  --text-secondary: #65676b;
  --border: #ced0d4;
  --hover: #f2f2f2;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; display: block; }

/* Top bar */
#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
}
#topbar .logo {
  color: var(--fb-blue);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
#topbar .tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
#topbar .tab-btn {
  padding: 10px 22px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 3px solid transparent;
}
#topbar .tab-btn:hover { background: var(--hover); }
#topbar .tab-btn.active {
  color: var(--fb-blue);
  border-bottom-color: var(--fb-blue);
}
#topbar .search-box {
  display: flex;
  align-items: center;
}
#topbar .search-box input {
  border: none;
  background: var(--bg);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  width: 200px;
}

/* Profile header */
#profile-header {
  max-width: 900px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  margin-bottom: 16px;
}
#profile-header .cover {
  width: 100%;
  height: 260px;
  object-fit: cover;
  background: linear-gradient(135deg, #dfe3ee, #c8d0e7);
}
#profile-header .info-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 0 24px 16px;
  margin-top: -60px;
}
#profile-header .avatar {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 4px solid var(--card-bg);
  object-fit: cover;
  background: #dbdfe4;
}
#profile-header .name-block { padding-bottom: 12px; }
#profile-header .name-block h1 { margin: 0; font-size: 32px; }
#profile-header .name-block .stats {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 4px;
}

/* Layout */
#app { max-width: 900px; margin: 0 auto; padding: 16px; }
#year-nav {
  position: fixed;
  right: 20px;
  top: 120px;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  padding: 8px;
  max-height: 70vh;
  overflow-y: auto;
  font-size: 13px;
  display: none;
}
#year-nav a {
  display: block;
  padding: 4px 10px;
  color: var(--text-secondary);
  border-radius: 4px;
}
#year-nav a:hover { background: var(--hover); color: var(--fb-blue); }

/* Post card */
.post-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  margin-bottom: 16px;
  overflow: hidden;
}
.post-card .post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.post-card .post-head .badge {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.post-card .post-head .meta { flex: 1; min-width: 0; }
.post-card .post-head .header-text {
  font-weight: 600;
  font-size: 14.5px;
  overflow-wrap: break-word;
}
.post-card .post-head .timestamp {
  color: var(--text-secondary);
  font-size: 12.5px;
  margin-top: 1px;
}
.post-card .post-text {
  padding: 0 16px 12px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.post-card .post-media {
  display: grid;
  gap: 2px;
  background: #000;
}
.post-card .post-media.n1 { grid-template-columns: 1fr; }
.post-card .post-media.n2 { grid-template-columns: 1fr 1fr; }
.post-card .post-media.n3 { grid-template-columns: 1fr 1fr; }
.post-card .post-media.n3 .m0 { grid-row: span 2; }
.post-card .post-media.nmany { grid-template-columns: 1fr 1fr 1fr; }
.post-card .media-item {
  position: relative;
  cursor: pointer;
  overflow: hidden;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  max-height: 420px;
}
.post-card .media-item img,
.post-card .media-item video {
  width: 100%; height: 100%; object-fit: cover;
}
.post-card .media-item .caption-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff;
  font-size: 12.5px;
  padding: 16px 10px 8px;
  opacity: 0;
  transition: opacity .15s;
}
.post-card .media-item:hover .caption-overlay { opacity: 1; }
.post-card .media-item .more-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.post-card .video-icon {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.5);
  color: #fff; border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  pointer-events: none;
}

.year-marker {
  text-align: center;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 17px;
  margin: 26px 0 14px;
  position: relative;
}
.year-marker::before, .year-marker::after {
  content: "";
  position: absolute; top: 50%;
  width: 40%; height: 1px;
  background: var(--border);
}
.year-marker::before { left: 0; }
.year-marker::after { right: 0; }

#loading-sentinel { text-align: center; padding: 20px; color: var(--text-secondary); }

/* Albums grid */
.albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.album-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  cursor: pointer;
}
.album-card .cover-wrap {
  width: 100%; height: 160px;
  background: #ddd;
  overflow: hidden;
}
.album-card .cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.album-card .album-info { padding: 10px 12px; }
.album-card .album-title { font-weight: 600; font-size: 15px; }
.album-card .album-count { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px;
}
.photo-grid .media-item {
  position: relative;
  cursor: pointer;
  aspect-ratio: 1;
  overflow: hidden;
  background: #111;
}
.photo-grid .media-item img, .photo-grid .media-item video { width: 100%; height: 100%; object-fit: cover; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  border-radius: 20px;
  padding: 8px 16px;
  margin-bottom: 14px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.back-btn:hover { background: var(--hover); }

.album-header {
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0 14px;
}

/* Lightbox */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
}
#lightbox.open { display: flex; }
#lightbox .lb-content {
  max-width: 90vw;
  max-height: 78vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox .lb-content img, #lightbox .lb-content video {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
}
#lightbox .lb-caption {
  color: #fff;
  max-width: 700px;
  text-align: center;
  padding: 16px;
  font-size: 15px;
}
#lightbox .lb-close, #lightbox .lb-prev, #lightbox .lb-next {
  position: absolute;
  color: #fff;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 22px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#lightbox .lb-close:hover, #lightbox .lb-prev:hover, #lightbox .lb-next:hover {
  background: rgba(255,255,255,0.3);
}
#lightbox .lb-close { top: 20px; right: 24px; }
#lightbox .lb-prev { left: 24px; top: 50%; transform: translateY(-50%); }
#lightbox .lb-next { right: 24px; top: 50%; transform: translateY(-50%); }

/* Instagram tab */
.ig-header {
  display: flex; align-items: center; gap: 24px;
  background: var(--card-bg); border-radius: var(--radius);
  padding: 24px; margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.ig-header .ig-avatar {
  width: 90px; height: 90px; border-radius: 50%;
  object-fit: cover; background: #dbdfe4;
  border: 2px solid #e1306c;
  padding: 3px;
}
.ig-header h2 { margin: 0 0 4px; }
.ig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
}
.ig-grid .ig-item {
  position: relative;
  cursor: pointer;
  aspect-ratio: 1;
  overflow: hidden;
  background: #111;
}
.ig-grid .ig-item img, .ig-grid .ig-item video { width: 100%; height: 100%; object-fit: cover; }
.ig-grid .ig-item .multi-badge {
  position: absolute; top: 8px; right: 8px;
  color: #fff; font-size: 16px;
  text-shadow: 0 0 3px rgba(0,0,0,0.7);
}

/* IG post modal reuse lightbox with caption panel */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
  font-size: 15px;
}

@media (max-width: 700px) {
  #topbar .search-box input { width: 120px; }
  #profile-header .avatar { width: 110px; height: 110px; }
  #profile-header .name-block h1 { font-size: 22px; }
  #year-nav { display: none !important; }
}

/* Upload screen */
#upload-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.upload-wrap {
  max-width: 480px;
  width: 100%;
  text-align: center;
}
.upload-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--fb-blue);
  margin-bottom: 10px;
}
.upload-lede {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0 0 28px;
  line-height: 1.5;
}
.drop-zone {
  background: var(--card-bg);
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 24px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--fb-blue);
  background: #f4f8ff;
}
.drop-zone.busy {
  cursor: default;
  opacity: 0.7;
  pointer-events: none;
}
.drop-zone-icon { font-size: 34px; margin-bottom: 10px; }
.drop-zone-text { color: var(--text-secondary); font-size: 15px; }
.name-label {
  display: block;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
}
.name-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
}
.upload-status {
  color: var(--fb-blue);
  font-size: 14px;
  min-height: 20px;
  margin-top: 18px;
}
.upload-error {
  color: #c0392b;
  font-size: 14px;
  background: #fdecea;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 14px;
}

/* Lazy media resolution states */
.media-missing {
  background: var(--hover);
  min-height: 60px;
  position: relative;
}
.media-missing::after {
  content: "Couldn't load this file";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px;
  text-align: center;
}
.lb-loading {
  color: #fff;
  padding: 40px;
  text-align: center;
}

/* Preview / paywall */
#preview-banner {
  max-width: 900px;
  margin: 0 auto 16px;
  background: #fff7e6;
  border: 1px solid #f2d38a;
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: #6b5313;
}
#preview-banner button {
  background: var(--fb-blue);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
#preview-banner button:hover { background: var(--fb-blue-dark); }

.locked-card {
  max-width: 480px;
  margin: 10px auto 30px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  padding: 32px 24px;
  text-align: center;
}
.locked-card-icon { font-size: 30px; margin-bottom: 10px; }
.locked-card-title { font-weight: 700; font-size: 17px; margin-bottom: 8px; }
.locked-card-sub { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-bottom: 18px; }

.unlock-btn {
  background: var(--fb-blue);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 12px 22px;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
}
.unlock-btn:hover { background: var(--fb-blue-dark); }
.unlock-btn:disabled { opacity: 0.6; cursor: default; }
.unlock-btn.large { padding: 14px 28px; font-size: 15.5px; width: 100%; }

#year-nav a.locked { color: #b08900; }

.album-card.locked .cover-wrap { filter: blur(6px) brightness(0.7); }
.album-card .lock-overlay {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.album-card { position: relative; }

.ig-grid .locked-tile {
  background: #efefef;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 13px;
  gap: 6px;
  text-align: center;
  padding: 10px;
}
.locked-tile-icon { font-size: 22px; }

#paywall-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
#paywall-modal.open { display: flex; }
.paywall-card {
  background: var(--card-bg);
  border-radius: 14px;
  max-width: 420px;
  width: 100%;
  padding: 32px 28px 26px;
  text-align: center;
  position: relative;
}
.paywall-card .paywall-close {
  position: absolute;
  top: 14px; right: 14px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
}
.paywall-icon { font-size: 32px; margin-bottom: 6px; }
.paywall-card h2 { margin: 0 0 12px; font-size: 20px; }
.paywall-card #paywall-detail { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-bottom: 20px; }
.paywall-fine { color: var(--text-secondary); font-size: 12.5px; line-height: 1.5; margin-top: 14px; }

.unlock-banner {
  font-size: 14px;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 18px;
  background: #eef4ff;
  color: #1b4e9b;
}
.unlock-banner.success { background: #e6f6ea; color: #1c6b34; }
.unlock-banner.error { background: #fdecea; color: #c0392b; }

.export-btn {
  background: var(--fb-blue);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.export-btn:hover { background: var(--fb-blue-dark); }
.export-btn:disabled { opacity: 0.6; cursor: default; }
.export-status {
  max-width: 900px;
  margin: 8px auto 0;
  padding: 0 20px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
}
