/* Reset default styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-color: #ffffff;
  --text-color: #333;
  --header-bg: #ffffff;
  --header-border: #e9e9e9;
  --input-bg: #f1f1f1;
  --input-focus-bg: #e9e9e9;
  --gallery-bg: #f1f1f1;
  --btn-bg: #e60023;
  --btn-hover-bg: #d50e2d;
  --error-color: #e60023;
  --loading-color: #e60023;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --modal-bg: rgba(0, 0, 0, 0.8);
  --footer-bg: #ffffff;
  --footer-border: #e9e9e9;
  --footer-height: 70px;
  --warning-color: #e60023;
  --date-color: #666;
}

[data-theme="dark"] {
  --bg-color: #1a1a1a;
  --text-color: #e0e0e0;
  --header-bg: #121212;
  --header-border: #333;
  --input-bg: #2d2d2d;
  --input-focus-bg: #3d3d3d;
  --gallery-bg: #2d2d2d;
  --btn-bg: #ff4d6d;
  --btn-hover-bg: #ff1a4d;
  --error-color: #ff4d6d;
  --loading-color: #ff4d6d;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --modal-bg: rgba(0, 0, 0, 0.9);
  --footer-bg: #121212;
  --footer-border: #333;
  --warning-color: #ff4d6d;
  --date-color: #999;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: var(--footer-height);
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  background: var(--header-bg);
  padding: 12px 16px;
  box-shadow: 0 1px 8px var(--shadow-color);
  z-index: 1000;
  border-bottom: 1px solid var(--header-border);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: var(--btn-bg);
  text-decoration: none;
}

.search-bar {
  flex: 1;
  max-width: 600px;
  margin: 0 12px;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 20px;
  background-color: var(--input-bg);
  font-size: 14px;
  color: var(--text-color);
  outline: none;
  transition: background-color 0.2s;
}

.search-input:focus {
  background-color: var(--input-focus-bg);
}

.theme-toggle {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-color);
}

/* Upload Section */
.upload-section {
  max-width: 1200px;
  margin: 16px auto;
  padding: 0 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.title-input {
  padding: 8px 12px;
  border: none;
  border-radius: 20px;
  background-color: var(--input-bg);
  font-size: 14px;
  color: var(--text-color);
  outline: none;
  flex: 1;
  max-width: 200px;
}

.title-input:focus {
  background-color: var(--input-focus-bg);
}

.upload-btn {
  background: var(--btn-bg);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.2s;
}

.upload-btn:hover {
  background: var(--btn-hover-bg);
}

.file-input {
  display: none;
}

.upload-status {
  font-size: 12px;
  color: var(--text-color);
}

.error {
  color: var(--error-color);
  font-size: 12px;
}

.loading {
  color: var(--loading-color);
  font-weight: bold;
  font-size: 12px;
}

/* Gallery Container */
.gallery-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 8px;
  flex: 1 0 auto;
}

/* Masonry Grid */
.gallery {
  column-count: 5;
  column-gap: 8px;
}

.gallery-item {
  display: inline-block;
  width: 100%;
  margin-bottom: 8px;
  break-inside: avoid;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer; /* Ensure cursor indicates clickability */
  transition: transform 0.2s ease-out;
  background: var(--gallery-bg);
  position: relative;
}

.gallery-item:hover {
  transform: scale(1.02);
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  object-fit: contain;
  cursor: pointer; /* Ensure image is clickable */
}

.gallery-title {
  padding: 4px 8px;
  font-size: 12px;
  text-align: center;
  color: var(--text-color);
  margin: 0;
}

.gallery-date {
  padding: 0 8px 4px;
  font-size: 10px;
  text-align: center;
  color: var(--date-color);
  margin: 0;
}

/* Overlay on hover */
.gallery-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s;
  border-radius: 12px;
  pointer-events: none; /* Prevent overlay from blocking clicks */
}

.gallery-item:hover::before {
  opacity: 1;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-bg);
  z-index: 2000;
  padding: 0;
}

.modal-content {
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  height: 100%;
  gap: 0;
}

.modal img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 0;
  object-fit: contain;
}

.modal-title {
  color: #fff;
  font-size: 16px;
  text-align: center;
  position: absolute;
  bottom: 60px;
  width: 100%;
  padding: 8px;
  background: rgba(0, 0, 0, 0.5);
}

.menu-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
  z-index: 2001;
}

.menu-btn:hover {
  background: rgba(230, 230, 230, 0.9);
}

.menu {
  display: none;
  position: absolute;
  top: 60px;
  right: 16px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: 0 2px 5px var(--shadow-color);
  z-index: 2001;
}

.menu-item {
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text-color);
  cursor: pointer;
  text-align: left;
}

.menu-item:hover {
  background: #f0f0f0;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 64px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
}

.close-btn:hover {
  background: rgba(230, 230, 230, 0.9);
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--footer-bg);
  border-top: 1px solid var(--footer-border);
  height: var(--footer-height);
  z-index: 1000;
  box-shadow: 0 -1px 8px var(--shadow-color);
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}

.copyright {
  font-size: 12px;
  color: var(--text-color);
  margin: 0;
}

.warning {
  font-size: 10px;
  color: var(--warning-color);
  font-style: italic;
  margin: 2px 0 0;
  line-height: 1.2;
  max-width: 100%;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .gallery {
    column-count: 3;
    column-gap: 6px;
  }

  .gallery-item {
    margin-bottom: 6px;
  }
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: row;
    gap: 8px;
    align-items: center;
  }

  .search-bar {
    margin: 0 8px;
    flex: 1;
  }

  .gallery-container {
    padding: 0 6px;
  }

  .gallery {
    column-count: 2;
    column-gap: 4px;
  }

  .gallery-item {
    margin-bottom: 4px;
  }

  .upload-section {
    padding: 0 8px;
    margin: 12px auto;
    gap: 6px;
  }

  .title-input {
    max-width: 150px;
    font-size: 12px;
    padding: 6px 10px;
  }

  .upload-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .footer-content {
    padding: 6px 12px;
  }

  .warning {
    font-size: 9px;
  }

  .gallery-date {
    font-size: 9px;
  }

  .menu-btn {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .close-btn {
    top: 12px;
    right: 56px;
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .menu {
    top: 48px;
    right: 12px;
  }

  .modal-title {
    bottom: 56px;
    font-size: 14px;
    padding: 6px;
  }
}

@media (max-width: 360px) {
  .gallery {
    column-count: 1;
    column-gap: 2px;
  }

  .gallery-item {
    margin-bottom: 2px;
  }

  .header-content {
    flex-direction: column;
    gap: 6px;
  }

  .search-bar {
    margin: 0;
    width: 100%;
  }

  .logo {
    font-size: 18px;
  }

  .theme-toggle {
    font-size: 16px;
  }

  .title-input {
    max-width: 100%;
    font-size: 10px;
    padding: 4px 8px;
  }

  .upload-btn {
    padding: 4px 8px;
    font-size: 10px;
  }

  .footer-content {
    padding: 4px 8px;
  }

  .warning {
    font-size: 8px;
  }

  .gallery-date {
    font-size: 8px;
  }

  .menu-btn {
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .close-btn {
    top: 8px;
    right: 48px;
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .menu {
    top: 40px;
    right: 8px;
  }

  .modal-title {
    bottom: 52px;
    font-size: 12px;
    padding: 4px;
  }
}
