.memory-item {
  background-color: #FFFFFF;
  border: 1px solid #BFC0B1;
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.memory-item-date {
  color: #8B8B8B;
  font-size: 12px;
  font-style: italic;
}

.memory-item-text {
  color: #525349;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  /* Match canvas background color to prevent white flash during overscroll */
  background-color: #F7F6E4;
}

canvas {
  display: block;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  /* Prevent browser zoom and scroll on canvas - allows JavaScript to handle all touch events */
  touch-action: none;
}

/* Home Button */
#home-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#home-btn:hover {
  background-color: rgba(0, 0, 0, 0.8);
  transform: scale(1.1);
}

#home-btn:active {
  transform: scale(0.95);
}

#home-icon {
  display: inline-block;
  line-height: 1;
}

/* Music Toggle Button */
#music-toggle-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#music-toggle-btn:hover {
  background-color: rgba(0, 0, 0, 0.8);
  transform: scale(1.1);
}

#music-toggle-btn:active {
  transform: scale(0.95);
}

#music-icon {
  display: inline-block;
  line-height: 1;
}

/* Year Navigation Buttons */
#year-prev-btn,
#year-next-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 24px;
  cursor: pointer;
  z-index: 999;
  display: none; /* Hidden by default, shown by JavaScript */
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#year-prev-btn {
  left: 20px;
}

#year-next-btn {
  right: 20px;
}

#year-prev-btn:hover,
#year-next-btn:hover {
  background-color: rgba(0, 0, 0, 0.8);
  transform: translateY(-50%) scale(1.1);
}

#year-prev-btn:active,
#year-next-btn:active {
  transform: translateY(-50%) scale(0.95);
}

#year-prev-btn:disabled,
#year-next-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

#year-prev-btn:disabled:hover,
#year-next-btn:disabled:hover {
  background-color: rgba(0, 0, 0, 0.6);
  transform: translateY(-50%) scale(1);
}

#year-prev-icon,
#year-next-icon {
  display: inline-block;
  line-height: 1;
}

/* Responsive buttons */
@media screen and (max-width: 600px) {
  #home-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
    top: 10px;
    left: 10px;
  }

  #music-toggle-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
    top: 10px;
    right: 10px;
  }
  
  #year-prev-btn,
  #year-next-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  #year-prev-btn {
    left: 10px;
  }
  
  #year-next-btn {
    right: 10px;
  }
}

/* Universal font family - Inter (Open Source) */
* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Modal Dialog Styles */
#entry-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  /* Prevent scrolling when touching the modal overlay */
  touch-action: none;
}

#entry-modal.show {
  display: flex;
}

/* Disable canvas interaction when modal is open */
#entry-modal.show ~ * canvas,
body:has(#entry-modal.show) canvas {
  pointer-events: none;
}

.modal-content {
  background-color: #F7F6E4;
  border-radius: 12px;
  padding: 30px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 20px;
  pointer-events: auto; /* Ensure modal content is clickable */
  position: relative;
  z-index: 1001;
  /* Prevent scrolling on modal content itself - only allow scrolling in #memories-list */
  touch-action: none;
}

#modal-title {
  margin: 0;
  color: #525349;
  font-size: 24px;
  font-weight: bold;
}

#modal-text-input {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 2px solid #BFC0B1;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  background-color: #FFFFFF;
  color: #525349;
  box-sizing: border-box;
}

#modal-text-input:focus {
  outline: none;
  border-color: #ff914d;
}

#image-upload-area {
  padding: 20px;
  background-color: #F5F4E3;
  border: 2px dashed #BFC0B1;
  border-radius: 8px;
  text-align: center;
  color: #8B8B8B;
  font-size: 14px;
}

/* Center image previews and view images */
#memory-image-preview-wrapper,
#memory-image-preview-wrapper-new,
#memory-view-image-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
}

#memory-view-image-wrapper {
  margin-top: 16px;
}

/* Memory View Section Styles */
#memory-view-title {
  margin: 0 0 4px 0; /* Small margin below title, closer to date */
  color: #525349;
  font-size: 24px;
  font-weight: 600;
}

.memory-view-date {
  font-size: 14px; /* Smaller font size */
  font-style: italic; /* Italic */
  color: #8B8B8B;
  margin: 0 0 16px 0; /* Small margin below date, more space before text */
}

.memory-view-text {
  color: #525349;
  font-size: 16px;
  line-height: 1.6;
  margin: 0;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-buttons button {
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

#modal-save-btn {
  background-color: #ff914d;
  color: #FFFFFF;
}

#modal-save-btn:hover {
  background-color: #e67d3a;
}

#modal-cancel-btn {
  background-color: #BFC0B1;
  color: #525349;
}

#modal-cancel-btn:hover {
  background-color: #A8A99A;
}

.delete-btn {
  background-color: #dc3545;
  color: #FFFFFF;
}

.delete-btn:hover {
  background-color: #c82333;
}

#memory-edit-content-btn,
#memory-close-view-btn {
  background-color: #BFC0B1;
  color: #525349;
}

#memory-edit-content-btn:hover,
#memory-close-view-btn:hover {
  background-color: #A8A99A;
}

/* Memories List Styles */
#memories-list-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#memories-list-title {
  margin: 0;
  color: #525349;
  font-size: 18px;
  font-weight: 600;
}

#memories-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 160px; /* Show approximately 3 memory items */
  overflow-y: auto;
  padding: 10px;
  background-color: #F5F4E3;
  border-radius: 8px;
  /* Smooth scrolling */
  scroll-behavior: smooth;
  /* Custom scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: #BFC0B1 #F5F4E3;
  /* Allow vertical scrolling in memories list, prevent zoom and horizontal panning */
  touch-action: pan-y;
  /* Ensure smooth scrolling works on iOS */
  -webkit-overflow-scrolling: touch;
  /* Prevent overscroll from affecting parent containers (modal, body, canvas) */
  overscroll-behavior: contain;
}

/* Webkit scrollbar styling for Chrome/Safari */
#memories-list::-webkit-scrollbar {
  width: 8px;
}

#memories-list::-webkit-scrollbar-track {
  background: #F5F4E3;
  border-radius: 4px;
}

#memories-list::-webkit-scrollbar-thumb {
  background: #BFC0B1;
  border-radius: 4px;
}

#memories-list::-webkit-scrollbar-thumb:hover {
  background: #9FA0A1;
}

.empty-memories {
  color: #8B8B8B;
  font-size: 14px;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* Memory Input Section */
#memory-input-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#memory-input-section label {
  color: #525349;
  font-size: 14px;
  font-weight: 500;
}

#memory-date-input {
  padding: 8px;
  border: 2px solid #BFC0B1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background-color: #FFFFFF;
  color: #525349;
  box-sizing: border-box;
}

#memory-date-input:focus {
  outline: none;
  border-color: #ff914d;
}

/* Responsive Design */
/* Mobile devices (phones, 600px and down) */
@media screen and (max-width: 600px) {
  .modal-content {
    padding: 20px;
    max-width: 95%;
    max-height: 95vh;
    gap: 15px;
  }
  
  #modal-title {
    font-size: 20px;
  }
  
  #memories-list-title {
    font-size: 16px;
  }
  
  .modal-buttons {
    flex-direction: column;
  }
  
  .modal-buttons button {
    width: 100%;
    padding: 12px;
  }
  
  .memory-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .memory-item-actions {
    width: 100%;
    justify-content: space-between;
  }
  
  .memory-item button {
    flex: 1;
    padding: 6px 8px;
  }
  
  #modal-text-input {
    min-height: 100px;
    font-size: 14px;
  }
  
  #memory-input-section label {
    font-size: 13px;
  }
}

/* Tablet devices (600px to 900px) */
@media screen and (min-width: 601px) and (max-width: 900px) {
  .modal-content {
    padding: 25px;
    max-width: 85%;
  }
  
  #modal-title {
    font-size: 22px;
  }
  
  .modal-buttons button {
    padding: 10px 20px;
  }
}

/* Small desktop (900px to 1200px) */
@media screen and (min-width: 901px) and (max-width: 1200px) {
  .modal-content {
    max-width: 70%;
  }
}

/* Ensure canvas is responsive */
canvas {
  max-width: 100%;
  height: auto;
}