body {
  background: radial-gradient(circle at top, #fefefe, #f2ede3 65%);
}

.memorial-hero {
  border: none;
  background: linear-gradient(135deg, rgba(13, 110, 253, 0.08), rgba(255, 193, 7, 0.1));
}

.memorial-bio {
  max-width: 720px;
  font-size: 1.05rem;
}

.timeline-container {
  position: relative;
  overflow-x: auto;
  padding: 1rem 0 1.5rem;
  scroll-padding-inline: var(--timeline-edge-gap, clamp(56px, 8vw, 120px));
}

.timeline-container.timeline-full-bleed {
  --timeline-container-bleed: max(var(--bs-card-spacer-x, 1.25rem), 16px);
  margin-inline: calc(-1 * var(--timeline-container-bleed));
  padding-inline: var(--timeline-container-bleed);
  width: calc(100% + (2 * var(--timeline-container-bleed)));
}

.timeline-scroll {
  --timeline-track-position: 55%;
  position: relative;
  min-width: max(100%, var(--timeline-min-width, 760px));
  height: 560px;
  padding-inline: var(--timeline-edge-gap, clamp(56px, 8vw, 120px));
}

.timeline-track {
  position: absolute;
  top: var(--timeline-track-position);
  left: 0;
  right: 0;
  height: 3px;
  background: #cfd7ff;
}

.timeline-item,
.timeline-anchor {
  position: absolute;
  top: var(--timeline-track-position);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 200px;
}

.timeline-item {
  transform: translate(-50%, 0);
  flex-direction: column;
}

.timeline-item.timeline-lane-top {
  flex-direction: column-reverse;
  transform: translate(-50%, -100%);
}

.timeline-item.timeline-lane-bottom {
  transform: translate(-50%, 0);
}

.timeline-item.timeline-edge-left {
  transform: translate(0, 0);
  align-items: flex-start;
}

.timeline-item.timeline-edge-left.timeline-lane-top {
  transform: translate(0, -100%);
}

.timeline-item.timeline-edge-right {
  transform: translate(-100%, 0);
  align-items: flex-end;
}

.timeline-item.timeline-edge-right.timeline-lane-top {
  transform: translate(-100%, -100%);
}

.timeline-anchor {
  transform: translate(-50%, -50%);
  flex-direction: column;
}

.timeline-anchor.timeline-start {
  transform: translate(0, -50%);
  align-items: flex-start;
}

.timeline-anchor.timeline-end {
  transform: translate(-100%, -50%);
  align-items: flex-end;
}

.timeline-anchor.timeline-end .timeline-label {
  text-align: right;
}

.timeline-marker {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #0d6efd;
  position: relative;
  top: 0;
  box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.timeline-context .timeline-marker {
  background: #6c757d;
  box-shadow: 0 0 0 4px rgba(108, 117, 125, 0.12);
}

.timeline-marker-personal {
  background: #0d6efd;
  box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.timeline-marker-context {
  background: #6c757d;
  box-shadow: 0 0 0 4px rgba(108, 117, 125, 0.12);
}

.timeline-marker-life {
  background: #9b51e0;
  box-shadow: 0 0 0 4px rgba(155, 81, 224, 0.14);
}

.timeline-content {
  background: #f8faff;
  padding: 0.75rem 1rem;
  border-radius: 0.65rem;
  box-shadow: inset 0 0 0 1px rgba(13, 110, 253, 0.08);
  max-width: 260px;
  text-align: left;
}

.timeline-context .timeline-content {
  background: #f7f7f7;
  box-shadow: inset 0 0 0 1px rgba(108, 117, 125, 0.18);
  opacity: 0.92;
}

.timeline-life .timeline-content {
  background: #f8f1ff;
  box-shadow: inset 0 0 0 1px rgba(155, 81, 224, 0.16);
}

.timeline-label {
  text-align: center;
  max-width: 200px;
}

.timeline-date {
  font-weight: 600;
  color: #0d6efd;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.timeline-title {
  margin-bottom: 0.35rem;
}

.timeline-legend .timeline-marker {
  width: 14px;
  height: 14px;
  box-shadow: none;
}

.story-accordion .accordion-button {
  font-weight: 600;
}

.story-accordion .accordion-button:focus {
  box-shadow: none;
}

.story-content {
  white-space: pre-wrap;
}

.story-content ul,
.story-content ol {
  padding-left: 1.2rem;
  margin-bottom: 0.75rem;
}

.story-content strong,
.story-content b {
  font-weight: 700;
}

.story-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.story-editor {
  border: 1px solid #ced4da;
  border-radius: 0.5rem;
  padding: 0.75rem;
  min-height: 140px;
  background: #fff;
  line-height: 1.5;
}

.story-editor:focus {
  outline: 3px solid rgba(13, 110, 253, 0.15);
  border-color: #86b7fe;
}

.story-editor-textarea {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.photo-card {
  background: #fff;
  padding: 0.75rem;
  border-radius: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

.photo-card img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: contain;
  border: 4px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  background: radial-gradient(circle at 50% 50%, #f5f5f5, #ececec);
  border-radius: 0.65rem;
}

.photo-caption-form .form-control {
  font-size: 0.85rem;
}

.family-tree-list {
  --family-card-width: 240px;
  border-radius: 1.5rem;
  background: linear-gradient(135deg, #fdf4e3, #ffffff);
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(120, 87, 37, 0.14);
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
}

.family-tree-shell {
  border: 1px solid rgba(107, 82, 33, 0.16);
  border-radius: 1.25rem;
  background: #fffaf2;
  overflow: hidden;
}

.family-tree-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(107, 82, 33, 0.14);
  background: linear-gradient(90deg, rgba(255, 219, 169, 0.35), rgba(255, 245, 227, 0.65));
}

.family-tree-zoom-slider {
  width: min(36vw, 380px);
}

.family-tree-viewport {
  max-height: 70vh;
  overflow: auto;
  padding: 1.25rem;
  background: radial-gradient(circle at 20% 20%, rgba(255, 238, 208, 0.55), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(255, 232, 196, 0.4), transparent 40%),
    #fffef9;
  cursor: grab;
}

.family-tree-viewport.is-panning {
  cursor: grabbing;
}

.family-tree-zoom {
  --tree-zoom: 1;
  transform: scale(var(--tree-zoom));
  transform-origin: top center;
  display: inline-block;
}

.family-tree-root,
.family-branch-children {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.family-tree-root {
  display: flex;
  flex-wrap: wrap;
  gap: var(--branch-gap, 1.75rem);
  justify-content: center;
}

.family-branch-children {
  margin-top: 1.5rem;
  padding-left: 0;
  padding-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: var(--branch-gap, 1.5rem);
  position: relative;
  width: max-content;
}

.family-branch-children::before {
  content: "";
  position: absolute;
  top: 0.25rem;
  left: 1.25rem;
  right: 1.25rem;
  border-top: 2px solid rgba(107, 82, 33, 0.25);
}

.family-branch-item {
  list-style: none;
  position: relative;
  text-align: center;
  padding: 0 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--branch-width, auto);
}

.family-branch-item::before {
  content: "";
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 16px;
  background: rgba(107, 82, 33, 0.25);
}

.family-tree-root > .family-branch-item::before {
  display: none;
}

.family-branch-item::marker {
  content: "";
}

.family-branch-card {
  background: #fff;
  border-radius: 1.25rem;
  padding: 1.25rem 1.1rem 1.1rem;
  border: 1px solid rgba(107, 82, 33, 0.14);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: var(--family-card-width);
  max-width: var(--family-card-width);
  width: var(--family-card-width);
  flex: 0 0 var(--family-card-width);
  position: relative;
}

.family-branch-card::after {
  content: "";
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 18px;
  background: rgba(107, 82, 33, 0.25);
}

.family-branch-item:not(.has-children) > .family-branch-card::after {
  display: none;
}

.family-branch-avatar {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 104px;
  height: 104px;
  margin: 0 auto;
  border-radius: 50%;
  border: 5px solid #fff8ec;
  box-shadow: 0 10px 25px rgba(67, 44, 16, 0.2);
  overflow: hidden;
  background: linear-gradient(135deg, #ffd7a8, #ffb180);
}

.family-branch-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.family-avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 2rem;
}

.family-branch-text {
  flex: 1;
}

.family-branch-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: #3b2a13;
}

.family-branch-relation {
  color: #8c7853;
  font-size: 0.92rem;
}

.family-branch-spouse {
  margin-top: 0.35rem;
  font-size: 0.9rem;
  color: #5c4b2f;
  background: rgba(252, 239, 218, 0.8);
  border-radius: 0.65rem;
  padding: 0.4rem 0.6rem;
}

.family-branch-spouse .label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  color: #a48b63;
  margin-right: 0.35rem;
}

.family-branch-spouse .value {
  font-weight: 600;
}

.family-branch-spouse .hint {
  color: #8c7853;
  margin-left: 0.25rem;
}

.family-branch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: auto;
}

.family-node-delete {
  margin: 0;
}

.family-inline-form {
  background: #fff;
  border-radius: 0.85rem;
  border: 1px solid rgba(107, 82, 33, 0.2);
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.04);
  display: none;
}

.photo-library {
  background: #fffaf2;
  border: 1px solid rgba(107, 82, 33, 0.18);
  border-radius: 0.85rem;
  padding: 0.65rem 0.75rem;
}

.photo-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 0.5rem;
}

.photo-library-option {
  position: relative;
  border-radius: 0.65rem;
  overflow: hidden;
  border: 2px solid transparent;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.photo-library-option:hover {
  transform: translateY(-2px);
}

.photo-library-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.photo-library-option img {
  width: 100%;
  height: 86px;
  object-fit: cover;
  display: block;
}

.photo-library-option.selected {
  border-color: rgba(13, 110, 253, 0.6);
  box-shadow: 0 10px 20px rgba(13, 110, 253, 0.15);
}

.inline-edit-form {
  background: #f8faff;
  border: 1px solid rgba(13, 110, 253, 0.15);
  border-radius: 0.75rem;
  padding: 0.75rem;
}

.inline-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.library-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.12), transparent);
}

.family-photo-canvas {
  width: 100%;
  max-width: 320px;
  border-radius: 1rem;
  display: block;
  margin: 0 auto;
  box-shadow: inset 0 0 0 1px rgba(107, 82, 33, 0.1), 0 10px 25px rgba(0, 0, 0, 0.08);
}

.cropper-wrapper {
  background: #fffaf2;
  border: 1px dashed rgba(107, 82, 33, 0.25);
  border-radius: 1rem;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.family-inline-form.show {
  display: block !important;
}

.family-tree-divider {
  position: relative;
  text-align: center;
  margin: 1.5rem 0;
}

.family-tree-divider span {
  padding: 0.35rem 1rem;
  background: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c757d;
  border: 1px dashed rgba(13, 110, 253, 0.35);
}

.family-root-form {
  background: #fffaf1;
  border-radius: 1rem;
  padding: 1rem;
  border: 1px solid rgba(107, 82, 33, 0.2);
}

@media (max-width: 992px) {
  .family-tree-root {
    grid-template-columns: 1fr;
  }

  .family-branch-children {
    grid-template-columns: 1fr;
    padding-left: 1rem;
  }
}

@media (max-width: 576px) {
  body {
    padding: 0 0.5rem;
  }

  .memorial-hero .display-5 {
    font-size: 1.9rem;
  }

  .timeline-scroll {
    height: 480px;
    min-width: max(100%, var(--timeline-min-width, 620px));
  }

  .timeline-item,
  .timeline-anchor {
    min-width: 180px;
  }

  .timeline-content {
    max-width: 230px;
  }

  .family-tree-list {
    --family-card-width: 200px;
    padding: 1.25rem 1rem;
    width: max-content;
    min-width: 100%;
  }

  .family-tree-viewport {
    max-height: none;
    padding: 1rem;
  }

  .family-tree-root {
    justify-content: flex-start;
  }

  .family-tree-root,
  .family-branch-children {
    flex-wrap: nowrap;
  }

  .family-tree-viewport {
    overflow-x: auto;
    overflow-y: auto;
  }
}
