/* Build 739: keep the full Create Memory sheet tucked directly beneath the
   shared MyMappi wordmark without allowing the sheet to cover it. */
html body .app-shell .map-stage.memory-editor-active > .topbar,
html body main.app-shell section.map-stage.memory-editor-active > .topbar {
  z-index: 1900 !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: none !important;
}

html body .app-shell .map-stage.memory-editor-active > .topbar > :is(.topbar-left, .topbar-actions),
html body main.app-shell section.map-stage.memory-editor-active > .topbar > :is(.topbar-left, .topbar-actions) {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html body .app-shell .map-stage.memory-editor-active > .topbar > .brand,
html body main.app-shell section.map-stage.memory-editor-active > .topbar > .brand {
  position: relative !important;
  z-index: 1 !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: none !important;
}

/* The editor hides both header rails. Give its wordmark intrinsic width:
   Memory Lane's normal 127px badge rules exclude this state, while the old
   editor heading could still inherit a larger font and spill out on iPad. */
html body main.app-shell section.map-stage.memory-editor-active:is(.home-focus, .map-focus, .memories-focus) header#appTopbar.topbar {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
}
html body main.app-shell section.map-stage.memory-editor-active #appTopbar > #brandHomeButton {
  display: inline-flex !important;
  grid-column: 2 !important;
  justify-self: center !important;
  align-items: center !important;
  justify-content: center !important;
  width: max-content !important;
  min-width: 0 !important;
  max-width: calc(100vw - 32px) !important;
  margin: 0 !important;
  padding-inline: 14px !important;
  inset: auto !important;
  transform: none !important;
}
html body main.app-shell section.map-stage.memory-editor-active #appTopbar #brandHomeButton h1 {
  width: max-content !important;
  max-width: none !important;
  margin: 0 !important;
  font-family: var(--mymappi-brand-font) !important;
  font-size: clamp(22px, 2.4vw, 28px) !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

@media (max-width: 720px) {
  html body .app-shell .map-stage.memory-editor-active > .memory-editor.open,
  html body main.app-shell section.map-stage.memory-editor-active > .memory-editor.open,
  html body.keyboard-open .app-shell .map-stage.memory-editor-active > .memory-editor.open,
  html body.keyboard-open main.app-shell section.map-stage.memory-editor-active > .memory-editor.open {
    position: fixed !important;
    /* The phone wordmark is about 46px tall. A 48px lane leaves a deliberate
       2px seam, matching the tucked desktop relationship without overlap. */
    top: calc(env(safe-area-inset-top, 0px) + 48px) !important;
    right: max(8px, env(safe-area-inset-right, 0px)) !important;
    bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
    left: max(8px, env(safe-area-inset-left, 0px)) !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    z-index: 1800 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Existing-memory edits are a focused task. Let the editor surface own the
     safe areas so Memory Lane or the map never peeks through above or below. */
  html body .app-shell .map-stage.memory-editor-active > #memoryForm.memory-editor.open.is-editing-memory,
  html body main.app-shell section.map-stage.memory-editor-active > #memoryForm.memory-editor.open.is-editing-memory,
  html body.keyboard-open .app-shell .map-stage.memory-editor-active > #memoryForm.memory-editor.open.is-editing-memory,
  html body.keyboard-open main.app-shell section.map-stage.memory-editor-active > #memoryForm.memory-editor.open.is-editing-memory {
    inset: 0 !important;
    box-sizing: border-box !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    padding-top: calc(env(safe-area-inset-top, 0px) + 66px) !important;
    padding-right: max(18px, env(safe-area-inset-right, 0px)) !important;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)) !important;
    padding-left: max(18px, env(safe-area-inset-left, 0px)) !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overscroll-behavior: contain !important;
  }
}

@media (min-width: 721px) {
  html body .app-shell .map-stage.memory-editor-active > .memory-editor.open,
  html body main.app-shell section.map-stage.memory-editor-active > .memory-editor.open,
  html body.keyboard-open .app-shell .map-stage.memory-editor-active > .memory-editor.open,
  html body.keyboard-open main.app-shell section.map-stage.memory-editor-active > .memory-editor.open {
    position: fixed !important;
    top: calc(env(safe-area-inset-top, 0px) + 68px) !important;
    right: auto !important;
    bottom: max(24px, env(safe-area-inset-bottom, 0px)) !important;
    left: 50% !important;
    box-sizing: border-box !important;
    width: min(680px, calc(100vw - 48px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))) !important;
    min-width: 0 !important;
    max-width: calc(100vw - 48px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    z-index: 1800 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    transform: translate3d(-50%, 0, 0) !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* An existing memory is a long-form editing task. Its introduction belongs to
   the document flow, not a full-height sticky sheet that covers later fields. */
html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header {
  position: relative !important;
  top: auto !important;
  z-index: auto !important;
  box-sizing: border-box !important;
  width: min(100%, var(--memory-form-content, 680px)) !important;
  min-height: 0 !important;
  max-width: none !important;
  margin: 0 auto 14px !important;
  padding: 10px 58px 16px 4px !important;
  border: 0 !important;
  border-bottom: 1px solid #d2e5e6 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  text-align: left !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header > div {
  min-width: 0;
  justify-items: start !important;
}

html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header #editorMode {
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  color: #287970 !important;
  font-size: 10px !important;
  letter-spacing: .14em !important;
}

html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header #editorTitle {
  margin: 4px 0 0 !important;
  font-size: clamp(23px, 3vw, 29px) !important;
  line-height: 1.15 !important;
  text-align: left !important;
}

html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header .editor-promise {
  display: none !important;
}

html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header #closeEditor {
  top: 8px !important;
  right: 0 !important;
}

/* Only the discreet exit affordance remains when the introduction has gone.
   It sits outside the scroll container so no field or media card is trapped
   beneath a repeated title. The app reveals it when the first X scrolls away. */
html body main.app-shell section.map-stage #closeEditorWhileScrolling[hidden] {
  display: none !important;
}

html body main.app-shell section.map-stage #editorEditTopRail[hidden] {
  display: none !important;
}

html body main.app-shell section.map-stage #closeEditorWhileScrolling {
  top: calc(env(safe-area-inset-top, 0px) + 70px) !important;
}

html body main.app-shell section.map-stage.memory-editor-active #closeEditorWhileScrolling:not([hidden]) {
  position: fixed !important;
  right: max(20px, calc(env(safe-area-inset-right, 0px) + 20px)) !important;
  z-index: 1850 !important;
  display: grid !important;
  place-items: center !important;
  box-sizing: border-box !important;
  width: 46px !important;
  height: 46px !important;
  min-width: 46px !important;
  min-height: 46px !important;
  padding: 0 !important;
  border: 1px solid #c6dce1 !important;
  border-radius: 50% !important;
  background: #f8fcfb !important;
  color: #00243f !important;
  box-shadow: 0 8px 24px rgba(0, 36, 63, .14) !important;
  cursor: pointer;
}

html body main.app-shell section.map-stage #closeEditorWhileScrolling:not([hidden]):focus-visible {
  outline: 3px solid #137b78 !important;
  outline-offset: 3px !important;
}

html body main.app-shell section.map-stage #closeEditorWhileScrolling:not([hidden]) svg {
  width: 20px;
  height: 20px;
}

@media (max-width: 720px) {
  /* The whole phone form begins below its own quiet brand/exit lane. A fixed X
     can then never cover a category picker, photo, or save control mid-scroll. */
  html body main.app-shell section.map-stage.memory-editor-active > #memoryForm#memoryForm.memory-editor.open.is-editing-memory {
    top: calc(env(safe-area-inset-top, 0px) + 60px) !important;
    height: calc(100dvh - env(safe-area-inset-top, 0px) - 60px) !important;
    min-height: 0 !important;
    padding-top: 14px !important;
  }

  html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header {
    padding-right: 4px !important;
  }

  html body main.app-shell section.map-stage #memoryForm#memoryForm.is-editing-memory > .editor-header #closeEditor {
    display: none !important;
  }

  html body main.app-shell section.map-stage.memory-editor-active #editorEditTopRail:not([hidden]) {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: 0 !important;
    z-index: 1825 !important;
    display: block !important;
    height: calc(env(safe-area-inset-top, 0px) + 60px) !important;
    border-bottom: 1px solid #d2e5e6 !important;
    background: linear-gradient(145deg, #f0f8fb, #f3faf5) !important;
    pointer-events: none !important;
  }

  html body main.app-shell section.map-stage #editorEditTopRail > span {
    position: absolute;
    bottom: 19px;
    left: max(20px, calc(env(safe-area-inset-left, 0px) + 20px));
    color: #3b6670;
    font-size: 13px;
    font-weight: 750;
    letter-spacing: .02em;
  }

  html body main.app-shell section.map-stage #closeEditorWhileScrolling,
  html body main.app-shell section.map-stage.memory-editor-active #closeEditorWhileScrolling:not([hidden]) {
    top: calc(env(safe-area-inset-top, 0px) + 7px) !important;
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 16px)) !important;
  }
}

@media (min-width: 721px) {
  html body main.app-shell section.map-stage #closeEditorWhileScrolling {
    top: calc(env(safe-area-inset-top, 0px) + 82px) !important;
  }

  html body main.app-shell section.map-stage.memory-editor-active #closeEditorWhileScrolling:not([hidden]) {
    right: max(42px, calc((100vw - 680px) / 2 + 18px)) !important;
  }
}
