:root {
  --bg: #faf7f2;
  --bg-elevated: #fffdf9;
  --bg-subtle: #f1ebe1;
  --bg-glass: rgba(250, 247, 242, 0.86);
  --text: #231e19;
  --text-muted: #6f655b;
  --border: rgba(35, 30, 25, 0.09);
  --border-strong: rgba(35, 30, 25, 0.16);
  --accent: #a66a3c;
  --accent-soft: rgba(166, 106, 60, 0.12);
  --accent-glow: rgba(210, 152, 98, 0.16);
  --shadow-sm: 0 2px 10px rgba(35, 28, 20, 0.05);
  --shadow-md: 0 12px 32px rgba(35, 28, 20, 0.1);
  --skeleton-a: #efe9df;
  --skeleton-b: #f7f3ec;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  --bg: #13110f;
  --bg-elevated: #1c1916;
  --bg-subtle: #26221e;
  --bg-glass: rgba(19, 17, 15, 0.86);
  --text: #f3ede4;
  --text-muted: #a99f93;
  --border: rgba(243, 237, 228, 0.09);
  --border-strong: rgba(243, 237, 228, 0.18);
  --accent: #d9a06b;
  --accent-soft: rgba(217, 160, 107, 0.15);
  --accent-glow: rgba(217, 160, 107, 0.13);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.45);
  --skeleton-a: #201d19;
  --skeleton-b: #2b2621;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg);
  color-scheme: light;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: radial-gradient(
    ellipse 70% 340px at 50% -40px,
    var(--accent-glow),
    transparent 72%
  );
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
}

body.lightbox-open {
  overflow: hidden;
}

.page-grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.024;
  background-image: radial-gradient(var(--text) 0.5px, transparent 0.5px);
  background-size: 14px 14px;
}

[hidden] {
  display: none !important;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition);
}

.brand:hover .brand-mark {
  transform: scale(1.06);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), color var(--transition);
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffdf9;
}

.btn-primary:hover {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn-subtle {
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color var(--transition), border-color var(--transition), transform var(--transition), background var(--transition);
}

.icon-btn-sm {
  width: 34px;
  height: 34px;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.icon-btn.is-spinning svg {
  animation: spin 700ms linear infinite;
}

.icon-sun {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Main Container & Header ---------- */

.container {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 72px;
}

.hero {
  text-align: center;
  padding: 40px 12px 24px;
}

.site-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 7.5vw, 5.2rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* ---------- Controls Bar ---------- */

.controls-bar {
  margin: 0 0 26px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sort-group {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.pill-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.pill-btn.is-active {
  background: var(--accent-soft);
  border-color: rgba(166, 106, 60, 0.26);
  color: var(--accent);
}

.view-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.photo-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.seg-btn {
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.is-active {
  background: var(--bg-elevated);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ---------- Gallery Layouts ---------- */

.gallery-masonry {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.masonry-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

/* ---------- Photo Card ---------- */

.photo-card {
  position: relative;
  margin: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 300ms ease, border-color 300ms ease;
}

.photo-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.photo-trigger {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: var(--skeleton-a);
  cursor: zoom-in;
  overflow: hidden;
}

.gallery-masonry .photo-trigger {
  min-height: 170px;
}

.gallery-grid .photo-trigger {
  aspect-ratio: 4 / 3;
}

.photo-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    var(--skeleton-a) 8%,
    var(--skeleton-b) 28%,
    var(--skeleton-a) 48%
  );
  background-size: 220% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  transition: opacity 280ms ease;
}

.photo-card.is-loaded .photo-shimmer {
  opacity: 0;
  pointer-events: none;
}

.photo-img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transform: scale(1.01);
  transition: opacity 380ms ease, transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.gallery-grid .photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card.is-loaded .photo-img {
  opacity: 1;
  transform: scale(1);
}

.photo-card:hover .photo-img {
  transform: scale(1.028);
}

.photo-error-veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--bg-subtle);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
  font-size: 0.8rem;
}

/* ---------- Skeleton & Empty/Error States ---------- */

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

.skeleton-card {
  border-radius: var(--radius-md);
  background: linear-gradient(
    110deg,
    var(--skeleton-a) 8%,
    var(--skeleton-b) 28%,
    var(--skeleton-a) 48%
  );
  background-size: 220% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-card.tall {
  height: 320px;
}

.skeleton-card.medium {
  height: 250px;
}

.skeleton-card.short {
  height: 200px;
}

.state-card {
  max-width: 460px;
  margin: 40px auto;
  padding: 38px 28px;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-strong);
  background: var(--bg-elevated);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.state-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.state-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 500;
}

.state-card p {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding-top: 36px;
}

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(12, 10, 9, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #f6f1ea;
  display: flex;
  flex-direction: column;
  animation: fadeIn 200ms ease;
}

.slideshow-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 5;
  opacity: 0;
  transition: opacity 200ms ease;
}

.lightbox.is-slideshow .slideshow-progress {
  opacity: 1;
}

.slideshow-progress-bar {
  height: 100%;
  width: 0%;
  background: #d9a06b;
}

.lightbox-top {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.45), transparent);
}

.lightbox-meta-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.lightbox-counter {
  flex-shrink: 0;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  font-size: 0.82rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: #f6f1ea;
}

.lightbox-date {
  font-size: 0.84rem;
  color: rgba(246, 241, 234, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  font-size: 0.74rem;
  color: rgba(246, 241, 234, 0.5);
}

.kbd-hint kbd {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  color: rgba(246, 241, 234, 0.8);
}

.lb-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #f6f1ea;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.lb-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.lightbox .icon-pause {
  display: none;
}

.lightbox.is-slideshow .icon-play {
  display: none;
}

.lightbox.is-slideshow .icon-pause {
  display: block;
}

.lightbox.is-slideshow #lightboxSlideshowBtn {
  background: rgba(217, 160, 107, 0.28);
  border-color: rgba(217, 160, 107, 0.65);
  color: #f5cca0;
}

.lightbox-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 76px;
  user-select: none;
}

.lightbox-image-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-image-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 260ms ease;
}

.lightbox-image-frame img.is-ready {
  opacity: 1;
}

.lb-spinner {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.18);
  border-top-color: #d9a06b;
  animation: spin 800ms linear infinite;
}

.lb-error {
  position: absolute;
  text-align: center;
  color: rgba(246, 241, 234, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #f6f1ea;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 180ms ease, transform 180ms ease;
}

.lb-nav:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lb-prev {
  left: 18px;
}

.lb-next {
  right: 18px;
}

.lightbox-thumbs-wrap {
  flex-shrink: 0;
  padding: 12px 16px 16px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.lightbox-thumbs {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 8px;
  min-width: max-content;
  margin: 0 auto;
}

.lb-thumb {
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  cursor: pointer;
  opacity: 0.5;
  flex-shrink: 0;
  transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.lb-thumb:hover {
  opacity: 0.9;
}

.lb-thumb.is-active {
  opacity: 1;
  border-color: #d9a06b;
  transform: scale(1.06);
}

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

/* ---------- Animations ---------- */

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .skeleton-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 780px) {
  .topbar-inner {
    padding: 10px 16px;
  }

  .container {
    padding: 0 16px 56px;
  }

  .hero {
    padding: 28px 4px 18px;
  }

  .controls-bar {
    justify-content: center;
  }

  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kbd-hint {
    display: none;
  }

  .lightbox-stage {
    padding: 8px 14px;
  }

  .lb-nav {
    width: 40px;
    height: 40px;
    background: rgba(15, 12, 10, 0.55);
  }

  .lb-prev {
    left: 10px;
  }

  .lb-next {
    right: 10px;
  }

  .lb-thumb {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 480px) {
  .skeleton-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
