* { box-sizing: border-box; }

:root {
  --bg: #e5e5f8;
  --text: #3b2550;
  --primary: #ff8fc7;
  --secondary: #a18cd1;
  --accent: #6fa8ff;
  --gold: #debb68;
  --panel: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent));
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 0;
}

button, input, textarea, select { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 90px;
  padding: 10px 20px;
  margin: 10px;
  border-radius: 25px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.left, .right, .center { display: flex; align-items: center; }
.right { gap: 12px; }
.center { justify-content: center; gap: 10px; }
.logo { width: 75px; height: 75px; object-fit: cover; border-radius: 20px; }
.golden { font-family: 'Playfair Display', serif; font-size: 36px; color: white; font-weight: 600; }
.frame { font-family: 'Playfair Display', serif; font-size: 42px; color: var(--gold); font-weight: 700; }

.admin-btn, .action-btn, .fab {
  width: 76px;
  height: 76px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
  font-weight: 700;
}

.small-top-btn, .inline-action {
  min-height: 38px;
  padding: 8px 12px;
  border: none;
  border-radius: 14px;
  background: rgba(255,255,255,0.28);
  color: white;
  cursor: pointer;
  font-weight: 700;
}
.user-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 210px;
  min-height: 50px;
  padding: 0 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.42);
  color: white;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.fab span, .action-btn span {
  font-size: 12px;
  line-height: 1;
}

.icon-img { width: 100%; height: 100%; object-fit: contain; display: block; }

.latest-section { margin: 10px 130px 0 30px; }
.latest-section h2 { margin: 0 0 10px; color: #6a1b9a; }
.latest-strip { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.latest-strip img { width: 120px; height: 88px; object-fit: cover; border-radius: 14px; cursor: pointer; }

#albums {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 25px;
  padding: 30px 130px 30px 30px;
}

.album-card {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 25px;
  overflow: hidden;
  cursor: pointer;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.album-card:hover { transform: translateY(-5px) scale(1.01); }
.album-card > img { width: 100%; height: 100%; object-fit: cover; display: block; }

.album-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: calc(100% - 70px);
}
.album-badges span {
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.74);
  color: #4b2762;
  font-size: 11px;
  font-weight: 700;
}

.album-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: var(--panel);
}
.album-title { max-width: 92%; overflow-wrap: anywhere; text-align: center; font-size: 20px; color: rgb(66, 6, 101); font-weight: 700; }

.album-admin-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(10px);
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
}

.action-rail {
  position: fixed;
  top: 120px;
  right: 30px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-rail .fab,
.action-rail .action-btn {
  width: 92px;
  min-height: 88px;
  padding: 8px 6px;
  border-radius: 18px;
  overflow: visible;
  background: rgba(255,255,255,0.52);
  box-shadow: 0 8px 22px rgba(0,0,0,0.08);
}
.action-rail .icon-img {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}
.action-rail .fab span,
.action-rail .action-btn span {
  display: block;
  max-width: 100%;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.1;
  overflow-wrap: anywhere;
  text-align: center;
}

.album-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 10px;
}
.album-page-title { margin: 0; font-size: 28px; color: #6a1b9a; }

.gallery {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding: 40px 130px 40px 40px;
}

.photo-card {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  background: rgba(255,255,255,0.35);
  box-shadow: 0 8px 22px rgba(0,0,0,0.08);
}
.photo-frame { width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 20px 20px 0 0; display: flex; align-items: center; justify-content: center; }
.photo { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; transition: transform 0.25s ease; }
.photo-info { display: grid; gap: 8px; padding: 10px; min-height: 50px; }
.photo-info p { margin: 0; font-size: 13px; overflow-wrap: anywhere; }
.photo-caption:empty { display: none; }
.photo-rating {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rating-average {
  color: #f4a100;
  font-size: 18px;
  letter-spacing: 1px;
  white-space: nowrap;
}
.rating-count {
  color: #5b436d;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}
.rating-picker {
  display: flex;
  gap: 4px;
}
.rating-picker button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.65);
  color: #9a7a9f;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.rating-picker button.active,
.rating-picker button:hover {
  color: #f4a100;
  background: white;
}
.photo-comments {
  display: grid;
  gap: 6px;
}
.photo-comment {
  display: grid;
  gap: 2px;
  padding: 7px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.52);
}
.photo-comment strong {
  color: #6a1b9a;
  font-size: 12px;
}
.photo-comment span {
  color: #3b2550;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.comment-actions button {
  min-height: 28px;
  padding: 4px 8px;
  border: none;
  border-radius: 9px;
  background: rgba(106, 27, 154, 0.12);
  color: #6a1b9a;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.comment-actions button:hover {
  background: rgba(106, 27, 154, 0.22);
}
.comment-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}
.comment-form input {
  min-height: 38px;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 12px;
}
.comment-form button {
  min-width: 44px;
  border: none;
  border-radius: 12px;
  background: #6a1b9a;
  color: white;
  cursor: pointer;
  font-weight: 700;
}
.photo-admin-btn { top: 8px; right: 8px; }
.empty-state { grid-column: 1 / -1; text-align: center; color: #6a1b9a; }

.lockscreen, .modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.6);
}
.modal { display: none; }
.modal.active { display: flex; }
.lock-box, .modal-box {
  position: relative;
  width: min(380px, 100%);
  padding: 24px 25px 25px;
  border-radius: 25px;
  background: var(--panel);
  color: white;
  text-align: center;
  box-shadow: 0 15px 40px rgba(0,0,0,0.3);
}
.wide-box { width: min(640px, 100%); }
.modal-header { position: relative; display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.modal-header h2, .modal-box h2, .lock-box h2 { margin: 0 34px 18px; font-size: 26px; font-weight: 600; }
.modal-header h2 { margin-bottom: 0; }
.modal-copy { margin: 8px 0 18px; font-size: 14px; opacity: 0.9; }
.close, #closeLock, #closeUpload, #closeVisitor {
  position: absolute;
  top: 12px;
  right: 15px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: none;
  color: white;
  cursor: pointer;
  font-size: 22px;
}

input, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: none;
  border-radius: 18px;
  outline: none;
  background: rgba(255,255,255,0.92);
  color: #333;
}
textarea { resize: vertical; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
#codeDisplay { min-height: 40px; margin: 15px 0; font-size: 30px; letter-spacing: 10px; }
.key, #validate {
  min-height: 60px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
  font-size: 20px;
}

#createAlbumBtn, #renameBtn, #deleteBtn, .primary-btn, #cancelDelete, #confirmDelete, #cancelPhotoDelete, #confirmPhotoDelete,
.move-actions button {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: none;
  border-radius: 14px;
  color: white;
  cursor: pointer;
  font-weight: 700;
}
#createAlbumBtn, #renameBtn, .primary-btn, #cancelDelete, #cancelPhotoDelete, .move-actions button {
  margin-top: 10px;
  background: rgba(255,255,255,0.3);
}
#deleteBtn, #confirmDelete, #confirmPhotoDelete, .danger { margin-top: 10px; background: rgba(255, 80, 80, 0.78); }
.confirm-actions, .move-actions { display: flex; gap: 10px; margin-top: 10px; }
.status-message, #status, #albumStatus, #adminStatus, #visitorStatus, #profileStatus, #uploadStatus, #photoDeleteStatus { margin-top: 10px; min-height: 20px; font-size: 14px; }
.status-message.success { color: #eaffea; }
.status-message.error { color: #ffe0e0; }

.upload-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.file-btn { width: 100%; padding: 12px 14px; border: none; border-radius: 14px; background: rgba(255,255,255,0.25); color: white; cursor: pointer; }
.upload-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.upload-preview img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }
.upload-progress { width: 100%; height: 14px; margin: 8px 0; }

.history-list { max-height: 420px; overflow: auto; text-align: left; }
.history-list div { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.25); }
.history-list span { display: block; font-size: 12px; opacity: 0.8; }
.trash-row button {
  margin-top: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.3);
  color: white;
  cursor: pointer;
}

.viewer-open { overflow: hidden; }
.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 88px 18px 76px;
  background: rgba(15, 9, 24, 0.94);
}
.photo-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; box-shadow: 0 18px 48px rgba(0,0,0,0.45); }
.viewer-close, .viewer-download, .viewer-slide {
  position: fixed;
  top: 18px;
  z-index: 2001;
  min-height: 48px;
  padding: 10px 18px;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
.viewer-close { right: 18px; }
.viewer-download { left: 18px; }
.viewer-slide { left: 150px; }
#viewerCaption { position: fixed; left: 18px; right: 18px; bottom: 18px; margin: 0; color: white; text-align: center; font-weight: 600; }

.fade-in { animation: fadeIn 0.25s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
  #albums, .gallery { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  body { padding-bottom: 96px; }
  .topbar { height: 68px; padding: 8px 12px; border-radius: 20px; }
  .logo, .admin-btn { width: 52px; height: 52px; }
  .golden { font-size: 22px; }
  .frame { font-size: 25px; }
  .user-badge { display: none; }
  .small-top-btn { display: none; }
  .latest-section { margin: 14px 12px; }
  #albums, .gallery { grid-template-columns: 1fr; justify-items: center; padding: 16px; gap: 18px; }
  .album-card, .photo-card { width: min(100%, 390px); }
  .action-rail {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(229,229,248,0.94);
    backdrop-filter: blur(12px);
  }
  .action-rail .action-btn, .action-rail .fab { width: 72px; min-height: 72px; border-radius: 18px; background: rgba(255,255,255,0.55); box-shadow: none; }
  .action-rail .icon-img { width: 32px; height: 32px; flex-basis: 32px; }
  .action-rail .fab span, .action-rail .action-btn span { font-size: 10px; }
  .album-admin-btn { width: 48px; height: 48px; }
  .modal, .lockscreen { align-items: flex-end; }
  .modal-box, .lock-box { width: 100%; max-width: 440px; border-radius: 24px 24px 18px 18px; }
  .confirm-actions, .move-actions, .upload-choices { flex-direction: column; display: flex; }
  .upload-preview { grid-template-columns: repeat(2, 1fr); }
  .photo-viewer { padding: 132px 10px calc(50px + env(safe-area-inset-bottom)); }
  .viewer-close, .viewer-download, .viewer-slide { top: calc(10px + env(safe-area-inset-top)); min-width: 0; }
  .viewer-download { left: 10px; right: auto; }
  .viewer-slide { left: 50%; transform: translateX(-50%); }
  .viewer-close { right: 10px; }
}
