:root {
  --color-bg: #e3f0ff;
  --color-text: #2a3a4b;
  --color-accent: #7ecbff;
  --color-accent-light: #bfe4ff;
  --color-border: #6bb6e6;
  --color-white: #fff;
  --color-gray: #7a8fa6;
  --color-gray-light: #f0f6fa;

  --color-mei-primary: #a2c9ff;
  --color-mei-secondary: #d1e6ff;
  --color-zobby-primary: #7ecbff;
  --color-zobby-secondary: #bfe4ff;
  --color-mei-glow: rgba(162, 201, 255, 0.5);
  --color-zobby-glow: rgba(126, 203, 255, 0.5);
  --color-mei-glow-hover: rgba(162, 201, 255, 0.7);
  --color-zobby-glow-hover: rgba(126, 203, 255, 0.7);
  --spacing: 16px;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  --transition: 0.3s ease;
}

body {
  margin: 0;
  font-family: sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem var(--spacing-md, 1rem);
  margin-bottom: var(--spacing-lg, 1.5rem);
  background: rgba(255, 255, 255, 0.8);
  border-radius: var(--radius-lg, 1.5rem);
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.1));
  border: 2px solid var(--color-border, #000);
  position: sticky;
  top: var(--spacing-md, 1rem);
  z-index: 100;
  backdrop-filter: blur(5px);
}

header h1 {
  color: var(--color-border, #000);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  padding: 0;
  text-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.1));
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: var(--spacing-md, 1rem);
}

.btn,
#uploadImageBtn {
  border: none;
  border-radius: var(--radius-xl, 2rem);
  padding: var(--spacing-sm, 0.5rem) var(--spacing-lg, 1.5rem);
  font-size: 1.1em;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: var(--transition, 0.3s ease);
  position: relative;
  overflow: hidden;
}

.btn {
  background: var(--color-border, #000);
  color: var(--color-white, #fff);
  box-shadow: var(--shadow-md, 0 4px 15px rgba(0, 0, 0, 0.15));
}

.btn:hover {
  background: #2563a6;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg, 0 8px 25px rgba(0, 0, 0, 0.15));
}

.btn:active {
  transform: translateY(0);
}

.modal-content {
  background: var(--color-white, #fff);
  padding: var(--spacing-md, 1rem);
  border-radius: var(--radius-lg, 1.5rem);
  max-width: 350px;
  width: 90%;
  box-shadow: var(--shadow-md, 0 4px 15px rgba(0, 0, 0, 0.15));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-md, 1rem);
}

.modal-header .close {
  font-size: 1.5em;
  cursor: pointer;
  color: var(--color-gray, #666);
  transition: color 0.2s;
}
.modal-header .close:hover {
  color: var(--color-accent, #ff69b4);
}

.modal-header h2 {
  color: var(--color-accent, #7ecbff);
}

.form-group {
  margin-bottom: var(--spacing-md, 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.form-group label {
  font-weight: bold;
  color: var(--color-border, #000);
  margin-bottom: 0.2em;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1em;
  margin-top: 0;
}

.note-error {
  color: var(--color-accent, #ff69b4);
  background: var(--color-accent-light, #ffb6c1);
  border-radius: var(--radius-md, 1rem);
  padding: 0.5em 1em;
  margin-top: 1em;
  font-size: 1em;
  text-align: center;
  min-height: 1.5em;
}

.main-header {
  background: var(--color-white);
  box-shadow: var(--shadow);
  padding: var(--spacing);
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-header h1 {
  margin: 0;
  font-size: 1.8em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing);
}

.btn-accent {
  background: var(--color-accent);
  color: white;
  padding: 0.75em 1.5em;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.1em;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 0.5em;
  transition: var(--transition);
}

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

.btn-accent i {
  font-size: 1.1em;
}

.btn-icon {
  background: transparent;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5em;
  cursor: pointer;
}

.view-filter {
  position: relative;
}

.view-filter-dropdown {
  position: absolute;
  right: 0;
  top: 110%;
  background: var(--color-white);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  display: none;
  flex-direction: column;
  min-width: 150px;
  z-index: 10;
}

.filter-option {
  padding: 0.75em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-option:hover {
  background: var(--color-bg);
}

.images-grid {
  padding: var(--spacing);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  grid-auto-rows: 8px;
  grid-gap: var(--spacing);
  align-items: start;
}

@media (max-width: 768px) {
  .images-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    padding: calc(var(--spacing) / 2);
    grid-gap: calc(var(--spacing) / 2);
  }
}

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

.image-card {
  border: 3px solid var(--color-border, #bfe4ff);
  border-radius: 1.2em;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  margin: 0;
  overflow: hidden;
  transition: border-color 0.2s;
  padding-bottom: 0.5em;
  display: block;
  width: 100%;
}

.image-card.zobby {
  border-color: #ff4d6d;
}

.image-card.mei {
  border-color: #a259ff;
}

.image-card img {
  width: 100%;
  display: block;
  border-bottom: 1px solid #eee;
}

/* grid row span helper */
.image-card {
  position: relative;
  grid-row-end: span var(--h, 1);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-gray);
  padding: var(--spacing);
}

.empty-state i {
  font-size: 2.5em;
  margin-bottom: 0.5em;
}

/* Modal Base */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-body img {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: var(--spacing);
}

form {
  display: flex;
  flex-direction: column;
  gap: 1em;
}

.desc-container {
  position: relative;
}

#imageDescription {
  width: 100%;
  padding: 0.5em;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  resize: none;
  max-width: 100%;
  box-sizing: border-box;
}

.char-count {
  color: var(--color-accent, #7ecbff);
  align-self: flex-end;
  margin-top: 0;
  position: static;
}

.file-upload {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-upload input[type="file"] {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-preview {
  position: relative;
  text-align: center;
  color: var(--color-gray);
}

.upload-preview img {
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
}

.upload-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1em;
  color: var(--color-gray);
  z-index: 2;
  transition: background 0.2s;
}

.upload-delete:hover {
  background: var(--color-accent-light);
  color: var(--color-accent);
}

.error-msg {
  color: red;
  font-size: 0.9em;
  margin-top: -0.5em;
}

.modal.active {
  display: flex;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.upload-preview i {
  font-size: 1.2em;
}

.upload-preview span {
  font-size: 0.95em;
}

.modal-content.modal-large {
  max-width: 600px;
  min-height: 400px;
}
.modal-content.modal-large .file-upload {
  height: 220px;
}
.modal-content.modal-large .upload-preview img {
  max-height: 200px;
}

.form-group.description-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2em;
}

.image-desc {
  padding: 0.5em 1em 0.7em 1em;
  color: var(--color-gray, #7a8fa6);
  font-size: 1em;
  text-align: center;
  background: transparent;
  word-break: break-word;
}

.card-menu {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.5em;
  color: var(--color-gray, #7a8fa6);
  cursor: pointer;
  z-index: 3;
}

.card-dropdown {
  position: absolute;
  top: 36px;
  right: 10px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 0.7em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  min-width: 120px;
  padding: 0.3em 0;
  z-index: 4;
  display: none;
}
.card-dropdown.open {
  display: block;
}
.card-dropdown button {
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  padding: 0.6em 1em;
  color: var(--color-text, #2a3a4b);
  font-size: 1em;
  cursor: pointer;
  transition: background 0.15s;
}
.card-dropdown button:hover {
  background: var(--color-accent-light, #bfe4ff);
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition:
    opacity 0.5s ease,
    visibility 0.5s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--color-accent-light);
  border-top: 4px solid var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.loading-text {
  font-size: 1.2em;
  color: var(--color-text);
  text-align: center;
}

.loading-progress {
  margin-top: 15px;
  font-size: 0.9em;
  color: var(--color-gray);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 768px) {
  .loading-spinner {
    width: 50px;
    height: 50px;
    border-width: 3px;
  }

  .loading-text {
    font-size: 1.1em;
  }

  .loading-progress {
    font-size: 0.8em;
  }
}

@media (max-width: 480px) {
  .loading-spinner {
    width: 40px;
    height: 40px;
    border-width: 3px;
  }

  .loading-text {
    font-size: 1em;
  }

  .loading-progress {
    font-size: 0.75em;
  }
}

#confirmModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  display: none;
}
#confirmModal.active {
  display: flex;
}
#confirmModal .modal-content {
  background: #fff;
  border-radius: 1em;
  padding: 2em 2em 1.5em 2em;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
  text-align: center;
}
#confirmModal .modal-actions {
  margin-top: 1.2em;
  display: flex;
  gap: 1em;
  justify-content: center;
}
#confirmModal .btn {
  min-width: 80px;
}

#editDescInput {
  resize: none;
  width: 96%;
  min-width: 220px;
  max-width: 100%;
}
