:root {
  color-scheme: dark;
  --ink: #f7f4ed;
  --muted: #aaa99f;
  --olive: #b7b99f;
  --paper: #171715;
  --serif: "Playfair Display", Georgia, serif;
  --sans: "DM Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.admin-trigger {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  display: inline-flex;
  min-width: 82px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: #34372d;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.35);
  color: #fffefa;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.96;
  cursor: pointer;
  transition: background 180ms ease, opacity 180ms ease, transform 180ms ease;
  backdrop-filter: blur(8px);
}

.admin-trigger:hover,
.admin-trigger:focus-visible {
  background: #515644;
  opacity: 1;
  transform: scale(1.05);
}

main {
  min-height: 100vh;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: 54px;
  grid-auto-flow: dense;
  align-content: start;
  gap: 30px;
  min-height: 100vh;
  padding: 50px clamp(24px, 5vw, 76px) 65px;
}

.memory-card {
  position: relative;
  z-index: 0;
  min-width: 0;
  animation: card-in 320ms ease both;
  transition: z-index 200ms step-end, transform 260ms cubic-bezier(0.2, 0.75, 0.25, 1);
}

.memory-card.layout-0 {
  grid-column: span 2;
  grid-row: span 3;
}

.memory-card.layout-1 {
  grid-column: span 3;
  grid-row: span 4;
}

.memory-card.layout-2 {
  grid-column: span 1;
  grid-row: span 2;
}

.memory-card.layout-3 {
  grid-column: span 2;
  grid-row: span 4;
}

.memory-card.layout-4 {
  grid-column: span 2;
  grid-row: span 3;
}

.memory-card.layout-5 {
  grid-column: span 3;
  grid-row: span 3;
}

.memory-card.layout-6 {
  grid-column: span 1;
  grid-row: span 2;
}

.memory-card.layout-7 {
  grid-column: span 2;
  grid-row: span 4;
}

.memory-card:nth-child(4n + 1) {
  transform: rotate(-1.1deg);
}

.memory-card:nth-child(4n + 3) {
  transform: rotate(0.9deg);
}

.memory-card:hover,
.memory-card:focus-within,
.memory-card.is-active {
  z-index: 2;
  transition-delay: 0s;
  transform: rotate(0) scale(1.045);
}

.photo-frame {
  width: 100%;
  height: 100%;
  padding: 15px 15px 25px;
  background: #f2efe7;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}

.photo-button {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 1px;
  background: #292925;
  cursor: pointer;
  transition: box-shadow 220ms ease;
  -webkit-tap-highlight-color: transparent;
}

.photo-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 240ms ease, transform 450ms cubic-bezier(0.2, 0.75, 0.25, 1);
}

.tile-caption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-height: 68px;
  flex-direction: column;
  justify-content: end;
  gap: 4px;
  padding: 28px 14px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.76));
  color: #fff;
  opacity: 0;
  text-align: left;
  transform: translateY(7px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.tile-caption strong {
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile-caption time {
  color: rgba(255, 255, 255, 0.7);
  font-size: 9px;
  letter-spacing: 0.09em;
}

.memory-card:hover .photo-button,
.memory-card:focus-within .photo-button,
.memory-card.is-active .photo-button {
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.42);
}

.memory-card:hover .photo-button img,
.memory-card:focus-within .photo-button img,
.memory-card.is-active .photo-button img {
  filter: brightness(0.83);
  transform: scale(1.02);
}

.memory-card:hover .tile-caption,
.memory-card:focus-within .tile-caption,
.memory-card.is-active .tile-caption {
  opacity: 1;
  transform: translateY(0);
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.memory-card:hover .card-actions,
.memory-card:focus-within .card-actions,
.memory-card.is-active .card-actions {
  opacity: 1;
}

.card-action {
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  background: rgba(15, 15, 14, 0.72);
  color: #fff;
  font-size: 10px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.card-action:hover {
  background: rgba(15, 15, 14, 0.95);
}

.empty-state {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state span {
  display: grid;
  width: min(42vw, 240px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.17);
  font-size: 34px;
}

.admin-dialog {
  width: min(440px, calc(100% - 32px));
  max-height: min(90vh, 850px);
  padding: 36px;
  overflow: auto;
  border: 1px solid #e9e4d9;
  border-radius: 8px;
  background: #f7f4ed;
  color: #292a24;
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.5);
}

.admin-dialog::backdrop {
  background: rgba(10, 10, 9, 0.8);
  backdrop-filter: blur(4px);
}

.admin-dialog[open] {
  animation: dialog-in 180ms ease both;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 15px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #77766d;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.dialog-icon {
  margin-bottom: 13px;
  color: #b89770;
  font-size: 26px;
}

.eyebrow {
  margin: 0;
  color: #73785c;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.19em;
}

.admin-dialog h2 {
  margin: 9px 0 5px;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
}

.dialog-copy {
  margin: 0 0 24px;
  color: #89877d;
  font-size: 12px;
  line-height: 1.65;
}

.admin-dialog label:not(.upload-zone) {
  display: block;
  margin: 15px 0 7px;
  color: #555449;
  font-size: 11px;
  font-weight: 600;
}

.admin-dialog input:not([type="file"]),
.admin-dialog textarea,
.admin-dialog select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #e0dbcf;
  border-radius: 4px;
  outline: none;
  background: #fffefa;
  color: #292a24;
  font-size: 12px;
}

.admin-dialog textarea {
  min-height: 83px;
  resize: vertical;
  line-height: 1.55;
}

.admin-dialog input:focus,
.admin-dialog textarea:focus,
.admin-dialog select:focus {
  border-color: #96977d;
  box-shadow: 0 0 0 3px rgba(115, 120, 92, 0.1);
}

.button {
  display: inline-flex;
  min-height: 43px;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms ease;
}

.button-dark {
  background: #34372d;
  color: #fffefa;
}

.button-dark:hover {
  background: #4a4e3e;
}

.button-light {
  border-color: #ded9ce;
  background: transparent;
  color: #555449;
}

.button-light:hover {
  background: #f0ede5;
}

.button-full {
  width: 100%;
  margin-top: 17px;
}

.button-full span,
.editor-actions span {
  font-size: 15px;
  font-weight: 400;
}

.form-error {
  min-height: 15px;
  margin: 6px 0 0;
  color: #a6493d;
  font-size: 11px;
}

.login-hint {
  margin: 18px 0 0;
  color: #929084;
  font-size: 10px;
  text-align: center;
}

.login-hint strong {
  color: #68675c;
  font-weight: 600;
}

.upload-zone {
  position: relative;
  display: flex;
  min-height: 145px;
  align-items: center;
  justify-content: center;
  margin: 17px 0 14px;
  overflow: hidden;
  border: 1px dashed #c9c4b5;
  border-radius: 4px;
  background: #f3f0e9;
  cursor: pointer;
}

.upload-zone:hover {
  border-color: #96977d;
}

.upload-placeholder {
  display: grid;
  justify-items: center;
  gap: 6px;
  color: #68675c;
}

.upload-placeholder strong {
  font-size: 11px;
  font-weight: 600;
}

.upload-placeholder small {
  color: #929084;
  font-size: 9px;
}

.upload-icon {
  color: #73785c;
  font-size: 25px;
  line-height: 1;
}

.upload-zone img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-field {
  min-width: 0;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.logout-button {
  display: block;
  margin: 17px auto 0;
  padding: 5px;
  border: 0;
  background: transparent;
  color: #929084;
  font-size: 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  padding: 12px 17px;
  border: 1px solid #e2ddcf;
  border-radius: 4px;
  background: #fffefa;
  box-shadow: 0 7px 24px rgba(0, 0, 0, 0.2);
  color: #4e5143;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 900px) and (min-width: 601px) {
  .gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: 52px;
    gap: 23px;
    padding: 38px 28px 50px;
  }

  .memory-card.layout-1,
  .memory-card.layout-5 {
    grid-column: span 2;
  }
}

@media (max-width: 600px) {
  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 62px;
    gap: 18px;
    padding: 30px 18px 42px;
  }

  .memory-card.layout-0,
  .memory-card.layout-3,
  .memory-card.layout-4,
  .memory-card.layout-7 {
    grid-column: span 1;
    grid-row: span 3;
  }

  .memory-card.layout-1,
  .memory-card.layout-5 {
    grid-column: span 2;
    grid-row: span 3;
  }

  .memory-card.layout-2,
  .memory-card.layout-6 {
    grid-column: span 1;
    grid-row: span 2;
  }

  .photo-frame {
    padding: 11px 11px 19px;
  }

  .tile-caption {
    min-height: 58px;
    padding: 23px 10px 9px;
  }

  .tile-caption strong {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
