:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --border: #e2ddd7;
  --text-primary: #1a1714;
  --text-secondary: #6b6560;
  --accent: #2d5a3d;
  --accent-hover: #1e3f2b;
  --accent-light: #e8f0eb;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
}

body {
  background: var(--bg);
  font-family: "Playfair Display", serif;
  color: var(--text-primary);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

header .row {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 64px;
}

header h1 {
  font-family: "Playfair Display", serif;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}

header a {
  text-decoration: none;
  color: inherit;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ── Shared button base ── */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.18s ease,
    transform 0.12s ease;
  white-space: nowrap;
}

.header-btn {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
}

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

/* ── Auth area ── */
.current-username {
  font-family: "DM Sans", sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Toggle / action buttons ── */
.toggle-image {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius);
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.18s ease,
    transform 0.12s ease;
  letter-spacing: 0.01em;
}

.toggle-image:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.toggle-image:active {
  transform: translateY(0);
}

/* ── Image count pill ── */
.image-count {
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.25rem 0.75rem;
  margin: 0;
  white-space: nowrap;
}

/* ── Error box ── */
#error-box {
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  margin: 0.75rem 2rem;
  display: none;
}

#error-box.visible {
  display: block;
}

/* ── New-updates polling indicator ── */
.updates-indicator {
  display: block;
  max-width: 1200px;
  width: calc(100% - 4rem);
  margin: 0.5rem auto 0;
  padding: 0.65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition:
    background 0.15s ease,
    transform 0.12s ease;
  letter-spacing: 0.02em;
}

.updates-indicator:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* ── Page toolbar (view headings + action buttons) ── */
/* Mirrors .image-gallery so content aligns with the cards below */
.page-toolbar {
  max-width: 1200px;
  margin: 1.5rem auto 0.5rem;
  padding: 0 2rem;
}

.page-toolbar-title {
  font-family: "Playfair Display", serif;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0.25rem 0 0;
  color: var(--text-primary);
}

/* ── Gallery list (home view) ── */
.image-gallery {
  margin: 2rem auto;
  padding: 0 2rem;
  max-width: 1200px;
}

.gallery-loading,
.gallery-end {
  text-align: center;
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 1rem 0;
}

/* Gallery cards on the home page share the same imageCard shell but get
   a hover lift to hint they're clickable */
.gallery-card {
  cursor: pointer;
  transition:
    box-shadow 0.18s ease,
    transform 0.15s ease;
  margin-bottom: 1.25rem;
}

.gallery-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* ── Back button (gallery view) ── */
#backToHome {
  background: none;
  border: none;
  padding: 0;
  font-family: "DM Sans", sans-serif;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: block;
  margin-bottom: 0.25rem;
  transition: color 0.15s ease;
}

#backToHome:hover {
  color: var(--accent);
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

footer a:hover {
  color: var(--accent);
}

/* ── Image Cards ── */
.imageCard {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}

.imageCard:last-child {
  margin-bottom: 0;
}

.image-card-img-wrapper {
  overflow-x: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.image-card-img {
  display: block;
  height: auto;
  width: auto;
}

.image-card-body {
  padding: 1.25rem 1.5rem 1.5rem;
}

.image-card-title {
  font-family: "Playfair Display", serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.image-card-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0.25rem 0 1.25rem;
}

.image-card-delete {
  background-image: url("../assets/delete-icon.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  width: 24px;
  height: 32px;
  border: none;
  background-color: transparent;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s ease;
  margin-left: auto;
}

.image-card-delete:hover {
  opacity: 0.85;
}

/* ── Comments Section ── */
.image-card-comments {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  margin-top: 0.5rem;
}

.image-card-comments h4 {
  font-family: "DM Sans", sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 1rem;
}

.comments-signin-notice {
  font-family: "DM Sans", sans-serif;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
  margin: 0.25rem 0 0;
}

/* ── Comment List (compact + full) ── */
.image-card-comment-list {
  padding-left: 1.5rem;
  border-left: 1px solid var(--border);
}

/* Individual comment */
.image-comment {
  position: relative;
  padding: 0.65rem 2rem 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.image-comment:last-of-type {
  border-bottom: none;
}

.comment-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.2rem;
}

.comment-content {
  font-size: 0.875rem;
  color: var(--text-primary);
  margin: 0 0 0.2rem;
  line-height: 1.5;
}

.comment-date {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin: 0;
}

.comment-delete {
  background-image: url("../assets/delete-icon.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  width: 18px;
  height: 18px;
  border: none;
  background-color: transparent;
  cursor: pointer;
  opacity: 0;
  position: absolute;
  top: 0.7rem;
  right: 0;
  transition: opacity 0.15s ease;
}

/* Only show comment delete on hover when it's not hidden */
.image-comment:hover .comment-delete:not(.is-hidden) {
  opacity: 0.4;
}

.image-comment:hover .comment-delete:not(.is-hidden):hover {
  opacity: 0.85;
}

/* "More" button — compact view */
.comments-more {
  display: inline-block;
  margin-top: 0.75rem;
  background: none;
  border: none;
  padding: 0;
  font-family: "DM Sans", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.comments-more:hover {
  color: var(--accent-hover);
}

/* ── Full (paginated) comment view ── */
.comments-full-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.comments-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.comments-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    color 0.15s ease;
}

.comments-close:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.comments-full-list {
  min-height: 2rem;
}

.comments-full-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.comments-prev,
.comments-next {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.9rem;
  font-family: "DM Sans", sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.comments-prev:hover:not(:disabled),
.comments-next:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.comments-prev:disabled,
.comments-next:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Global loading spinner ── */
#globalSpinner {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

#globalSpinner.active {
  display: flex;
}

.spinner-inner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Utility ── */
.is-hidden {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 576px) {
  header {
    padding: 0 1rem;
  }

  header .row {
    min-height: auto;
    padding: 0.75rem 0;
    gap: 0.5rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  .header-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Auth form goes full width on mobile */
  .auth-form {
    position: static;
    flex-wrap: wrap;
    width: 100%;
    min-width: unset;
    margin-top: 0.5rem;
  }

  .auth-form input {
    flex-basis: 100%;
  }

  .auth-form button[type="submit"] {
    flex-basis: 100%;
  }

  .image-gallery {
    margin: 1rem auto;
    padding: 0 1rem;
  }

  .updates-indicator {
    width: calc(100% - 2rem);
    margin: 0 1rem 1rem;
  }

  .imageCard {
    margin-bottom: 1.25rem;
    border-radius: calc(var(--radius) / 2);
  }

  .image-card-body {
    padding: 1rem;
  }

  .image-card-title {
    font-size: 1.05rem;
  }

  .image-card-comment-list {
    padding-left: 0;
    padding-top: 1.25rem;
    border-left: none;
    border-top: 1px solid var(--border);
    margin-top: 1.25rem;
  }

  .comments-full-controls {
    flex-direction: column;
  }

  .comments-prev,
  .comments-next {
    width: 100%;
    text-align: center;
  }

  footer {
    padding: 1.25rem 1rem;
  }
}

@media (min-width: 577px) and (max-width: 768px) {
  header {
    padding: 0 1.25rem;
  }

  .image-gallery {
    padding: 0 1.25rem;
  }

  .image-card-body {
    padding: 1rem 1.25rem 1.25rem;
  }
}
