/* ความทรงจำ — full-screen app. Each "memory" is a book (list of cover cards); tapping one
   opens a scrollable stack of diary pages. Colors follow the active theme like todo.css. */

.memories-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 14px;
  padding: 16px 20px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
}

.memories-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.memories-list-title {
  font-size: 17px;
  font-weight: 800;
}

.memories-create-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.memories-empty {
  color: var(--sub);
  font-size: 13px;
  text-align: center;
  padding: 40px 10px;
  font-style: italic;
}

.memories-shelf {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.memories-book {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 10px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.memories-book-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  background: linear-gradient(160deg, var(--accent), var(--card-hi));
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.memories-book-cover-icon {
  font-size: 32px;
}

.memories-book-name {
  font-size: 13.5px;
  font-weight: 700;
  word-break: break-word;
}

.memories-book-meta {
  font-size: 11px;
  color: var(--sub);
}

.memories-book-del {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-circle);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Book detail: page stack ---------- */

.memories-back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 700;
  padding: 4px 0;
  cursor: pointer;
}

.memories-book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.memories-book-title {
  font-size: 18px;
  font-weight: 800;
  word-break: break-word;
}

.memories-edit-btn {
  flex-shrink: 0;
  background: var(--card-hi);
  border: none;
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.memories-book-details {
  font-size: 13px;
  color: var(--sub);
  margin-top: -8px;
}

.memories-book-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.memories-viewonly-toggle {
  background: var(--card-hi);
  border: none;
  color: var(--sub);
  border-radius: var(--radius-pill);
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.memories-viewonly-toggle.active {
  background: var(--accent);
  color: #fff;
}

.memories-add-page-btn-sm {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- Two-page spread (open-book layout) ---------- */

.memories-spread {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.memories-spread-page {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 14px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.memories-spread-page.clickable {
  cursor: pointer;
}

.memories-spread-page.empty {
  align-items: center;
  justify-content: center;
}

.memories-spread-gutter {
  flex-shrink: 0;
  width: 2px;
  background: linear-gradient(to bottom, transparent, var(--hairline) 15%, var(--hairline) 85%, transparent);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.25);
}

@keyframes memories-spread-in-fwd {
  0% {
    opacity: 0;
    transform: translateX(20px) rotateY(-8deg);
  }
  100% {
    opacity: 1;
    transform: translateX(0) rotateY(0);
  }
}

@keyframes memories-spread-in-back {
  0% {
    opacity: 0;
    transform: translateX(-20px) rotateY(8deg);
  }
  100% {
    opacity: 1;
    transform: translateX(0) rotateY(0);
  }
}

.memories-spread.dir-fwd .memories-spread-page {
  animation: memories-spread-in-fwd 0.35s ease both;
}

.memories-spread.dir-back .memories-spread-page {
  animation: memories-spread-in-back 0.35s ease both;
}

.memories-spread-pager {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.memories-spread-nav {
  background: var(--card-hi);
  border: none;
  color: var(--text);
  border-radius: var(--radius-circle);
  width: 36px;
  height: 36px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.memories-spread-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.memories-spread-pager-label {
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
}

.memories-page-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.memories-page-del {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  background: none;
  border: none;
  color: var(--sub);
  font-size: 16px;
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.memories-page-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memories-page-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.memories-page-text {
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.memories-page-impression {
  font-size: 12.5px;
  font-style: italic;
  color: var(--accent);
  word-break: break-word;
}

.memories-page-meta {
  font-size: 11px;
  color: var(--sub);
}

.memories-add-page-btn {
  align-self: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 26px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}

.memories-add-page-placeholder {
  margin-top: 0;
}

/* Book-opening entrance — perspective lives on the page container so the flip has depth. */
.memories-book-open {
  perspective: 1000px;
}

.memories-book-open > .memories-book-header {
  transform-origin: left center;
  animation: memories-book-flip 0.5s ease both;
}

@keyframes memories-book-flip {
  0% {
    opacity: 0;
    transform: rotateY(-35deg);
  }
  100% {
    opacity: 1;
    transform: rotateY(0);
  }
}

/* ---------- Create/edit/add-page forms ---------- */

.memories-form-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--duration-base) ease;
  padding: 24px;
}

.memories-form-overlay.show {
  opacity: 1;
}

.memories-form-panel {
  width: 100%;
  max-width: 360px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: default;
}

.memories-form-title {
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.memories-form-input,
.memories-form-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--card-hi);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
}

.memories-form-input::placeholder,
.memories-form-textarea::placeholder {
  color: var(--sub);
}

.memories-form-textarea {
  resize: vertical;
  min-height: 70px;
}

.memories-form-row {
  display: flex;
  gap: 10px;
}

.memories-form-row .memories-form-input {
  flex: 1;
  min-width: 0;
}

.memories-photo-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--card-hi);
  border: 1.5px dashed var(--sub);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12.5px;
  color: var(--sub);
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.memories-photo-preview {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.memories-form-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 4px;
}
