/* Memories Page Styles */

.memories-container {
  max-width: 720px;
  margin: 0 auto;
}

/* Memories Index Page - Book Layout */
.memories-index-page,
.memories-show-page,
.memories-thank-you-page,
.memories-new-page {
  min-height: 100vh;
  background-color: #FFFFFF;
  padding: 0 var(--space-xl);
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

.memories-new-page .notebook-page {
  width: 100%;
  max-width: 720px;
  min-height: 600px;
  background-color: var(--paper-aged);
  border-radius: 4px;
  background-image:
    linear-gradient(to left, rgba(0, 0, 0, .05) 0%, rgba(0, 0, 0, 0) 5%),
    repeating-linear-gradient(transparent,
      transparent 31px,
      rgba(200, 184, 154, 0.1) 31px,
      rgba(200, 184, 154, 0.1) 32px);
  padding: var(--space-xl);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  max-height: 80vh;
}

.memories-new-page .memories-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

turbo-frame#memory_content {
  display: block;
  width: 100%;
}

.memories-book-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  perspective: 2000px;
}

.memories-book {
  width: 100%;
  position: relative;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  min-height: 600px;
}

.memories-book__page {
  position: absolute;
  top: 0;
  height: 100%;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transition: transform 1.4s;
  user-select: none;
}

.memories-book__page--left {
  width: 25%;
  left: 0;
  transform-origin: 100% 0;
  transform: rotateY(0deg);
  pointer-events: all;
  z-index: 1;
}

.memories-book__page--right {
  width: 75%;
  right: 0;
  transform-origin: 0 0;
  transform: rotateY(0deg);
  pointer-events: all;
  z-index: 2;
}

/* Hover effect for right page (odd) - similar to reference */
.memories-book__page--right:hover:not(.flipped) {
  transform: rotateY(-10deg);
}

.memories-book__page--right:hover:not(.flipped) .notebook-page--right::before {
  background: rgba(0, 0, 0, 0.03);
}

/* When flipped, right page flips to show back (becomes left) */
.memories-book__page--right.flipped {
  transform: translateX(calc(2 * var(--space-xl) + max(0px, (100% - (720px + 2 * var(--space-xl))) / 2))) rotateY(-180deg) scaleX(0.3333);
  pointer-events: none;
  z-index: 1;
}

.memories-book__page--right.flipped .notebook-page--right {
  backface-visibility: visible;
}

.memories-book__page--right.flipped .notebook-page--right::before {
  background: rgba(0, 0, 0, 0.2);
  z-index: 3;
}

.memories-book__page--right.flipped .notebook-page--right::before {
  background: rgba(0, 0, 0, 0.2);
}

/* Left page stays visible, can be clicked to go back */
.memories-book__page--left:hover:not(.flipped) {
  transform: rotateY(10deg);
}

.memories-book__page--left:hover:not(.flipped) .notebook-page--left::before {
  background: rgba(0, 0, 0, 0.03);
}

.notebook-page--left {
  width: 100%;
  height: 100%;
  min-height: 600px;
  background-color: var(--paper-aged);
  border-radius: 4px 0 0 4px;
  background-image:
    linear-gradient(to left, rgba(0, 0, 0, .12) 0%, rgba(0, 0, 0, 0) 10%),
    repeating-linear-gradient(transparent,
      transparent 31px,
      rgba(200, 184, 154, 0.1) 31px,
      rgba(200, 184, 154, 0.1) 32px);
  position: relative;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.memory-navigation__prev-area:hover .notebook-page--left {
  opacity: 0.85;
}

.memory-navigation__next-area {
  position: relative;
}

.memory-navigation__content {
  position: relative;
  z-index: 1;
}

.notebook-page--left::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.2);
  pointer-events: none;
  border-radius: 4px 0 0 4px;
}

.notebook-page--right {
  width: 100%;
  height: 100%;
  min-height: 600px;
  border-radius: 0 4px 4px 0;
  background-image:
    linear-gradient(to right, rgba(0, 0, 0, .15) 0%, rgba(0, 0, 0, 0) 10%);
  position: relative;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

/* Next page container (positioned behind the flipping page) */
/* Fullscreen Image Modal */
.image-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
}

.image-fullscreen--active {
  opacity: 1;
  visibility: visible;
}

.memories-book__page--next {
  position: absolute;
  top: 0;
  right: 0;
  width: 75%;
  height: 100%;
  z-index: 0;
  display: none;
  pointer-events: none;
}

.notebook-page--next-back {
  width: 100%;
  height: 100%;
  min-height: 600px;
  background-color: var(--paper-aged);
  border-radius: 0 4px 4px 0;
  background-image:
    linear-gradient(to left, rgba(0, 0, 0, .15) 0%, rgba(0, 0, 0, 0) 10%);
  overflow: auto;
  padding: var(--space-xl);
  box-sizing: border-box;
}

/* Show next page when right page starts flipping */
.memories-book__page--right.flipped~.memories-book__page--next {
  display: block;
  z-index: 1;
  pointer-events: auto;
}

/* Previous page container (positioned behind the flipping left page) */
.memories-book__page--prev {
  position: absolute;
  top: 0;
  right: 0;
  width: 75%;
  height: 100%;
  z-index: 0;
  display: none;
  pointer-events: none;
}

/* Show previous page when left page starts flipping backward */
.memories-book__page--left.flipped-backward~.memories-book__page--prev {
  display: block;
  z-index: 1;
  pointer-events: auto;
}

/* When flipped backward, left page flips to reveal previous page (rotates 180deg to the right) */
.memories-book__page--left.flipped-backward {
  transform: translateX(40px) rotateY(180deg) scaleX(3);
  pointer-events: none;
  z-index: 1;
}

.memories-book__page--left.flipped-backward .notebook-page--left {
  backface-visibility: visible;
}

.memories-book__page--left.flipped-backward .notebook-page--left::before {
  background: rgba(0, 0, 0, 0.2);
  z-index: 3;
}

/* Hide current right page when going backward (it will be replaced by previous page) */
.memories-book__page--left.flipped-backward~.memories-book__page--right {
  z-index: 0;
  pointer-events: none;
}

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  color: var(--ink-soft);
  font-size: var(--text-md);
}

.notebook-page--right::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.7s;
  z-index: 2;
  pointer-events: none;
  border-radius: 0 4px 4px 0;
}

.notebook-page--left::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.2);
  transition: background 0.7s;
  z-index: 2;
  pointer-events: none;
  border-radius: 4px 0 0 4px;
}

/* Book page for animations */
.book-page {
  transform-style: preserve-3d;
  backface-visibility: hidden;
  position: relative;
}

/* Thank You Page */
.thank-you-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  text-align: center;
  padding: var(--space-xl);
}

.thank-you-page__icon {
  margin-bottom: var(--space-lg);
  opacity: 0.6;
}

.thank-you-page__icon svg {
  width: 64px;
  height: 64px;
  stroke: var(--ink-soft);
  fill: none;
  stroke-width: 1.5;
}

.thank-you-page__title {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: 32px;
  color: var(--ink-dark);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.thank-you-page__message {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: var(--text-lg);
  color: var(--ink-soft);
  margin-bottom: var(--space-xl);
  line-height: 1.8;
  font-style: italic;
}

.thank-you-page__actions {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  justify-content: center;
}

.thank-you-page__actions .btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: var(--text-md);
}

.thank-you-page__actions .btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* Table of Contents */
.table-of-contents__header {
  margin-bottom: var(--space-xl);
  text-align: left;
}

.table-of-contents__title {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: 28px;
  color: var(--ink-dark);
  margin-bottom: var(--space-lg);
  font-weight: 600;
}

.table-of-contents__date {
  display: flex;
  justify-content: center;
}

.table-of-contents__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.table-of-contents__item {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s ease;
  line-height: 1.6;
}

.table-of-contents__item:hover {
  opacity: 0.7;
}

.table-of-contents__item-number {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: var(--text-sm);
  color: var(--ink-soft);
  font-weight: 400;
  min-width: 24px;
  flex-shrink: 0;
  text-align: right;
}

.table-of-contents__item-title {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: var(--text-md);
  color: var(--ink-dark);
  font-weight: 400;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-of-contents__item-dots {
  flex: 1;
  min-width: 20px;
  height: 1px;
  border-bottom: 1px dotted rgba(200, 184, 154, 0.4);
  margin: 0 var(--space-xs);
  flex-shrink: 0;
}

.table-of-contents__item-date {
  font-family: 'EB Garamond', 'Libre Baskerville', serif;
  font-size: var(--text-xs);
  color: var(--ink-soft);
  font-variant: small-caps;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  white-space: nowrap;
}

.memories-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
}

.memories-header__title {
  font-family: 'EB Garamond', serif;
  font-size: var(--text-xl);
  color: var(--ui-text);
  margin: 0;
}

.memory-form {
  margin-top: var(--space-lg);
}

.memory-form__errors {
  background-color: rgba(224, 90, 90, 0.1);
  border: 1px solid var(--ui-danger);
  border-radius: 4px;
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  color: var(--ui-danger);
}

.memory-form__errors h3 {
  font-size: var(--text-md);
  margin-bottom: var(--space-sm);
}

.memory-form__errors ul {
  margin: 0;
  padding-left: var(--space-lg);
}

.memory-form__field {
  margin-bottom: var(--space-lg);
}

.memory-form__section-title {
  font-family: 'EB Garamond', serif;
  font-size: var(--text-lg);
  color: var(--ink-dark);
  margin-bottom: var(--space-md);
}

.memory-form__actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  justify-content: flex-end;
}

.external-link-form {
  margin-bottom: var(--space-md);
  padding: var(--space-md);
  background-color: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}

.external-link-form__fields {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
  flex-wrap: wrap;
}

.external-link-form__fields .input-notebook-style {
  flex: 1;
  min-width: 200px;
}

.memory-title {
  font-family: 'EB Garamond', serif;
  font-size: 24px;
  color: var(--ink-dark);
  margin-bottom: var(--space-lg);
  font-weight: 600;
}

.memory-content {
  margin-bottom: var(--space-xl);
}

.memory-content__text {
  font-family: 'EB Garamond', serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink-dark);
  white-space: pre-wrap;
}

.memory-files {
  margin-bottom: var(--space-xl);
}

.memory-links {
  margin-bottom: var(--space-xl);
}

.memory-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid rgba(200, 184, 154, 0.3);
}

.memories-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.memory-card {
  background-color: var(--ui-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: var(--space-lg);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.memory-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.memory-card__date {
  font-size: var(--text-sm);
  color: var(--ui-muted);
  margin-bottom: var(--space-sm);
}

.memory-card__title {
  font-family: 'EB Garamond', serif;
  font-size: var(--text-lg);
  color: var(--ui-text);
  margin-bottom: var(--space-md);
}

.memory-card__link {
  color: var(--ui-text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.memory-card__link:hover {
  color: var(--ui-accent);
}

.memory-card__excerpt {
  font-size: var(--text-md);
  color: var(--ui-muted);
  line-height: 1.6;
  margin-bottom: var(--space-md);
}

.memory-card__meta {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.memory-card__meta-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-sm);
  color: var(--ui-muted);
}

.memory-card__meta-item svg {
  width: 16px;
  height: 16px;
}

.memory-card__actions {
  display: flex;
  gap: var(--space-sm);
}

.media-block__file {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
}

.media-block__file-icon {
  width: 48px;
  height: 48px;
  color: var(--ink-dark);
}

.media-block__file-icon svg {
  width: 100%;
  height: 100%;
}

.media-block__file-name {
  font-family: 'EB Garamond', serif;
  font-size: var(--text-md);
  color: var(--ink-dark);
}

/* Tablet and below - Hide left page */
@media (max-width: 1024px) {

  .memories-index-page,
  .memories-show-page,
  .memories-thank-you-page {
    padding: var(--space-lg);
  }

  .memories-book-container {
    max-width: 100%;
  }

  .memories-book__page--left {
    display: none;
    /* Hide left page on tablet and below */
  }

  .memories-book__page--right {
    width: 100%;
  }

  .notebook-page--left {
    display: none;
  }

  .notebook-page--right {
    border-radius: 4px;
    min-height: 100vh;
  }

  .table-of-contents__title {
    font-size: 26px;
  }
}

/* Tablet portrait */
@media (max-width: 768px) {
  .memories-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .memory-form__actions {
    flex-direction: column;
  }

  .memory-form__actions .btn {
    width: 100%;
  }

  .memory-actions {
    flex-direction: column;
  }

  .memory-actions .btn {
    width: 100%;
  }

  .external-link-form__fields {
    flex-direction: column;
  }

  .external-link-form__fields .input-notebook-style {
    width: 100%;
  }

  /* Memories Index/Show/Thank You - Tablet */
  .memories-index-page,
  .memories-show-page,
  .memories-thank-you-page,
  .memories-new-page {
    padding: var(--space-md);
    align-items: flex-start;
  }

  .memories-new-page .notebook-page {
    min-height: 100vh;
    box-sizing: border-box;
  }

  .memories-book-container {
    perspective: 1500px;
  }

  .memories-book {
    min-height: 100vh;
  }

  .memories-book__page--left {
    display: none;
    /* Already hidden at 1024px breakpoint */
  }

  .memories-book__page--right {
    width: 100%;
    right: 0;
    left: auto;
  }

  .notebook-page--left {
    display: none;
  }

  .notebook-page--right {
    border-radius: 4px;
    min-height: 100vh;
    box-sizing: border-box;
  }

  .table-of-contents__title {
    font-size: 24px;
    margin-bottom: var(--space-md);
  }

  .table-of-contents__header {
    margin-bottom: var(--space-lg);
  }

  .table-of-contents__item {
    gap: var(--space-xs);
    padding: var(--space-xs) 0;
  }

  .table-of-contents__item-number {
    min-width: 20px;
    font-size: var(--text-xs);
  }

  .table-of-contents__item-title {
    font-size: var(--text-sm);
  }

  .table-of-contents__item-date {
    font-size: 10px;
  }
}

/* Mobile */
@media (max-width: 480px) {

  /* Memories Index/Show/Thank You - Mobile */
  .memories-index-page,
  .memories-show-page,
  .memories-thank-you-page,
  .memories-new-page {
    padding: 0;
    margin: 0;
  }

  .memories-book-container {
    perspective: 1000px;
  }

  .memories-book {
    min-height: 100vh;
  }

  .memories-book__page--left {
    display: none;
    /* Hide left page on mobile */
  }

  .memories-book__page--right {
    width: 100%;
    right: 0;
    left: auto;
    position: relative;
    /* Change to relative on mobile for normal flow */
  }

  .notebook-page--left {
    display: none;
  }

  .notebook-page--right {
    border-radius: 4px;
    min-height: 100vh;
    padding: var(--space-md);
    box-sizing: border-box;
  }

  .table-of-contents__title {
    font-size: 22px;
    margin-bottom: var(--space-md);
  }

  .table-of-contents__header {
    margin-bottom: var(--space-md);
  }

  .table-of-contents__list {
    gap: var(--space-xs);
  }

  .table-of-contents__item {
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-sm);
    align-items: flex-start;
  }

  .table-of-contents__item-number {
    min-width: 20px;
    font-size: var(--text-xs);
    margin-top: 2px;
  }

  .table-of-contents__item-title {
    font-size: var(--text-sm);
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    flex: 1 1 100%;
    margin-bottom: var(--space-xs);
  }

  .table-of-contents__item-dots {
    display: none;
  }

  .table-of-contents__item-date {
    width: 100%;
    margin-left: 0;
    font-size: 10px;
    white-space: normal;
  }

  .thank-you-page {
    min-height: 100vh;
    padding: var(--space-lg);
    box-sizing: border-box;
  }

  .thank-you-page__title {
    font-size: 24px;
  }

  .thank-you-page__message {
    font-size: var(--text-md);
  }

  .thank-you-page__actions {
    flex-direction: column;
    width: 100%;
  }

  .thank-you-page__actions .btn {
    width: 100%;
    justify-content: center;
    box-sizing: border-box;
  }

  .memories-new-page .notebook-page {
    min-height: 100vh;
    padding: var(--space-md);
    box-sizing: border-box;
    border-radius: 0;
  }
}

/* Small mobile */
@media (max-width: 360px) {

  .memories-index-page,
  .memories-show-page,
  .memories-thank-you-page,
  .memories-new-page {
    padding: var(--space-xs);
  }

  .notebook-page--right {
    padding: var(--space-sm);
  }

  .table-of-contents__title {
    font-size: 20px;
  }

  .table-of-contents__item-title {
    font-size: var(--text-xs);
  }
}

/* Memory Images Grid */
.memory-images-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

@media (min-width: 768px) {
  .memory-images-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.memory-images-grid__item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background-color: var(--ui-surface);
  border: 1px solid rgba(200, 184, 154, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.memory-images-grid__item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.memory-images-grid__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Book Navigation (Left Spine) */
.book-navigation {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  align-items: center;
  width: 100%;
  z-index: 10;
}

.book-navigation__link {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--ink-light);
  transition: color 0.2s ease, transform 0.2s ease;
  opacity: 0.8;
}

.book-navigation__link:hover {
  color: var(--ink-dark);
  opacity: 1;
}

.book-navigation__icon {
  width: 28px;
  height: 28px;
  margin-bottom: var(--space-xs);
}

.book-navigation__icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 2.5;
}

.book-navigation__label {
  font-family: var(--font-handwriting);
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  position: relative;
  padding-bottom: 2px;
}

/* Handwritten Underline Effect */
.book-navigation__label::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0.15em;
  background-color: var(--ink-dark);
  border-radius: 50% 50% 50% 50% / 10% 20% 40% 10%;
  transform: rotate(-1deg) scaleX(0);
  transform-origin: bottom right;
  transition: transform 0.3s ease-out;
  opacity: 0.8;
}

.book-navigation__link:hover .book-navigation__label::after {
  transform: rotate(-1.5deg) scaleX(1);
  transform-origin: bottom left;
}

@media (max-width: 768px) {
  .book-navigation {
    flex-direction: row;
    justify-content: space-evenly;
    bottom: var(--space-md);
    top: auto;
    left: 0;
    transform: none;
    padding: 0 var(--space-md);
  }

  .notebook-page--left {
    display: block !important;
    /* Ensure it's visible on mobile if we hide it/collapse it elsewhere */
  }
}

/* Mobile Navigation (Top Right) */
.book-navigation--mobile {
  display: none;
}

@media (max-width: 1024px) {
  .book-navigation--mobile {
    display: flex;
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    flex-direction: row;
    gap: var(--space-md);
    z-index: 20;
  }

  .book-navigation--mobile .book-navigation__label {
    display: none;
    /* Hide labels on mobile to save space, show only icons if preferred, or keep small */
  }

  .book-navigation--mobile .book-navigation__icon {
    margin-bottom: 0;
    width: 24px;
    height: 24px;
  }
}